Hacker News new | ask | show | jobs
by grahamburger 3702 days ago
Well I'm not exactly a teacher or an expert, just an armchair critic - so I won't pretend that my ideas will be revolutionary or even all that good :) but, because this is something I've been thinking about recently, I'll contribute. My oldest son is 5 and I've been thinking about how I'll start to teach him programming, if he finds himself so inclined. Right now I'm thinking I'll start by working through a Christmas wish list program with him. For OOP specifically, the wish list items might make a good (if simplified) example of classes/objects, with maybe some inheritance for 'things I would like' vs 'things I would like to give to other people' vs 'things I would like to do' etc.

Essentially my gripe with the animal and car analogies is exactly what Alex3917 wrote above - you're (almost?) never going to actually implement anything like a car on an animal in a real program. And if you do, you're almost certainly not going to give it methods like 'Honk' and 'Meow' (which is exactly how OOP was described in my first class on the subject.) It's not that they're bad analogies - in fact it's almost that they're too good of analogies. They represent the OOP concepts very well, just not the practical usage of the concepts.

Actually the truth is I'm a little bit disillusioned with OOP altogether, and it seems like there's a lot of movement in the industry away from OOP with things like Go, Rust and other more purely functional languages.

3 comments

> never going to actually implement anything like a car on an animal in a real program.

Did you mean "on" or "or"?

Using OOP to implement a vehicle is a no-brainer. It's a completely standard model for games.

Extending the animal class to make a car would be weird though.

One point of OOP isn't that you make classes, but that the classes you make can be easily duplicated and automated.

So you can make an animal with a few simple behaviours, use your animal prototype to make a herd or flock, and suddenly you've got emergent semi-intelligence, which you can define by changing a few lines in the prototype.

It's not just a way of giving properties to something that's kind of like a real object - it's a way of simplifying automation and bulk updates of related entities.

>Extending the animal class to make a car would be weird though.

Carriage extends Animal with Cart Car implements Carriage with Engine as Animal

That sounds more like composition then inheritance.
Actually, a language not having a class system does not mean it's not object-oriented. Javascript prior to ES6 did not have a class system, but was OO. Classes are just one of many ways to implement objects in a language (just saying, because you mention go & rust)
Yeah for sure. I should have specified class based. Regardless, I think those languages place much less emphasis on OO than, say, Java or Ruby, right?
Lightbot and code.org are suitable from 5yo or earlier IMO. Code.org uses the "jigsaw" visual programming pane (blockly) that Scratch uses so they work well together - Scratch can export to flash for sharing online.