Array#sort() implementations not interoperable

Mark S. Miller erights at google.com
Thu Jun 13 09:09:20 PDT 2013


How would any test verify that a sort is unstable?


On Thu, Jun 13, 2013 at 8:56 AM, Kevin Gadd <kevin.gadd at gmail.com> wrote:

> I don't really care about the precise language or semantics. I just don't
> want applications to break in the wild because an Array.sort
> implementation's stability changes based on the number of elements. That
> feels like a much easier problem to solve than the problem of some browsers
> being unstable and some being stable. This is absolutely the sort of thing
> that would bite me as a JS dev and will bite every person who uses my
> compiler to convert an application. Why would they test with both small and
> large element counts?
>
> -kg
>
>
> On Thu, Jun 13, 2013 at 8:16 AM, Mark S. Miller <erights at google.com>wrote:
>
>> On Thu, Jun 13, 2013 at 7:01 AM, Kevin Gadd <kevin.gadd at gmail.com> wrote:
>>
>>> Even if stable sorts don't get required, it would make sense to require
>>> that a given implementation is either always stable or always not stable.
>>>
>>
>> How would such a requirement differ from the status quo? Doesn't the
>> current v8 impl satisfy it, since a sort that happens to be stable still
>> meets the requirements of an unstable sort? What does "always not stable"
>> mean?
>>
>>
>>
>>
>>> The current situation with V8 seems likely to result in subtly broken
>>> software shipping to the web, where it works in testing environments with
>>> small amounts of data and then breaks in the wild only on certain browsers
>>> and only if you have a certain amount of data. Yuck.
>>>
>>> -kg
>>>
>>>
>>> On Thu, Jun 13, 2013 at 6:05 AM, Mathias Bynens <mathias at qiwi.be> wrote:
>>>
>>>> Bumping this old thread since V8 issue #90 (
>>>> https://code.google.com/p/v8/issues/detail?id=90) has been getting
>>>> lots of comments lately.
>>>>
>>>> It appears that unstable sort, while perfectly spec-compliant, doesn’t
>>>> match user expectations. It doesn’t help that some browsers/engines _do_
>>>> use a stable sorting algorithm, while others don’t — which surprises people
>>>> and occasionally breaks (badly-written, but hey) code. (See the thread I
>>>> linked to for examples.) Then, there’s V8, which uses stable sort for small
>>>> arrays with 10 or fewer elements, but an unstable sorting algorithm for
>>>> larger arrays, causing even more confusion.
>>>>
>>>> Here’s a test case that tests arrays of varying sizes:
>>>> http://ofb.net/~sethml/is-sort-stable.html The results in different
>>>> browsers are listed, too.
>>>>
>>>> IMHO it would be nice if ES would require a stable sorting algorithm:
>>>> it would match user expectations, cause fewer issues in existing code, and
>>>> improve operability in general.
>>>>
>>>> What would be the best way to make TC39 consider this change?
>>>>
>>>> _______________________________________________
>>>> es-discuss mailing list
>>>> es-discuss at mozilla.org
>>>> https://mail.mozilla.org/listinfo/es-discuss
>>>>
>>>
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> es-discuss at mozilla.org
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>>
>> --
>>     Cheers,
>>     --MarkM
>>
>
>


-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130613/d3addcd3/attachment-0001.html>


More information about the es-discuss mailing list