Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'm pretty sure that the parent comment's author is aware of this. It does not change the fact that it's broken.


I don't know - it's just a default general API, obviously it's not going to match everyone's use case. I would say that even relying on sort made by someone else is already not fit for many use cases.

If such a petty and trivial "problem" is what you have against Javascript, then you are basically saying it's a good language :--)


Or you're saying that you know so little about it you don't know of its real problems.


Yet somehow it works just fine out of the box in plenty of other languages, including Python, Erlang, Clojure, Ruby, etc.


Yeah, plus it's not just thing one thing, but there is a good amount of seemingly little things like this that add up.


Why? Sorting strings is a far more common thing to do than just sorting numbers, so it makes sense to use simple string comparisons as the default algorithm. Rather than come up with something that first evaluates the types in the list and then tries to figure out what to do.


No, it makes sense to sort strings when you get handed strings, and sort numbers when handed numbers. Period. Default behavior is now exactly as expected by 100% of developers.

Your creativity as a language designer should only come in to play when dealing with sets of mixed type.


So how should [1, "a", 2, 3] be sorted by default?


Both Python and Erlang would return [1,2,3,"a"], Ruby and Clojure won't allow the comparison. Either of these approaches makes more sense than JavaScript's.


Javascript returns [1,2,3,a]. What's the problem.


    > [1,2,"10",3].sort()
    [ 1, '10', 2, 3 ]
That's the problem.


Not when I posted this, he's edited his comment.


It's not broken.




Consider applying for YC's Winter 2026 batch! Applications are open till Nov 10

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: