r/programminghorror • • Jun 12 '25 • This 1

Javascript Javascript is filled with horror

Post image
2.4k Upvotes

337 comments sorted by

View all comments

-8

u/d0pe-asaurus Jun 12 '25

It would take an O(n) pass to determine if the array consists of numbers only, to decide between a numerical sort and a lexicographic sort.

24

u/n0tKamui Jun 12 '25

i mean, O(n + n · log n) conflates to O(n · log n)

20

u/sparant76 Jun 12 '25

Ya. JavaScript is known for its blazing speed. Wouldn’t want to a o(n) pass to a nlogn algorithm.

9

u/jsrobson10 Jun 12 '25

js code continues running where any sane language would crash. like, if you have a default comparator function that takes numbers, and if not all items are numbers, then crash.

-4

u/brainpostman Jun 12 '25

It's dynamically weakly typed. Default comparator takes anything. What's the expected behavior here?

0

u/EmuChance4523 Jun 12 '25

To be a decent language and have types.

Don't talk about JS failures as if they were features.

1

u/brainpostman Jun 12 '25

It's been 30 years. These are documented behaviors.
But if you want to uselessly complain about things, be my guest.

6

u/octocode Jun 12 '25

3

u/lapubell Jun 12 '25

Talk about "what color is your function", except now we can also say "what color is your array" too.

All snark aside, it's good to know about this. Just another thing to keep in the back of my mind while writing js

2

u/Tyfyter2002 Jun 12 '25

And that's O(0) instead for statically typed languages

1

u/Lithl Jun 12 '25

Which is completely irrelevant...

1

u/Tyfyter2002 Jun 12 '25

It's JavaScript, the fact that it's not statically typed is always relevant because it's the main source of its problems

1

u/TorbenKoehn Jun 12 '25

And it won’t ever be. We can all stop crying about it now.

0

u/Lithl Jun 12 '25

I mean that something which is true of a non-JavaScript language is completely irrelevant to a JavaScript project.

2

u/Tyfyter2002 Jun 12 '25

It's irrelevant to a JavaScript project, but it's always relevant to complaints about JavaScript because the only things people complain about about JavaScript are that it has problems every other language doesn't and that it uses the only floating point standard anything uses.

1

u/arto64 Jun 12 '25

You know other dynamic type languages exist, right.

-2

u/inputwtf Jun 12 '25

You could just throw an error when the elements can't be compared in a sane way. It's better to throw an error than to just do lexical comparison silently