Hacker News new | ask | show | jobs
by weatherlight 856 days ago
ruby does too. its not remotely the same
1 comments

What are you saying isn’t the same? This is a very hostile, dismissive response when I was simply pointing out Python had a similar concept in the hopes it might help the person understand something they said confused them.

As far as I can tell all three languages, Python, Elixir, Ruby, have pattern matching and the matching can set variables. Python’s has a “match” keyword. I’m not as familiar with Ruby, but I know it uses “case”.

I like Elixir’s the best because it’s not just what I would call a fancy switch statement. You can use it on single lines and in function definitions. Someone else might like a different form of pattern matching better. It’s just an opinion.

Pattern matching is fundamental to programming in elixir/Erlang the way go channels are in Go and super clean metaprogramming interfaces are in Ruby or types are in Haskell etc, you can do those things in other languages but when it's fundamental to the design of the language itself it filters down (or up) to every layer, where it significantly impacts how useful/powerful it is.

Elixirs pattern matching is the one thing I wish every language had from day one. Besides maybe an Optional/Maybe concept for error handling / data enclosures.

It makes for some very readable code and encourages passing return values that are easily consumed in a simple/functional way. Not capturing random error objects or unpredictable data structures.

Although I'm biased towards functional style, even though I code JS/Ruby for a living.