The Zen of Python-How to write beautiful Python code

The Zen of Python-How to write beautiful Python code

Writing clean and beautiful code is really impressive and very advantageous. Writing code with clarity acts as a strong foundation for your code and improves your relationship with the code readers. While programming the first mistake is that you forget that you have to read the code again. Developing habits to write elegant codes is important and a principle called The Zen of Python to discuss the various principles for writing beautiful codes.
The Zen of Python-How to write beautiful Python code
The Zen of Python is a collection of 19 programming principles for writing beautiful and clean python codes. In 1999 Software Engineer Tim Peters first wrote this collection and posted it in the python mailing list. He left the 20th position to filled in by others. Technically he wrote " for Guido to fill in " at the 20th position referring to the great python developer also the author of the famous book Python Programming Language Guido Van Rossum. This collection is also included in the Python Enhancement Proposal (PEP) at number 20. It is also included in python interpreter which you can access by:
import this

The principles in that collections are:

  • Beautiful is better than Ugly
  • Explicit is better than Implicit.
  • Simple is better than Complex.
  • Complex is better than Complicated.
  • Flat is better than Nested.
  • Sparse is better than Dense.
  • Readability Counts.
  • Special cases are not special enough to break the rules.
  • Although practicality beats purity.
  • Error should never pass silently.
  • Unless explicitly silenced.
  • In the face of ambiguity, refuse the temptation to guess.
  • Ther should be one-- and preferably only one --obvious way to do it.
  • Although that way may not be obvious at first unless you are Dutch.
  • Now is better than never.
  • Although never is better than *right * now.
  • If the implementation is hard to explain it is a bad idea.
  • If the implementation is easy to explain it may be a good idea.
  • Namespaces are one honking idea --let's do more of those!



Post a Comment

Previous Post Next Post