[Python-ideas] Null coalescing operator

Mark E. Haase mehaase at gmail.com
Mon Oct 31 11:51:39 EDT 2016


Stephen J. Turnbull wrote:

> I gather you think you have a deadlock here.  The way to break it is
> to just do it.  Pick a syntax and do the rewriting.  My memory of some
> past instances is that many of the senior devs (especially Guido) will
> "see through the syntax" to evaluate the benefits of the proposal,
> even if they've said they don't particularly like the initially-
> proposed syntax.


I don't feel deadlocked, but I think you're right about committing to a
syntax. So I updated the PEP, summarized here:

   1. Spelling a new operator as a keyword is difficult due to backward
   compatibility. It can be done (see PEP-308 and PEP-492) but requires
   extreme care.
   2. A keyword operator is considered less ugly than punctuation, but it
   makes assignment shortcut syntax very ugly. Assume the coalesce operator is
   "foo", then the assignment shortcut would be "x foo= y". This is
   unacceptable.
   3. If eliminate the possibility of a keyword and focus on punctuation,
   we find that most people think "??" — the syntax that exists in several
   other mainstream languages — is ugly and not Pythonic.
   4. However, any other punctuation spelling will be at least as ugly and
   will not have the benefit of being familiar to programmers who have seen
   null coalescing in other languages.
   5. Therefore, the most reasonable spelling is to borrow the same
   spelling that other languages use, e.g. "??", "?.", and "?[".

I did go down the road of trying to create a new keyword, trying some
mundane ideas ("foo else bar") and some more exotic ideas ("try foo then
bar"), but I don't know if those syntaxes are even parseable, and as I
worked through a bunch of examples, I realized that all of the keywords I
was trying were very awkward in practical use, especially when combined
with other expressions.

Therefore, I have updated the PEP with the punctuation mentioned above, and
at this point the PEP can't go any farther. If the best spelling for this
new operator is unacceptable, then there's no getting around that. This PEP
should be rejected.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161031/5f303e0a/attachment.html>


More information about the Python-ideas mailing list