ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:91957] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
       [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
@ 2019-03-23 10:13 ` s
  2019-03-23 14:03 ` [ruby-core:91958] " shevegen
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: s @ 2019-03-23 10:13 UTC (permalink / raw
  To: ruby-core

Issue #15725 has been reported by sikachu (Prem Sichanugrist).

----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725

* Author: sikachu (Prem Sichanugrist)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`, `#reverse_sort_by`, and `#reverse_sort_by!` to Array.

These methods provides the most efficient way for user to get a reversed sorted array by calling `sort(_by)` then `.reverse!`.

As a language designer, I believe that we should suggest the most efficient way to perform a certain action to user. By introduce these methods, we can discourage user to use them instead of do `array.sort.reverse` or `array.sort {|a,b| b<=>a}` which are less performant.

I've looked through Redmine, and I saw that there was a proposal to introduce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422, but was somewhat rejected due to the complication with infinite Enumerable. Given that Array is finite, I think this is the best place for these methods to be implemented.

I've attached a patch to implement these methods based on other `ary_sort` related methods. Please let me know your thought on how I could improve them to be mergeable, as I am not proficient in writing C.

I'm looking forward to hear your thoughts about this proposal. Thank you very much.

---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:91958] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
       [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
  2019-03-23 10:13 ` [ruby-core:91957] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by! s
@ 2019-03-23 14:03 ` shevegen
  2019-05-27  0:53 ` [ruby-core:92852] " s+ruby
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2019-03-23 14:03 UTC (permalink / raw
  To: ruby-core

Issue #15725 has been updated by shevegen (Robert A. Heiler).


As this is a duplicate it may be best to discuss it in #12648.

I have not yet commented so just briefly; I am mostly neutral, can see 
both ways. I think a slight problem is that the method names can be
a bit long and clumsy, especially #reverse_sort_by! - this is in my 
opinion a bit too long.

I am also not completely sure whether we really need it. I myself usually
use .sort and .sort_by, and then apply .reverse afterwards. But I can also
understand people wanting to do all in one go; we just should see that the
method names are useful, if this is approved that is (see what matz wrote
in the other issue). But again, I have no real strong preference either
way.

----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725#change-77292

* Author: sikachu (Prem Sichanugrist)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`, `#reverse_sort_by`, and `#reverse_sort_by!` to Array.

These methods provides the most efficient way for user to get a reversed sorted array by calling `sort(_by)` then `.reverse!`.

As a language designer, I believe that we should suggest the most efficient way to perform a certain action to user. By introduce these methods, we can discourage user to use them instead of do `array.sort.reverse` or `array.sort {|a,b| b<=>a}` which are less performant.

I've looked through Redmine, and I saw that there was a proposal to introduce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422, but was somewhat rejected due to the complication with infinite Enumerable. Given that Array is finite, I think this is the best place for these methods to be implemented.

I've attached a patch to implement these methods based on other `ary_sort` related methods. Please let me know your thought on how I could improve them to be mergeable, as I am not proficient in writing C.

I'm looking forward to hear your thoughts about this proposal. Thank you very much.

---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:92852] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
       [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
  2019-03-23 10:13 ` [ruby-core:91957] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by! s
  2019-03-23 14:03 ` [ruby-core:91958] " shevegen
@ 2019-05-27  0:53 ` s+ruby
  2019-06-13  5:54 ` [ruby-core:93087] " matz
  2019-06-13  6:41 ` [ruby-core:93092] " duerst
  4 siblings, 0 replies; 5+ messages in thread
From: s+ruby @ 2019-05-27  0:53 UTC (permalink / raw
  To: ruby-core

Issue #15725 has been updated by sikachu (Prem Sichanugrist).


Thank you for your initial feedback. I would like to quote one thing:

> I myself usually use .sort and .sort_by, and then apply .reverse afterwards.

That's definitely the reason why I submit this proposal, because `array.sort.reverse` will actually create new Array twice, meanwhile `reverse!` will just flip the array in-place and is a better way memory-wise. These methods will suggest programmers the most efficient way to do thing when they want to sort and reverse and Array, as I describe in the description of the ticket.

One alternative other than introducing these methods: I wonder if we can detect if a result of a sort operation is being passed to `reverse` right away in the chain, (e.g. detect if user is doing `array.sort.reverse`) and doing a in-place reverse instead. That seems complicated though, and I don't have enough knowledge of the interpreter to know if that sort of thing is possible.

----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725#change-78233

* Author: sikachu (Prem Sichanugrist)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`, `#reverse_sort_by`, and `#reverse_sort_by!` to Array.

These methods provides the most efficient way for user to get a reversed sorted array by calling `sort(_by)` then `.reverse!`.

As a language designer, I believe that we should suggest the most efficient way to perform a certain action to user. By introduce these methods, we can discourage user to use them instead of do `array.sort.reverse` or `array.sort {|a,b| b<=>a}` which are less performant.

I've looked through Redmine, and I saw that there was a proposal to introduce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422, but was somewhat rejected due to the complication with infinite Enumerable. Given that Array is finite, I think this is the best place for these methods to be implemented.

I've attached a patch to implement these methods based on other `ary_sort` related methods. Please let me know your thought on how I could improve them to be mergeable, as I am not proficient in writing C.

I'm looking forward to hear your thoughts about this proposal. Thank you very much.

---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:93087] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
       [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2019-05-27  0:53 ` [ruby-core:92852] " s+ruby
@ 2019-06-13  5:54 ` matz
  2019-06-13  6:41 ` [ruby-core:93092] " duerst
  4 siblings, 0 replies; 5+ messages in thread
From: matz @ 2019-06-13  5:54 UTC (permalink / raw
  To: ruby-core

Issue #15725 has been updated by matz (Yukihiro Matsumoto).

Status changed from Open to Rejected

Those methods do not make me feel 'spark joy'. If you really care about the performance, use `reverse!` after `sort!`.

Matz.

----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725#change-78509

* Author: sikachu (Prem Sichanugrist)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`, `#reverse_sort_by`, and `#reverse_sort_by!` to Array.

These methods provides the most efficient way for user to get a reversed sorted array by calling `sort(_by)` then `.reverse!`.

As a language designer, I believe that we should suggest the most efficient way to perform a certain action to user. By introduce these methods, we can discourage user to use them instead of do `array.sort.reverse` or `array.sort {|a,b| b<=>a}` which are less performant.

I've looked through Redmine, and I saw that there was a proposal to introduce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422, but was somewhat rejected due to the complication with infinite Enumerable. Given that Array is finite, I think this is the best place for these methods to be implemented.

I've attached a patch to implement these methods based on other `ary_sort` related methods. Please let me know your thought on how I could improve them to be mergeable, as I am not proficient in writing C.

I'm looking forward to hear your thoughts about this proposal. Thank you very much.

---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)


-- 
https://bugs.ruby-lang.org/

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:93092] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
       [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-06-13  5:54 ` [ruby-core:93087] " matz
@ 2019-06-13  6:41 ` duerst
  4 siblings, 0 replies; 5+ messages in thread
From: duerst @ 2019-06-13  6:41 UTC (permalink / raw
  To: ruby-core

Issue #15725 has been updated by duerst (Martin Dürst).


Clarified that .reverse! can/should be used for reverse order with commit  2a26c1ea24..7f79a86d8b.

----------------------------------------
Feature #15725: Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by!
https://bugs.ruby-lang.org/issues/15725#change-78514

* Author: sikachu (Prem Sichanugrist)
* Status: Rejected
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Hello,

I would like to propose four new methods: `#reverse_sort`, `#revert_sort!`, `#reverse_sort_by`, and `#reverse_sort_by!` to Array.

These methods provides the most efficient way for user to get a reversed sorted array by calling `sort(_by)` then `.reverse!`.

As a language designer, I believe that we should suggest the most efficient way to perform a certain action to user. By introduce these methods, we can discourage user to use them instead of do `array.sort.reverse` or `array.sort {|a,b| b<=>a}` which are less performant.

I've looked through Redmine, and I saw that there was a proposal to introduce a similar method to Enumerable in https://bugs.ruby-lang.org/issues/8422, but was somewhat rejected due to the complication with infinite Enumerable. Given that Array is finite, I think this is the best place for these methods to be implemented.

I've attached a patch to implement these methods based on other `ary_sort` related methods. Please let me know your thought on how I could improve them to be mergeable, as I am not proficient in writing C.

I'm looking forward to hear your thoughts about this proposal. Thank you very much.

---Files--------------------------------
0001-Add-Array-reverse_sort-reverse_sort_by-methods.patch (6.29 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-06-13  6:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <redmine.issue-15725.20190323101355@ruby-lang.org>
2019-03-23 10:13 ` [ruby-core:91957] [Ruby trunk Feature#15725] Proposal: Add Array#reverse_sort, #revert_sort!, #reverse_sort_by, and #reverse_sort_by! s
2019-03-23 14:03 ` [ruby-core:91958] " shevegen
2019-05-27  0:53 ` [ruby-core:92852] " s+ruby
2019-06-13  5:54 ` [ruby-core:93087] " matz
2019-06-13  6:41 ` [ruby-core:93092] " duerst

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).