views:

464

answers:

15

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?

+1  A: 

I 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.

Brian
It actually automatically names it 'Program' if it's a console appy.
Kev
A: 

XApplication, where X is a descriptive name of the program.

driAn
+1  A: 

In Objective-C Cocoa, main() is the C function itself. It sends a message to the NSApplication object which represents the running application.

mouviciel
Can you explain some more for us folks that aren't familiar with Obj-C Cocoa? Are you saying there is not an initial class that is used?
Joe Philllips
@d03boy: Bingo. Same for C++. Not all OO languages are as obsessive about forcing everything into object classes as Java/C# (and C# is becoming less so).
Shog9
Obj-C is a superset of C. Everything which is OK in C is also OK in Obj-C, including the way main() is used.
mouviciel
+8  A: 

Visual Studio creates "Program.cs" these days, which seems pretty reasonable. Another self-documenting name I rather like is "EntryPoint".

Jon Skeet
Oooh, I like "EntryPoint". "Program" just seems ambiguous to me, outside of knowing that Visual Studio uses the name by default.
Daniel Schaffer
I like EntryPoint -- very clear
Joe Philllips
Yup EntryPoint was what I always used in the days before Visual Studio started defaulting to Program. Still prefer EntryPoint though.
Sam Meldrum
+1 for Program.cs - keep it default for the sake of people that have to maintain your code later.
Jon Tackabury
@Kev: I'm afraid your comment still leaves me none the wiser as to why my answer apparently deserves a downvote. For being obvious? I don't see that as a barrier to "goodness". Ah well.
Jon Skeet
@Jon - Sorry Jon...I should have a big yellow sticky on the PC reminding me that Stackoverflow and a bottle and a half of Chilean red don't mix. I'm sure I had a point but it got lost in the mists of inebriation at 2am.
Kev
@Kev: Not to worry. If you think of it again, please add it :)
Jon Skeet
A: 

I think use the default name of the language would be a good idea...others will know that there is the main()

Rulas
+1  A: 

I prefer ConsoleStub.cs for console applications and Core.cs for other

abatishchev
I usually call it Core too. I also give my classes abstract names, though, that have nothing to do with its actual function (unless necessary).
BBetances
A: 

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
    {
        ...
    }
}
Michael Buen
I'm not sure if it's just me, but FootwearRemotingStubProject does not sound very descriptive to me even though it has a lot of words. I'm not sure why.
Joe Philllips
I somehow concur, it's just an interim approach for me to name Remoting code-partners(DLL + EXE[runs on Mono]). Also, it helps me not to think too hard how to name my class differently from the namespace that contains it.
Michael Buen
A: 

I like "StartUp"

dotjoe
+2  A: 

I use either Main or Main

willcodejavaforfood
But not Main, right?
Joe Philllips
+1  A: 

Program seems to be the standard. Works for me :D

Diones
+2  A: 

"Launcher"

Krougan
A: 

VB.NET:

Public Module Main
Public Sub Main(String args())
End Sub
End Module

Joshua
+1  A: 

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

OscarRyz
I think that would not work in C#, since a static method Main in class Main would be the static constructor :)
OregonGhost
@OregonGost. Really? Is there a difference between "main" and "Main" in C#? additionally, what is an static constructor ? :P
OscarRyz
+1  A: 

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.

Kirk Wylie
A: 

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!'
Jörg W Mittag
Whoever voted this down is wrong. Execute this one-line ruby script: `raise 'snafu'`. You'll see `foo.rb:1:in \`<main>': snafu (RuntimeError)`. The code is already wrapped in a "main" method...
macek
@smotchkiss: Actually, `main` is an *object*, not a method. It's the anonymous global object that all code that is not inside a class, module or method is executed in.
Jörg W Mittag