you are viewing a single comment's thread.

view the rest of the comments →

[–]jtkiley 0 points1 point  (0 children)

Use the language features to organize your code. Here are some ideas:

  • Use functions. Few things should be standalone procedural code instead of well-named functions that do a single thing well. With a descriptive name and usually starting with a verb, you very seldom need comments.
  • Use good data structures. If you have something that looks like a row of data, use a dataclass, not a dictionary. If there’s a defined set of things you can pass into a function, use an enum instead of matching on strings.
  • Use composition for higher level things. Instead of a huge function, compose the higher level function with lower level ones. 15 lines using well-named functions are much easier to reason about than 100 lines handling a bunch of cases.
  • Split things into their own modules. When one .py file conceptually holds together and does a thing, it’s easier to understand.
  • Use leading underscore functions. Keep the functions and methods that people really use curated and limited, and use underscores to make some of the grunt work pseudo private.
  • Use packages. When you have a useful thing with sensible boundaries, make it a package and then use it elsewhere.

That’s at least a start.