I can think of a real problem with your approach however: in languages with a main function you usually can't have top level statements, only declarations. So in C if you write at the top level `while (1) { printf("Hi\n"); }` you get a compilation error. Now as compilers get smarter you can get constexprs in some languages but it's still very specific and entirely static. I guess you could also mention global constructors, but that generally comes with severe caveats and should be used very carefully.
Python on the other hand treats top level code like anything else. That's why the `if __name__ == "__main__"` pattern even works in the first place. Having a real-looking main function would send the wrong message IMO, because it would make people that it's the real entry point of the program which it's not, in Python the entry point is the first line of the file being executed, end of story.
I do think that Python would benefit having a clearer and more explicitly named helper function or variable for this use case however, something like "if this_file_is_executed()" or something like that. At least this way you'd know what the code is doing instead of this awkward anti-pattern being used these days. But of course by now it's probably not worth changing.
It's a good technique prior to introducing formal unit testing (and even then, supplemental ad hoc has advantages).
2) This is not a hurdle to hello world.
print("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.
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
If “main” has to be a special function, it must keep the dunder.
I wouldn't really say that it's a hurdle to greeting the world since you can just throw `print("Hello world")` at the top level.
Here, name is the name of the module. When the module is run by itself, this is the same as __main__, in which case I want the things specified by the if to run right away. This could be calling a main function, but a lot of times it's just is some tests or examples.
When the module is imported into another file, it's name is not the same as __main__. In this case I usually only want things in it to do stuff when they are called by the other file.
This doesn't have anything to do with a function literally called "main" though.
if __name__ == "__main__":
main()
Is a common idiom, but there's no connection between the two uses of the word main.