3 ms·
In most languages that offer this distinction, unsigned integers also don't really express your intent in an effective way. Imagine you have a bug in your prog
by UncleMeat 5y ago
In most languages that offer this distinction, unsigned integers also don't really express your intent in an effective way.
Imagine you have a bug in your program. If you intend for a value to be non-negative and use a signed integer, you get a negative value. Your code is broken. You didn't want a negative value. But you do have have a very easy way of checking for this at runtime, at least.
Now imagine you instead use an unsigned integer. The bug is still there but now it manifests as overflow or underflow. Your program is still broken. Nothing about using an unsigned integer saved you. And worse, you don't have an easy predicate to check that something has gone wrong.
I think this can only be a reasonable choice if you are working in a language that has dynamic checks for overflow and so using an unsigned integer enforces not only the predicate that the value is nonnegative but also that all operations stay within its expected arithmetic domain.
- deleted 5y ago[deleted]