News for hackers. Stuff that matters.
Re:Shopify invests in research for Ruby at scale by bin_bash on Monday May 16, 2022 @05:20PM (#31403257)
The amount of times in my career where the performance would be even measurable between these 2 styles is vanishingly few. If I cared I could just use #filter_map or a classic for-each loop. If we're assuming the project is written in Ruby in the first place, clearly we're not valuing performance that highly.

The more important thing is the ruby version is chainable and more readable—and that matters far more often.

Re:Shopify invests in research for Ruby at scale by gkop on Tuesday May 17, 2022 @12:19AM (#31405989)
You had me until

> more readable

Without having more context, User in your code is possibly an ActiveRecord class, so to read the #select, you have to consider that it could be radically different and heavier than Enumerable#select (eg. it may execute a DB query as a side effect). So I like your example still, because it’s representative, and certainly expressive, but not readable per se. IMO this sin here is simply that ActiveRecord shouldn’t have overloaded select.

Re:Shopify invests in research for Ruby at scale by bin_bash on Tuesday May 17, 2022 @04:23AM (#31407462)
That’s more of an argument against ORMs which I realize my example used. I was mostly trying to convey using map/filter against POROs though.

Using an ORM was a poor choice on my part. I agree the magic there does harm readability since it makes it a lot harder to understand what it really is doing.