Why is it standard in Python to have the main()
function and the if __name__ == '__main__'
check at the end of the block of code? It also seems standard for the abstraction of the functions to follow the same pattern upwards. What I mean is that the definition of the function to be executed by main()
is above the main()
and the definition of the functions inside that are above and so on..
That seems odd because when one opens the module to read the code, it ends up starting with low-level code and moves up to higher level functions. Isn't it hard to grasp what the module is doing that way?
Why not do the alternative? Have the if __name__
check at the top followed by the main()
function, and so on. This way, one quickly glances at what the main()
function does and understands what the code is about.
main()
before it is defined. Andmain
cannot call other functions before they are defined.