Live data from Hacker News

Inheritance was invented as a performance hack

catern.com

21–30 of 268 posts

Re: Inheritance was invented as a performance hack

#21

I spent way too long trying to figure out how giving your kids your lifetime's earnings would be a performance hack beyond, you know, giving them a head start, before realizing what the headline was talking about.

People care tons about their kids -> Working hard and creating value results in a larger inheritance for their kids -> Exploit biological desires to protect offspring to get yourself to be more productive?

Re: Inheritance was invented as a performance hack

#22

Earlier quoted context omitted.

"Catching on" doesn't mean "is the right way to do things". Code reuse is in fact a prime example of a misuse of inheritance

Why is code reuse your prime example for bad inheritance? What should people do instead?

In OO languages, inheritance gets the most bang for the buck when used for polymorphism.

All code reuse can be expressed with composition and delegation, bringing more flexibility, testability, cohesion, decoupling, etc, etc, etc.

Re: Inheritance was invented as a performance hack

#23

Earlier quoted context omitted.

"Catching on" doesn't mean "is the right way to do things". Code reuse is in fact a prime example of a misuse of inheritance

Why is code reuse your prime example for bad inheritance? What should people do instead?

Interfaces with default implementations are better than classes for a number of reasons, including the diamond problem, and that as systems grow large they almost never fit cleanly into an inheritance tree. Fat pointers with two words, one for an interface vtable and one for the object, work really well.

Re: Inheritance was invented as a performance hack

#25

Earlier quoted context omitted.

"Catching on" doesn't mean "is the right way to do things". Code reuse is in fact a prime example of a misuse of inheritance

Why is code reuse your prime example for bad inheritance? What should people do instead?

Inheritance is just a tool to mostly avoid. It tightly couples different class implementations. So will make later refactors error-prone and tend to scatter logic. It's misunderstanding OO as messaging between objects.

Using composition or lay out data differently may yield designs with more desirable properties. There's no one answer and it depends.

Re: Inheritance was invented as a performance hack

#26

I think discussions of OOP and inheritance often miss the influence of Knowledge Representation on OOP: I’m not entirely clear of the history myself, but I’ve gotten the impression that knowledge representation research (things like frame systems) was a semi-independent influence on the design of OO systems

c2 has some interesting thoughts on the topic.

https://wiki.c2.com/?KnowledgeRepresentations

https://wiki.c2.com/?TypeInferenceStory

https://www.cin.ufpe.br/~mtcfa/files/in1122/Knowledge%20Repr...

Re: Inheritance was invented as a performance hack

#27
post #23

Earlier quoted context omitted.

Why is code reuse your prime example for bad inheritance? What should people do instead?

Interfaces with default implementations are better than classes for a number of reasons, including the diamond problem, and that as systems grow large they almost never fit cleanly into an inheritance tree. Fat pointers with two words, one for an interface vtable and one for the object, work really well.

In your view, how is "interfaces with default implementations" different from "inheritance for code reuse"? At a minimum it looks like a virtual function with a default implementation in the base class. If a derived class doesn't override it, isn't that code reuse?

Re: Inheritance was invented as a performance hack

#28
post #4

Fine. But obviously it caught on for other reasons, like code reuse and an intuitive mental model. The HN appetite for posts ragging on inheritance will never be sated.

The best practices I've read mostly say that inheritance should be limited to one non-interface parent. I.E. obly one parent with an invariant. For everything else composition. That mostly lines up with my experience, but I mostly deal with problem spaces that aren't terribly OO like DSP.

Re: Inheritance was invented as a performance hack

#29
post #26

I think discussions of OOP and inheritance often miss the influence of Knowledge Representation on OOP: I’m not entirely clear of the history myself, but I’ve gotten the impression that knowledge representation research (things like frame systems) was a semi-independent influence on the design of OO systems

c2 has some interesting thoughts on the topic. https://wiki.c2.com/?KnowledgeRepresentations https://wiki.c2.com/?TypeInferenceStory https://www.cin.ufpe.br/~mtcfa/files/in1122/Knowledge%20Repr...

How is it that c2 has remained so quality?

Re: Inheritance was invented as a performance hack

#30
post #29
post #26

Earlier quoted context omitted.

c2 has some interesting thoughts on the topic. https://wiki.c2.com/?KnowledgeRepresentations https://wiki.c2.com/?TypeInferenceStory https://www.cin.ufpe.br/~mtcfa/files/in1122/Knowledge%20Repr...

How is it that c2 has remained so quality?

It turned write-only before the Eternal September of wikispam set in
Post reply on HN