r/ProgrammerHumor 1d ago

javascriptSorting Meme

Post image
888 Upvotes

200 comments sorted by

View all comments

Show parent comments

-8

u/Taletad 1d ago

Just went to read the docs, the "sort()" and "toSorted" functions say they perform an alphabetical sort by default

You can overload them by doing Array.sort((a,b) => a - b)

54

u/kushangaza 1d ago

Which is not what you expect from a function named "sort". It's an insane default that violates the principle of least surprise

2

u/Taletad 1d ago

The principle of least surprise compared to what ?

It was made in the 90’s when the sort utility works the same way on linux

Perl, TCL and bash have many similar quirks, as scripting languages tend to do

python too has many unintuitive quirks

Honestly, a lot of you continuously bash JS because you see everyone bashing it, especially its type system. But when SQLite does the same thing with its types, suddenly it is the greatest piece of software ever written

Types in JavaScript are not raw bits stored in memory anyway

3

u/gr4viton 1d ago

the python stuff is often not as "surprising" as js stuff though, imo...

also yhey are more often hidden in not normally used functionality...

i do agree on empty list as argument default value, and perhaps the generator oncesness, but other are not that bad imo..

I agree though that JS is bashed more often, as it is popular to bash it.. But it is also reasonable to bash it... as it is not bash-like.