5

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

ergosys
  • 47,835
  • 5
  • 49
  • 70
  • 1
    Pretty self explanatory. What are the origins of "GoTo" or "Return"? Nothing, they just do what they say. – NibblyPig Apr 21 '10 at 17:43
  • @SLC - I agree 'main' is a good label for the entry point of a program, but that doesn't explain its origins. –  Apr 21 '10 at 17:46
  • @SLC: I disagree. Return is a verb that doesn't really have alternatives (yield maybe?). Goto is IMHO a surprising break with the traditional "Jump". Main is one of many possible nouns that could have been chosen. – Uri Apr 21 '10 at 17:47
  • 1
    @Uri it's BASIC, it's a language for beginners that is supposed to be syntacically like English, so GoTo is logical. The originals of Main are that someone sat down and went, we need a name for the first method, it's the main method of the program, so let's call it main. Not rocket science is it? This question is not useful. – NibblyPig Apr 21 '10 at 17:55
  • @SLC - where did you get BASIC from? Your comment and the original question aren't even related. – KevinDTimm Apr 21 '10 at 17:58
  • @SLC: I'm not sure why Goto is more logical than Jump. Most assembly languages called it Jump, which in some ways is a clearer concept. – Uri Apr 21 '10 at 18:02
  • @Uri - correct, typically assembly's use jump, whereas goto is a 'high level' language concept – KevinDTimm Apr 21 '10 at 18:05
  • @uri @kevin: Jump or branch is typical in assembly. – Toad Apr 21 '10 at 18:14
  • @reinier - but not goto - and, who said anything about branch ;) – KevinDTimm Apr 21 '10 at 19:30
  • Assemblers often used the word branch instead of jump, especially in the company that invented a language where a main program was called a main program. – Windows programmer Apr 22 '10 at 04:18

4 Answers4

4

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
  • 198,648
  • 61
  • 360
  • 533
1

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
  • 998
  • 10
  • 22
1

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
  • 7,871
  • 1
  • 22
  • 23
0

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
  • 88,451
  • 51
  • 221
  • 321
  • 1
    B (the predecessor to C) used main - see http://cm.bell-labs.com/cm/cs/who/dmr/btut.html – KevinDTimm Apr 21 '10 at 17:46
  • @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 Apr 21 '10 at 17:49
  • @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 Apr 21 '10 at 17:53
  • 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 Apr 22 '10 at 04:40
  • @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 Apr 22 '10 at 13:19
  • @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 Apr 23 '10 at 00:55