Why "flat is better than nested"?

Lie Ryan lie.1296 at gmail.com
Wed Oct 27 06:52:42 EDT 2010


On 10/26/10 06:56, Steve Holden wrote:
> On 10/25/2010 3:11 PM, kj wrote:
>> In <mailman.232.1288020268.2218.python-list at python.org> Steve Holden <steve at holdenweb.com> writes:
>>
>>> On 10/25/2010 10:47 AM, rantingrick wrote:
>>>> On Oct 25, 5:07 am, kj <no.em... at please.post> wrote:
>>>>> In "The Zen of Python", one of the "maxims" is "flat is better than
>>>>> nested"?  Why?  Can anyone give me a concrete example that illustrates
>>>>> this point?
>>>>
>>>> Simple. This commandment (endowed by the anointed one, GvR) is
>>>> directed directly at lisp and those filthy lispers. If you don't know
>>>> what lisp is then Google it. Then try to program with it for one hour.
>>>> Very soon after your head will explode from the nested bracket plague
>>>> and then you shall be enlightened!
>>>>
>>> And everyone taking the Zen too seriously should remember that it was
>>> written by Tim Peters one night during the commercial breaks between
>>> rounds of wrestling on television. So while it can give useful guidance,
>>> it's nether prescriptive nor a bible ...
>>
>> Well, it's pretty *enshrined*, wouldn't you say?  After all, it is
>> part of the standard distribution, has an easy-to-remember invocation,
>> etc.  *Someone* must have taken it seriously enough to go through
>> all this bother.  If it is as trivial as you suggest (and for all
>> I know you're absolutely right), then let's knock it off its pedestal
>> once and for all, and remove it from the standard distribution.
>>
> I don't know who decided to put the "this" module into Python as an
> Easter egg. But don't think you can suppress it now. Trying to do so
> would only bring out people's inherent religious fervor and cause an
> outcry you would regret.

Now you know who to blame (assuming mercurial log is not lying:)

$ hg blame this.py
21335: s = """Gur Mra bs Clguba, ol Gvz Crgref
21337:
21335: Ornhgvshy vf orggre guna htyl.
21335: Rkcyvpvg vf orggre guna vzcyvpvg.
21335: Fvzcyr vf orggre guna pbzcyrk.
21335: Pbzcyrk vf orggre guna pbzcyvpngrq.
21335: Syng vf orggre guna arfgrq.
21335: Fcnefr vf orggre guna qrafr.
21335: Ernqnovyvgl pbhagf.
21335: Fcrpvny pnfrf nera'g fcrpvny rabhtu gb oernx gur ehyrf.
21335: Nygubhtu cenpgvpnyvgl orngf chevgl.
21335: Reebef fubhyq arire cnff fvyragyl.
21335: Hayrff rkcyvpvgyl fvyraprq.
21335: Va gur snpr bs nzovthvgl, ershfr gur grzcgngvba gb thrff.
21335: Gurer fubhyq or bar-- naq cersrenoyl bayl bar --boivbhf jnl gb qb vg.
21335: Nygubhtu gung jnl znl abg or boivbhf ng svefg hayrff lbh'er Qhgpu.
21335: Abj vf orggre guna arire.
21335: Nygubhtu arire vf bsgra orggre guna *evtug* abj.
21335: Vs gur vzcyrzragngvba vf uneq gb rkcynva, vg'f n onq vqrn.
21335: Vs gur vzcyrzragngvba vf rnfl gb rkcynva, vg znl or n tbbq vqrn.
21335: Anzrfcnprf ner bar ubaxvat terng vqrn -- yrg'f qb zber bs gubfr!"""
21337:
29075: d = {}
29075: for c in (65, 97):
29075:     for i in range(26):
29075:         d[chr(i+c)] = chr((i+13) % 26 + c)
29075:
29075: print "".join([d.get(c, c) for c in s])

$ hg log -r 21335 this.py
changeset:   21335:56190cb9ccb6
branch:      trunk
user:        fdrake
date:        Fri Feb 08 21:13:47 2002 +0100
summary:     [svn r25249] Python 10 was a success, commemorate it\!



More information about the Python-list mailing list