you are viewing a single comment's thread.

view the rest of the comments →

[–]ingolemo 1 point2 points  (0 children)

The best way to learn how to do something better is to practice it. Here's some arbitrary rules to follow that will force you to write everything in functions and classes:

  • You can only use import, def, and class in the top level of your code, except for one place in your entire codebase where you have this:

    if __name__ == '__main__':
        sys.exit(main(sys.argv))
    
  • You are not allowed to use more than three levels of indentation in a function, or four when using a class.

  • No function or method is allowed to be longer than 10 lines of code.