r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

Show parent comments

1

u/[deleted] Aug 26 '20

Suppose that instead of 5, there is a 55-bit integer. Now the promotion caused data loss. In any case, JS promotes implicitly to string because it just does. If you really want it to error, you can probably replace Object.prototype.toString() with your own implementation that throws an error.

1

u/yizzlezwinkle Aug 26 '20

Suppose that instead of 5, there is a 55-bit integer.

Pretty sure ints are 32 bits. And if you did write a 55 bit integer as a literal, then no, it's not promotion anymore and yes, an error should be thrown.

In any case, JS promotes implicitly to string because it just does.

So it's totally arbitrary then. Seems like an awful design decision.

1

u/[deleted] Aug 26 '20

Most JavaScript implementations handle integers upto... 52 bits (?) as integers. 53 fits into a double without precision loss, IIRC. After that you start getting problems.