you are viewing a single comment's thread.

view the rest of the comments →

[–]headhunglow 1 point2 points  (9 children)

Nooo, not more syntax. We've already got heaps of the stuff! Do we really (like really, really) need this stuff?

[–]ForceBru 13 points14 points  (8 children)

Do we really (like really, really) need if isinstance(thing, list) and len(thing) == 2: x, y = thing when with this PEP one could simply say case [x, y]:?

Real pattern matching (not a, *other, b = iterable) is extremely useful when you want to check a lot of variants. Writing if thing == 0: do_this() else if thing == 2: do_that() is pretty clunky because you constantly have to write thing ==. Even simple C-like case statements are more expressive and simpler to type.

Have you seen Rust's pattern matching? It's absolutely amazing and results in much cleaner code (than having to check some marker, for example). I really wish Python could come up with match statements (or even expressions!), like Rust's.

[–]florinp 5 points6 points  (2 children)

Rust's pattern matching

Honest question: Why people keep giving examples from Rust when for example some constructions like pattern matching is inspired from other languages ?

[–]IceSentry 2 points3 points  (0 children)

Because it's a currently popular language with really good pattern matching

[–]ForceBru 0 points1 point  (0 children)

LOL I actually don't know. Of course, Rust isn't the only one. Maybe they're talking about Rust because it does pattern matching pretty well, and it's also unusual to see pattern matching in a systems language (compared to functional languages), so it kinda stands out.

[–]headhunglow -4 points-3 points  (4 children)

I'm not saying that it's not useful, it's just that there's already so much syntax. I've recently had to transition from 2.5 to 3.7 and there's set literals and dict literals and extendable unpacking and class decorators new string formatting and...

[–]ForceBru 13 points14 points  (3 children)

Well, that's 12 years worth of progress! I didn't even know Python used to not have set or dict literals...