Live data from Hacker News

Inheritance was invented as a performance hack (2021)

catern.com

191–200 of 252 posts

Re: Inheritance was invented as a performance hack (2021)

#191
post #65

Earlier quoted context omitted.

Java and C# are already a huge step up from what came before, since they at least introduce the concept of an interface as a distinct thing from a parent class. The fact that you don't notice that is proof that progress does happen, if only slowly.

Java wasn't the first to do that Objective-C (10? years before) had interfaces. Even C++ has that with multiple inheritance - some parents can just be interfaces. As to whether Smalltalk needs interfaces see https://stackoverflow.com/a/7979852/151019 and https://www.jot.fm/issues/issue_2002_05/article1/

Also:

2003 Traits: Composable Units of Behaviour

https://www.cs.cmu.edu/~aldrich/courses/819/Scha03aTraits.pd...

" Traits as described in this paper are implemented in Squeak [22], an open-source dialect of Smalltalk-80."

Re: Inheritance was invented as a performance hack (2021)

#192
post #17
post #10

I'm not sold the evidence is there to show inheritance is a good idea - it basically says that constructors, data storage and interfaces need to be intertwined. That isn't a very powerful abstraction, because they don't need to be and there isn't an obvious advantage from doing so over picking up the concepts separately as required. And inheritance naturally suggests grouping interfaces into a tree in the way that se…

I'm on the fence about inheritance myself; I often regret having used it, and I never regret having not used it. On the other hand, it's awfully expedient. I designed and implemented a programming language called Bicicleta whose only argument-passing mechanism is inheritance, and I'm not sure that was a bad idea. The object-oriented part of OCaml, by the way, has inheritance that's entirely orthogonal to interfaces,…

1992 "Interfaces and Specifications for the Smalltalk Collection Classes"

https://dl.acm.org/doi/pdf/10.1145/141936.141938

Re: Inheritance was invented as a performance hack (2021)

#193
post #97

Earlier quoted context omitted.

> a tree probably doesn't represent the fundamental truth of things It does. Trees appear in nature all the time. It's the basis of human society, evolution and many things. Most of programming moves towards practicality rather then fundamental truth. That's why you get languages like golang which are ugly but practical.

A city is not a tree: https://www.patternlanguage.com/archive/cityisnotatree.html Even trees are not trees: https://en.wikipedia.org/wiki/Anastomosis Evolution is most definitely not a tree. Nature also tends towards practicality, even more so than programming. Trees aren’t a fundamental truth, they’re a made-up oversimplified abstraction.

evolution is a tree. Follow the ancestral lines. Even the term inheritance comes from evolution.

Re: Inheritance was invented as a performance hack (2021)

#194
post #90

Earlier quoted context omitted.

> a tree probably doesn't represent the fundamental truth of things It does. Trees appear in nature all the time. It's the basis of human society, evolution and many things. Most of programming moves towards practicality rather then fundamental truth. That's why you get languages like golang which are ugly but practical.

Botanical trees appearing in nature don't make them "the fundamental truth of things". And in what way are trees the basis of human society? Thats such a strange claim. Are you talking about family trees? Because they're actually directed acyclic graphs. Even if you want to claim that trees are a common data structure, that doesn't mean they're appropriate in any specific case. Should we therefore arrange all website…

fundamental truth of things is probably the wrong word choice.

It's more like there are many fundamental concepts and trees are one such concept. I don't think there is a singular fundamental truth of things.

>Even if you want to claim that trees are a common data structure, that doesn't mean they're appropriate in any specific case. Should we therefore arrange all websites in a tree? Should relational databases be converted to trees, because "they're the basis of human society"? What tosh.

I never made this claim though?

>Programming moves toward practicality because software is created to do work. Taxonomies are entirely and completely worthless. The classic Animal -> Mammal -> Cat example for inheritance is a fascinating ontology, and an entirely worthless piece of software.

I mentioned this because parent poster is talking about fundamental truths. I'm saying trees are fundamental... But they may not be practical.

Re: Inheritance was invented as a performance hack (2021)

#195
post #80

Earlier quoted context omitted.

>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 cha…

> But assume there are 3 objects with distinct properties... Why would we assume that? If the objects are entirely distinct, why are you combining them together into one class at all? That doesn't make any sense. Let distinct types be distinct. Let consumers of those types combine them however they like. > But fundamentally there's no OTHER SIMPLER way to merge two objects without resorting to complex nesting. [...]…

>Why would we assume that? If the objects are entirely distinct, why are you combining them together into one class at all? That doesn't make any sense. Let distinct types be distinct. Let consumers of those types combine them however they like.

Human = torso, legs, arms. Three distinct objects combine into one thing. A human by definition is the union of these things. It's fundamental. It's just your bias is trying to see it as something else.

>So now the objects have 90% of their properties shared. That's different from what you were saying earlier. But moving on...

So? I can talk about multiple things right? This is allowed in life right? Did i break the law here?

>The composition answer is similar to the inheritance answer. Take the common parts and extract them out into a self contained type. Use that type everywhere you need it - eg by including it in both A and B.

Composition is the same thing. But it's saying instead of overriding duplicate properties, Clone the duplicate property. That's it. And it uses nesting to achieve this. This arbitrary rule isn't more fundamental then overriding the duplicate property.

>Via composition, you do it like this:

Why don't you take a look at my examples again. You are either not able to comprehend or you didn't read it. I literally said the same thing:

   B = {a: A, e}
The above a complete dupe of what I wrote.

   B = {a, b, c , d, e}
Just nested. Which I brought up:

   B = {{a, b, c, d}, e}
Is it not? Please read my response replying with stuff like this. Read it thoroughly.

>And that's an incredibly damning criticism, because complexity is an absolute killer.

Not exactly it's not that straightforward. Because inheritance minimizes code copying. It reuses code in the most efficient way possible. So actually lines of code and duplicate code actually goes down. So complexity in one area falls and rises in another area.

Our brains are biased towards handling complexity of duplicate code better then tightly coupled code.

Re: Inheritance was invented as a performance hack (2021)

#196

Earlier quoted context omitted.

>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 cha…

> 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. why inheritance would make it easier?

I have: A = {a, b, c, d, e}

I want to write: B = {a, b, c, d, e, f, g}

But I don't want to write duplicate code

So I write:

   B = B(A) = {A, e, f, g} 
aka I use inheritance.

Are there easier ways? No. Inheritance is the most fundamental way of doing this. Composition is just a work around as it results in arbitrary nesting. But ultimately it's the same thing too.

Re: Inheritance was invented as a performance hack (2021)

#197

I always thought this was common knowledge. I guess it isn’t. The only reason inheritance continues to be around is social convention. It’s how programmers are taught to program in school and there is an entire generation of people who cannot imagine programming without it. Aside from common social practice inheritance is now largely a net negative that has long outlived its usefulness. Yes, I understand people will…

Or because there are some situations where inheritance is useful. There was a reason Simula, Smalltalk, C++, Common Lisp (CLOS), Java, OCaml, Ruby, etc. implemented OOP. That's a lot of different languages. The program designers found it to be a useful abstraction and so did the language users.

There's no reason to be dogmatic about programming abstractions. Just because OOP became dogma for a while and got abused doesn't mean we have to be dogmatic entirely in the opposite direction. Abstractions have their use for those programming languages that choose to implement them.

Re: Inheritance was invented as a performance hack (2021)

#198
post #67
post #17

Earlier quoted context omitted.

I'm on the fence about inheritance myself; I often regret having used it, and I never regret having not used it. On the other hand, it's awfully expedient. I designed and implemented a programming language called Bicicleta whose only argument-passing mechanism is inheritance, and I'm not sure that was a bad idea. The object-oriented part of OCaml, by the way, has inheritance that's entirely orthogonal to interfaces,…

Python has Protocols. They work like Go interfaces

Sure, but for the most part people don't use them, because you don't have to; Python method calls are always potentially polymorphic, unlike Golang method calls.

Re: Inheritance was invented as a performance hack (2021)

#199
post #43

Earlier quoted context omitted.

I don't think Inheritance is always bad - sometimes it's a useful tool. But it was definitely overused and composition, interfaces work much better for most problems. Inheritance really shines when you want to encapsulate behaviour behind a common interface and also provide a standard implementation. I.e: I once wrote a RN app which talked to ~10 vacuum robots. All of these robots behaved mostly the same, but each wa…

Inheritance is not the only way to share behavior across different implementations — it'a just the only way available in the traditional 1990s crop of static OOP languages like C++, Java and C#. There are many other ways to share an implementation of a common feature: 1. Another comment already mentioned default method implementations in an interface (or a trait, since the example was in Rust). This technique is even…

To my mind, the challenge is not "sharing behavior"; it is "sharing behavior in a way that capture human-understandable semantics and make code easier to reason about instead of harder."

I suspect part of the problem of inheritance is that it is a way to share behavior that some humans, especially visual thinkers who understand VMTs, find easy to reason about.

In my experience verbal thinkers struggle with inheritance, because it requires jumping between levels of abstraction and they aren't thinking in terms of semantic units. I have found that books like Refactoring can help bridge the gap, but we have to identify it as a gap to be bridged and people have to want to learn this new skill.

And then on the flip side you have people who try to use it just as a way to de-dupe code, even when it doesn't reflect a meaningful semantic unit.

Re: Inheritance was invented as a performance hack (2021)

#200
post #36

Earlier quoted context omitted.

> The bottom line is, no one ever really used inheritance that much anyway If you think that, you have no idea how much horrible code is out there. Especially in enterprise land, where deadlines are set by people who get paid by the hour. I once worked on a java project which had a method - call a method - call a method - call a method and so on. Usually, the calls were via some abstract interface with a single imple…

> The reason is that inheritance is almost always a bad idea in practice. It's just slightly too strong of a statement. I'm working in a very large Spring codebase right now, with a lot of horrible inheritance abuse (seriously, every component extended common hierarchy of classes that pulled in a ton of behavior). I suspect part of the reason is the Spring context got out of control, and the easiest way to reliably "…

That is a great example! Abstraction is most useful when it captures the way several things are more-specific versions of a more general thing. At that point it's not just about the functionality: it communicates to the reader. Anyone coming in can now easily answer the question, "what kinds of payments exist?"
Post reply on HN