r/ProgrammerHumor • • Jun 21 '18

Thanks Brendan for giving us the Javascript

Post image
3.1k Upvotes

302 comments sorted by

View all comments

50

u/Ericakester Jun 21 '18

And it's your fault if you do any of these

14

u/lettuceOutbreak Jun 21 '18

0.1+0.2==0.3 being false is wild though. I didn't know that. what's the workaround here?

13

u/reed_foster Jun 21 '18

Use fixed point arithmetic (e.g. 1 + 2 == 3 where 1, 2, and 3 are the numbers you're comparing multiplied by 10).

0

u/[deleted] Jun 22 '18

[deleted] — view deleted comment

4

u/[deleted] Jun 25 '18

Then you're out of luck, son, as every native float implementation is like that in every language.

You can import libraries that implement Decimal but bye-bye floating point acceleration in the CPU.. now your runtime/library is doing all the decimal arithmetic, slowing you down n-fold.

1

u/xIcarus227 Jun 22 '18 edited Jun 22 '18

Sorry, I disagree. I can understand the difference between == and === because of the dynamic types, or adding booleans again because of the dynamic types. But some of those are borderline ridiculous and downright unintuitive.
For example many bugs are introduced by unsuspecting programmers by adding an int with a string since everything in the DOM is a string. A very common break point of Javascript code.

'Quirky' is fun sometimes, but this is over the line. Defending languages which do this will make sure we get this in the next generation languages, which nobody wants.
I get this language was designed in a very short period of time, but excusing is terrible behaviour is unacceptable.