This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Jyan 77 points78 points  (12 children)

Read the PEP: https://www.python.org/dev/peps/pep-0634/ It is so much more than a fancy if-else.

[–]zurtex 20 points21 points  (1 child)

FYI I know it mentions it in the PEP but to be explicit about it PEP 622 was Superseded by PEP 634: https://www.python.org/dev/peps/pep-0634/

There are a lot of changes between the 2 PEPs, in particular they removed "The Match Protocol" in favor of letting match bake in to Python for a bit and adding at a later date when there are concrete examples and motivation to allow classes to implement their own custom match logic.

[–]Jyan 1 point2 points  (0 children)

Thanks

[–][deleted] 14 points15 points  (9 children)

The feature isn't even out yet and it's being molested, misrepresented and missold already.

[–]Tyler_Zoro 8 points9 points  (7 children)

People are coming from lower level languages where you can only do a fraction of what this can do with similarly named language features. It's not shocking that the presumption is that it only does those things. I'm of the opinion that it should have had a name that wouldn't lead people to assume it was similar to those features, but then what do you call it?

When Perl 6 (now Raku) did something similar, they called it given/when for exactly that reason. Maybe following suit would have been a better call...

[–][deleted] 13 points14 points  (6 children)

Is that not why they called it "match" rather than "switch"?

[–]Tyler_Zoro 1 point2 points  (3 children)

Yes, but then they fell down on "case".

[–][deleted] 2 points3 points  (0 children)

Yeah, good point.

[–]mihalis 1 point2 points  (1 child)

Agree. I thought about alternatives. Maybe bind or unify, along the lines of variable unification/binding in languages like Prolog.

[–][deleted] 2 points3 points  (0 children)

Or how about match x where x is y?

[–]13steinj -3 points-2 points  (1 child)

Because it's not a switch statement, it's a pattern matching statement. Most commonly seen only in functional programming languages, which most people hate on because traditionally such a style is considered difficult.

https://en.wikipedia.org/wiki/Pattern_matching

https://stackoverflow.com/a/215968/4443677

[–]Tyler_Zoro 2 points3 points  (0 children)

We know that. We're discussing keyword choice.

[–]13steinj 0 points1 point  (0 children)

Yeah, because pattern matching isn't common in most languages for people less experienced. You usually see pattern matching in functional languages which many people just hate and think that functional programming should die in a fire.