On 2011-08-15, Chris Rebert <c...@rebertia.com> wrote:
> On Sun, Aug 14, 2011 at 6:54 PM, Steven D'Aprano
><steve+comp.lang.pyt...@pearwood.info> wrote:
>> As a rule, chaining method calls risks violating the Law of Demeter. Just
>> sayin'.

> Not in the specific case of fluent interfaces[1] though, which could
> have been what Seebach had in mind.

They're the most obvious example, from my point of view.

I tend to write stuff like

        foo.array_of_things.sort.map { block }.join(", ")

I like this a lot more than
        array = foo.array_of_things
        sorted_array = array.sort()
        mapped_array = [block(x) for x in sorted_array]
        ", ".join(mapped_array)

(I am still not used to Python's attachment of join to strings rather
than to arrays.  I don't really object to it, it's just not how I think
about join operations.)

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nos...@seebs.net
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.
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to