3 ms·
Here's a thing: Coming from a world of Perl, PHP, Ruby, Bash, BASIC, batch etc. scripts, a main function is not neccessary at all. The procedural code just star
by ktpsns 6y ago
Here's a thing: Coming from a world of Perl, PHP, Ruby, Bash, BASIC, batch etc. scripts, a main function is not neccessary at all. The procedural code just starts from the first line.
With this in mind, it is weird to even ask for a main function. :-)
- pantaloony 6y agoMy immediate reaction was “it does—but it’s in the interpreter so of course you don’t have to write it”.
- marcosdumay 6y agoAnd you can perfectly well compile them and keep that same behavior. C's entry point is in the runtime too, it's not your main function (but yeah, the optimizer will probably inline your main). At the end of the day, there's no real difference between compiled and interpreted languages, all the difference is on the toolset.
- benbristow 6y agoEven with those languages, I find a main method is a good idea just for local-scoping of variables compared to the top level variables being 'global' by default.
- munk-a 6y agoPHP is actually my favorite here - since the standard way people use it (behind a webserver) means that old-style PHP had as many entry points as it had files which could get really confusing really quickly. Modern PHP usage will generally concede the point now and pipe all requests through internal routing executed off of a single script exposed to the webserver/whatever.
- mypalmike 6y agoComing from the other direction, random code that executes outside of functions is sloppy. It's harder to reason about and is a regular source of confusion and bugs.