by ninetyninenine | 2025-05-08 06:45:19+00:00
>What? Using multiple inheritence?

You just threw this in out of nowhere. I didn't mention anything about "multiple" inheritance. Just inheritance which by default people usually mean single inheritance.

That being said multiple inheritance is equivalent to single inheritance of 3 objects. The only problem is because two objects are on the same level it's hard to know which property overrides which. With a single chain of inheritance the parent always overrides the child. But with two parents, we don't know which parent overrides which parent. That's it. But assume there are 3 objects with distinct properties.

A -> B -> C

would be equivalent to

A -> C <- B.

They are isomorphic. Merging distinct objects with distinct properties is commutative which makes inheritance of distinct objects commutative.

C -> B -> A == A -> B -> C

>I've been programming for 30 years and I've still never seen an example of multiple inheritance that hasn't eventually become a source of regret.

Don't ever tell me that programming for 30 years is a reason for being correct. It's not. In fact you can be doing it for 30 years and be completely and utterly wrong. Then the 30 years of experience is more of a marker of your intelligence.

The point is YOU are NOT understanding WHAT i am saying. Read what I wrote. The problem with inheritance has to do with human capability. We can't handle the complexity that arises from using it extensively.

But fundamentally there's no OTHER SIMPLER way to merge two objects without resorting to complex nesting.

Think about it. You have two classes A and B and both classes have 90% of their properties shared. What is the most fundamental way of minimizing code reuse? Inheritance. That's it.

Say you have two structs. The structs contain redundant properties. HOW do you define one struct in terms of the other? There's no simpler way then inheritance.

>> Composition is often more appropriate than inheritance.

You can use composition but that's literally the same thing but wierder, where instead of identical properties overriding other properties you duplicate the properties via nesting.

So inheritance

A = {a, b}, C = {a1}, A -> C = {a1, b}

Composition:

A = {a, b}, C = {a1}, C(A) = {a1, {a, b}}

That's it. It's just two arbitrary rules for merging data.

If you have been programming for 30 years you tell me how to fit this requirement with the most minimal code:

given this:

A = {a, b, c, d}

I want to create this:

B = {a, b, c, d, e}

But I don't want to rewrite a, b, c, d multiple times. What's the best way to define B while reusing code? Inheritance.

Like I said the problem with inheritance is not the concept itself. It is human nature or our incapability of DEALING with the complexity that arises from it. The issue is the coupling is two tight so you make changes in one place it creates an unexpected change in another place. Our brains cannot handle the complexity. The idea itself is fundamental not stupid. It's the human brain that is too stupid to handle the emergent complexity.

Also I don't give two flying shits about google style guides after the fiasco with golang error handling. They could've done a better job.