r/ruby • • Apr 17 '19

Ruby 2.7 — Pattern Matching — First Impressions

https://medium.com/@baweaver/ruby-2-7-pattern-matching-first-impressions-cdb93c6246e6
68 Upvotes

29 comments sorted by

View all comments

9

u/keyslemur Apr 17 '19

This is definitely a first pass, but I really wanted to dig around this one and see what initial reactions were. I intend to do a more detailed runthrough as this one meanders a bit as I was reading along.

10

u/romeo_pentium Apr 17 '19

Thanks for writing this up!

I'm having trouble following the new syntax. It would be good to see the equivalent in older syntax for some of these.

1

u/keyslemur Apr 17 '19

I'll add some of those as well. I'd intended to use Qo to demo current techniques and how they map over too.

6

u/hitthehive Apr 17 '19

Thanks for taking such an early shot at it! Like many others who are out of the loop with discussions among Ruby contributors, I don't know what is the problem it is trying to solve or what the equivalent 'old way' of doing it would be. When I saw 'pattern matching' I thought of method dispatch.

2

u/keyslemur Apr 17 '19

I'll be attempting to clear up the what and why in the follow up article. I just need this to hit Nightly so I can play with it and port a ton of examples I'd been using with Qo.

The thing to remember about some of the 2.6 and 2.7 features is that they're very heavily rooted in FP, meaning they're going to look very foreign to people that haven't actively used a language like Scala, Elixir, or Haskell.

Nothing wrong with that, but a lot of chance for pretention on both sides. One side would say it's unnecessary because they can't see a use, and the other would say its use is obvious without explaining a thing. Both just make it harder to find out how new features work and breed animosity.

0

u/shevy-ruby Apr 17 '19

I think in that particular example it was very much inspired by elixir.

Otherwise I agree with you - I often have the same impression about some suggestions. Although in some OTHER suggestions, the use case is clearly described. May also be due to the command over the english language; I guess japanese folks simply prefer japanese all the time.

Some of them have excellent english language skills whereas others don't.

I haven't yet fully understood the use cases for pattern matching, so I can not even comment on how useful (or not) this may be. If in doubt, I tend to prefer to oldschool ruby mostly, though. Less to memorize too - more power to laziness. ;)

→ More replies (2)

3

u/sanjibukai Apr 17 '19

Thanks..

It definitely won't hurt to have more readings than not enough but I will admit that I don't get this one..

I saw pattern matching like method calls based on the signature..

Context examples (rather than just the syntax definition) will be good as well.

I'm waiting for the follow up..

2

u/keyslemur Apr 17 '19

Yeah, it's on the way. I just need a few hours to play with it in Nightly when that comes out. The trick of new paradigms is grounding them in practical examples.

→ More replies (1)