allow line break at operators
Chris Angelico
rosuav at gmail.com
Wed Aug 10 04:39:55 EDT 2011
On Wed, Aug 10, 2011 at 9:32 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
>>> Of course, the dot operator is also included, which may facilitate method
>>> chaining:
>>>
>>> x = svg.append( 'circle' ).
>>> r(2).cx(1).xy(1).
>>> foreground('black').bkground('white')
>
> If you are chaining six dots like that, you are in gross violation of the
> Law Of Demeter. That is poor code, and should be discouraged, not
> encouraged.
I would only accept that this is poor code IF there is a viable
alternative, such as:
x = svg.append(circle(r=2,cx=1,xy=1,foreground='black',bkground='white'))
This would, imho, be a more Pythonic way to do it. But if this isn't
available, and if the methods already return self, then I see nothing
wrong with chaining. It's a handy way of getting additional mileage
out of lambdas and list comps when writing one-liners. :)
(Cue long thread about whether or not one-liners are Pythonic.)
Chris Angelico
More information about the Python-list
mailing list