[Python-ideas] PEP 505: None-aware operators

Mikhail V mikhailwas at gmail.com
Mon Jul 23 12:35:37 EDT 2018


I personally do almost only classical programming, and I am somewhat
opposed to OOP in general. So here my somewhat outlandish view,
(and I am biased becase I will probably never need this feature).

First thoughts after reading the PEP: what is so super-special and fundamental
about None value?
Is it more special and required to treat more often than "true" or
"false" values in
similar manner?
Is there statistics for occurence of code checking 'None' versus 'not None'?

So:

if x is None:
   x = 10

converts to:

x ??= 10

But what if one need to do something else than just return a value?
E.g. I want to insert `print(x)` in the first example?
Or check against other value than 'None'?
Supposed to write it so then rewrite it so, then if I need it other way -
again rewrite it so.

So from the PEP I understand only two things:
1) de-facto None became special in some contexts.
2) one may need to short-circuit an expression if None pops up.

So it is syntax good only for special kind of applications I suppose.
It seems motivating examples come mainly from situations where
one has a Python script serving some database framework or something alike.
So it smells like specialized usage and design-specific pattern.
It looks (from a passer-by POV) like the proposed syntax tries to
treat some sticking out
parts of something that may not be necessarily present in an application at all.
Of course that maybe argued easily because many concepts that
does not directly belong to programming are sometimes appearing in form of
dedicated syntax. Though such cases not so common in Python.

I don't know whether the feature adressed by '?.' is often in those contexts,
but first thing that comes to mind - it regards only experts and NOT
intended for reading the code that I am not familiar with.

E.g. this "improved" code in examples:

def find_module(self, fullname, path):
    return getattr(self, 'find_spec', None)?.__call__(fullname, path)?.loader

I could not decipher this and I have tried for a while.

I could probably understand the motivation better if it were some
more or less fundamental or general pattern, but is it? IDK


-----

More important that the syntax part is really worrying.
Does everybody realize that there are only 2 or 3 ASCII characters left free?
IIRC those are question mark "?", exclamation mark "!" and dollar sign "$".

Imagine that in some time someone comes up with a good general syntax feature
that would require new symbol - and there is nothing left. That's not
funny actually.
This makes decisions about symbols into agony and heats up discussions
to extreme
because some PEP authors maybe hoping for a better-looking symbol for
their 'child' while other proposals and possible future proposals may
be more important.

At this time point I think one should first consider exploring the
possibility to
add non-ASCII characters to syntax. I think it is resonable because Unicode
became standard.
It should at least help to relax the atmosphere around syntax proposals.

'Niche' features IMO should be better added as functions, or, if non-ASCII
symbols could be added, as some '2nd class' symbols (i.e. not so nice looking).
And nicely looking symbols should be reserved for future proposals for
general syntax features which are potentially useful for wider user groups.


More information about the Python-ideas mailing list