[Python-Dev] Re: PEP 622 version 2 (Structural Pattern Matching)

2020年7月31日 12:17:14 -0700

On 31/07/2020 17:24, Rik de Kort via Python-Dev wrote:
1. Semantic operator overloading in generic contexts is very different from this use case. It's surrounded by a clear context. 2. Python programmer intuition varies across python programmers, and I would find it hella unintuitive if I had to explicitly capture every variable. I just want to write down what the thing looks like and have the interpreter figure out the correct bindings. Extra binding syntax will get in the way rather than be helpful.
Until you want to do something slightly different, and the interpreter's choice is not what you want.
Python Dev <[email protected]> wrote:
 +10. See
 
https://stackoverflow.com/questions/36825925/expressions-with-true-and-is-true-give-different-results/36826262#36826262
 for concrete evidence where another semantically inconsistent
 operator overloading caused trouble and what Stroustroup has to
 say on the matter.
 On 31.07.2020 13:42, Larry Hastings wrote:
 On 7/31/20 12:36 AM, Tobias Kohn wrote:
 And since pattern matching is really
 a new feature to be introduced to Python, a feature that can
 be seen in different lights, there is no 'Python-Programmer
 intuition' that would apply in this case.
 It's not fair to say "intuition doesn't apply because it's new
 syntax". There are plenty of examples of intuition serving a
 Python programmer well when encountering new syntax. A Python
 programmer's intuition is informed by existing syntax and
 conventions in the language. When they see a new construct,
 its similarity to existing constructs can make understanding
 the new syntax quite intuitive indeed.
 Take for example list comprehensions. Python 1 programmers
 hadn't seen
 a = [x for x in y]
 But they knew what square brackets meant in that context, it
 meant "creates a new list". And they knew what "for x in y"
 meant, that meant iteration. Understanding those separate two
 concepts, a Python 1 programmer would be well on their way to
 guessing what the new syntax meant--and they'd likely be
 right. And once they understood list comprehensions, the
 first time they saw generator expressions and set and dict
 comprehensions they'd surely intuit what those did immediately.
 The non-intuitiveness of PEP 622, as I see it, is that it
 repurposes what looks like existing Python syntax but
 frequently has wholly different semantics. For example, a
 "class pattern" looks like it's calling a function--perhaps
 instantiating an object?--but the actual semantics and
 behavior is very different. Similarly, a "mapping pattern"
 looks like it's instantiating a dict, but it does something
 very different, and has unfamiliar and seemingly arbitrary
 rules about what is permitted, e.g. you can't use full
 expressions or undotted-identifiers when defining a key. Add
 the "capture pattern" to both of these, and a Python
 programmer's intuition about what this syntax traditionally
 does will be of little help when encountering a PEP 622 match
 statement for the first time.
 Cheers,
 //arry/
 _______________________________________________
 Python-Dev mailing list [email protected] 
<mailto:[email protected]>
 To unsubscribe send an email [email protected] 
<mailto:[email protected]>
 https://mail.python.org/mailman3/lists/python-dev.python.org/
 Message archived 
athttps://mail.python.org/archives/list/[email protected]/message/Q5KULD7E3TZSSQ5CFUOQSJTGS5JQS4WM/
 Code of Conduct:http://python.org/psf/codeofconduct/
-- Regards,
 Ivan
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/4L7LXGVYTMHPF5I54Z2DVSIKSL75ES6H/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/[email protected]/message/54TQPNOPDIPTCBBY6XJVI5RBSUWUQ6XH/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to