Why "flat is better than nested"?

Steven D'Aprano steve-REMOVE-THIS at cybersource.com.au
Thu Oct 28 07:02:35 CEST 2010


On Tue, 26 Oct 2010 08:02:19 +1100, Ben Finney wrote:

> Steve Holden <steve at holdenweb.com> writes:
> 
>> 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 ...
> 
> Even to those who don't know or don't remember its history, the Zen has
> an excellent reminder of just how seriously it should be taken:
> 
> Load the source code for the ‘this’ module into a text editor, and see
> how many of the maxims it violates.

None of them. It's a straightforward implementation of rot13, but written 
as a one-off script rather than a re-usable function. That's okay -- not 
everything has to be re-usable.

The worst sin of this.py is something which is not mentioned in the Zen: 
the use of magic constants rather than named values, and the use of ints 
instead of characters. But as sins go, they're venal rather than mortal 
in a module this small, and I interpret this as a deliberate: it's a 
reminder that the Zen is not the last word in programming maxims.



-- 
Steven



More information about the Python-list mailing list