[Python-ideas] PEP 505: None-aware operators
David Mertz
mertz at gnosis.cx
Sun Jul 22 09:01:58 EDT 2018
On Sun, Jul 22, 2018, 8:11 AM Steven D'Aprano <steve at pearwood.info> wrote:
> On Sun, Jul 22, 2018 at 12:13:04PM +0200, Giampaolo Rodola' wrote:
> > Please let's drop the argument that + - * / = and ? are the same.
> We shouldn't judge proposals on how mysterious they are the first time we
> see them, because everything is mysterious the first time.
> All the obvious operators are already in use. Anything we add now is going
> to be a little bit niche, a little bit unusual. It's not like
> we're going to suddenly realise we forgot to include a "subtract"
> operator. So it is perfectly natural that any new operators won't be as
> familiar as + or - operators. But it might become as familiar as ** or <<
> operators, or some of the less common regex patterns,
>
I'm glad you've moved to better acknowledging the relative familiarity of
symbols. This simple can't be brushed away as a non-concern, as you did in
prior posts.
We're not promoting or reaching Python to Martians with entirely different
systems of writing. Nor, for that matter, even to humans of the 14th
entirety CE, before some basic math symbology became universal.
+, -, /, <, >, <=, >= are taught to small children throughout the world,
over the last 5 or more generations (the compound inequalities drawn in
combined glyphs, but iconically very close). Yes they are characters with
no inherent meaning, but they are as well known as the sounds of Latin
letters, or probably more. '*' is a bit more computer specific. 'x' or some
nicer typographic variation is taught to children. But '*' is close to
universal in computer languages. '**' is funny. It's used in many computer
languages, but ^ is also a commonplace and probably more iconic for
"superscript", the actual middle school notation on exponentiation.
Actually, I have a ten Pythin line command-line calculator that accepts 'x'
and '^' in their "obvious" meanings.
The various question mark operators are only reasonable to compare to e.g.
@ for either __matmul__ or introducing decorators. Or to bitwise operators
like |, ~, ^, <<. But in both of those areas, the programs are ones dealing
with specialized domains where "experts" are necessary to understand the
semantics, not only the iconography.
Here the question mark operators are very different. They are proposed as
general constructs with no particularly special area of use. Programmers or
hobbyists who come from different or no programming language would
encounter them. Even as a scientific Python export, my linear algebra is
weak... if I see code with a bunch of '@' marks I know I'm not really going
to understand it, but before I look I'm warned about the domain
difficulties by the comments, function names, and so on.
The question marks are basic—though obscure and hard to reason about–flow
control.
To me, the ?? operator seems like a clear and obvious win. The other
> variants are more complex and the benefit is not as obvious to me, so I
> haven't decided where I stand on them.
>
Yes, that is the only one I'm merely -0 on. The others I'm -1000. Even
experienced developers in this thread keep tripping over the actual
semantics of those others, and the PEP proposer is unsure about what's best
for some edge behaviors that are actually really important were they to be
adopted.
The most any of these can possibly do is save a few characters in a ternary
line, or perhaps a few lines of if/elif that make the intention far more
obvious.
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180722/8b1c293a/attachment-0001.html>
More information about the Python-ideas
mailing list