Live data from Hacker News

Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

web.archive.org

71–80 of 113 posts

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#72
post #3

Earlier quoted context omitted.

Are you sure? His argument is one simple paragraph: The `Car extends Vehicle` or `Duck extends Bird` type of tutorial obscures more than it illuminates. In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. We make class hierarchies in order to simplify the code by allowing different parts of it to be changed independently of each other, and to eliminate duplication (which co…

Indentation breaks HN. Blockquote should not inherit from Codeblock. Please remove it and use > for quotes. > The `Car extends Vehicle` or `Duck extends Bird` type of tutorial obscures more than it illuminates. In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. We make class hierarchies in order to simplify the code by allowing different parts of it to be changed independe…

Agreed, if the '1337 hax0rs at HN would implement quoting, then > would be a good way to express it.

As it stands, > does nothing on HN, so we're treated to endless complaints about people misusing code blocks for quoting. The complaints are valid, since code blocks don't work properly on mobile. Complain enough about either of these issues and they'll gripe at you for complaining. It never occurs to them that fixing the problems would avoid both the need for complaining and the need for griping. Oh, well, life goes on.

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#73

>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…

I disagree. The whole reason Linnaeus created taxonomies was to simplify what had to be expressed about living things, so basically to shorten the "mental code" involved. If you know something is true of all mammals, and humans are mammals, then everything that is true of all mammals is also true of all humans (but the converse isn't true; things can be true of humans that aren't true of all mammals). Of course, later on taxonomies had another purpose; Darwin and later thinkers realized that taxonomies often correspond to the actual historical evolutionary relationship between organisms. But Linnaeus himself had no evolutionary beliefs.

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#74

>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…

Well said. And #3 is also an area where Functional Programming falls completely flat. There is simply no easy way in any FP language that I know to capture such a simple mechanism as: "Reuse 90% of this piece of code but alter just this 10%". Specialization is a very, very powerful aspect of OOP, one that's extremely easy to explain and which comes in handy to model a surprisingly wide variety of problems.

I actually think FP languages I know of have this functionality, although it's used to differing degrees in each ecosystem.

ML modules have modules and functors, which can exactly mimic this and in fact can be even more flexible because they are structurally rather than nominally typed.

Clojure can get some of this via multimethods, but it's not quite the same thing.

Haskell has Backpack. This is fairly new, but takes an approach similar to ML modules. (Interestingly enough to your point elsewhere in this thread, this is a good example of how type classes were not sufficient for this use case).

Scala has it, but that's cheating :). Although it does have a really cool thing which is that every object instance is itself an importable package, which leads to some really nice code reuse at times.

Stepping back, I actually think "Reuse 90% of this piece of code but alter just this 10%" is actually best captured just with splitting things up into functions/procedures in imperative and functional programming languages, rather than building a large class hierarchy, but that's another story altogether.

EDIT: I suppose what you're talking about specifically is overriding an already implemented method, which you can get via module name shadowing and re-exporting of a parent module as Hermitian909 points out elsewhere.

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#76
post #33

>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…

> 3. Often you want to use the default protocol implementation with some changes. Instead of re-implementing the rest of the protocol, it's highly convenient to be able to specify only the differences. > #3 is the core reason why inheritance was developed. No, absolutely not. As sibling comments say, composition is sufficient for that. I can only see exactly one reason why inheritance is necessary: to allow superclas…

Firstly, late binding is orthogonal to inheritance. It simply means that methods are looked up based on runtime information, rather than determined at compile time. You can have late binding in a language with no inheritance or classes at all.

Secondly, OO composition does not solve the problem I described in #3. If object X has 9 methods I want to reuse in object Y, making X a component of Y still requires me to re-implement those 9 methods in Y, even if they are just pass-throughs.

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#77
This is good.

I've even seen OO tutorials which make it explicit to give the bad advice that all your objects should match real world _things_.

This does not match my experience of OO programming or what the actual challenges or rewards are:

> We make class hierarchies in order to simplify the code by allowing different parts of it to be changed independently of each other, and to eliminate duplication (which comes to the same thing). Without any context as to what the code needs to accomplish, you can’t make a judgment about whether a particular design decision is good or bad.

YES.

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#78
post #61

Earlier quoted context omitted.

“Geez” is a minced oath designed specifically to avoid blasphemy—avoiding it by a millimeter, to be sure. Even some devout Christians say things like “gosh”, “darn”, and “geez”.

"Overhead, without any fuss, the stars were going out" I once knew a baptist preacher who was a serious student of theology and moral philosophy. He liked to discuss the distinction between theology and law, particularly when framing behaviour as the imperative expression of faith, and not faith as the expression itself. Needless to say, the parishioners loathed him and he was hounded out for exposing their constant…

Landīca!

Some Christians aren't in favor of cursing in general, even if it's not blasphemous. My best understanding is that they feel that it expresses a lack of gratitude for the blessings they have—that, at least for a moment, you are forgetting that every moment of life is a miracle, allowing yourself to become enslaved to your wrath, which is of course a sin in standard versions of Christianity. (This does of course pose some difficulties to reconcile with the stories of cursing the fig tree and the money changers, which the Christians resolve in various creative ways.)

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#79

>In good OO programming, we don’t make class hierarchies in order to satisfy our inner Linnaeus. This correctly identifies one of the worst problems with how people construct OO programs when they get out of college. They are infected with the idiotic desire to make neat taxonomies. They don't know why. They can't even explain the rules that make one taxonomy good and another one bad. They just feel some immense pres…

Well said. And #3 is also an area where Functional Programming falls completely flat. There is simply no easy way in any FP language that I know to capture such a simple mechanism as: "Reuse 90% of this piece of code but alter just this 10%". Specialization is a very, very powerful aspect of OOP, one that's extremely easy to explain and which comes in handy to model a surprisingly wide variety of problems.

Haskell’s typeclasses[1] support this use case—though they are oftentimes a bit clukier to use than OOP approaches.

[1]: https://en.m.wikipedia.org/wiki/Type_class

Re: Goodbye, shitty Car extends Vehicle object-orientation tutorial (2011)

#80
i sat down with tech yourself java in n-days (forget the exact title) around 1998/99 and promptly returned the book because of my frustration with the `vehicle->wheeled vehicle->engine powered vehicle->motorcycle` explanation of OOP. i had been using a niche OOP lang (lpc) for quite a while and the examples in that book felt oddly ridiculous. just my opinion (at the time), but it certainly did not resonate with me
Post reply on HN