Live data from Hacker News

Inheritance was invented as a performance hack

catern.com

61–70 of 268 posts

Re: Inheritance was invented as a performance hack

#61
post #49

Earlier quoted context omitted.

There are lots of bad uses of implementation inheritance, but it's not all bad. One pattern I use a lot is the "just these 5 missing methods". The base class might be complicated and large, with a lot of logic driving the process, but it needs to have 5 specific functions that it calls. One way is to have that big base class have almost all the logic and then 5 abstract methods and expect a subclass to implement thos…

I think for the usecase you mention, there is a different solution that I personally prefer. Optimally, if your language supports it, just define an interface with these 5 methods and then define extension methods that work on any type that implements the interface. The reason why this works is that all the other functions are usually helper functions / convenience functions and they only need the other 5 functions t…

Yeah, I generally like composition better, but sometimes the coupling between the base class and those subclasses that provide the 5 methods is just too strong to ignore, and if you break out the methods into another interface, then you are struggling to find a place to put the shared logic (which you proposed to do with extension methods).

Your example with the counting stack made use of "super", which is always a red flag to me. "super" is such a bad smell to me, that I literally never use it. In fact, in Virgil, my language project (http://github.com/titzer/virgil), there is no super construct at all, nor static methods or interfaces for that matter. 15 years of writing it, 200k lines later, and I can say that personally, having delegates, first-class functions, partial application, and tuples go way further than more complex trait/interface/extension method madness.

Re: Inheritance was invented as a performance hack

#64

I'm a little confused. Inheritance, types and all that stuff are just language concepts right? Simula may have been one of the first to implement inheritance as a means to an end, but how could they have "invented" inheritance? I'm sure the idea of inheritance was already there in language proofs. [I might be really really wrong here]

Theory usually comes after practice. People create something that works, then theorists formalizes it into a well defined concept.

Re: Inheritance was invented as a performance hack

#66

I'm a little confused. Inheritance, types and all that stuff are just language concepts right? Simula may have been one of the first to implement inheritance as a means to an end, but how could they have "invented" inheritance? I'm sure the idea of inheritance was already there in language proofs. [I might be really really wrong here]

Theory usually comes after practice. People create something that works, then theorists formalizes it into a well defined concept.

Just like some artists create art? First they do then they explain.

Re: Inheritance was invented as a performance hack

#67

After reading all the comments of many confused and curious, here is when inheritance is bad and why so _in the absence of any performance considerations_. First, inheritance from an interface/trait is totally okay. The problem is class inheritance, meaning implementation inheritance. There are two cases: 1) you inherit from a class and only add methods but don't overwrite anything. This is the good case, you can do…

Why create virtual methods in a class if you have no intention of it being a parent class? And if you intend for it to be a parent class you can design it so that these things aren't an issue.

Could you give a code example of how you would design things so that they aren't an issue?

Re: Inheritance was invented as a performance hack

#68
post #29

Earlier quoted context omitted.

How is it that c2 has remained so quality?

It turned write-only before the Eternal September of wikispam set in

I am trying to start a wiki project and I have no idea what sort of world of stupidity I’m about to step in to, do I?

I had thought of building the history system on top of a theory of patches system would be a nice stretch goal. But it seems to me that having an infinite undo function drastically changes the account creation situation. I only have to be passingly sure you’re not a bot, and I can decide after the fact if you’re approximating a decent human being or not.

Re: Inheritance was invented as a performance hack

#69
post #61

Earlier quoted context omitted.

I think for the usecase you mention, there is a different solution that I personally prefer. Optimally, if your language supports it, just define an interface with these 5 methods and then define extension methods that work on any type that implements the interface. The reason why this works is that all the other functions are usually helper functions / convenience functions and they only need the other 5 functions t…

Yeah, I generally like composition better, but sometimes the coupling between the base class and those subclasses that provide the 5 methods is just too strong to ignore, and if you break out the methods into another interface, then you are struggling to find a place to put the shared logic (which you proposed to do with extension methods). Your example with the counting stack made use of "super", which is always a r…

Not sure if I understand you correctly here. With "the coupling ... is just too strong to ignore" you mean that if someone has one of the subclasses at hand, they should automatically have all the extension methods at hand not having to look for them somewhere?

> Your example with the counting stack made use of "super", which is always a red flag to me. "super" is such a bad smell to me, that I literally never use it.

I think that's a sign that you have developed a good intuition of that it can lead to problems! :)

Re: Inheritance was invented as a performance hack

#70
post #68

Earlier quoted context omitted.

It turned write-only before the Eternal September of wikispam set in

I am trying to start a wiki project and I have no idea what sort of world of stupidity I’m about to step in to, do I? I had thought of building the history system on top of a theory of patches system would be a nice stretch goal. But it seems to me that having an infinite undo function drastically changes the account creation situation. I only have to be passingly sure you’re not a bot, and I can decide after the fac…

I'm not really sure, I think a fork and merge-request system might be useful? Or requiring registration for all editors. The big issue is figuring out how to reduce the moderation burden to a reasonable amount.
Post reply on HN