Live data from Hacker News

Inheritance was invented as a performance hack

catern.com

171–180 of 268 posts

Re: Inheritance was invented as a performance hack

#171
Inheritance is static composition. Everything we do statically is for two reasons:

1. Static invariants (not subject to runtime-defined conditions).

2. Performance (AOT compilers know more about the system and can elide more code and devirtualize more calls, etc.).

I think the characterization of performance features as a "hack" is misleading. The article builds a bit of strawman, being dismissive of a performance feature for the fact it was for performance, then does a 180 in the Conclusion section saying "it's not bad" to look for performance.

Did we forget inheritance vs. composition is also for performance? Honestly I've not seen such a strong characterization of inheritance as being purely semantic. If anything, today we see inheritance as the thing a junior dev reaches for first, in order to share code, because they don't know better.

Sure, there's the "Cat extends Animal" shtick that refuses to die. But everyone refers to this kind of talk of inheritance ironically these days.

Re: Inheritance was invented as a performance hack

#172
post #144

Earlier quoted context omitted.

> 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 Sounds broadly true, but I'm not sure it's precisely right. How could std::is_same be implemented?

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

> You would perform manual static context-sensitive text expansion, just like the C++ template expander does.

Sure, if you move all your code into your new language that transpiles to C, but that was my point, the lack of language integration means there's plenty it can't do that C++ templates can do.

An example from [0]:

    std::is_same_v
In C, I don't know that there's any way to determine whether int and int64_t are the same type.

[0] https://en.cppreference.com/w/cpp/types/is_same

Re: Inheritance was invented as a performance hack

#173
post #144

Earlier quoted context omitted.

> 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 Sounds broadly true, but I'm not sure it's precisely right. How could std::is_same be implemented?

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

[deleted]

Re: Inheritance was invented as a performance hack

#175

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…

> Inheritance is a natural phenomenon. Biological inheritance, property inheritance, however, is not. > 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. Even if one agrees that that is true, that’s not an argument that inheritance is natural, that’s an argument th…

property inheritance seems like it is also a natural phenomenon. For example animals can "inherit" territory.

https://ideas.ted.com/humans-arent-the-only-ones-that-help-o...

Re: Inheritance was invented as a performance hack

#177
post #171

Inheritance is static composition. Everything we do statically is for two reasons: 1. Static invariants (not subject to runtime-defined conditions). 2. Performance (AOT compilers know more about the system and can elide more code and devirtualize more calls, etc.). I think the characterization of performance features as a "hack" is misleading. The article builds a bit of strawman, being dismissive of a performance fe…

I frequently hear people malign inheritance, and while it can obfuscate code in some circumstances, it can also produce code that is easily and clearly extendable. For example, a class with a static method that uses class properties to control behavior is cleaner than a function factory that takes a config object. Interface inheritance is also quite useful.

Re: Inheritance was invented as a performance hack

#178
post #3

Seems like a cool era to be working on computers. For lack of a better phrase, the world was your oyster.

Yes, I agree - you had much fewer pre-existing ideas to guide you, and really good new ideas were coming out all the time and you could pick between them - you could do all kinds of innovative things and they would really be novel.

Although today we have a much better grasp on formal semantics, which makes it easier to make up new ideas. But those new ideas aren't likely to ever displace the old ideas popularly, and it's hard to come up with them in the first place since old ideas live in your head...

Re: Inheritance was invented as a performance hack

#179

Earlier quoted context omitted.

I read it similarly as "inheriting money". And it's true that inheritance IS a performance hack--not for the children, but for the parents. Inheritance incentivizes parents to accumulate wealth not just for one lifetime but for multiple lifetimes. (Granted it may paradoxically have the opposite effect on the children as you mention.) Here's Milton Friedman on the matter: https://www.youtube.com/watch?v=km9OCw3f5w4

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…

It's also an extension of basic property rights. An owner of property may will it to whomever he pleases on the event of his passing. It's no different from simply gifting property while alive.

Re: Inheritance was invented as a performance hack

#180

Earlier quoted context omitted.

Ted Kazinsky was talking about it in his manifesto. https://unabombermanifesto.com/#THE%20POWER%20PROCESS It depends on how much you provide for your offspring according to this deranged terrorist. And I've read stories from billionaire kids not living "the good life" because they never have to fight/work for anything.

An atheistic/secular lifestyle tends to result in such outcomes.

yikes. why?
Post reply on HN