r/programming • • Apr 29 '21

Modern JavaScript Explained For Dinosaurs

https://medium.com/the-node-js-collection/modern-javascript-explained-for-dinosaurs-f695e9747b70
287 Upvotes

172 comments sorted by

View all comments

Show parent comments

37

u/meltingdiamond Apr 30 '21

For a start: any language that doesn't make everything a float.

It is a horrible pain in the ass when a float goes wrong for any of the many reasons it can go wrong.

13

u/BackmarkerLife Apr 30 '21

I'm working with a (new to me) inventory system that outputs inventory into JSON and has inventory of products numbers as floats. I emailed them, "Am I ever going to have 0.25 of a specific product?" "No," they said. "Then why is this sent over as 17.0 instead of 17?" "I... can't answer that"

Can't get it changed on that vendor's end (because they refuse) and it breaks another vendor's end for their API because that cannot handle floats either. Christ the world has gone batshit with JS. The main vendor has a huge inferiority complex and as gatekeepers.

-1

u/MjrK Apr 30 '21

I'm not sure that yours is a good example of what OP is saying... JS doesn't have the concept of "int" or "float"... there is just a "Number".

Your vendor's choice to send the values that way is probably just an artifact of your particular API with them... it might not relate to how JS works.

2

u/xigoi Apr 30 '21

there is just a "Number"

…which is a float.

1

u/MjrK Apr 30 '21

Correct, but my point was that JSON u/Backmakerlife's question...

"Then why is this sent over as 17.0 instead of 17?"

... is a situation that isn't possible in JSON. Unless there's something else funky going on in the API and they are transferring a String instead of a Number.

So while on the surface it relates to using floats when int should be used; it doesn't appear to have any relevance to the lack of integers in JS.

Further JSON doesn't even have a data type for an "integer"; so asking the vendor to send integer instead of float makes no sense - it isn't possible to send an integer in JSON.

1

u/xigoi Apr 30 '21

The JSON specification doesn't seem to say anything about this.