Re:An exploration of why Python doesn't require a 'main' fun...
by zelphirkalt on Tuesday July 21, 2020 @12:20PM
(#23908130)
And still I do write a main procedure in Python usually, which is called from that if __name__ == "__main__" thing. It is convenient to leave the top level asap and begin as quickly as possible to use procedures/function, getting out of the area, where one can accidentally change global variables, without noticing (in procedures you would have to write global as a keyword and would hopefully then notice you are doing something possibly dangerous).
[ Parent
| on HN ]
Re:An exploration of why Python doesn't require a 'main' fun...
by quietbritishjim on Tuesday July 21, 2020 @12:46PM
(#23908409)
Absolutely. But on the other hand, it's still very useful that Python does work like this: it's nice to be able to directly do things at the top level (e.g. setting up "constants" with a little computation, conditionally importing modules or importing fallbacks, etc.). As the article says, it's also an extremely clean way of defining what gets run in what order during startup.