4 ms·
I very strongly think that rust went the right route here: error[E0277]: cannot add a float to an integer --> src/main.rs:2:6 | 2 | 1+1.
by Tuna-Fish 8y ago
I very strongly think that rust went the right route here:
error[E0277]: cannot add a float to an integer
--> src/main.rs:2:6
|
2 | 1+1.0;
| ^ no implementation for `{integer} + {float}`
Casts are historically such a massive source of bugs and unstability that the correct casting rule for every numerical computation is always: "Make the programmer explicitly choose."
- pjmlp 8y agoInterestingly enough, most of the boilerplate and straight jacket rules from Algol language stream, that cowboy programmers used to complain about, are being adopted again thanks to the age of rising CVEs in always connected devices.
- renox 8y agoI disagree, while C signed/unsigned type conversion is a source of bug and should be explicit, it doesn't mean that all implicit conversion are bad.. I think that implicit conversion from int to float is mostly harmless, as the result is a float and the float to int conversion is explicit, this is unlikely to create bugs. intX to intY or uintX to uintY if Y>=X are two other conversions which are unlikely to create bugs but save a lot of boilerplate.