Live data from Hacker News

Why general inheritance is flawed and how to finally fix it

minborgsjavapot.blogspot.com

51–60 of 104 posts

Re: Why general inheritance is flawed and how to finally fix it

#51
post #44

Earlier quoted context omitted.

> Language Design: Let's start with the admission that there's a lot of cargo culting in language design. Evidence is hard to come by and the best evidence is other languages that succeed with different choices. You are going to get a lot of false positives using success as a metric for good language design. I cannot think of a single popular language, other than Python, in the last 40 years that did not have huge co…

People keep telling this about Python, always ignoring who was paying Guido's salary.

> People keep telling this about Python, always ignoring who was paying Guido's salary.

Well, reveal the spoilers and don't keep us all in suspense :-)

Who was paying GvR a salary[1] when Python took off circa 2001/2002?

[1] I don't think paying a single person a salary is the same as the millions of dollars poured into marketing and development as done with all the other popular languages.

Re: Why general inheritance is flawed and how to finally fix it

#52
The final keyword is one of those places where Java shows its age to me. I agree with the overall point that inheritance is flawed, but I cannot bring myself to conclude that the use of final is the answer to the problem.

Simple example, String is final in Java. It is also immutable, and that is (mostly) irrelevant. Lots of string fields on inbound requests have validations, a simple one would be a field that contains a fixed length string. So obviously you validate that at the ingress before passing it down. Now, the question arises, should the core library be defensive and re-validate the string? Why not simply capture the subtype, TenCharacterString and parameterize methods with that?

Modern languages get this right. Subtyping is not inheritance. Inheritance is not subtyping. I should be able to subtype at zero cost, I don't need inheritance to do that, [and encapsulation is definitely not subtyping].

But Java doesn't have that. You mark something as final and you lose the ability to subtype just to eliminate the possibility of inheritance. On the other hand, to be fair to the argument against final, the real answer to my complaint is a proper type aliasing support.

Re: Why general inheritance is flawed and how to finally fix it

#53

I (happily) write a lot of OOP code, "inheritance is bad, use composition" is such a trite and unhelpful dogma that gets in the way of any actual discussion about where inheritance is useful. IMO, the case where inheritance makes the most sense is when you have a set of objects polymorphically answering some question, usually with a simple answer. class Subset class Whole which is used as such: subset = Subset::Whole…

The thing I don’t like about passing objects around is that the state inside the object is opaque, and debugging it can be extremely frustrating, especially in something like Ruby some people are way too liberal with magic for my taste. My personal preference is to see immutable data structures being passed around through reasonably named functions, and that the is usually good enough for me.

Re: Why general inheritance is flawed and how to finally fix it

#54

Or you could learn to use it properly. Make no mistake, designing classes to support inheritance is much harder than just declaring everything final, and in many scenarios there is no good reason to do so

Isn't the "use it properly"-argument pretty much the same arguments as those saying that real C developers don't need the safeties offered by rust, they just need to use C or C++ properly?

The whole idea of language design (in my opinion) is to reduce the opportunities for mistakes, without getting in the way (thus reducing productivity). The biggest problem with Java and C# is that they are deceiptively simple. Anyone can get off the ground and the path of least resistance initially is the path of maximum pain in the end. That's the path of making large classes, lots of mutable state, long inheritance chains and so on. The languages aren't forcing anyone to use these antipatterns, but neither are they guiding the hand of the newcomer not to do that.

Re: Why general inheritance is flawed and how to finally fix it

#55

Earlier quoted context omitted.

Language Design: Let's start with the admission that there's a lot of cargo culting in language design. Evidence is hard to come by and the best evidence is other languages that succeed with different choices. I remember the flame wars about how multiple inheritance would cause a language to fall apart. When will languages adopt the idea that encapsulation is not sacrosant, as the theoretical issue about the backdoor…

> Language Design: Let's start with the admission that there's a lot of cargo culting in language design. Evidence is hard to come by and the best evidence is other languages that succeed with different choices. You are going to get a lot of false positives using success as a metric for good language design. I cannot think of a single popular language, other than Python, in the last 40 years that did not have huge co…

> Programming languages do not succeed based on merit. They may fail based on lack of it.

Merit is what I'm talking about, in a way. The ability to use more robust forms of composition is a positive quality for a language. So much so, even if not explicitly stated, most languages have adopted new mechanisms over time beyond simple rigid inheritance trees.

Re: Why general inheritance is flawed and how to finally fix it

#56

I (happily) write a lot of OOP code, "inheritance is bad, use composition" is such a trite and unhelpful dogma that gets in the way of any actual discussion about where inheritance is useful. IMO, the case where inheritance makes the most sense is when you have a set of objects polymorphically answering some question, usually with a simple answer. class Subset class Whole which is used as such: subset = Subset::Whole…

[deleted]

Re: Why general inheritance is flawed and how to finally fix it

#57

Earlier quoted context omitted.

> Language Design: Let's start with the admission that there's a lot of cargo culting in language design. Evidence is hard to come by and the best evidence is other languages that succeed with different choices. You are going to get a lot of false positives using success as a metric for good language design. I cannot think of a single popular language, other than Python, in the last 40 years that did not have huge co…

> Programming languages do not succeed based on merit. They may fail based on lack of it. Merit is what I'm talking about, in a way. The ability to use more robust forms of composition is a positive quality for a language. So much so, even if not explicitly stated, most languages have adopted new mechanisms over time beyond simple rigid inheritance trees.

> Merit is what I'm talking about, in a way. The ability to use more robust forms of composition is a positive quality for a language.

Maybe so, but what I am saying is that merit cannot make a language popular, but marketing can.

Re: Why general inheritance is flawed and how to finally fix it

#58
post #49

Earlier quoted context omitted.

Language Design: Let's start with the admission that there's a lot of cargo culting in language design. Evidence is hard to come by and the best evidence is other languages that succeed with different choices. I remember the flame wars about how multiple inheritance would cause a language to fall apart. When will languages adopt the idea that encapsulation is not sacrosant, as the theoretical issue about the backdoor…

Spring does (and perhaps even prefers where possible) constructor-based inheritance though — which is as pluggable as it gets, making testing easy.

> Spring does (and perhaps even prefers where possible) constructor-based inheritance though

OFC Spring does lots of things (too many things), but that varies project to project based on what series of Spring-related libraries are being used.

More likely I'll see non Spring-core annotations like @RestController + @RequestMapping-attributes and have to figure a standard way to mock up some of what Spring does just to assert the outputs. Perhaps there will be a series of full functional tests which requires a setup/teardown. Maybe the project just ignores endpoint tests and focus on the less Spring annotated business logic claiming "it's simple enough".

Spring has resulted in slow, complex, and incomplete (coverage) testing almost anywhere it's used because it's literally hiding functionality behind a runtime composition that you can't access casually by calling a routine.

It's problematic because it's complex and the versions

Re: Why general inheritance is flawed and how to finally fix it

#59

The final keyword is one of those places where Java shows its age to me. I agree with the overall point that inheritance is flawed, but I cannot bring myself to conclude that the use of final is the answer to the problem. Simple example, String is final in Java. It is also immutable, and that is (mostly) irrelevant. Lots of string fields on inbound requests have validations, a simple one would be a field that contain…

The "extends" keyword gives it away that inheritance in Java was not positioned to support the restrictive cases you have in mind (Square : Rectangle, NegativeNumber : Number, TenCharacterString : String).

What issues do you see with wrapping? TenCharacterString eg. could use char[] as its backing store and implement CharSequence if you want to get it to speak a common language with String.

Re: Why general inheritance is flawed and how to finally fix it

#60
post #44

Earlier quoted context omitted.

People keep telling this about Python, always ignoring who was paying Guido's salary.

> People keep telling this about Python, always ignoring who was paying Guido's salary. Well, reveal the spoilers and don't keep us all in suspense :-) Who was paying GvR a salary[1] when Python took off circa 2001/2002? [1] I don't think paying a single person a salary is the same as the millions of dollars poured into marketing and development as done with all the other popular languages.

Zope was, which was one of the best ways to do CMS back in those days.
Post reply on HN