Talk Python To Me

#404: Clean Code in Python

39 snips
Feb 20, 2023
Ask episode
AI Snips
Chapters
Transcript
Episode notes
ADVICE

Avoid Magic Numbers

  • Replace magic numbers with named constants using uppercase and underscores (PEP 8).
  • Group constants in a constants.py file or use enums.
ADVICE

Typing.final

  • Leverage typing.final for constants to enforce immutability with type checkers.
  • This helps prevent accidental modification, unlike regular constants.
ADVICE

Sentinel and Null Object Patterns

  • Use sentinel values for unset or special number cases instead of arbitrary integers.
  • Consider the Null Object pattern for default no-op behavior.
Get the Snipd Podcast app to discover more snips from this episode
Get the app