[Python-ideas] PEP 505 (None coalescing operators) thoughts
Georg Brandl
g.brandl at gmx.net
Tue Sep 29 18:37:46 CEST 2015
On 09/29/2015 03:40 PM, Eric Snow wrote:
> On Tue, Sep 29, 2015 at 3:49 AM, M.-A. Lemburg <mal at egenix.com> wrote:
>> On 28.09.2015 23:49, Guido van Rossum wrote:
>>> But that's a different point (for the record I'm not a big fan of the ?
>>> either).
>>
>> Me neither.
>
> Same here.
>
>>
>> The proposal simply doesn't have the right balance between usefulness
>> and complexity added to the language (esp. for new Python programmers
>> to learn in order to be able to read a Python program).
>
> +1
I agree as well.
>> In practice, you can very often write "x or y" instead of
>> having to use "x if x is None else y", simply because you're
>> not only interested in catching the x is None case, but also
>> want to override an empty string or sequence value with
>> a default. If you really need to specifically check for None,
>> "x if x is None else y" is way more expressive than "x ?? y".
>>
>> For default parameters with mutable types as values,
>> I usually write:
>>
>> def func(x=None):
>> if x is None:
>> x = []
>> ...
>
> I do the same. It has the right amount of explicitness and makes the
> default-case branch more obvious (subjectively, of course) than the
> proposed alternative:
>
> def func(x=None):
> x = x ?? []
Looking at this, I think people might call ?? the "WTF operator". Not a
good sign :)
Georg
More information about the Python-ideas
mailing list