Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

The Zen of Python

6,133 views

Published on

A summary of Python's philosophy for the Barcelona Python Meetup.

Published in: Technology

The Zen of Python

  1. 1. The Zen of Python A summary of Python's philosophy David Arcos - @DZPM Barcelona Python Meetup #pybcn
  2. 2. PEP 20 – The Zen of Python http://legacy.python.org/dev/peps/pep-0020/ >>> import this
  3. 3. The Zen of Python Beautiful is better than ugly. Write for humans. Be consistent. Explicit is better than implicit. Be clear. Simple is better than complex. KISS. 'print' statement. Memory management, garbage collector. Complex is better than complicated. Manage complexity. 'Import' existing libraries.
  4. 4. The Zen of Python Flat is better than nested. Coding style. Modularity instead of nesting 'if'. Sparse is better than dense. Loose coupling. Separate modules. 'UNIX' philosophy. Readability counts. Whitespace, no brackets. Doc. Again, for humans. Special cases aren't special enough to break the rules. Everything is an object.
  5. 5. The Zen of Python Although practicality beats purity. When needed, break the rules. Errors should never pass silently. Throw Exceptions. Unless explicitly silenced. Catch exceptions. Use tracebacks, logging, etc. In the face of ambiguity, refuse the temptation to guess. 'a' + 1
  6. 6. The Zen of Python There should be one-- and preferably only one --obvious way to do it. DRY. Don't reinvent the wheel. Use existing libraries. Although that way may not be obvious at first unless you're Dutch. BDFL Guido van Rossum is Dutch. 'Redundant' projects. Now is better than never. 'Perfect is the enemy of good'. Python 3. Although never is often better than *right* now. Some PEPs are rejected.
  7. 7. The Zen of Python If the implementation is hard to explain, it's a bad idea. 'If you can't explain it simply, you don't understand it well enough' If the implementation is easy to explain, it may be a good idea. Simplicity Namespaces are one honking great idea -- let's do more of those! 'from foo import bar' instead of 'from foo import *'
  8. 8. Questions? 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 aren't special enough to break the rules. Although practicality beats purity. Errors should never pass silently. In the face of ambiguity, refuse the temptation to guess. There should be one-- and preferably only one --obvious way to do it. Although that way may not be obvious at first unless you're Dutch. Now is better than never. Although never is often better than *right* now. If the implementation is hard to explain, it's a bad idea. If the implementation is easy to explain, it may be a good idea. Namespaces are one honking great idea -- let's do more of those!

×