[Python-ideas] PEP 505 (None coalescing operators) thoughts

Guido van Rossum guido at python.org
Mon Sep 28 22:06:18 CEST 2015


On Mon, Sep 28, 2015 at 1:00 PM, Carl Meyer <carl at oddbird.net> wrote:

> On 09/28/2015 01:53 PM, Guido van Rossum wrote:
> > On Mon, Sep 28, 2015 at 12:43 PM, Carl Meyer <carl at oddbird.net
> >     Or put differently, that whereas these two are trivially equivalent
> (the
> >     definition of left-to-right binding within a precedence class):
> >
> >         foo.bar.baz
> >         (foo.bar).baz
> >
> >     these two are not equivalent:
> >
> >        foo?.bar.baz
> >        (foo?.bar).baz
> >
> >
> > Right.
> >
> >
> >     I'm having trouble coming up with a parallel example where the
> existing
> >     short-circuit operators break "extractibility" of a sub-expression
> like
> >     that.
> >
> >
> > Why is that an interesting property?
>
> Because breaking up an overly-complex expression into smaller
> expressions by means of extracting sub-expressions into temporary
> variables is a common programming task (in my experience anyway --
> especially when trying to decipher some long-gone programmer's
> overly-complex code), and it's usually one that can be handled pretty
> mechanically according to precedence rules, without having to consider
> that some operators might have action-at-a-distance beyond their
> precedence.
>

Well, if just the foo?.bar.baz part is already too complex you probably
need to reconsider your career. :-)

Seriously, when breaking things into smaller parts you *have* to understand
the shortcut properties. You can't break "foo() or bar()" into

  a = foo()
  b = bar()
  return a or b

either.


> >     I guess this is because the proposed short-circuiting still "breaks
> out
> >     of the precedence order" in a way that the existing short-circuiting
> >     operators don't. Both member access and indexing are within the same
> >     left-to-right binding precedence class, but the new operators would
> have
> >     a short-circuit effect that swallows operations beyond where normal
> >     left-to-right binding would suggest their effect should reach.
> >
> >     Are there existing examples of behavior like this in Python that I'm
> >     missing?
> >
> >
> > I don't know, but I think you shouldn't worry about this.
>
> I think it's kind of odd, but if nobody else is worried about it, I
> won't worry about it either :-)
>

Good idea.

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150928/85a7e46f/attachment-0001.html>


More information about the Python-ideas mailing list