Where does the “main” function in programing languages came from?
Where does the “main” function in programing languages came from?
This article explores where does the main
concept came from, and why is it needed.
Programing language like C, C++, Java, etc
has the concept of a main
function, where it is the starting point of program execution.
Languages Without Main
Scripting languages sans main:
- JavaScript
- Ruby
- Python
- Perl
- PHP
- Lua
- Bash
- PowerShell
- Common
- Lisp (Scheme Lisp, Racket Lisp, Emacs Lisp)
- WolframLang
- Smalltalk
- Self
Compiled languages sans main
- FORTRAN
- Swift
- Ocaml
- Scala
- Clojure
- Dart
Preliminary Explanation
Here's some preliminary explanation on history of the main
concept or why it is there.
Where did C lang's main came from?
Here's a sketch of history of where did C get its main
.
- [Why do programming languages have a main() function? By Alexwlchan. At https://alexwlchan.net/2020/why-do-programming-languages-have-a-main-function/ ]
- ok.
main
, came from the abomination of C (1972). and its daddy B (1969). - and the concept may came from BCPL (1967), which uses
start()
. - the main(), seems, do not exist before that. e.g. not in fortran (1957), lisp (1960). A decade earlier than the C virus.
Is main good idea?
- So concludes xah view. Another huge damage from the c unix gang.
- Do compiler need it? Not really.
- Does it make the progamer easier to read for human? Not really.
- It's just a abomination of c.
- it seems, the purpose of main block, is just to make writing compiler easier.
- designed for the benefit of the machine, as opposed to the programer.
- here, it forces u, to learn another extraneous idea. that, there is something special about the name
main
.
The real reason main is invented
- ok. i think i get the idea why c and usually compiled lang has main.
- basically, in the early days of computing, at least electronic computers, the idea of a programing language, is not like, english language, where u read from begin to end to understand it.
- rather, a file containing programing lang code, is meant, to be compiled, into diff components, for the hardware to run.
- specifically, your source code file, is not a “script” as in the natural language sense of the word.
- it is not meant, to be run from top to bottom. but, code such that, meant to be transformed into assembly lang or machine lang, which are not, one single file of sequential meaning.
- the first few paragraphs of the wp linker article makes it clear
- u see, they talk about object files, and refer to each other as symbols, and addresses.
- so, to run a program, the program in the end is bunch of machine code in disparate parts in the hardware.
- this is how things are , actually, in the era of electronic computers, or so i think.
- now, this is opposed to, modern times, or earlier times. for example, in modern times, we think of a python script, or ruby, bash, js, as something like a natural language, we read it from top to bottom. The meaning of the code is accumlated sequentially in order, like english.
- from a high level of view, a language, not for human but for computers, is like this. similar to human langs.
- and this is indeed so, for most high level langs, or scripting langs eg python ruby bash pwsh, or functional langs eg lisp wolfram, or math langs eg apl matlab.
- or, in more primitive times, eg punch cards, or hand written instructions on how to solve math problems, algorithems r written in a script, to be executed from top to bottom in order.
- but in the electronic computer era, eg the times of c, it created this... aberration, due to the concept of 'compilation'.
- in this scheme, u do not start by writing a program of step by step instructions of an algorithm. instead, u need to setup the machine hardware, so each component needs to contain certain code. and in order to do that easily, u created the concept of c, that 'compiles', into these diff 'objects', to be placed in diff places in the hardware.
- so, the source code of c, is not really, meant to be sequential spec of something. rather more like, a bunch of modules. as georrg said.
Programing Language Design
- Ontology of Programing Languages
- A Class of Programing Languages: Math Languages
- Why I Hate Exceptions
- Iterator, Enumerator, Abstraction Went Wrong
- Should Array Index Start at 0 or 1?
- Where does the “main” function in programing languages came from?
- Syntactic Semantic Difference of Map
- Should Map f Specify Order?
- Abuse of Logic Operators (Short-Circuit) as Control Flow
- Programing Language Idiocy: Bit Operators
- Hack of Bitmask as Boolean Parameters
- Function Dependency
- The Complexity of Java Access Specifiers