[Python-Dev] Re: Zen of Python
Alex Martelli
aleax at aleax.it
Thu Jan 20 09:09:36 CET 2005
On 2005 Jan 20, at 02:47, Skip Montanaro wrote:
> Phillip> Actually, this is one of those rare cases where
> optimization
> Phillip> and clarity go hand in hand. Human brains just don't
> handle
> Phillip> nesting that well. It's easy to visualize two levels of
> nested
> Phillip> structure, but three is a stretch unless you can abstract
> at
> Phillip> least one of the layers.
>
> Also, if you think about nesting in a class/instance context,
> something like
>
> self.attr.foo.xyz()
>
> says you are noodling around in the implementation details of
> self.attr (you
> know it has a data attribute called "foo"). This provides for some
> very
> tight coupling between the implementation of whatever self.attr is and
> your
> code. If there is a reason for you to get at whatever xyz() returns,
> it's
> probably best to publish a method as part of the api for self.attr.
Good point: this is also known as "Law of Demeter" and relevant
summaries and links are for example at
http://www.ccs.neu.edu/home/lieber/LoD.html .
Alex
More information about the Python-Dev
mailing list