Re:PEP 622 – Structural Pattern Matching
by BiteCode_dev on Wednesday June 24, 2020 @10:05AM
(#23627997)
I prefer the PEP syntax: it looks like the instanciation of the object I'm trying to match, so it makes sense to me.
[ Parent
| on HN ]
Re:PEP 622 – Structural Pattern Matching
by kevinmgranger on Wednesday June 24, 2020 @10:30AM
(#23628277)
That's their entire point: you're _not_ instantiating the object you're trying to match.
Re:PEP 622 – Structural Pattern Matching
by BiteCode_dev on Wednesday June 24, 2020 @10:35AM
(#23628327)
I know.
It doesn't bother me since I see that match/case is a whole different context, I know I'm matching, and have no reason to instanciate anything here.
But since Foo(a=1) looks like instanciation, it's obvious to me what it's supposed to match.
I think that's one of the things that motivated to:
- use new keywords, but existing ones like "as", nor symbols;
- force 2 levels of indentation despite the cost of it.
This makes it very clear, with little effort, that the context is completly different.
It will make scanning the code easy, and avoid confusion.
Re:PEP 622 – Structural Pattern Matching
by dragonwriter on Wednesday June 24, 2020 @11:53AM
(#23629404)
Pattern matching traditionally resembles instantiation except potentially with wildcards, because the “pattern” in “pattern matching” is a object representation template in the same representation used elsewhere in the language.
Using a different syntax for pattern matching loses the main point of pattern matching.
Re:PEP 622 – Structural Pattern Matching
by hombre_fatal on Wednesday June 24, 2020 @11:14AM
(#23628795)
And the counter-point is: you learn one time that it's not instantiation and remember it forever, and you get to resume reusing/overloading muscle-memory syntax to get the job done.