Re:An exploration of why Python doesn't require a 'main' fun...
by kzrdude on Tuesday July 21, 2020 @12:21PM
(#23908140)
Ad 1,
the current idiom uses dunder name, which is implicitly defined and looks special.
Making main special would be about the same level of a solution, yet more conventional
Re:An exploration of why Python doesn't require a 'main' fun...
by toyg on Tuesday July 21, 2020 @12:34PM
(#23908286)
Dunder methods don’t “look” special, they are. Marking them as such has side-effects, and as soon as you see a dunder, you know you’re going “lower”.
If “main” has to be a special function, it must keep the dunder.
Re:An exploration of why Python doesn't require a 'main' fun...
by hansvm on Tuesday July 21, 2020 @12:34PM
(#23908277)
There's always `__main__.py` if you want something special.
Re:An exploration of why Python doesn't require a 'main' fun...
by jimbob45 on Tuesday July 21, 2020 @12:29PM
(#23908230)
I understand that what you have is a complete program but every new Pythonist is going to next read the documentation that says, “Having a main method is a really good idea” and go try to implement one. Sure, in 1% of cases, you’ll need the granular control over how main is called but since when do languages cater to the 1%?
Re:An exploration of why Python doesn't require a 'main' fun...
by mcintyre1994 on Tuesday July 21, 2020 @12:56PM
(#23908508)
Can't you just put code in `def main` and then have `main()` at the top-level if you don't need to worry about imports? It seems like you can probably get pretty far as a beginner before you need to worry about being able to both import and run the same file.
2) This is not a hurdle to hello world.
is a complete program that does exactly what you want. Needing to wrap it in a function would be an additional hurdle.For complex programs; that is a hurdle well worth jumping. But for simple scripts (python is a scripting language), or teaching purposes, it is not always needed.