[Python-ideas] Dart-like method cascading operator in Python

Cameron Simpson cs at zip.com.au
Fri Nov 22 00:25:02 CET 2013


On 21Nov2013 14:34, Masklinn <masklinn at masklinn.net> wrote:
> On 2013-11-21, at 13:40 , Nick Coghlan <ncoghlan at gmail.com> wrote:
> 
> > On 21 November 2013 20:55, Perešíni Peter <ppershing at gmail.com> wrote:
> >> gnuplot.newPlot()
> >> ..set("xrange [0:5]")
> >> ..set("yrange [0:20]")
> >> ..newPlot()
> >>     ..addSeries("Linear", [1,2,3])
> >>     ..addSeries("Quadratic", [1,4,6])
> >> ..run()
> > 
> > If you just want structural grouping of some code, you can already
> > define an appropriate context manager:
> > 
> > @contextlib.contextmanager
> > def value(x)
> >    yield x
> > 
> > with value(gnuplot.newPlot()) as p:
> >    p.set("xrange [0:5]")
> >    p.set("yrange [0:20]")
> >    with value(p.newPlot()) as n:
> >        n.addSeries("Linear", [1,2,3])
> >        n.addSeries("Quadratic", [1,4,6])
> >    p.run()
> > 
> > It doesn’t define a new scope
> 
> And it requires naming things.

That's a feature. The last thing I want in a traceback is a recitation
of the line:

  ..foo = 1

Hmm. Setting .foo on... what?

Personally, because this is so easy to do with a context manager or
even just a simple temporary variable, I'm -1 on the whole cascading
idea.

Cheers,
-- 
Cameron Simpson <cs at zip.com.au>

The wireless music box has no imaginable commercial value.   Who would pay
for a message sent to nobody in particular?
      --David Sarnoff's associates in response to his urgings for
        investment in  the radio in the 1920s.


More information about the Python-ideas mailing list