Crafting Pythonic Code: A Manifesto

Firdaus Adib
2 min readJul 28, 2023

The Zen of Python contains 19 software principles that provide guidance on writing idiomatic, aesthetically pleasing Python code. When combined with established clean code practices, these principles form a manifesto for creating Python code that is simple, explicit, and maintainable.

Image by gdtography. Pexels.

Beautiful is Better Than Ugly

Clean code places high value on consistency and aesthetics. Code should be pleasing to read almost like poetry. This means:

  • Consistent indentation, spacing, and formatting per PEP 8.
  • Descriptive names rather than abbreviations or single letters.
  • Preferring clean, obvious code over clever hacks.

Explicit is Better Than Implicit

Clean code leaves no room for guessing — it is obvious in intent and behavior. In Python this means:

  • Avoiding tricky side effects and magic behavior.
  • Using explicit names that match the purpose rather than cryptic names.
  • Explicitly raising errors rather than failing silently.

Less is More

Clean code is minimal and to the point. As the Zen principles state:

  • Simple is better than complex.
  • Readability counts.

This means:

  • Breaking code into small, single-purpose functions.
  • Removing unused code rather than leaving commented out blocks.
  • Splitting large files into logically organized modules.

Consistency Rules

The Zen principles emphasize consistency repeatedly:

  • There should be one — and preferably only one — obvious way to do it.
  • Although practicality beats purity.

For clean Python code, this means:

  • Following PEP 8 and other naming/formatting conventions.
  • Using a single style consistently within a codebase.
  • Preferring explicitness over implicit tricks.

Final Thoughts

The Zen of Python and clean code principles align on emphasizing code that is easy to understand, minimizes complexity, and promotes pleasing aesthetics. Adopting these practices leads to more Pythonic code that is a joy to read, write, and maintain.

The clean code principles I referenced in this post are from the book Clean Code by Robert C. Martin, considered one of the classic texts on writing maintainable and readable code.

Here is the full reference:

Martin, Robert C. Clean Code: A Handbook of Agile Software Craftsmanship. Upper Saddle River, NJ: Prentice Hall, 2008.

The key clean code principles I incorporated from this book included:

  • Use explanatory and intention-revealing names rather than cryptic names.
  • Minimize the use of comments by writing clean self-documenting code.
  • Split code into small single-purpose functions and modules.
  • Replace magic numbers and strings with named constants.

I leveraged these clean coding best practices from Martin’s book and showed how they align with the Zen of Python principles from PEP 20. The concepts of readable, minimal, and explicit code are emphasized by both sources.



Firdaus Adib

Web craft. Rails. Data Science. Biohack. Currently learning iOS.