Re:Teach Programming to become a better programmer
by slobotron on Sunday June 17, 2018 @07:02PM
(#17334878)
Some would argue that OOP and class hierarchies are orthogonal concepts, so any analogy with biological taxonomies is bound to leave you unenlightened for a long time.
Re:Teach Programming to become a better programmer
by gleenn on Sunday June 17, 2018 @10:02PM
(#17335451)
And yet sadly that almost always what authors reach for when looking to explain OOP...
Re:Teach Programming to become a better programmer
by ibeckermayer on Monday June 18, 2018 @01:41AM
(#17336193)
Can you go into a bit more detail about what you mean with these special fn_for_* things? I learned OOP recently with all the animal->mammal->cat analogies, however those all seem to focus on inheritance and miss the key concept which might be summarized as “managing context”. Am I on the right track here?
Re:Teach Programming to become a better programmer
by Majora320 on Monday June 18, 2018 @03:50AM
(#17336558)
I'm not the original commenter (and on mobile, so this response might be a little terse), but I think what he's talking about is polymorpism. For an example, if you have two classes, Int and String, and you have a method special_fn you want to implement for both in different ways, (e.g. "addition/concatanation"), you can either make a bunch of special_fn_* stuff, or simply create an interface SpecialFner with the special_fn method, and implement it for Int and Str. This lets you use this interface in other places without worrying about all the different versions of this function.
A class is not a car, you don't explode your car when you go off road, create a SUV using the base of the car along with what's in the trunk, then do it back again when you reach a road.
Analogies are a terrible way to teach. Both dogs and cows are mammals with 4 legs and a tail, but you will have an interesting experience playing catch with a cow and trying to milk a dog.
I only learned what a class is and why it matters after writing a bunch of C spaghetti code trying to keep track of special_fn_for_strings, special_fn_for_ints, special_fn_for_big_ints, etc. You can teach that way quite easily if you have more than a week to do it in.