ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: shevegen@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95744] [Ruby master Feature#1089] Stable sorting for sort and sort_by
Date: Thu, 07 Nov 2019 16:00:16 +0000 (UTC)	[thread overview]
Message-ID: <redmine.journal-82562.20191107160015.26aa37d436152a02@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-1089.20090202163243@ruby-lang.org

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


sawa wrote:

> Do you really mean it's sad? Or do you mean it's said?

I think he meant "sad", rather than "said", possibly due to the desire (by a ruby user)
to see that ruby behaves in the same way across different operating systems - at the
least this is what I think rogerdpack meant. :)

I myself have no particular pro/con opinion on the issue; it may be better to create
a new one, in the event that people feel strongly about it (11 years ago is quite a
long time). I can, however had, understand that ruby users would like to see ruby 
behaves in the same way whenever they use it. In that sense, ruby abstracts away
complexities and oddities of different platforms - that is convenient for a user.

I think matz and the core team also have that goal, in the sense that I remember
suggestions that were rejected in the past if it would have led to different 
behaviour on different operating systems (or disparate features, e. g. things
that would only work on linux+ruby, but not on windows+ruby or mac+ruby).

To sorting in general: some time ago the insert-order remained the same for
hashes, so that "first-in" or "last-in" could be distinguished for free. I
liked that addition. Whenever I use .each_pair on a hash, I know that the
more recent additions will, by default, appear at the "end" of the output,
if we use e. g. .each_pair combined with puts/print output. I think that
was a good change - we sort of gain additional information for free, which
can be helpful sometimes. So I think that was convenient.

On the particular issue here, I have no particular opinion, but I also think
that both murphy and rogerdpack made good points. Even then I think it is 
better to make a new proposal, as naruse suggested back then (sorry for
commenting on that old issue as well). Matz objection was very much in 
regards to speed/slow-downs, so I think new proposals should consider
any speed trade-off as well, if it may affect other ruby users and their
code.

----------------------------------------
Feature #1089: Stable sorting for sort and sort_by
https://bugs.ruby-lang.org/issues/1089#change-82562

* Author: murphy (Kornelius Kalnbach)
* Status: Rejected
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 
----------------------------------------
=begin
 I'd like to have stable sorting in Ruby. Stable sorting means that if two items are ==, they will retain their order in the list after sorting. In other words, stable sort does never switch two equal items.
 
 In Ruby 1.9.1, you'd have to use something like
 
   enum.sort_by.with_index { |a, i| [a, i] }
 
 to achieve a stable sort in Ruby.
 
 It would also be nice to minimize the number of comparisons, since method calling is expensive in Ruby.
 
 Python is using a highly optimized implementation of a variant of merge sort, which is stable and uses very few comparisons (called Timsort after Tim Peters); maybe Ruby can adopt it for sort and sort_by:
 
   http://svn.python.org/projects/python/trunk/Objects/listsort.txt
 
 Introducing stable sorting would not be a problem for old code because the order of equal items after sorting is currently not specified.
=end




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

      parent reply	other threads:[~2019-11-07 16:00 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-1089.20090202163243@ruby-lang.org>
2019-05-02 16:56 ` [ruby-core:92527] [Ruby trunk Feature#1089] Stable sorting for sort and sort_by jonathan
2019-11-07  3:58 ` [ruby-core:95736] [Ruby master " rogerpack2005
2019-11-07  4:29 ` [ruby-core:95737] " sawadatsuyoshi
2019-11-07 16:00 ` shevegen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.journal-82562.20191107160015.26aa37d436152a02@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).