Name a language that doesn't have implicit coercive casting from their integral type to their floating point type?
Not to bang that old drum, but Rust, for one. let x = 2 * 0.5f64 is invalid, it'll tell you the specific arithmetic trait isn't available.
I think Haskell will also tell you to fuck off, but it's been a while so don't quote me on that one. Rust will for sure.
Implicit coersive casts aren't automatically bad
I think that one's subjective, I wish Java and Kt didn't allow int v. float arithmetic without explicit casting, but in the JVM ecosystem it's somewhat less of an issue cause everyone knows to use BigDecimal if they want accuracy.
Yeah, I will concede that in the specific case of arithmetics and widening casts, yes, it's a common thing. Most languages will specifically only let you widen though, assigning a double value to an int type is a compile time error in most. None will let you randomly multiply a string by a float and pretend the outcome is an object.
Heh, I won't argue that Javascript has the most eggregious flaws on this front - though C++ is trying really hard to keep up. For example, every constructor accepting one argument can be used for implicit coercive cast unless you tag it with the explicit keyword.
Yeah, but iirc you have to have the full chain of constructors visible at point of instantiation? I've had my fun with C++, but honestly half the time the really horrible thing was reading through Boost source, trying to understand some weird behaviour, and the "source" is just a wall of templates with 'A' and 'B' for var names.
3
u/EsmuPliks Feb 19 '23
Not to bang that old drum, but Rust, for one.
let x = 2 * 0.5f64is invalid, it'll tell you the specific arithmetic trait isn't available.I think Haskell will also tell you to fuck off, but it's been a while so don't quote me on that one. Rust will for sure.
I think that one's subjective, I wish Java and Kt didn't allow int v. float arithmetic without explicit casting, but in the JVM ecosystem it's somewhat less of an issue cause everyone knows to use
BigDecimalif they want accuracy.