4 ms·
> Yet, as you say, adding a new case requires modifying the definition and existing functions. The same is true in java if you use instanceof. The thing is, ju
by AnaniasAnanas 8y ago
> Yet, as you say, adding a new case requires modifying the definition and existing functions.
The same is true in java if you use instanceof. The thing is, just like enums inductive data type definitions are not supposed to be extended by any module other than the one declaring them, and adding more should be considered an API change.
- chriswarbo 8y ago> The same is true in java if you use instanceof. Java isn't a particularly pure example of OOP: it has `if`/`for`/`while`/etc. from structured programming, non-OO "primitive types", non-polymorphic `+`/`-`/`*`/etc. and so on. `instanceof` is another example of a non-OOP feature (the OOP approach would be an `isFoo` method, where each class can decide what to return). > inductive data type definitions are not supposed to be extended by any module other than the one declaring them, and adding more should be considered an API change. Exactly. Yet in OOP, anyone can add new subclasses whenever they like, without ever telling the original author, and instances of those subclasses can co-exist alongside any other subclasses and will (in theory) work fine with all the existing code written for the superclasses. What if I altered your sentence to say the following: "Functions acting on a datatype are not supposed to be extended by any module other than the one declaring that type, and adding more should be considered an API change." This would seem crazy if we applied it to an FP language; yet that's exactly the case in OOP, where a fixed set of methods are implemented inside each class.