A robust defense of programming language type system

published on 2022/11/02

Another great example is money! I've lost count of how many applications express monetary values using the decimal type. Why? There are so many issues with that type that I find it incomprehensible. Where is the currency? Every domain that deals with people's money should have a dedicated type called Money. At the very least it should include the currency and some operator overloads (or other safety features) to prevent silly mistakes like multiplying $100 with £20. Besides, not every currency has only two digits after the decimal point. Some currencies such as the Bahraini or Kuwaiti dinar have three. If you deal with investments or bank loans in Chile then you better make sure that you render the Unidad de Fomento with 4 decimal points. These concerns are already important enough to warrant a dedicated Money type, but that's not even all.

dusted