[Python-ideas] PEP 505 (None coalescing operators) thoughts
mal at egenix.com
Tue Sep 29 11:49:17 CEST 2015
On 28.09.2015 23:49, Guido van Rossum wrote:
> On Mon, Sep 28, 2015 at 2:06 PM, Donald Stufft <donald at stufft.io> wrote:
>> I’m not a big fan of the punctuation though. It took me a minute to
>> realize that post?.tag.lower() was saying if post is None, not if post.tag
>> is None and I feel like it’s easy to miss the ?, especially when combined
>> with other punctuation.
> But that's a different point (for the record I'm not a big fan of the ?
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).
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:
if x is None:
x = 
IMO, that's better than any of the above, but perhaps that's
just because I don't believe in the "write everything
in a single line" pattern as something we should strive
for in Python.
The other variants (member and index access) look like
typos to me ;-)
Professional Python Services directly from the Experts (#1, Sep 29 2015)
>>> Python Projects, Coaching and Consulting ... http://www.egenix.com/
>>> Python Database Interfaces ... http://products.egenix.com/
>>> Plone/Zope Database Interfaces ... http://zope.egenix.com/
2015-09-25: Started a Python blog ... ... http://malemburg.com/
2015-10-21: Python Meeting Duesseldorf ... 22 days to go
::::: Try our mxODBC.Connect Python Database Interface for free ! ::::::
eGenix.com Software, Skills and Services GmbH Pastor-Loeh-Str.48
D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
Registered at Amtsgericht Duesseldorf: HRB 46611
More information about the Python-ideas