3 ms·
I don't understand why some functional programmers have so much difficulty with the concept of inheritance. Discriminated Unions and pattern matching is just in
by HumanDrivenDev 9y ago
I don't understand why some functional programmers have so much difficulty with the concept of inheritance. Discriminated Unions and pattern matching is just inheritance and virtual dispatch turned inside out. Yet no one is naval gazing about whether their algebraic datatypes are 'ontological' or not.
I also really wish people wouldn't try and dismiss concepts they're ignorant of:
because multiple inheritance is incompatible with the goal of implementation inheritance due to the diamond problem
I have no idea what that sentence is supposed to mean. It doesn't make sense even given their own definition of implementation inheritance.
- kccqzy 9y agoYes it's true that discriminated unions and pattern matching is just inheritance and virtual dispatch turned inside out. But discriminated unions and pattern matching are easier to use, easier to understand than inheritance and virtual dispatch. And you don't need to struggle with principles like "is-a relationship" which can be confusing.
- HumanDrivenDev 9y agoBut discriminated unions and pattern matching are easier to use, easier to understand than inheritance and virtual dispatch. That seems incredibly subjective. It's 50/50 for me, I just go with the grain with the language I'm using. I'll admit that in practice pattern matching wins due to the depressing lack of multiple dispatch in OO and pseudo-OO languages. And you don't need to struggle with principles like "is-a relationship" which can be confusing. Why would you struggle with that question with inheritance and not DUs? what is it about DUs that make it not an issue?
- ufo 9y agoActually, I think they are kind of duals to each other. With pattern matching it is easy to write new functions but hard to add a new case (you need to edit every previous pattern match you wrote). On the other band with classes it is easy to add a new class but hard to add a new method (you need to edit every single class you previously wrote that implements that interface) Functional programmers call this the "expression problem"