This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Less Blockage
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
As I'm sitting here, working on my own little suite of tests and benchmarks for the Array class, I've decided that I hate all methods that support blocks for the sole purpose of avoiding a call to Enumerable#map, and that's most of them. Actually, I decided that a while ago, but I thought I'd share it with you all. Because you care, right?
The main issue is that it's more work on the C side of the house, where you have to write (and maintain) code logic based on the various permutations of arguments to make sure the user does the right thing: Was a single argument passed? Ok, if a single argument was passed but not a block do X, but if a single argument was passed *and* a block was passed do Y. If a block was passed but not an argument do Z. Oh, and two arguments is acceptable, but then a block shouldn't be allowed. Oh, and BLAH, BLAH, fucking BLAH.
I've also decided that I hate Enumerable#inject. It's become the Ruby equivalent of Perl Golf, but instead of trying to find the shortest solution to a problem, people try to find the most clever use of inject to solve the problem.