Signed Integers By Default

23 points by runxiyu


david_chisnall

I am generally of the opinion that languages shouldn't do automatic type promotion and should default to signed integers. Multiplication should always have a result type that is double the width of the operands and should have explicit non-widening versions.

The thing I would like to see more of is Ada-style (Pascal-style?) explicit ranges. Unsigned integers are a special case of this that happens to be easy to represent. But if I know that I'm storing integers in the range [0,100], then I should be able to say that, not just say 'well, it fits in an 8-bit integer and I don't want negative values so I'll pick u8 as the type'. And I want to define wrapping or saturating behaviour, or operations that return larger ranges or require me to put the thing back in line. And the compiler should pick the narrowest machine type that can store the range I want.