4 ms·
Why not? Ada, Pascal, Nim and others have ranged integer types. Many modern languages use some kind of type inference. You could easily define that the type of
by captainmuon 5y ago
Why not? Ada, Pascal, Nim and others have ranged integer types. Many modern languages use some kind of type inference. You could easily define that the type of an integer expression has to be large enough, for most expressions. It doesn't have to be general (I wouldn't be surprized if the general case is theoretically impossible). But you could fix the most obvious cases easily with this (for loops that can't go below 0 because of unsigned counters, calculating the average but the temporary overflows, ...).
And if the compiler gives you a warning... "Inferred variable would require a bignum (int128)" then you could either silence it by specifying the type explicitly, or maybe you are missing a manual range-check?
> If you have numbers from an untrusted source, you can and should range-check them immediately on input.
You should, but you are going to forget in some places. The point of a stongly-typed language to me is that the compiler will make sure you do. It is the edge cases and the cases where you accidentially don't sanitize properly where you get evil bugs.
- ncmncm 5y agoAnd if you do "forget in some places", Ada, Pascal, and Nim will not produce the correct response. What will they do instead? We don't need to guess, we saw in the first Ariane 5: catastrophic loss of vehicle and payload, as a result of sending a crash dump report to the engine steering gimbals. $500M payload, in that case.