HNHacker News
TopNewBestAskShowJobs

my_new_account0

-1 karma · joined August 20, 2023

submissionscomments
my_new_account0··on Ruby's hash is a Swiss-army knife
Unless things have changed and Ruby has stream fusion now, this is bad advice for scale. You are iterating over a fat object multiple times. Even if its uglier its much better in this case to create an empty array/hash, iterate over with #each and #<< to the hash.

I worked at the largest Rails shop in the world and this would be rejected in code review.

Edited to add more detail: the only method you need to write to implement Enumerable is #each. Every step of your pipeline here is _another_ call to #each. Just do it once.

my_new_account0··on Ruby's hash is a Swiss-army knife
Yes. The OP's post is basically "baby's first API." The are a very handy API but relying on them at scale is much less efficient than structs or arrays. This post doesn't even go into the different performance characters of these APIs, which can be a major foot gun.

I've noticed a lot of novice-level posts on here lately. Although I admit the post was very well written.