For instance in C# or Java, you always have a main() method used to get your program running. What do you name the class that it is in? Some ideas I would use would just be "Program" or the name of the program itself. What would be considered conventional in this case?
views:
464answers:
15I name the main class after the application itself. E.g. a Calculator program might have a "CalculatorProgram" or just a "Calculator" class.
Considering that VS names your main class whatever you name your application, I think this is pretty standard.
In Objective-C Cocoa, main() is the C function itself. It sends a message to the NSApplication object which represents the running application.
Visual Studio creates "Program.cs" these days, which seems pretty reasonable. Another self-documenting name I rather like is "EntryPoint".
I think use the default name of the language would be a good idea...others will know that there is the main()
I prefer ConsoleStub.cs for console applications and Core.cs for other
I think Program is a conventional case. In my case, I'm more somehow bothered to think about the name I should give to namespace especially if it contains only one class. In absence of definitive guidelines for naming of namespace with only one class, I come up with a pattern like this: Stub for abstract classes, Impl for implementation, Project for the name of compiled dll/exe.
example:
FootwearRemotingStubProject.dll:
namespace FootwearRemotingStubProject
{
public class FootwearRemotingStub
{
...
}
}
FootwearRemotingImplProject.exe:
using FootwearRemotingStubProject;
namespace FootwearRemotingImplProject
{
public class FootwearRemotingImpl: FootwearRemotingStub
{
...
}
}
VB.NET:
Public Module Main
Public Sub Main(String args())
End Sub
End Module
Main. The package where it is placed says the rest.
com.finance.calculator.Main
And in the Main I only have:
public static void main( String [] args ) {
FinanceCalculator calc = new FinanceCalculator();
calc.show(); // or start(); or init. or whatever.
}
:S I hope I never have to code a Finance Calculator :S :S
I've always used FooLauncher, because it allows me to encapsulate all the logic about command-line parsing in one class (rather than trying to get it into one method), which also allows better testability. It's also better segregation of concerns: Foo might be something that you use outside the command line, but FooLauncher is there to launch Foo given command-line processing.
This is particularly important in an application that overall has multiple command-line tools available: each one has its own Launcher. Just saying Program makes little sense if your "program" has multiple command-line tools.
I don't put it in a class. In fact, I don't even use a method, just a snippet of code:
#!/usr/bin/env ruby
puts 'Look Ma, no class, no method!'