Live data from Hacker News

Inheritance was invented as a performance hack

catern.com

161–170 of 268 posts

Re: Inheritance was invented as a performance hack

#161
post #154

Earlier quoted context omitted.

Inheritance is a natural phenomenon. If all my money were stolen when I die (let's say, 100% inheritance tax), I wouldn't have much incentive to grow my business more once my business makes more money than I can possibly spend in a lifetime. Sure, some people may still do it because they love working or because they love providing for their society. The main reason I want to accumulate money, is so I can offer them a…

Your business doesn't operate in a vacuum. It is licensed and supported by society. The same society that benefits from inheritance redistribution.

By that logic, why let the business owner make any money at all? It's really society's business after all.

Re: Inheritance was invented as a performance hack

#162
post #144

Earlier quoted context omitted.

> How could std::is_same be implemented? You would perform manual static context-sensitive text expansion, just like the C++ template expander does. In this case, you end up just manually expanding it all the way out to a true or false by hand. I'm just saying that the C++ template expander only performs static context-sensitive text replacements, ending in valid template-free C++ code. The template engine doesn't in…

C++ templates cannot be implemented purely by text replacement as most of it is type driven. It is true that you can do anything that templates do by hand, but that's true for any language construct (at the limit you could write asm).

> C++ templates cannot be implemented purely by text replacement as most of it is type driven.

The static types (and constant values in some cases) are the context. That's the "context-sensitive" part of "context-sensitive expansion".

> It is true that you can do anything that templates do by hand, but that's true for any language construct (at the limit you could write asm).

Yes. That's my point. I was replying to someone saying that they could remove a layer of indirection from a linked list by writing a custom data structure that had the next and previous references, and I was pointing out that they're essentially running C++ template expansion by hand. There's nothing surprising there.

Re: Inheritance was invented as a performance hack

#163
post #160
post #135

Earlier quoted context omitted.

Yes, I mean java.util.LinkedList. Obviously, one can do manual writing of Java (or even use m4 macros or hijack the C preprocessor... the preprocessor doesn't know anything about C beyond tokenization) for anything C++ templates can do. It's just tedious and potentially error-prone. Here's hoping Java eventually gets reified generics.

Obviously you can do public class Node { Node prev, next; //stuff comes here .... } Then extend and have the overall code that deals with modifying the datastructure, but it's overall ugly. Personally I have written enough datastructures where linking nodes is useful. For example: red/black tree + insert order 'next' makes for a decent implementation of a moving median. Yet, that's not what almost any developer would…

But isn't that just what you were suggesting in the GP post in order to get rid of a layer of indirection?

Re: Inheritance was invented as a performance hack

#164
post #154

Earlier quoted context omitted.

Your business doesn't operate in a vacuum. It is licensed and supported by society. The same society that benefits from inheritance redistribution.

By that logic, why let the business owner make any money at all? It's really society's business after all.

[deleted]

Re: Inheritance was invented as a performance hack

#165
post #154

Earlier quoted context omitted.

Your business doesn't operate in a vacuum. It is licensed and supported by society. The same society that benefits from inheritance redistribution.

By that logic, why let the business owner make any money at all? It's really society's business after all.

The business owner won't exist if that person doesn't have the potential to make some money. There is a surprisingly large amount of possibilities between 0% and 100% inheritances tax rate.

Re: Inheritance was invented as a performance hack

#166
post #163
post #160

Earlier quoted context omitted.

Obviously you can do public class Node { Node prev, next; //stuff comes here .... } Then extend and have the overall code that deals with modifying the datastructure, but it's overall ugly. Personally I have written enough datastructures where linking nodes is useful. For example: red/black tree + insert order 'next' makes for a decent implementation of a moving median. Yet, that's not what almost any developer would…

But isn't that just what you were suggesting in the GP post in order to get rid of a layer of indirection?

Perhaps, most of the time I have not created a general use data structure - just highly specialized ones. Extending would allow no references/indirection but it's rather ugly and it has to provide another function to instantiate (I'd consider reflection, i.e. Class.newInstance() not to be a good way to handle the case).

Re: Inheritance was invented as a performance hack

#167

Pretty off topic comment, but I read the title as "inheriting money is a way avoid being a high performer", which happens to be true, although completely irrelevant to the actual article. ;)

How to improve your TC with this one trick (other relatives hate this)

Re: Inheritance was invented as a performance hack

#168
post #23

Earlier quoted context omitted.

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.

> Interfaces with default implementations are better than classes for a number of reasons it's literally the same thing in practice > including the diamond problem, the diamond problem has only ever been a "problem" in OOP textbooks, in years and years of working on OO system I have never saw it be a problem in practice

Do you know if the mechanism in described by Stroustrup in 1989 for supporting multiple inheritance is actually used by modern C++ compilers?

https://www.usenix.org/legacy/publications/compsystems/1989/...

The plan seems so complex that it makes complete sense to me why languages would avoid multiple class inheritance (where each class is afforded direct access to member variables).

In contrast:

• With single inheritance, you don't have to resolve different member variable layouts because there is only one.

• With interface inheritance (with or without default methods), interface methods don't get to access struct members directly and know nothing about object memory layout.

Re: Inheritance was invented as a performance hack

#169
post #55

Earlier quoted context omitted.

My roots are in OO but for the life of me I could never figure out why people found inheritance intuitive beyond some automatic delegation (like Go’s struct embedding). I certainly don’t miss the guesswork of trying to figure out which class’s virtual method is being executed out of the dozen in the hierarchy (especially when one virtual method is calling other virtual methods).

Because some people understand "is a" better than "has a".

That's just a restatement of the original problem. Inheritance just is "is a" and composition just is "has a", so if a person doesn't understand why someone would find inheritance more intuititve than composition, they wouldn't understand why a person finds "is a" more intuitive than "has a".

Re: Inheritance was invented as a performance hack

#170
post #125
post #38

Earlier quoted context omitted.

Maybe he meant something similar to Go interfaces, but they are abstract and coupled loosely with implementations after the fact. That or abstract class/pure interface. There's no need for default implementations introducing assumptions in code.

"Interfaces with default implementations" are a thing in Java and in some other languages, but most people don't know about them: https://docs.oracle.com/javase/tutorial/java/IandI/defaultme...

I knew that Java added "default methods" to its interfaces a few years ago, but wasn't sure whether Java uses "fat pointers" like Rust and Go.
Post reply on HN