Originally Posted by rnd me
I never denied that "sort algorithms may compare an element to itself [...] All i said was that zero never comes up on an Array of unique strings.
And that is exactly what I want you to think very carefully about. Even in an array of unique elements, if an algorithm compares an element to itself*, it will
*) Which does not mean comparing it to another element with the same value, it means comparing it to actually the very same object.
You keep asking for examples and maybe it will help to simply point out that I currently can't provide such an example. I will gladly admit that. However, that has never been my point. My point is that the implementation may change in the future, then
causing problems. It would be conform to ECMAScript definitions as it does say that the function has to return zero in case of equal elements, it never says that the compare function won't be called with the same element for both arguments.
the user-supplied sort function is not a low-level sort implementation.
otherwise, i'm pretty sure this code block would freeze the browser:
a violation to ECMAScript definitions. It typically just isn't a good idea to ignore the specifications you get from implementations you don't have access to.
In web development, we already live in a world full of quirks with every browser doing their own thing and only slowly coming to a common standard. Why add more violations to standards on top of that? Well, you did bring up one point: Performance. Agreed – that's an argument I can accept. However, I'd personally say that you should only violate the specification if performance is crucial at this point of your application (which it isn't in many cases), even if it may potentially break your code in the future.
Thanks for the correction, I don't know how that slipped past me when re-reading my post before submitting it. However, the glass house saying really doesn't make sense here. I never argued that there wasn't a mistake, nor did I say anything about anyone's grammar.