[Python-ideas] Method chaining notation

Paul Moore p.f.moore at gmail.com
Mon Feb 24 16:12:11 CET 2014


On 24 February 2014 15:01, Ron Adam <ron3200 at gmail.com> wrote:
> You would probably see it used more often like this...
>
>    def names(defaults, pos_names, pos_args, kwds):
>        return  {}.=update(defaults) \
>                  .=update(zip(pos_names, pos_args) \
>                  .=update(kwds)

How is this better than

    def names(defaults, pos_names, pos_args, kwds):
        ret = {}
        ret.update(defaults)
        ret.update(zip(pos_names, pos_args)
        ret.update(kwds)
        return ret

(I originally named the return value _ to cater for the tendency to
insist on punctuation rather than names in this thread, but honestly,
why *not* name the thing "ret"?)

I get the idea of chained updates, I really do. But translating
between mutation of a named value and chained updates is pretty
trivial, so I don't see how this is anything but a case of "follow the
preferred style for the language/API you're using". And Python uses
updating named values, why is that so bad?

Paul


More information about the Python-ideas mailing list