3 ms·
I've heard of some Ada coding standards that require this in all variable names. It must have made the code awfully clumsy, but as the examples in OP show, it
by throwaway81523 5y ago
I've heard of some Ada coding standards that require this in all variable names. It must have made the code awfully clumsy, but as the examples in OP show, it can be made nice. So the general advice is good. I'm slightly disappointed that the Haskell library didn't use a newtype, e.g. threadDelay (Microseconds 300).
- wyager 5y agoHaskell has a couple libraries that would be great here; either the excellent time library, or the very powerful dimensional library with full statically typed SI units. Of course for something as core as threadDelay, a newtype is more appropriate as you say.
- throwaway81523 5y agoAnother approach (used somewhat by Python, at least for time units) is use SI units or some other standard or convention, and be willing to use floating point numbers for measurements. That was considered bloat in the old days, but reasonable general purpose computers these days almost always have FPU hardware.
- p_l 5y ago"Native" Ada way would be to declare units in types and require explicit casts (also, you can prevent casting to unsupported types, so no retrieving Int64 from hypothetical Duration_Nanoseconds