From: Michael Neumann Date: 2004-09-30T23:18:37+09:00 Subject: Re: Too Many Ways? Gavin Kistner wrote: > On Sep 30, 2004, at 7:12 AM, Chris Pine wrote: > >> (Yes, if you are teaching Ruby to a functional programmer, you use map >> instead of collect (are those really the same? I just always avoided >> collect: wrong english word, I think), but you still teach them only >> *one* of them.) > > > Funny, I never understood what #map did. People used it all the time and > it baffled me. I kept saying "I should learn this method, because people > keep showing how to use it for powerful, terse solutions, but...I'm > baffled." How would you feel if you were forced to use #map all the time? That's why I think it's good that Ruby follows TMTOWTDI. Python for example AFAIK only provides map() and #collect comes from Smalltalk, I think. Now, everyone from both worlds feel happy in Ruby ;-) Of course when reading others' sourcecodes you'll get into trouble. But I don't as often as I write new code. > Then someone showed me the #collect method, and I fell in love. It's > awesome. I extended arrays in Javascript to use it, I love it so much. > > ...it was a week later than I pulled up the documentation and saw that > they're the same thing. Something about 'map' made absolutely no sense > to me (it implies a hash-like permanent connection between the old and > the new), and collect made perfect sense (go traipsing through the > entire field of daisies, picking up only the best ones). > > So if we were deprecating duplicates, I vote to get rid of #map. > (This is the part where 100 rubyists say "No! #collect sucks, #map is > king!" and my entire argument for less duplication is shot down by the > fact that people like different things.) Well, of course both #map and #collect behave in the same way, but I'm not sure I use both of them in the same way! That's a bit similar to "{...}" and "do ... end" block, which are similar but used by some people in different situations. I think, I use #map when the result is short and very similar to the source (e.g. {|a| a+1}), and #collect if it spans multiple lines and the calcluation is big. Regards, Michael