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

Jeff Hardy jdhardy at gmail.com
Mon Sep 28 18:02:54 CEST 2015

+1 for the idea
-1 on the propagating member-access or index operators
+1 on spelling it "or?"

C# has had null-coalescing since about 2005, and it's one feature I miss in
every other language that I use. I view null/None as a necessary evil, so
getting rid of them as soon possible is a good thing in my book. Nearly
every bit of Python I've ever written would have benefitted from it, if
just to get rid of the "x if x is not None else []" mess.

That said, I think the other (propagating) operators are a mistake, and I
think they were a mistake in C# as well. I'm not I've ever had a situation
where I wished they existed, in any language. Better to get rid of the
Nones as soon as possible than bring them along. It's worth reading the C#
design team's notes and subsequent discussion on the associativity of "?."
[1] since it goes around and around with no really good answer and no
particularly intuitive behaviour.

Rather than worry about that, I'd prefer to see just the basic
None-coalescing added. I like Alessio's suggestion of "or?" (which seems
like it should be read in a calm but threatening tone, a la Liam Neeson).
It just seems more Pythonic; ?? is fine in C# but seems punctuation-heavy
for Python. It does mean the ?= and ?. and ?[] are probably out, and I'm OK
with that.

- Jeff

[1] https://roslyn.codeplex.com/discussions/543895
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150928/27723f55/attachment-0001.html>

More information about the Python-ideas mailing list