Live data from Hacker News

Pattern Matching in Ruby 2.7 (2019)

speakerdeck.com

81–90 of 110 posts

Re: Pattern Matching in Ruby 2.7 (2019)

#81
post #11

Earlier quoted context omitted.

Hmmm. I'm definitely in favor of more functional programming features / capabilities, particularly in a language like Ruby that allows for pretty effective mixing of OOP/functional paradigms. Right tool for the job, where the job is usually "communicating with other programmers what this code should do". I've always found Ruby to be an amazing mix of functional & OOP already, what with blocks, and that class definiti…

Ruby blocks are another example of something that looks like a functional programming feature but is actually not. As in Java 8 and C++11, which also added lambdas, it doesn't have much in common with FP lambdas. These are essentially syntax sugar for an ad-hoc function that's too small to factor our and give a name. FP lambdas are the most elementary unit of computation. You're supposed to be doing absolutely everyt…

> [Java 8 and C++11 lambdas] are essentially syntax sugar for an ad-hoc function

that's what a lambda is pretty much anywhere, FP or not :)

> [in FP] you're supposed to be doing absolutely everything with lambdas even addition

in imperative programming, are you supposed to be doing everything by writing symbols to a moving tape, a la Turing? there's more to FP than pure lambda calculus, even if it was the starting point.

sure, natural numbers and other types can be implemented with lambdas. no serious FP language actually does that.

Re: Pattern Matching in Ruby 2.7 (2019)

#82
I'm 80% in favour of this change. JSON parsing is tedious and this looks like it will help pretty cleanly on something that rubyists do quite frequently. I could also see myself using this pretty frequently elsewhere.

That said, I do see some minor drawbacks:

1. I personally find the case statement in ruby confusing. It uses === which I find hard to use without stopping and thinking.

2. I don't understand why the bitwise or operator is being used for the pattern matcher or. Was it not possible to just use `or` itself?

3. Deconstruct keys reads a bit weird. Easy enough to understand and remember, but I can imagine being new to ruby or programming and finding the pattern matching pretty hard to follow.

Re: Pattern Matching in Ruby 2.7 (2019)

#83
post #12

...semi off-topic, but man, how I wish Ruby had won the hearts of data-science and machine-learning practitioners instead of Python or R! It looks like such a wonderful and extensible and programmer friendly language compared to all the others in the "multi-purpose dynamic 'scripting' languages class". Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in, so sad it…

I agree with this. I did rails for a long time and honestly became pretty disenchanted on Ruby as a web services platform. But now that I interact with data analyses in Python fairly regularly (because they are everywhere) I really miss Ruby. I wish Ruby had landed on a different killer app!

Re: Pattern Matching in Ruby 2.7 (2019)

#84
I used both Python and Ruby extensively for a while, love both, but Ruby was just nicer to code in. The problem for me was the much smaller ecosystem, especially for anything numerical/data related. Numpy was, pre Pandas days, the killer library for the type of work I do.

Re: Pattern Matching in Ruby 2.7 (2019)

#85
post #12

...semi off-topic, but man, how I wish Ruby had won the hearts of data-science and machine-learning practitioners instead of Python or R! It looks like such a wonderful and extensible and programmer friendly language compared to all the others in the "multi-purpose dynamic 'scripting' languages class". Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in, so sad it…

Does Julia scratch that itch now?

Re: Pattern Matching in Ruby 2.7 (2019)

#86

Do we have something similar in python, if not I am going to make one.

There is this: https://github.com/grantjenks/python-pattern-matching

This project is just someone wrote a proposal or something. Here is actually implemented pattern matching as a library https://github.com/santinic/pampy

Re: Pattern Matching in Ruby 2.7 (2019)

#88
post #12

...semi off-topic, but man, how I wish Ruby had won the hearts of data-science and machine-learning practitioners instead of Python or R! It looks like such a wonderful and extensible and programmer friendly language compared to all the others in the "multi-purpose dynamic 'scripting' languages class". Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in, so sad it…

> Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in

Compared to Haskell, its performance is not good. Same with J for that matter.

Re: Pattern Matching in Ruby 2.7 (2019)

#89
post #12

...semi off-topic, but man, how I wish Ruby had won the hearts of data-science and machine-learning practitioners instead of Python or R! It looks like such a wonderful and extensible and programmer friendly language compared to all the others in the "multi-purpose dynamic 'scripting' languages class". Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in, so sad it…

Same! I never used Rails much but did learn Ruby and used it a lot for the kind of stuff people tend to use Python for nowadays. Data crunching, prototyping, sciency stuff.. It's excellent for that. I mean, Ruby is so much more elegant and consistent than Python, I'll never understand how Python became the more widely appreciated language of the two, especially with the effective head start that Ruby had through Rail…

>I'll never understand how Python became the more widely appreciated language of the two

NumPy, maybe? Lots of resources make it easy to get small impressive projects off the ground quickly.

Re: Pattern Matching in Ruby 2.7 (2019)

#90
post #17
post #12

...semi off-topic, but man, how I wish Ruby had won the hearts of data-science and machine-learning practitioners instead of Python or R! It looks like such a wonderful and extensible and programmer friendly language compared to all the others in the "multi-purpose dynamic 'scripting' languages class". Every time I read Ruby code it almost puts a smile on my face, it seems such a joy to write and think in, so sad it…

I shudder to think what datascience code would look like if a language with a culture of monkeypatching/metaclassing had won. Clear code is nice, but not when the price is sweeping all of the details too deeply under the carpet.

I don't think OP is talking about metaprogramming, but more about syntax and how ergonomic Enumerable chains are, which I can see being really nice in data wrangling.
Post reply on HN