allow line break at operators

Seebs usenet-nospam at seebs.net
Mon Aug 15 18:32:07 CEST 2011


On 2011-08-15, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:
> Seebs wrote:
>> 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)

> If you insist on a one-liner for four separate operations, what's wrong with
> this?

> ", ".join([block(x) for x in sorted(foo.array_of_things)])

Nothing in particular; I was just contrasting two styles, not asserting
that Python couldn't do that.

In general, I don't like to do things that either involve making a lot of
variables that are assigned to once and then read from once, or making a
whole lot of x = foo(x) type assignments to one variable.  It feels cluttered
to me.

> I think I would be less skeptical about fluent interfaces if they were
> written more like Unix shell script pipelines instead of using attribute
> access notation:

> foo.array_of_things | sort | map block | join ", "

Interesting!  I think that's probably why I find them so comfortable;
shell was one of the first languages I got serious about.

-s
-- 
Copyright 2011, all wrongs reversed.  Peter Seebach / usenet-nospam at 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.



More information about the Python-list mailing list