https://bugs.ruby-lang.org/https://bugs.ruby-lang.org/favicon.ico?17113305112009-12-23T00:19:30ZRuby Issue Tracking SystemRuby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=74112009-12-23T00:19:30Zshyouhei (Shyouhei Urabe)shyouhei@ruby-lang.org
<ul></ul><p>=begin<br>
Not a bug at least... Moved to the Feature tracker.<br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=84832010-02-28T21:24:42Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Rejected</i></li></ul><p>=begin<br>
Hi,</p>
<p>The feature was discussed in the thread from <a href="https://blade.ruby-lang.org/ruby-core/27242">[ruby-core:27242]</a>.<br>
In the thread, many English speaking people disagree this. So I close<br>
this ticket as "rejected".</p>
<p>If you still want this feature, please reopen with "some real use of<br>
select!" <a href="https://blade.ruby-lang.org/ruby-core/27323">[ruby-core:27323]</a>, or another convincing reason that beats<br>
English nuance.</p>
<p>--<br>
Yusuke Endoh <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=84992010-03-02T04:34:51Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<ul><li><strong>Status</strong> changed from <i>Rejected</i> to <i>Open</i></li></ul><p>=begin<br>
Hmm.</p>
<p>I personally have had uses for select! in the past, as others have as well.<br>
<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/27316" class="external">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/27316</a><br>
<a href="http://www.ruby-forum.com/topic/200640#875371" class="external">http://www.ruby-forum.com/topic/200640#875371</a></p>
<p>Currently we are forced to use reject! which is surprising...<br>
Think of select! as a destructive version of select, which currently doesn't exist in the std lib.</p>
<p>For example if you have this (albeit trivial) example :</p>
<p>a = some_large_array<br>
c = a.select{|b| b%2 == 1}</p>
<p>and then want to change this to a destructive select to the array, because it is very large, the first thing you try is</p>
<p>a.select!{|b| b %2 == 1}</p>
<p>But it surprisingly doesn't exist (reject has its destructive counterpart, map does too, but select doesn't), so you are forced to rewrite your boolean logic to use reject!</p>
<p>a.reject!{|b| (b%2) != 3}</p>
<p>which can be less readable, but more importantly--it is surprising to have to do so, at least to me.</p>
<p>It would be more convenient and less surprising to have a select!</p>
<p>Reopening.<br>
Thanks.<br>
-rp<br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85012010-03-02T05:04:05Zhgs (Hugh Sasse)hgs@dmu.ac.uk
<ul></ul><p>=begin<br>
On Tue, 2 Mar 2010, Roger Pack wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Array#select! (Closed)" href="https://bugs.ruby-lang.org/issues/2515">#2515</a> has been updated by Roger Pack.<br>
[...]<br>
Currently we are forced to use reject! which is surprising...<br>
[...]<br>
But it surprisingly doesn't exist (reject has its destructive<br>
[...]<br>
which can be less readable, but more importantly--it is surprising to have to do so, at least to me.</p>
<p>It would be more convenient and less surprising to have a select!</p>
</blockquote>
<p>You can use the "surprising" argument 4 or more times if you like, but<br>
since about 2005 Matz has said he will not accept changes<br>
based on the Principle Of Least Surprise, because it is his surprise<br>
that matters.<br>
<a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/144077" class="external">http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/144077</a></p>
<p>However, if you can build the case based on orthogonality, you may<br>
stand more of a chance. Possibly. I can't be certain.</p>
<pre><code> Hugh
</code></pre>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85042010-03-02T12:22:09Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi, Roger</p>
<p>Hugh Sasse wrote:</p>
<blockquote>
<p>On Tue, 2 Mar 2010, Roger Pack wrote:</p>
<blockquote>
<p>It would be more convenient and less surprising to have a select!</p>
</blockquote>
<p>You can use the "surprising" argument 4 or more times if you like, but<br>
since about 2005 Matz has said he will not accept changes<br>
based on the Principle Of Least Surprise, because it is his surprise<br>
that matters.</p>
</blockquote>
<p>I agree with Hugh.</p>
<p>In Ruby design, POLS is very unconvincing reason currently. Instead,<br>
it may make an enemy of committer.</p>
<a name="Anyone-should-know-that-many-committers-are-bored-with-suggestion"></a>
<h1 >Anyone should know that many committers are bored with suggestion<a href="#Anyone-should-know-that-many-committers-are-bored-with-suggestion" class="wiki-anchor">¶</a></h1>
<a name="based-on-POLS"></a>
<h1 >based on POLS.<a href="#based-on-POLS" class="wiki-anchor">¶</a></h1>
<p>In addition, consistency rarely beats name argument, AFAIK. I propose<br>
you find another reason.</p>
<p>I leave this ticket open for a couple of days. But I'll close again<br>
if discussion will seem to be still stalemated.</p>
<p>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85072010-03-02T14:39:38Zmarcandre (Marc-Andre Lafortune)marcandre-ruby-core@marc-andre.ca
<ul><li><strong>Category</strong> set to <i>core</i></li><li><strong>Target version</strong> set to <i>2.0.0</i></li></ul><p>=begin<br>
I would suggest that this feature request be extended to also introduce Array#keep_if.</p>
<p>Indeed, Enumerable#reject has two corresponding in-place Array methods: Array#delete_if and Array#reject!</p>
<p>I feel that Enumerable#select would benefit from also having two in-place Array methods: Array#keep_if and Array#select!</p>
<p>The same difference would apply: select! returns nil if no change is made.</p>
<p>I feel the name select! is as appropriate as map! , collect! and reject!<br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85132010-03-02T18:54:33Zsdsykes (Stephen Sykes)sdsykes@gmail.com
<ul></ul><p>=begin<br>
I agree with Marc-Andre, and also with his suggestion of keep_if.</p>
<p>I have sometimes wished for each of these methods, and it seems logical and reasonable that they should exist.</p>
<p>As for the names, I have reviewed the previous discussions, and I strongly suggest, as a native english speaker, that no-one will have any trouble understanding how select! or keep_if work. They are good and understandable names.</p>
<p>The use case for select! is clear. I quote from an example from the original discussion:</p>
<p>Code starts out as something like</p>
<p>result = collection.map { |x| ... }.select { |x| ... }</p>
<p>But then I might add code to the "map" part, and the code now extends<br>
over a few lines and looks poor if it's chained together. So it gets<br>
changed to:</p>
<p>result = collection.map { |x|<br>
...<br>
}<br>
result.select! { |x| ... }</p>
<p>+1 from me, a useful addition.</p>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85142010-03-02T19:45:53Zhgs (Hugh Sasse)hgs@dmu.ac.uk
<ul></ul><p>=begin<br>
I got tripped up by redmine there: I thought that was going off list,<br>
but while the name of the addressee was there, the address was the<br>
redmine one, which I didn't notice. I'd argue that is a misfeature.</p>
<p>I think the case for orthogonality is a much stronger one than POLS.<br>
select and reject are opposites, so having reject! and not select!<br>
is not orthogonal, to my mind.</p>
<p><a href="http://www.artima.com/intv/dry3.html" class="external">http://www.artima.com/intv/dry3.html</a></p>
<p>Roger's argument, it seems to me, is essentially that to achieve<br>
an effect in one direction it is straightforward, but in the other<br>
you have to interact either with another method, or with assignment,<br>
a = a.select(&blocK)<br>
a.reject!(&complementary_block)<br>
This is rather like the helicopter pilot in the above (artima.com) story,<br>
and there is a case for saying it makes the code less clear. It is<br>
a circumlocution.</p>
<p>I tend to use the assignment myself, though, because the ! signifier<br>
is a rather subtle thing, visually, for something destructive[1]. The<br>
assignment makes overwriting clearly apparent. However, that would<br>
be a case against almost all ! methods. So if destructive methods<br>
are idiomatic ruby, and if one may consider methods to be verbs, why<br>
make the language unnecessarily irregular, especially when all these<br>
reject, select, and map come from the same conceptual space of<br>
functional programming? [Of course, functional programming languages<br>
don't allow variables to change value, once bound...]</p>
<p>Is there a significant cost to adding this, and is it more then the<br>
cost of remembering the exceptions to the rules about which destructive<br>
methods exist? I've not looked at the source, yet, for this.</p>
<pre><code> Hugh
</code></pre>
<p>[1] To this same vision that failed to notice my message wasn't off<br>
list. That's why I used to use (<em>...</em>) comments in Pascal, in<br>
preference to {...}, because the printers back then made the star into<br>
a big splat. So I'm not saying Matz was wrong to choose this, I'm<br>
saying my tastes differ.</p>
<p>On Tue, 2 Mar 2010, Yusuke Endoh wrote:</p>
<blockquote>
<p>Issue <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Array#select! (Closed)" href="https://bugs.ruby-lang.org/issues/2515">#2515</a> has been updated by Yusuke Endoh.</p>
<p>Hi, Roger</p>
<p>Hugh Sasse wrote:</p>
<blockquote>
<p>On Tue, 2 Mar 2010, Roger Pack wrote:</p>
<blockquote>
<p>It would be more convenient and less surprising to have a select!</p>
</blockquote>
<p>You can use the "surprising" argument 4 or more times if you like, but<br>
since about 2005 Matz has said he will not accept changes<br>
based on the Principle Of Least Surprise, because it is his surprise<br>
that matters.</p>
</blockquote>
<p>I agree with Hugh.</p>
<p>In Ruby design, POLS is very unconvincing reason currently. Instead,<br>
it may make an enemy of committer.</p>
<a name="Anyone-should-know-that-many-committers-are-bored-with-suggestion"></a>
<h1 >Anyone should know that many committers are bored with suggestion<a href="#Anyone-should-know-that-many-committers-are-bored-with-suggestion" class="wiki-anchor">¶</a></h1>
<a name="based-on-POLS"></a>
<h1 >based on POLS.<a href="#based-on-POLS" class="wiki-anchor">¶</a></h1>
<p>In addition, consistency rarely beats name argument, AFAIK. I propose<br>
you find another reason.</p>
<p>I leave this ticket open for a couple of days. But I'll close again<br>
if discussion will seem to be still stalemated.</p>
<h2>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a>
</h2>
<p><a href="http://redmine.ruby-lang.org/issues/show/2515" class="external">http://redmine.ruby-lang.org/issues/show/2515</a></p>
<hr>
<p><a href="http://redmine.ruby-lang.org" class="external">http://redmine.ruby-lang.org</a></p>
</blockquote>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85342010-03-03T01:16:52Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>2010/3/2 Marc-Andre Lafortune <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>I feel the name select! is as appropriate as map! , collect! and reject!</p>
</blockquote>
<p>Some feel appropriate, and some inappropriate.<br>
Seems like "he said she said" scenario.<br>
Is there another reason than feeling and consistency (= orthogonality) ?</p>
<p>I'm almost neutral for the suggestion, but take a opposite point of view<br>
for the discussion. If I ignore Array#reject! and consider only the name<br>
"select!", I can imagine the different behavior. The name seems to me to<br>
return an array whose elements meet condition, and removes the <em>selected</em><br>
elements from the original array, like Array#delete_at and #shift:</p>
<p>ary = [1, 2, 3, 4, 5]<br>
p ary.select! {|x| x.even? } #=> [2, 4]<br>
p ary #=> [1, 3, 5]</p>
<p>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a><br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85372010-03-03T03:55:52Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<ul></ul><p>=begin<br>
Oh I see your argument now--that select! is too confusing of a name...</p>
<p>For me, though, it makes sense (given some background ruby knowledge), ex:</p>
<blockquote>
<blockquote>
<p>a = [1,2,3]<br>
a.select!{|b| b == 1}<br>
a<br>
=> [1]</p>
</blockquote>
</blockquote>
<p>This makes sense based on my knowledge of how reject and reject! work, map and map! work, etc. My thinking is that only more advanced Ruby programmers use ! methods, and they would probably already know that "! means a destructive change to self".</p>
<p>Is it too confusing?</p>
<p>Much thanks.</p>
<p>-rp<br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85382010-03-03T04:05:19Zhgs (Hugh Sasse)hgs@dmu.ac.uk
<ul></ul><p>=begin<br>
On Wed, 3 Mar 2010, Yusuke Endoh wrote:</p>
<blockquote>
<p>Hi,</p>
<p>2010/3/2 Marc-Andre Lafortune <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a>:</p>
<blockquote>
<p>I feel the name select! is as appropriate as map! , collect! and reject!</p>
</blockquote>
<p>Some feel appropriate, and some inappropriate.<br>
Seems like "he said she said" scenario.<br>
Is there another reason than feeling and consistency (= orthogonality) ?</p>
<p>I'm almost neutral for the suggestion, but take a opposite point of view<br>
for the discussion. If I ignore Array#reject! and consider only the name<br>
"select!", I can imagine the different behavior. The name seems to me to<br>
return an array whose elements meet condition, and removes the <em>selected</em><br>
elements from the original array, like Array#delete_at and #shift:</p>
<p>ary = [1, 2, 3, 4, 5]<br>
p ary.select! {|x| x.even? } #=> [2, 4]<br>
p ary #=> [1, 3, 5]</p>
</blockquote>
<p>I've been using Reek a lot recently. This makes me think of the<br>
"code smell" called "Greedy Method" in which a method is trying to<br>
do more than one thing. I think it would be difficult to remember<br>
which way round the outputs are: "Does the receiver get what the<br>
block selected, or the return value get it?"</p>
<p>This would break my metaphor of methods as verbs, and ! as a verb<br>
ending, which I've found helpful.</p>
<p>I can see such a function could have its uses, but even Python's<br>
filter() doesn't work like this, even accounting for the lack of<br>
blocks.</p>
<p>I'd be inclined to call such a thing ifelse, and allow it to be<br>
applied to objects which don't iterate, as well. It seems to be<br>
related to unfold, because it takes one thing and returns two (i.e.<br>
a list),</p>
<pre><code> Hugh
</code></pre>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85402010-03-03T04:23:03Zcoatl (caleb clausen)
<ul></ul><p>=begin<br>
I will also sign up as being in favor of adding this feature, perhaps with a different name, tho select! makes the most sense to me.<br>
=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85412010-03-03T04:24:23Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul></ul><p>=begin<br>
Hi,</p>
<p>In message "Re: <a href="https://blade.ruby-lang.org/ruby-core/28398">[ruby-core:28398]</a> [Feature <a class="issue tracker-2 status-5 priority-4 priority-default closed" title="Feature: Array#select! (Closed)" href="https://bugs.ruby-lang.org/issues/2515">#2515</a>] Array#select!"<br>
on Tue, 2 Mar 2010 14:39:39 +0900, Marc-Andre Lafortune <a href="mailto:redmine@ruby-lang.org" class="email">redmine@ruby-lang.org</a> writes:</p>
<p>|I feel the name select! is as appropriate as map! , collect! and reject!</p>
<p>Okay, okay. I understand your feeling.</p>
<p>|I would suggest that this feature request be extended to also introduce Array#keep_if.</p>
<p>The biggest reason (for me at least) was lack of counterpart of<br>
delete_if, so if keep_if could gain consensus, I'd agree with adding<br>
select! (and keep_if). I was thinking of delete_unless, but was not<br>
satisfied by the name.</p>
<pre><code> matz.
</code></pre>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85512010-03-03T12:49:20Zmame (Yusuke Endoh)mame@ruby-lang.org
<ul></ul><p>=begin<br>
Hi,</p>
<p>2010/3/3 Yukihiro Matsumoto <a href="mailto:matz@ruby-lang.org" class="email">matz@ruby-lang.org</a>:</p>
<blockquote>
<p>|I would suggest that this feature request be extended to also introduce Array#keep_if.</p>
<p>The biggest reason (for me at least) was lack of counterpart of<br>
delete_if</p>
</blockquote>
<p>It's a revelation... In <a href="https://blade.ruby-lang.org/ruby-core/27254">[ruby-core:27254]</a>, you only said the reason<br>
was the inappropriate name.</p>
<p>Anyway, good, I'm happy since the ticket will be closed positively :-)</p>
<p>+1 for keep_if</p>
<p>--<br>
Yusuke ENDOH <a href="mailto:mame@tsg.ne.jp" class="email">mame@tsg.ne.jp</a></p>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=85562010-03-03T14:37:05Zmatz (Yukihiro Matsumoto)matz@ruby.or.jp
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul><p>=begin<br>
This issue was solved with changeset r26800.<br>
Roger, thank you for reporting this issue.<br>
Your contribution to Ruby is greatly appreciated.<br>
May Ruby be with you.</p>
<p>=end</p> Ruby master - Feature #2515: Array#select!https://bugs.ruby-lang.org/issues/2515?journal_id=86132010-03-05T04:08:43Zrogerdpack (Roger Pack)rogerpack2005@gmail.com
<ul></ul><p>=begin<br>
Many thanks!<br>
-rp<br>
=end</p>