8 ms·
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
by rectang 6y ago
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.
- SilverRed 6y agoWhat benefit does inheritance provide over importing files containing functions? Ruby and loads of other languages let you import files and those functions work like they were part of the class itself.
- rectang 6y agoMany benefits (e.g. attaching behavior to instances rather than modules, though there are other ways to accomplish the same goal), many drawbacks (fragility, yoyoing, etc.). C could be described as "files containing functions", and C++ was originally "C with classes", so it's not like "files with functions" is a revolutionary idea. This is all extremely well-traveled ground. I'm happy these days using languages like Rust and Go that avoid classical inheritance, so I'm not here to argue in favor of inheritance. I'm just irritated by the pile-on.
- fiddlerwoaroof 6y agoI’d also add that live systems like Smalltalk avoid a lot of the fragility and dynamism of inheritance by the way the browsers show all the currently active extensions to the class, and all the current subclasses in a fairly compact view. It’s a lot easier to find and modify affected child classes in this way than it is with “code in files” systems. Also, the way CLOS does inheritance avoids a lot of the drawbacks too by decoupling classes and inheritance from behavior.
- deleted 6y ago[deleted]
- FpUser 6y agoThese are those different features. Delphi / ObjectPascal for example support either. As for what benefit - your example with Ruby can be reversed and I can ask you the same question. Anyways large part of a programming is an art and different people have different approaches. If you do not like the concept do not use it. Just do not assume that what you think is the "right way".
- bradrobertson 6y ago"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
- Varriount 6y agoHow is it a misuse? And what are the alternatives? To be clear, I do agree with your assertion, however I'm having a hard time actually putting "how/why" into words.
- Spivak 6y agoIt’s a misuse because (if you really are only using it for code reuse) it’s creating an essential relationship between different objects that is actually incidental. A list containing two different subclasses of your avoiding-copy-paste base class is now most likely a logical error.
- deleted 6y ago[deleted]
- findjashua 6y agohow is that different from a list containing 2 implementations of an interface?
- foo_barrio 6y agoThere is no state to track. If there is, 99% composition has worked out way better for me in the long run since I don't have this really strong coupling between two objects.
- username90 6y agoSo you don't have a need for code reuse then since you don't have many types with the same base structure, just say that instead of saying that it is bad.
- foerbert 6y agoIs this ragging on inheritance? I don't see much in the way of value judgements mentioned. The closest is an assertion that doing things for performance is not bad, which seems more like a way of heading off comments like yours than anything else. It's a bit of interesting history. I don't know why it would get a "Fine. But unrelated stuff" response.
- rectang 6y agoI suspect that many will read the title as derogatory, even if the post is not a firebreather. Also, from the conclusion: > Personally, for code reuse and extensibility, I prefer composition and modules.
- FpUser 6y agoEvery once in a while one concept goes out of fashion and another one becomes current fetish. Often the new is actually an old one and sometime is masquerading under new name. And then you have army of prophets that are here to show you "the right way". Rinse and repeat. Personally I read and try various things and use whatever I think is appropriate for given situation. Do not really give a fuck about what is the official point of view on subject at the moment. It changes of course if doing job for client and client insists on things done in particular way. Luckily I mostly design and build complete products so clients mostly care about the end result and do not interfere in the internal plumbing matters.
- galangalalgol 6y agoThe 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.
- throwaway894345 6y agoMy 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).
- junon 6y agoBecause some people understand "is a" better than "has a".
- squiggleblaz 6y agoThat'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".
- dang 6y ago"Please don't sneer, including at the rest of the community." https://news.ycombinator.com/newsguidelines.html https://news.ycombinator.com/newsguidelines.html
- eternalban 6y agodang, amazed at your parsing abilities at hn comment scale I checked your profile to make sure you are not a machine and read that passage you quoted which assures me you are a Human being with exceptional taste. Beautiful. For others who may be interested, poked around and found that it is a quote from The Street of Crocodiles and Other Stories, by Bruno Schulz. https://www.goodreads.com/book/show/1576188.The_Street_of_Crocodiles_and_Other_Stories https://www.goodreads.com/book/show/1576188.The_Street_of_Cr...
- rectang 6y agoI take your critique, Dan, and in the future I'll try to find different ways to make similar points. I'm a bit deflated though, that now that this subthread has been demoted and dropped to the bottom, the usual "everybody knows inheritance sucks" comments are accumulating up at the top. I really enjoyed having a discussion for once that tried to suss out why inheritance, despite its flaws, was historically so semantically compelling.
- dang 6y agoWe downweight generic subthreads when we see them stuck at the top of a page. I've downweighted that one now. Obviously they're a problem (a big problem - maybe the biggest - because the most generic tangent from any topic is also the one that people are most familiar with, and familiarity breeds both repetition and upvotes). But the solution is not to have a generic tangent which is also a flamewar! However, you already agreed on that point and I don't mean to pile on.