3 · 15 lessons

Clean code in Python

Names, small functions, guard clauses, value objects and clear errors: refactor working code so others can read and change it.

Progress and your code are kept in this browser only.

  1. 1Names that say what they mean
  2. 2Small functions with one job
  3. 3One level of abstraction
  4. 4Guard clauses and early return
  5. 5Replacing flag arguments
  6. 6Constants and enums
  7. 7Comments versus clear code
  8. 8Duplication and when to remove it
  9. 9From primitives to value objects
  10. 10Prefer immutable values
  11. 11Pure functions, effects at the edges
  12. 12Exceptions instead of error codes
  13. 13One reason to change
  14. 14Open for extension
  15. 15Type hints as documentation