Live data from Hacker News

Inheritance Often Doesn't Make Sense

sicpers.info

121–130 of 255 posts

Re: Inheritance Often Doesn't Make Sense

#121

If we are doing OO programming, and we have rectangles, IsSquare would be a good method for a Rectangle whose dimensions are mutable rather than Square being a subclass of Rectangle.

Now you have to remember to check (and repeatedly check) IsSquare at runtime to somehow deal with rectangles that aren't squares, which probably means throwing an exception that someone else has to remember to catch or face runtime errors. But if the dimensions are mutable, no alternative is very satisfactory.

Re: Inheritance Often Doesn't Make Sense

#122

The programmer's perspective: The phrase 'object-oriented' means a lot of things. Half are obvious, and the other half are mistakes. - Paul Graham. Implementation inheritance causes the same intertwining and brittleness that have been observed when goto statements are overused. As a result, OO systems often suffer from complexity and lack of reuse. - John Ousterhout Scripting, IEEE Computer, March 1998. The problem w…

I think the problem is more that OOP and FP teach that the solution is in the language constructs, when in fact the solution is in the developer. OOP and FP are typically taught as outputs. You take a problem, you apply FP or OOP magic, and you get a solution squeezed into an FP or OOP shape. The implication is that the language somehow half-solves your problem just by being how it is, and all you have to do is apply…

Neither OOP nor FP can fix a bad programmer. I agree. Static typing is similar.

But, like static typing, the right environment can prevent whole classes of bugs and maintenance issues.

It's just harder to write bad code in FP when your inputs are explicit and there is no implicit state.

Re: Inheritance Often Doesn't Make Sense

#123
post #21

Earlier quoted context omitted.

I always find that the common example of Rectangles and Squares leads me to a different conclusion. It assume that the best way to go about is to only have a single sideLength method, but from a data structure perspective it seems more obvious that the Squares class substitute instead the validation method by adding constraints that a valid square only exist when both sides are equal. Rectangle class must already hav…

Agreed. In fact I would expect the Square subclass to implement width= and height= so that they each actually set both internal values.

So this behavior is reasonable?

Rectangle r=getRectangle(); r.width=1; Assert(1, r.width); //passes r.height=2; Assert(1, r.width); //fails or passes depending on subclass

Re: Inheritance Often Doesn't Make Sense

#124
post #119

Earlier quoted context omitted.

I really dislike this kind of hand-wavy dismissal of ideas/opinions as “programmer-hipster”. It seems to assume the person in question has no intelligent reason behind their thoughts/opinions. And it dismisses the opinion instead of engaging with it intellectually. And having been on the receiving end, it’s insulting. It feels like being called stupid. It’s fine to disagree with opinions, but when you assume people a…

I get what you're saying, but I'm still persuaded this is what happens with Kay and/or smalltalk. 100 times I've seen threads about OO. 99 times someone brought up Kay/smalltalk. Zero times did they specify why the messaging model was relevant to the present discussion. That's important to do, because more OO programmers use C++/C#/Java, and are not smalltalk experts. So, it seemed to me that they were namedropping.…

That makes sense. Sounds like the kind of comments you tend to see are out of context and don’t engage with the subject matter. I can see how that comes across as signaling.

Re: Inheritance Often Doesn't Make Sense

#125

The programmer's perspective: The phrase 'object-oriented' means a lot of things. Half are obvious, and the other half are mistakes. - Paul Graham. Implementation inheritance causes the same intertwining and brittleness that have been observed when goto statements are overused. As a result, OO systems often suffer from complexity and lack of reuse. - John Ousterhout Scripting, IEEE Computer, March 1998. The problem w…

I think the problem is more that OOP and FP teach that the solution is in the language constructs, when in fact the solution is in the developer. OOP and FP are typically taught as outputs. You take a problem, you apply FP or OOP magic, and you get a solution squeezed into an FP or OOP shape. The implication is that the language somehow half-solves your problem just by being how it is, and all you have to do is apply…

I think the problem is more that Roman and Indo-Arabic numerals teach that the solution is in the notation, when in fact the solution is in the mathematician. . .

Re: Inheritance Often Doesn't Make Sense

#126

The programmer's perspective: The phrase 'object-oriented' means a lot of things. Half are obvious, and the other half are mistakes. - Paul Graham. Implementation inheritance causes the same intertwining and brittleness that have been observed when goto statements are overused. As a result, OO systems often suffer from complexity and lack of reuse. - John Ousterhout Scripting, IEEE Computer, March 1998. The problem w…

Another quote: ------------------ The No True Scotsman fallacy leads to arguments like this: Person A: “No Scotsman ever steals.” Person B: “I know of a Scotsman who stole.” Person A: “No True Scotsman would ever steal.” Person A is thus protected from the harmful effects of new information. New information is dangerous, as it might cause someone to change their mind. New information can be rendered safe simply by de…

I don’t think those are No True Scotsman fallacies. Or at least not as you describe them. The problem appears to stem from using specific languages to argue about a broader concept. Java being verbose, Scala having too much ceremony and Ruby allowing monkey patching aren’t really complaints about OOP per se. Nor are issues of static or dynamic typing, bugs or bloat.

For example the discussion here hasn’t seen a lot of shying away from the practical and conceptual issues with inheritance.

Re: Inheritance Often Doesn't Make Sense

#127
post #78

Earlier quoted context omitted.

"Everything changes and nothing remains still; you cannot step twice into the same stream"

Ironically, the latter part of what you quoted shows the solution to representing change in an immutable system: create a different stream object instead of mutating the same stream object. (Streams in this case not being streams in an I/O sense, just an example of a class).

Yes, that's exactly what I meant. Sorry for not being clearer.

Re: Inheritance Often Doesn't Make Sense

#128
post #94

I took over the maintenance and enhancement of a customer's eCommerce site. It's written in Python, using an ancient framework - Pylons. The person who originally designed and wrote it, coded large super classes and then subclassed off those. And then somtimes subclassed off those subclasses. So now I'm lost in a maze of twisty classes/subclasses, which makes maintaining and enhancing this eCommerce site much, much m…

Inheritance was probably was a good idea for a small thing and quickly achieve certain goals until features ballooned and he keep promising to deliver more features on top promptly

There’s a rule from XP that people still ignore at their own peril. The rule of Three is, for those who tend to overengineer, a plea to wait a little longer. But for everyone else it’s a call to action.

When you hit three copies of a pattern is when you should reconsider your choices. Just because a pattern was fine ten minutes ago doesn’t mean you should keep doing it now. At some point it has become “too much and as part of the campsite rule you have to ask if the block of code is ridiculous. It may have already been ridiculous, or you might be the one who took it there, but that doesn’t matter because you’re here now and what are you gonna do about it?

Re: Inheritance Often Doesn't Make Sense

#129
post #86
post #77

Earlier quoted context omitted.

This matches my experience: ontological inheritance gets in the way. What we actually want is traits . What can something do , not what it is .

This seems like structural subtyping? Are these synonyms?

I think traits (as I know them) are still nominal subtyping. E.g.: a Rust struct implementing a next() method does not implement the Iterator trait even if they are structurally equivalent. You have to explicitly implement the trait.

Re: Inheritance Often Doesn't Make Sense

#130

The programmer's perspective: The phrase 'object-oriented' means a lot of things. Half are obvious, and the other half are mistakes. - Paul Graham. Implementation inheritance causes the same intertwining and brittleness that have been observed when goto statements are overused. As a result, OO systems often suffer from complexity and lack of reuse. - John Ousterhout Scripting, IEEE Computer, March 1998. The problem w…

Another quote: ------------------ The No True Scotsman fallacy leads to arguments like this: Person A: “No Scotsman ever steals.” Person B: “I know of a Scotsman who stole.” Person A: “No True Scotsman would ever steal.” Person A is thus protected from the harmful effects of new information. New information is dangerous, as it might cause someone to change their mind. New information can be rendered safe simply by de…

The No True Scotsman fallacy is based on the arguments of a single interlocutor who is trying to evade the conclusion.

Your description sounds more like a series of different conversations with different people at different times starting from different topics. Since people, times and topics vary, yeah, you'll get different counterarguments.

Especially since, like all programming theories, the content, meaning and boundaries of OOP are widely disagreed on.

But that doesn't make it a No True Scotsman.

Post reply on HN