3 ms·
> Then there's more power unlocked by giving dimensions/units to your types/instances. For instance, overloading the division operator in a class representing l
by Archelaos 4y ago
> Then there's more power unlocked by giving dimensions/units to your types/instances. For instance, overloading the division operator in a class representing length so that when dividing length by time, you get speed. Or, one could overload addition/subtraction in classes representing a currency so that trying to add ¥100 to $100 raises an exception.
I sometimes even go one step further and use specific types for dimensionless factors in financial calculations, such as specific types for the rates of different kinds of taxes. This way I get a compiler error, when I am trying to use the wrong type of tax rate in a calculation.