4 ms·
The downside to that is if you want to write a new function that deals different subclasses, you can't keep all the logic in one place; you have to spray its im
by peterkelly 4y ago
The downside to that is if you want to write a new function that deals different subclasses, you can't keep all the logic in one place; you have to spray its implementation across all the different types it has to handle. This is the #1 reason I prefer languages with sum types and pattern matching (or the ability to emulate it via unions and instanceof checks, e.g. TypeScript or Python + mypy).
- pharmakom 4y agoYou could implement a crappy union type in Java with a type-safe API, but if you want to program in that style you are really better off using an ML or Scala.