[Python-ideas] Null coalescing operator

Ethan Furman ethan at stoneleaf.us
Wed Nov 2 16:21:49 EDT 2016


On 11/02/2016 12:32 PM, Nikolaus Rath wrote:
> On Nov 02 2016, Zero Piraeus <schesis-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org> wrote:
>> On Wed, 2016-11-02 at 08:46 -0700, Guido van Rossum wrote:
>>> [...] we need to agree on what even the right definition of ?. is. It's
>>> been frighteningly difficult to explain this even on this list, even
>>> though I have a very clear view in my head, and PEP 505 also has the
>>> same semantics and explains well why those are the right semantics.
>>
>> I think the proposed semantics for ?. are confusing (and the operator
>> itself dangerous, but more on that later).
>>
>> If I write something like obj.attr, the failure mode I care about is that
>> obj has no attribute attr, rather than that obj is specifically None (or
>> one of a defined group of somewhat Nonelike objects).
>>
>> Clearly, in such a circumstance, obj is not what I expected it to be,
>> because I thought it was going to have an attribute attr, and it
>> doesn't.
>
> That means that you do not need null coalescing operators. They're not
> intended for your use-case, and you are not the target audience.

However, it's definitely a point for the confusiness of it all.

I like the idea of null-(coalescing|negation|borrowing|what-have-you), but I also very much appreciate the keyword approach used in Python.  I can already feel the headache coming on from trying to read and decipher the various ? accesses...

--
~Ethan~


More information about the Python-ideas mailing list