Re:Almost Always Unsigned
by barrkel on Sunday January 02, 2022 @09:19AM
(#29768857)
What you want is range subtypes of signed integers.
[ Parent
| on HN ]
Important: without silent conversion. Languages like Pascal and Ada require explicit conversions in more places to make that sort of thing useful.
It also allows creating type checked "new" numerical types for semantics purposes to help improve interfaces. This helps prevent things like accidentally passing an integer in the wrong units for example. Two of the worst offenders I've seen of this is: "Is this uint64_t (or float) "dt" parameter in ticks, seconds, milliseconds, microseconds or nanoseconds?" and "Is this angle parameter in radians or degrees?"