The python, the egg, and the back-tick

This seems like a fun place to start posting my musings on software. One thing I like to show people who are learning the craft is an easter egg built in to Python.

When the egg hatches, it prints out a little poem of style rules to follow in your code:

The Zen of Python, by Tim Peters


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.
Unless explicitly silenced.
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!


Honestly, I don't understand the difference between complex and complicated. My favorite lately has been explicit over implicit. I think understanding code that explicitly assumes context, business rules, object types provides easier comprehension a year later. Implicit may use less characters on the screen, and it certainly has its place, but production code should allow new readers to digest it easily. As a digestion metaphor, its kind of like how recipes tell you to soak beans before cooking them, rather than presuming everyone knows to get out the hose.

To find the egg, open a python shell and run `import this` without backticks. Or as a one liner, at the terminal run `python -c "import this"`


-dmann

ps backticks is a pretty gross sounding thing

To view or add a comment, sign in

More articles by David Mann

  • come get sum

    Mathematics consists in proving the most obvious thing in the least obvious way. — George Polya Too Long, Didn't Read…

  • MS in CS: amortization and off-by-ones

    Hi Remember games like hide-and-seek where the seeker counts out loud for some number of seconds? The way I learned to…

    2 Comments

Explore content categories