DEV Community

Cover image for The Zen Of Python Is A Joke And Here Is Why (You Should Not Take It Too Seriously)
Abdur-Rahmaan Janhangeer
Abdur-Rahmaan Janhangeer

Posted on • Updated on

The Zen Of Python Is A Joke And Here Is Why (You Should Not Take It Too Seriously)

The Zen of Python inspires programmers all over the world, but, it is not to be taken too literally.

The Venerable Zen, A Presentation

typing this

import this

gives us

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!

that is called the Zen of python

The One Line That Is A Hilariously Good Joke

let us take a look at the following line.

There should be one-- and preferably only one --obvious way to do it.

most developers understand it to mean that python makes you write your code in one way, instead of having many ways to express it. many then go on to contrast the linguist-invented perl with the mathematician-invented python.

however, there are two catch with this line

  • should there be or should there preferably be
  • the --

so, should there be one way meaning, is it obligatory to have one way or is it recommended to have one way? is it compulsory or just recommended?

the line does not leave us to guesses, it actually showed it with the --.

to preserve consistency, it should have been either

There should be one-- and preferably only one-- obvious way to do it.

or

There should be one --and preferably only one --obvious way to do it.

but it is both

There should be one-- and preferably only one --obvious way to do it.

As David Goodger mentionned, see the last line:

Namespaces are one honking great idea -- let's do more of those!

Another way of using!

Saying Hi To The Import Itself

Let us take this line

Explicit is better than implicit.

but we import by

import this

oxforddictionaries.com defines explicit as

Stated clearly and in detail, leaving no room for confusion or doubt.

and implicit as

Suggested though not directly expressed.

so, was the name and way of printing explicit or implicit?

What The File Tell Us

here is the zen module source code in py3.7

s = """Gur Mra bs Clguba, ol Gvz Crgref

Ornhgvshy vf orggre guna htyl.
Rkcyvpvg vf orggre guna vzcyvpvg.
Fvzcyr vf orggre guna pbzcyrk.
Pbzcyrk vf orggre guna pbzcyvpngrq.
Syng vf orggre guna arfgrq.
Fcnefr vf orggre guna qrafr.
Ernqnovyvgl pbhagf.
Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
Nygubhtu cenpgvpnyvgl orngf chevgl.
Reebef fubhyq arire cnff fvyragyl.
Hayrff rkcyvpvgyl fvyraprq.
Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
Abj vf orggre guna arire.
Nygubhtu arire vf bsgra orggre guna *evtug* abj.
Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""

d = {}
for c in (65, 97):
    for i in range(26):
        d[chr(i+c)] = chr((i+13) % 26 + c)

print("".join([d.get(c, c) for c in s]))

and yet, in the zen we see

Readability counts.

very readable ...

But Wait, There Are Exceptions

well, you are right, there are exceptions. yes maybe the zen file is an exception to the zen but wait ... the zen tells us

Special cases aren't special enough to break the rules.

ok then ... guess we've got the message

Conclusion

the concluding words are the title of this article. pay attention to the word too .

Top comments (3)

Collapse
 
ladydascalie profile image
Benjamin Cable

very readable ...

That's the joke

Collapse
 
billbezos profile image
William Bezos

i appreciate this about the python core. we're all adults.

Collapse
 
itr13 profile image
Mikael Klages

Mu