> This is yet another reason why I say bare numbers can be poison in a sufficiently complicated system.
In Racket, I tended to use keyword arguments, and include the units in the keyword argument. For example, one library used `:velocity-mm/s`. (The `/` character is an identifier constituent, not some special operator syntax.)
In Rust, I'm going to try out using language features for static checking of some units (with 0 runtime cost).
Yes, the newtype pattern in Rust works very well, say to wrap a string. The somewhat annoying thing is that it is born without any properties so you have to teach it to be comparable, etc from scratch.
The newtype pattern in Go is easier to use, but isn't strict enough - your wrapped string can still appear directly in a string concatenation without a cast. Any wrapped integer can still be used to index a slice! Considering how careful the language is with mixed arithmetic (can't add uint8 to uint16 without casting) this feels like an oversight.
In Racket, I tended to use keyword arguments, and include the units in the keyword argument. For example, one library used `:velocity-mm/s`. (The `/` character is an identifier constituent, not some special operator syntax.)
In Rust, I'm going to try out using language features for static checking of some units (with 0 runtime cost).