> this looks like a really broken implementation over weak typing
No dammit, javascript does not coerce numbers to strings when comparing them, a "weak typing" implementation would behave exactly as he wants.
> What OP was probably annoyed by was the typical excuse the JS community offers for this behaviour: "it's weakly-typed so you can treat the arguments as anything you want".
That makes OP fractally wrong instead of merely broadly wrong.
> avoiding the verbosity typical of strongly-typed languages (where you have to specify the comparison function with the correct type signature)
Which you don't, not every language is Java and some actually have defaults. Which work. In fact, even in Java bloody java you don't have to provide a comparator to sort a list, as long as the list's items implement Comparable (that is, they can be compared to one another)
> No dammit, javascript does not coerce numbers to strings when comparing them, a "weak typing" implementation would behave exactly as he wants.
Please note that I wrote it's a broken implementation over weak typing, not of weak typing. The typing system is fine, at least as far as this matter is concerned, but the standard library is badly applied over it.
> Please note that I wrote it's a broken implementation over weak typing, not of weak typing.
But weak typing is a complete red herring, as I noted previously the behaviour of the default sort function is independent from the typing system, you could have a default sort function doing more or less the same thing in a very strict statically typed system.
Haskell's `sort` is defined (more or less) as
sort :: Ord a => [a] -> [a]
sort = sortBy compare
it could be (uselessly) defined as
sort :: Show a => [a] -> [a]
sort = sortBy (comparing show)
resulting in the same behaviour you see in javascript.
Yes, of course it is a red herring! OP's rage was against the JS community taking it as an excuse for shity implementation, that's all I was trying to clarify...
No dammit, javascript does not coerce numbers to strings when comparing them, a "weak typing" implementation would behave exactly as he wants.
> What OP was probably annoyed by was the typical excuse the JS community offers for this behaviour: "it's weakly-typed so you can treat the arguments as anything you want".
That makes OP fractally wrong instead of merely broadly wrong.
> avoiding the verbosity typical of strongly-typed languages (where you have to specify the comparison function with the correct type signature)
Which you don't, not every language is Java and some actually have defaults. Which work. In fact, even in Java bloody java you don't have to provide a comparator to sort a list, as long as the list's items implement Comparable (that is, they can be compared to one another)