[Python-ideas] Pattern Matching Syntax

Tim Peters tim.peters at gmail.com
Sat May 5 02:23:46 EDT 2018


[Tim]
>> ... I liked the way he _reached_ that conclusion:  by looking at real-
>> life Python code that may have been written instead to use constructs
>> "like this".  I find such examination far more persuasive than abstract
>> arguments or made-up examples.

[Serhiy Storchaka <storchaka at gmail.com>]
> I would like to see such examination for PEP 572. And for all other syntax
> changing ideas.

I did it myself for 572, and posted several times about what I found.
It was far more productive to me than arguing (and, indeed, I sat out
of the first several hundred msgs on python-ideas entirely because I
spent all my time looking at code instead).

Short course:  I found a small win frequently, a large win rarely, but
in most cases wouldn't use it.  In all I expect I'd use it
significantly more often than ternary "if", but far less often than
augmented assignment.  But that's me - everybody needs to look at
their own code to apply _their_ judgment.

572 is harder than a case/switch statement to consider this way,
because virtually every assignment statement binding a name could
_potentially_ be changed to a binding expression instead, and there
are gazillions of those.  For considering case/switch additions, you
can automate searches to vastly whittle down the universe of places to
look at (`elif` chains, and certain nested if/else if/else if/else ...
patterns).


> I withdrew some my ideas and patches when my examinations showed that the
> number of cases in the stdlib that will take a benefit from rewriting using
> a new feature or from applying a compiler optimization is not large enough.

Good!  I approve :-)


More information about the Python-ideas mailing list