|
|
|
|
|
by ryandrake
326 days ago
|
|
I remember a long, long time ago, working on a project that handled lots of different types of physical quantities: distance, speed, temperature, pressure, area, volume, and so on. But they were all just passed around as "float" so you'd every so often run into bugs where a distance was passed where a speed was expected, and it would compile fine but have subtle or obvious runtime defects. Or the API required speed in km/h, but you passed it miles/h, with the same result. I always wanted to harden it up with distinct types so we could catch these problems during development rather than testing, but I was a junior guy and could never articulate it well and justify the engineering effort, and nobody wanted to go through the effort of explicitly converting to/from primitive types to operate on the numbers. |
|
https://kotlinlang.org/docs/inline-classes.html
https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3320.htm
https://doc.rust-lang.org/rust-by-example/generics/new_types...