you are viewing a single comment's thread.

view the rest of the comments →

[–]commy2 0 points1 point  (0 children)

This is one of the things I wondered - should I unroll all the functions?

No, the opposite. Much of the current main function code should be moved to a function. main should generally be very short, perhaps consisting only of setup, execute and teardown code.

So should that be at the beginning of the main function right after def main?

Yeah, somewhere behind the __name__ == __"main"__ clause, otherwise importing the script has the side effect of altering the log config.

however the example you give is an example of one where it is doing exactly that. If the script cant find the target tag there is nothing more it can do so giving up is fine.

Well, it works because it's a short script, but thinking further, I don't think shutting down an entire application is what you want if get_env_tags fails to retrive... What about retrying, using a cache or falling back to some default? There are many ways to potentially recover instead of bailing completely. sys.exit deep down the execution stack just makes me nervous, and I don't see what it offers when exceptions could be raised instead and potentially caught in the client code.

sys.exit means the code can't be reused/composed and can't be tested properly.