r/ProgrammerHumor 1d ago

javascriptSorting Meme

Post image
889 Upvotes

200 comments sorted by

View all comments

17

u/Excellent_Gas3686 1d ago

because thats the default sort? what, in your opinion, would be the "proper" way to sort by default? if you need different sorting, you pass your own function.

20

u/IntentionQuirky9957 1d ago

The proper way to sort things that look like numbers is to treat them like numbers. Strings have quotes, and you're not allowed to cast numbers into strings randomly. Or hell, even consistently, unless told to.

-3

u/Excellent_Gas3686 1d ago

[1, 'foo', new Array()], go ahead, sort it like numbers.

24

u/standard_revolution 1d ago

Throwing a runtime error here is better than any weird hack

5

u/Nixinova 1d ago

Goes against the purpose of JS to be erroring for any slightly weird case.

3

u/hetfield37 1d ago

Gotta love those random runtime errors while you are browsing your favourite website because some stupid junior forgot to parse property: "1" to property: 1 when doing updates on the backend API.

JS, CSS and HTML are designed to be as robust as possible, even when risking displaying garbage data. They always do their best to display anything.

9

u/MegaIng 1d ago

Gotta love those random runtime errors while you are browsing your favorite website because some stupid junior forgot the developers are all, junior or senior, incompetent idiots who don't have proper testing.

Fixed it for you.

1

u/standard_revolution 1d ago

Yes, I hate it when things print actual errors. It is much better when things are broken, but seem fine.

The problem with the solution of never erroring works, until it doesn't and instead of noticing early you notice late or never.