3 ms·
Even in Ruby, no one uses loops, they use Enumerable. Eliminates off-by-1 errors! Reduce (inject, etc.) are tricky to understand at first but once you do, you
by pmarreck 6y ago
Even in Ruby, no one uses loops, they use Enumerable. Eliminates off-by-1 errors!
Reduce (inject, etc.) are tricky to understand at first but once you do, you realize the power in it. Granted, it’s harder to understand than loops, but loops with iteration and mutability get you into a lot more trouble.
It sounds like you’re simply not over the learning curve yet.
- dragonwriter 6y ago> Even in Ruby, no one uses loops, they use Enumerable. Enumerable#each is quite deeply equivalent to a for…in loop. But no one uses for loops in Ruby because not only are they basically an alternate syntax for Enumerable#each, but they became non-idiomatic because in earlier versions (through at least 1.8.x, IIRC; I think this may have been resolved by the switch to YARV in 1.9) “for” had some implementation inefficiencies which made it notably slower than #each.