[Python-ideas] Using "||" (doubled pipe) as the null coalescing operator?
Guido van Rossum
guido at python.org
Fri Sep 25 00:30:45 CEST 2015
Using "?" as a (pro)noun is even worse than using it as an
operator/modifier.
On Thu, Sep 24, 2015 at 3:28 PM, Erik <python at lucidity.plus.com> wrote:
> On 24/09/15 04:00, Nick Coghlan wrote:
>
>> data = data if ? is not sentinel else default()
>>
>
> This reads OK in a short example like this and when using word-based
> operators such as "is not". However, it's a bit clumsy looking when using
> operators spelled with punctuation:
>
> data = data if ? != None else default()
> data = data if foo <= ? <= bar else default()
>
> > title = user_title if ? is not None else local_default_title if ? is not
> None else global_default_title
>
> I don't think I like the way '?' changes its target during the line in
> this example.
>
> For example, the equivalent of the admittedly-contrived expression:
>
> foo = bar if foo is None else baz if baz is not None else foo.frobnicate()
>
> is:
>
> foo = bar if ? is None else baz if ? is not None else foo.frobnicate()
>
> ... so you still have to spell 'foo' repeatedly (and only due to the
> subtle switch of the '?' target, which might go away (or be added) during
> code maintenance or refactoring).
>
>
> Also, if '?' is sort of a short-cut way of referencing the LHS, then one
> might naively expect to be able to write this:
>
> [(x, y) for x in range(5) if ? < 3 for y in range(5) if ? > 2]
>
> Regs, E.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
--
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20150924/33bd4c88/attachment.html>
More information about the Python-ideas
mailing list