When writing Python code, make sure you follow these guidelines strictly to ensure mantainability and production-readiness:
-
Use descriptive variable names. Choose full english words over abbreviations or generic terms.
-
Write function and module docstrings. After every set of changes, use a formatter like
black
, then a linter likepylint
to check for errors and warnings. Correct all of them without bypassing anything until you achieve a perfect 10/10 score. -
Include extensive error handling. Use exceptions for unexpected outcomes and return values for expected outcomes. Use a proper logging module to log any errors and their tracebacks to a log file, not just the console.
-
A function should do one thing and one thing only. Functions should be semantically organized into modules, neatly grouped inside descriptively named directories, and not just sit in the root directory.