From: Hugh Sasse Date: 2010-03-03T04:05:03+09:00 Subject: [ruby-core:28426] Re: [Feature #2515] Array#select! On Wed, 3 Mar 2010, Yusuke Endoh wrote: > Hi, > > 2010/3/2 Marc-Andre Lafortune : > > I feel the name select! is as appropriate as map! , collect! and reject! > > Some feel appropriate, and some inappropriate. > Seems like "he said she said" scenario. > Is there another reason than feeling and consistency (= orthogonality) ? > > I'm almost neutral for the suggestion, but take a opposite point of view > for the discussion. If I ignore Array#reject! and consider only the name > "select!", I can imagine the different behavior. The name seems to me to > return an array whose elements meet condition, and removes the *selected* > elements from the original array, like Array#delete_at and #shift: > > ary = [1, 2, 3, 4, 5] > p ary.select! {|x| x.even? } #=> [2, 4] > p ary #=> [1, 3, 5] I've been using Reek a lot recently. This makes me think of the "code smell" called "Greedy Method" in which a method is trying to do more than one thing. I think it would be difficult to remember which way round the outputs are: "Does the receiver get what the block selected, or the return value get it?" This would break my metaphor of methods as verbs, and ! as a verb ending, which I've found helpful. I can see such a function could have its uses, but even Python's filter() doesn't work like this, even accounting for the lack of blocks. I'd be inclined to call such a thing ifelse, and allow it to be applied to objects which don't iterate, as well. It seems to be related to unfold, because it takes one thing and returns two (i.e. a list), Hugh