[Python-ideas] Null coalescing operator

Barry Warsaw barry at python.org
Fri Oct 28 14:19:30 EDT 2016


On Oct 28, 2016, at 03:24 PM, Gustavo Carneiro wrote:

>The main drawback of this type of approach is that code checking tools will
>hardly ever support checking expressions inside the string like that.
>Also, you don't get proper syntax highlighting, code completion, etc.
>
>You can do anything you want by writing another programming language that
>is passed as string to a function, but that is not the same thing as having
>a proper syntax, is it?  Just like type annotations with mypy: sure, you
>can add type annotations in comments, but it's not the same...

The bar for adding new language syntax is, and must be, high.  Every new bit
of syntax has a cost, so it has to be worth it.  Guido deemed type annotations
to be worth it and he may do the same for null coalescing operators.  I don't
personally think the need is so great or the use cases so common to incur that
cost, but I'm just one opinion.

The advantage of lower-cost approaches such as adopting the syntax in
attrgetter() is that you piggyback on an existing API.  Then you can use that
as an experiment to see whether you really do solve enough problems in Python
for a syntax change to be worth it.  It's a lot like the ability to create
properties and such before the syntactic sugar of decorators was added.  I
think that feature's pre-syntax popular and utility proved that the cost of
adding syntax was worth it.

Cheers,
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 801 bytes
Desc: OpenPGP digital signature
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20161028/3dff52d7/attachment-0001.sig>


More information about the Python-ideas mailing list