<div dir="auto">Strong -1 still from me. Too special case for syntax. Just write a function 'first_non_none()' that can perfectly will handle the need.</div><div class="gmail_extra"><br><div class="gmail_quote">On Nov 28, 2017 10:09 PM, "Steven D'Aprano" <<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Tue, Nov 28, 2017 at 12:31:06PM -0800, Raymond Hettinger wrote:<br>
><br>
> > I also cc python-dev to see if anybody here is strongly in favor or against this inclusion.<br>
><br>
> Put me down for a strong -1. The proposal would occasionally save a<br>
> few keystokes but comes at the expense of giving Python a more Perlish<br>
> look and a more arcane feel.<br>
<br>
I think that's an unfair characterisation of the benefits of the PEP.<br>
It's not just "a few keystrokes".<br>
<br>
Ironically, the equivalent in Perl is // which Python has used for<br>
truncating division since version 2.4 or so. So if we're in danger of<br>
looking "Perlish", that ship has sailed a long time ago.<br>
<br>
Perl is hardly the only language with null-coalescing operators -- we<br>
might better describe ?? as being familiar to C#, PHP, Swift and Dart.<br>
That's two mature, well-known languages and two up-and-coming languages.<br>
<br>
<br>
[...]<br>
> timeout ?? local_timeout ?? global_timeout<br>
<br>
As opposed to the status quo:<br>
<br>
timeout if timeout is not None else (local_timeout if local_timeout is not None else global_timeout)<br>
<br>
Or shorter, but even harder to understand:<br>
<br>
(global_timeout if local_timeout is None else local_timeout) if timeout is None else timeout<br>
<br>
I'd much prefer to teach the version with ?? -- it has a simple<br>
explanation: "the first of the three given values which isn't None". The<br>
?? itself needs to be memorized, but that's no different from any other<br>
operator. The first time I saw ** I was perplexed and couldn't imagine<br>
what it meaned.<br>
<br>
Here ?? doesn't merely save a few keystrokes, it significantly reduces<br>
the length and complexity of the expression and entirely cuts out the<br>
duplication of names.<br>
<br>
If you can teach<br>
<br>
timeout or local_timeout or global_timeout<br>
<br>
then you ought to be able to teach ??, as it is simpler: it only<br>
compares to None, and avoids needing to explain or justify Python's<br>
truthiness model.<br>
<br>
<br>
> 'foo' in (None ?? ['foo', 'bar'])<br>
<br>
If you can understand<br>
<br>
'foo' in (False or ['foo', 'bar'])<br>
<br>
then surely you can understand the version with ??.<br>
<br>
<br>
> requested_quantity ?? default_quantity * price<br>
<br>
Again:<br>
<br>
(default_quantity if requested_quantity is None else requested_quantity) * price<br>
<br>
<br>
I'd much prefer to read, write and teach the version with ?? over the<br>
status quo.<br>
<br>
<br>
--<br>
Steve<br>
______________________________<wbr>_________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer" target="_blank">http://python.org/psf/<wbr>codeofconduct/</a><br>
</blockquote></div></div>