[Python-ideas] Dart-like method cascading operator in Python
Perešíni Peter
ppershing at gmail.com
Thu Nov 21 17:17:53 CET 2013
I really like the colon to show that the indentation is going to change --
it is Pythonic and consistent with the language plus helps both interactive
console and parsers/editors to expect the indentation.
However, I would still make cascading operator different from dot just to
be more explicit (to avoid confusion of the programmers that do not know
about this feature yet -- double dot will indicate that this is a new
syntax)
On Thu, Nov 21, 2013 at 4:00 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Fri, Nov 22, 2013 at 1:56 AM, Masklinn <masklinn at masklinn.net> wrote:
> > The primary issue with it is that the API must be crafted specifically
> > for chaining: everything must be done with methods, and methods must
> > return their `self`. Not only does this mean mutator methods which could
> > return something else can’t, it goes against the usual Python grain
> > (at least that of the builtins and standard library) where mutator
> > methods generally return None.
> >
> > Cascading adds “chaining” to all (mutable) objects without having to
> > alter them or build the API specifically to that end. Or duplicate
> > setattr & setitem via additional methods.
> >
> > But yes, as noted if the situation of “infix operators line breaks” is
> > not changed, it will also affect chaining (not that I think it’s a big
> > deal to put a chain in parens).
>
> I get that. But what I'm saying is that this is needing some clear
> definitions in terms of indentation and beginnings of lines anyway, so
> it clearly cannot conflict with method chaining. It can simply use the
> dot, so it'll look like normal method invocation, but with an indent
> meaning "same as the previous" - like how a BIND file is often laid
> out:
>
> @ IN SOA .... blah blah ....
> IN NS ns1.blah.blah
> IN NS ns2.blah.blah
> IN MX 10 mail
>
> This would have things look pretty much the same:
>
> foo.bar():
> .quux()
> .asdf()
> .qwer()
>
> ChrisA
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20131121/6a4af31d/attachment.html>
More information about the Python-ideas
mailing list