6 ms·
A simple example would be instead of this: int temperature_a; int temperature_b; or even: Temperature a; Temperature b; you would have:
by spc476 10y ago
A simple example would be instead of this:
int temperature_a;
int temperature_b;
or even:
Temperature a;
Temperature b;
you would have:
Celsius a;
Fahrenheit b;
And an assignment between a and b would be an error, as Celcius and Fahrenheit are different types. Going along this path then, if you can extend the type system enough:
Yards width;
Yards length;
Acre size = width * length; /* this would be okay */
Yards width;
Yards length;
Yards height;
Acre money_bin = width * length * height; /* error */
/* as acre is a measure of area, not volume */
Think of the type of calculations that the Unix command 'units' does, but built into a language instead of an application.
- dkersten 10y agoThe Frink[1] language has units like this built in. Its pretty cool what you can do with it. I definitely agree that doing that or, at least, something like your code samples, is a good bug-avoidance idea. [1] https://frinklang.org/ https://frinklang.org/