4 ms·
I guess you mean typedefs and not separate classes for Money, TaxPercentage etc. I recently came across a codebase that implement type classes for almost all t
by thameera 11y ago
I guess you mean typedefs and not separate classes for Money, TaxPercentage etc.
I recently came across a codebase that implement type classes for almost all types of things it handles and found that to be overkill. Almost always, name and age can be represented by a string and an integer respectively; separate Name and Age classes just reduce the readability in your code.
- nhaehnle 11y agoIn a language that supports it reasonably, the advantage of genuinely separate types is that the language will prevent you from doing stupid things like accidentally multiplying to monetary amounts or adding a percentage to a monetary amount. Reasonable support here mostly means that you can implement operator overloads, so that you can define e.g. a Money type that can be added but not multiplied. Money handling may not actually be such a good example for this, because you should really have proper unit testing there anyway. I did work on a codebase that had types for SI units, and it was quite a nice experience.