Live data from Hacker News

99 Bottles of OOP now available in Python

sandimetz.com

91–93 of 93 posts

Re: 99 Bottles of OOP now available in Python

#91
post #90
post #88

Earlier quoted context omitted.

> Inheritance is not a banned practice. Maybe it should be. Go and Rust do not provide implementation inheritance, and I think that's for the best. Few language features have led to so much spaghetti code. > It should just be your second choice when there's a better path through composition. Do you see one here? I don't think this logic should be split over a graph of objects at all. This is highly cohesive code; it…

> Maybe it should be. Go and Rust do not provide implementation inheritance, and I think that's for the best. Few language features have led to so much spaghetti code. I agree, but there are reasons inheritance becomes problematic. Just throwing the baby is not helpful. Go, Elixir, Rust are all relatively young languages and although they did away with inheritance, they make use of interfaces/protocols/traits, hintin…

> they make use of interfaces/protocols/traits

Oh I very much agree, I love interface polymorphism.

> "No Bottle", "One Bottle", [etc] are distinct things and should be represented accordingly

I completely disagree. The problem is to generate a 100-line poem, line by line. Our challenge is to express the rules which govern how to derive a line from its line number in the clearest way possible. Creating an ontology for bottle types makes that overcomplicated. What if there were a special rule for bottle numbers divisible by 3? What if there were a special rule for doubled digits? Would we need to create a DivisibleByThreeWithDoubleDigitsBottle using multiple inheritance to write a line for 66 bottles? Why?

The big gift of OOP is interface polymorphism. The big curse of OOP is the philosophy that objects should model "real distinct things." Object-oriented domain modelling often causes more problems than it solves. Clear dataflow, cohesively represented logic, and loosely coupled modules are much more important than some philosophical notion about what sorts of ideas ought to be given associated objects. That's how you get Joe Armstrong's "gorilla holding the banana and the entire jungle."

Re: 99 Bottles of OOP now available in Python

#92
post #85

Earlier quoted context omitted.

Your problem was a misuse of inheritance, not encapsulation or interfaces.

That is exactly what I said you could say: > You could say that I just did not do it right, but that is the problem. You need to know precisely what the future will want to do it right and that is never possible to know in advance. Every time inheritance causes a headache, you can call it a misuse of inheritance, but that is only obvious after you have been to the future.

You don't need to precisely know about the future to know that inheritance isn't for sharing behavior. Unfortunate it's not really taught properly.

Re: 99 Bottles of OOP now available in Python

#93
post #85

Earlier quoted context omitted.

That is exactly what I said you could say: > You could say that I just did not do it right, but that is the problem. You need to know precisely what the future will want to do it right and that is never possible to know in advance. Every time inheritance causes a headache, you can call it a misuse of inheritance, but that is only obvious after you have been to the future.

You don't need to precisely know about the future to know that inheritance isn't for sharing behavior. Unfortunate it's not really taught properly.

That is easy to say in hindsight when given the example. It is not so easy to see in advance. After all, OOP’s proponents say that OOP makes everything better. You never hear them saying “don’t use OOP here”.

https://duckduckgo.com/?q=oop+inheritance+behavior

I doubt you would find a single result in the top 10 saying not to do this and many will seem to encourage it. One of the results says:

> Inheritance is frequently used to integrate your code with library code

A much younger version of myself said: Daemonizing should be a library function. Let’s use inheritance to do that.

Saying it is not really taught properly is avoiding the reality that you just can’t teach it properly. Knowing for certain when it will not cause problems requires knowing the future.

Post reply on HN