On Thu, Nov 12, 2020 at 06:33:52PM +0000, Rob Cliffe via Python-ideas wrote:
I find this a curious argument. A bit like saying "Here are your new shoes; they weigh 10Kg but that's absolutely great because you'll develop stronger legs wearing them".
Do you honestly think that writing
if __name__ == '__main__'
is equivalent to a 10kg pair of shoes? If that is the case, then the suggestion to use `if __main__` alone is surely 7kg, and writing a function with `def` is probably 2000 kg.
Fortunately Python coders are mighty, with powerful muscles, who think nothing of lifting thousands of tonnes at a time.
All joking, and bad analogies, aside, I am disturbed at the idea that expecting Python programmers to understand what the code they wrote actually does, and what the code means, is a bad thing.
Sure, there are plenty of people who, due to time constraints, lack of interest, or some other reason, *don't care* why the `if __name__` idiom works or what it does. For them, they can just memorize it as a magic incantation, or copy it from Stackoverflow as required. I have plenty of code like that myself.
But I'm not convinced that we should add a language feature specifically to enable that behaviour, just to save a few characters of typing.
For years, as a beginner, I used to forget the string quotes:
if __name__ == __main__:
Oops! But at least I got a NameError and my mistake was then obvious. With this suggested feature, the code will just silently fail.