Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #26327

Why 'Flat is better than nested'

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'suppose': 0.07; 'python': 0.09; 'hierarchical': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:Why': 0.09; 'terry': 0.09; 'message-id:@dough.gmane.org': 0.16; 'necessity.': 0.16; 'nodes': 0.16; 'peters': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'reedy': 0.16; 'structure.': 0.16; 'unstructured': 0.16; 'items.': 0.17; 'jan': 0.18; 'tim': 0.18; '>>>': 0.18; 'equivalent': 0.20; 'import': 0.21; 'nearly': 0.23; 'header:User-Agent:1': 0.26; '(which': 0.26; 'header:X -Complaints-To:1': 0.28; 'learn,': 0.29; 'parent': 0.29; 'prints': 0.29; 'says': 0.33; 'rid': 0.33; 'to:addr:python-list': 0.33; 'along': 0.35; 'so,': 0.35; 'there': 0.35; 'add': 0.36; 'received:org': 0.36; 'child': 0.36; 'being': 0.37; 'things': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'multiplying': 0.84; 'received:fios.verizon.net': 0.84; 'subject:better': 0.84; 'why?': 0.84; 'zen': 0.84
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Terry Reedy <tjreedy@udel.edu>
Subject Why 'Flat is better than nested'
Date Tue, 31 Jul 2012 17:04:44 -0400
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 7bit
X-Gmane-NNTP-Posting-Host pool-173-75-251-66.phlapa.fios.verizon.net
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:13.0) Gecko/20120614 Thunderbird/13.0.1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.2795.1343768702.4697.python-list@python.org> (permalink)
Lines 22
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1343768702 news.xs4all.nl 6899 [2001:888:2000:d::a6]:48244
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:26327

Show key headers only | View raw


 >>> import this

prints 'The Zen of Python', a poem by Tim Peters that consists of python 
proverbs such as "Flat is better than nested." (Others things being 
equal) why? Because it is a restatement of the principle of parsimony, 
of not multiplying entities without necessity.

Suppose we have a unstructured collection of N items. Organizer comes 
along and says 'Let there be structure. Let us organize the items as 
leaf nodes in a hierarchical tree' (which is equivalent to nesting). To 
do so, we can add as many as N-1 new non-leaf nodes and as many as 
(about) 2*N - log2(N) parent child relationships. In other words, nearly 
quadruple the number of entities to learn, discuss, and remember. Well, 
there had better be a good necessity to do so ;-).

And, of course, once new entities *are* conjured up, it is hard to get 
rid of them.

-- 
Terry Jan Reedy

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Why 'Flat is better than nested' Terry Reedy <tjreedy@udel.edu> - 2012-07-31 17:04 -0400

csiph-web