loading...

Discussion on: Has type safety gone too far?

Collapse
lietux profile image
Janne "Lietu" Enberg


What bugs can you possibly make by "accidentally" multiplying an integer by a double?

Pseudocode:

int x = 2;
double y = 3.0;
print("Answer is: ", x / y);

// Alternatively
int x = 2;
double y = 1.0 / 3.0;
print("Answer is: ", x * y);

It's unclear which answer you want out of that, since one of the components is an integer it's quite likely you want to perform integer math and want an integer result (0), or you might want a result that is rounded to the nearest integer (1), or you might want a double (~0.6666667).

Better be explicit than have the compiler guess for you.