2 ms·
It's certainly not, although it can be used in switch cases. Pattern matching is a great language feature but I've been watching the development of it for Pyth
by cassianoleal 6y ago
It's certainly not, although it can be used in switch cases.
Pattern matching is a great language feature but I've been watching the development of it for Python for a while and have felt nothing but horror.
If you want a great example of how it can be useful and how clear and elegant it can be, check out how it's done in Elixir [0].
There are many other languages that implement it in great ways, I'm sure others will comment on them.
[0] https://elixir-lang.org/getting-started/pattern-matching.html https://elixir-lang.org/getting-started/pattern-matching.htm...
- sammorrowdrums 6y agoYes,oddly I love it I Rust, it is probably a favourite feature, but I am not really excited about it in Python. https://doc.rust-lang.org/book/ch06-02-match.html https://doc.rust-lang.org/book/ch06-02-match.html
- aynyc 6y agoLooking at the examples in the doc. That’s just tuple/list unpacking in Python. Am I misreading it?
- ketzu 6y agoThe linked doc seems to show only what python does as tuple unpacking, but as far as I know elixir can also do the matched unpacking. Based on [1] (which also gives a more matchy example), elixir just has a warning when not using the variable in the case block and you can denote that you want to match against the contents of the variable by prepending ^. [1] https://www.reddit.com/r/programming/comments/lgqhmj/stack_overflow_users_rejoice_as_pattern_matching/gmtypn2/ https://www.reddit.com/r/programming/comments/lgqhmj/stack_o...
- fortran77 6y ago> If you want a great example of how it can be useful and how clear and elegant it can be, check out how it's done in Elixir [0]. If you want to see what it _really_ should look like, see Erlang, and then look at Prolog.