views:

109

answers:

4

Out of curiosity, what are the origins of the name 'main' for a program entry point?

A: 

My understanding (though I couldn't find a reference to confirm) is that some early languages had a notion of a main procedure (the first might have been Ada), even though you did not have to name it main().

I think that C was the first language to actually use this token as a name. C largely replaced Pascal which didn't have a named start procedure, if I remember correctly.

From there it influenced subsequent languages that were C inspired like C++, Java and C#.

It also influenced culturally languages that do not mandate such a function, like Python.

Uri
B (the predecessor to C) used main - see http://cm.bell-labs.com/cm/cs/who/dmr/btut.html
KevinDTimm
@KevinDTimm: That's a good point. Though my understanding (likely wrong) is that it was more of a local in-house prototype until C.
Uri
@Uri - not a prototype, actually pretty highly used for quite some time. B came from BCPL (which did not contain main). It was Ken Thompson removing everything from BCPL that created B, which then eventually morphed into C (the lineage of B to C is much more apparent than BPCL to B)
KevinDTimm
You think *Ada* was the first with a main procedure as a concept? **Ada**?! What *are* they teaching in schools these days? History is apparently not on the menu....
JUST MY correct OPINION
@ttmrichter: Well, they don't teach Ada, for one. Which is why I said *might*. My knowledge of PL history is somewhat limited, I admit.
Uri
@Uri: http://www.scriptol.com/programming/languages.php Read and learn how little new there is under the Sun. I mean Oracle. (Sorry. Very bad joke that, I know. I am deeply ashamed.)
JUST MY correct OPINION
+1  A: 

I'm pretty sure that it has to do with the fact that it is the 'main' function of the program. Anything more than that is unknown to me.

sphennings
how could anyone have upvoted this answer?
KevinDTimm
It may well be the correct answer. :)
Evgeny
+3  A: 

Before C, there was IBM's PL/I. In PL/I you declared a procedure with options. If you wrote

PROC MUMBLE OPTIONS(MAIN);

that told the compiler that the MUMBLE procedure was the main procedure. PL/I may have adopted this convention from elsewhere, or C may have adopted it from PL/I, or maybe it was just in the air. But it definitely predates C.

(If anyone is wondering why all upper case, the IBM keypunches of the day did not support lower-case characters. Yes, I wrote programs on punched cards. That's probably why I'm a bit shaky on the syntax; it has been a while.)

Norman Ramsey
+1  A: 

In Fortran the main program was the main program even though it didn't have a name. It was distinguished from subroutines and functions by having an executable statement (or other non-commentary statement) without a preceding SUBROUTINE or FUNCTION statement.

When later languages decided they wanted the main routine to start with a beginning line like other procedures or functions, some of them adopted the word MAIN or main in various ways.

As someone else pointed out, Pascal did it differently. Shell scripts and Perl resemble Fortran.

Windows programmer