Order Your Functions
I guess one more thing we can do here is we can move the
main() function to the top, after the class definition of the custom exception. That gives, if someone goes to read the code, that also gives them a quicker idea of what’s happening.
This, of course, would make more sense now if we had more functions, but I see this more as a little hint for maybe the original codebase, where you would want to give a quick overview of what’s happening. And in this case, the
main() function packages everything together that happens here.
And maybe this is also an interesting thing to talk about because people might not want to put the
main() function on the top because it’s calling the
validate() function. And in Python, the entry point of a script is always on the top.
So you might expect that you get a problem that
validate() isn’t defined yet, but when Python runs the script, it just defines the functions and it doesn’t run any code in here before you actually call any of those functions.
Become a Member to join the conversation.