Method Chaining

Lawrence D’Oliveiro lawrencedo99 at gmail.com
Fri Jun 17 00:37:00 EDT 2016


On Friday, June 17, 2016 at 4:24:24 PM UTC+12, Michael Selik wrote:
> On Thu, Jun 16, 2016 at 10:53 PM Lawrence D’Oliveiro wrote:
> 
> > Example from <http://default-cube.deviantart.com/art/Truchet-612095093>,
> > concisely expressing a complex drawing sequence:
> >
> >     (g
> >         .move_to((p1 + p2a) / 2)
> >         .line_to(p1 + (p2 - p1) * frac)
> >         .line_to((p1 + p1a) / 2)
> >         .stroke()
> >         .move_to((p2 + p2a) / 2)
> >         .line_to(p2 + (p1 - p2) * frac)
> >         .line_to((p2 + p1a) / 2)
> >         .stroke()
> >     )
> 
> Wouldn't that look nicer with the ``g`` repeated on every line, no extra
> indentation, and no extraneous parentheses?
> 
>     g.move_to((p1 + p2a) / 2)
>     g.line_to(p1 + (p2 - p1) * frac)
>     g.line_to((p1 + p1a) / 2)
>     g.stroke()
>     g.move_to((p2 + p2a) / 2)
>     g.line_to(p2 + (p1 - p2) * frac)
>     g.line_to((p2 + p1a) / 2)
>     g.stroke()

Clearly, no.



More information about the Python-list mailing list