Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Why "flat is better than nested"?

Reply
Thread Tools

Why "flat is better than nested"?

 
 
Terry Reedy
Guest
Posts: n/a
 
      10-25-2010
On 10/25/2010 3:11 PM, kj wrote:

> Well, it's pretty *enshrined*, wouldn't you say?


No.

> After all, it is part of the standard distribution,


So is 'import antigravity'

> 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.


If you are being serious, you are being too serious (as in humorless).
The 'Zen of Python' is somewhere between 'trivial' and 'enshrined on a
pedestal'. The two undocumented easter egg imports (visible in
pythonx.y/Lib) are for both fun and edification.

--
Terry Jan Reedy

 
Reply With Quote
 
 
 
 
Steve Holden
Guest
Posts: n/a
 
      10-25-2010
On 10/25/2010 3:11 PM, kj wrote:
> In <(E-Mail Removed)> Steve Holden <(E-Mail Removed)> writes:
>
>> On 10/25/2010 10:47 AM, rantingrick wrote:
>>> On Oct 25, 5:07 am, kj <(E-Mail Removed)> 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.

Besides which I am sure Tim Peters derives a lot of harmless fun from
seeing people take it so seriously.

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

 
Reply With Quote
 
 
 
 
Ethan Furman
Guest
Posts: n/a
 
      10-25-2010
kj wrote:
> In <(E-Mail Removed)> Steve Holden <(E-Mail Removed)> writes:
>
>>> On Oct 25, 5:07 am, kj <(E-Mail Removed)> 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?


Two points on the practical side: most folk only remember a few levels
deep, so shallow is easier to work with*; and, while premature
optimization is usually a waste of time, effort, money, hair, etc., each
level costs another lookup.

>> 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.


The Zen is good humor, and good advice. An excellent reminder to strive
for balance in all things...

~Ethan~

--
* citation needed, I know
 
Reply With Quote
 
Jorgen Grahn
Guest
Posts: n/a
 
      10-26-2010
On Mon, 2010-10-25, http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On 25 oct, 15:34, Alex Willmer <(E-Mail Removed)> wrote:
>> On Oct 25, 11:07*am, kj <(E-Mail Removed)> 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?

>>
>> I take this as a reference to the layout of the Python standard
>> library and other packages i.e. it's better to have a module hierarchy
>> of depth 1 or 2 and many top level items, than a depth of 5+ and only
>> a few top level items.
>>

> (snip)
>
> This also applies to inheritance hierarchies (which tend to be rather
> flat in Python compared to most mainstreams OOPLs), as well as nested
> classes etc.


Which mainstream languages are you thinking of? Java? Because C++ is
as flat as Python.

/Jorgen

--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
 
Reply With Quote
 
Carl Banks
Guest
Posts: n/a
 
      10-26-2010
On Oct 25, 11:20*pm, Jorgen Grahn <(E-Mail Removed)> wrote:
> On Mon, 2010-10-25, (E-Mail Removed) wrote:
> > On 25 oct, 15:34, Alex Willmer <(E-Mail Removed)> wrote:
> >> On Oct 25, 11:07*am, kj <(E-Mail Removed)> 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?

>
> >> I take this as a reference to the layout of the Python standard
> >> library and other packages i.e. it's better to have a module hierarchy
> >> of depth 1 or 2 and many top level items, than a depth of 5+ and only
> >> a few top level items.

>
> > (snip)

>
> > This also applies to inheritance hierarchies (which tend to be rather
> > flat in Python compared to most mainstreams OOPLs), as well as nested
> > classes etc.

>
> Which mainstream languages are you thinking of? *Java? *Because C++ is
> as flat as Python.


Not in my experience. The only way to get dynamic polymorphism (as
opposed to the static polymorphism you get with templates) in C++ is
to use inheritance, so when you have a class library in C++ you tend
to get hierarchies where classes with all kinds of abstract base
classes so that types can be polymorphic. In Python you don't need
abstract base classes so libraries tend to be flatter, only inheriting
when behavior is shared.

However it's not really that big of a difference.


Carl Banks

 
Reply With Quote
 
kj
Guest
Posts: n/a
 
      10-26-2010
In <(E-Mail Removed)> Terry Reedy <(E-Mail Removed)> writes:

>On 10/25/2010 3:11 PM, kj wrote:


>> Well, it's pretty *enshrined*, wouldn't you say?


>No.


> > After all, it is part of the standard distribution,


>So is 'import antigravity'


Are you playing with my feelings?

% python
Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
>>> import antigravity

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named antigravity

Too bad, I was looking forward to that.

> > 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.


>If you are being serious, you are being too serious (as in humorless).


Guilty as charged, both in the "too serious" and the "humorless"
counts. :/ Blame it on the Asperger's.

My only defense is that, while learning Python over the past year,
I've had *many* "you've got to be joking" moments while reading
what's ostensible "serious" Python documents (e.g. PEP 8, PEP 257)
as well as assorted threads featuring GvR and others involved in
the design of Python, to the point that sometimes I do have a hard
time gauging the seriousness of what's considered "good programming"
/ "best practice" in the Python world.

Plus, I think it's fair to say that the Python community as a whole
(or at least its more vocal members) are more concerned with
"correctness" (for lack of a better term) and "code aesthetics"
than, say, the Perl community. E.g., only in Python-related threads
I've seen the adjective "icky" used routinely to indicate that some
code is unacceptable on (more or less) aesthetic grounds.

My point is that, even if one detects some levity in ZoP, given
everything else one runs into in the Python world, for the uninitiated
like me it is still hard to distinguish between what's in jest and
what's in earnest.

Perhaps the disconnect here is that you're seeing the whole thing
from an insider's point of view, while I'm still enough of an
outsider not to share this point of view. (I happen to think that
one the hallmarks of being an initiate to a discipline is an almost
complete loss of any memory of what that discipline looked like
when the person was a complete novice. If this is true, then it's
easy to understand the difference in our perceptions.)

Anyway, thanks for letting me in on the joke. I'll pass it on.

(Though, humorless as it is of me, I still would prefer the ZoP
out of the standard library, to save myself having to tell those
who are even newer to Python than me not to take it seriously.)

~kj
 
Reply With Quote
 
Benjamin Kaplan
Guest
Posts: n/a
 
      10-26-2010
On Tue, Oct 26, 2010 at 9:05 AM, kj <(E-Mail Removed)> wrote:
> In <(E-Mail Removed)> Terry Reedy <(E-Mail Removed)> writes:
>
>>On 10/25/2010 3:11 PM, kj wrote:

>
>>> Well, it's pretty *enshrined*, wouldn't you say?

>
>>No.

>
>> > *After all, it is part of the standard distribution,

>
>>So is 'import antigravity'

>
> Are you playing with my feelings?
>
> % python
> Python 2.6.1 (r261:67515, Feb 11 2010, 00:51:29)
> [GCC 4.2.1 (Apple Inc. build 5646)] on darwin
>>>> import antigravity

> Traceback (most recent call last):
> *File "<stdin>", line 1, in <module>
> ImportError: No module named antigravity
>
> Too bad, I was looking forward to that.
>


Try it in Python 3.

>> > 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.

>
>>If you are being serious, you are being too serious (as in humorless).

>
> Guilty as charged, both in the "too serious" and the "humorless"
> counts. :/ *Blame it on the Asperger's.
>
> My only defense is that, while learning Python over the past year,
> I've had *many* "you've got to be joking" moments while reading
> what's ostensible "serious" Python documents (e.g. PEP 8, PEP 257)
> as well as assorted threads featuring GvR and others involved in
> the design of Python, to the point that sometimes I do have a hard
> time gauging the seriousness of what's considered "good programming"
> / "best practice" in the Python world.
>


This is a programming language named after a British comedy group (not
the snake). There are going to be jokes inserted in lots of otherwise
serious things. Like the standard library.


> http://mail.python.org/mailman/listinfo/python-list
>

 
Reply With Quote
 
Seebs
Guest
Posts: n/a
 
      10-26-2010
On 2010-10-26, kj <(E-Mail Removed)> wrote:
> (Though, humorless as it is of me, I still would prefer the ZoP
> out of the standard library, to save myself having to tell those
> who are even newer to Python than me not to take it seriously.)


Well, not to take it *too* seriously.

It's like any other Zen -- it's wonderful as long as you take it about
the right amount seriously. If someone could tell you how seriously
that is, it wouldn't be Zen.

-s
--
Copyright 2010, all wrongs reversed. Peter Seebach / (E-Mail Removed)
http://www.seebs.net/log/ <-- lawsuits, religion, and funny pictures
http://en.wikipedia.org/wiki/Fair_Game_(Scientology) <-- get educated!
I am not speaking for my employer, although they do rent some of my opinions.
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      10-26-2010
On 10/26/2010 9:05 AM, kj wrote:
> Perhaps the disconnect here is that you're seeing the whole thing
> from an insider's point of view, while I'm still enough of an
> outsider not to share this point of view. (I happen to think that
> one the hallmarks of being an initiate to a discipline is an almost
> complete loss of any memory of what that discipline looked like
> when the person was a complete novice. If this is true, then it's
> easy to understand the difference in our perceptions.)
>

That can be true of most technical communities, and Python is no
exception. As someone who does quite a lot of training the challenge is
always to hold on to those outsider perceptions to avoid the learners
feeling lost.

> Anyway, thanks for letting me in on the joke. I'll pass it on.
>
> (Though, humorless as it is of me, I still would prefer the ZoP
> out of the standard library, to save myself having to tell those
> who are even newer to Python than me not to take it seriously.)


The answer is probably the same as you will see if you try

from __future__ import braces

That feature *is* available in Python 2.6

regards
Steve
--
Steve Holden +1 571 484 6266 +1 800 494 3119
PyCon 2011 Atlanta March 9-17 http://us.pycon.org/
See Python Video! http://python.mirocommunity.org/
Holden Web LLC http://www.holdenweb.com/

 
Reply With Quote
 
Robin Becker
Guest
Posts: n/a
 
      10-26-2010
On 26/10/2010 15:42, Steve Holden wrote:
> he answer is probably the same as you will see if you try
>
> from __future__ import braces
>
> That feature*is* available in Python 2.6

In the past I used to think it was really cool that one could do

from __future__ import exciting_and_cool_new_stuff


now I really wish we had

from __past__ import old_and_boring_syntax_26

etc etc
-trapped on level five-ly yrs-
Robin Becker

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Is a blank at the end of a C file a better style than a newline atthe end of the file or is it better to place none? Jimmy C Programming 3 09-09-2011 10:36 PM
GL2 better than the XLs? Consumer grade HDs better than pro-sumer Mini DVs? dh@. DVD Video 1 08-28-2008 07:20 PM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
Is splint really better than lint? Is there a better tool than splint? Peter Bencsik C Programming 2 09-21-2006 10:02 PM
Build a Better Blair (like Build a Better Bush, only better) Kenny Computer Support 0 05-06-2005 04:50 AM



Advertisments