3 ms·
oh my god people still do class Car examples. So hard to use a real world example with all this open source code...
by brainzap 7y ago
oh my god people still do class Car examples. So hard to use a real world example with all this open source code...
- moksly 7y agoThey do. I have a side job as an external examiner for CS students and the first years are still taught the same Car/Animal examples when learning about polymorphism that I was decades ago. I’ve never once used that knowledge professionally to any sort of success. The complexity of polymorphism always ended up biting us (any company/org I’ve worked at) in the ass when things eventually grew way too far apart than what was originally envisioned when the polymorphism made sense. Kinda hilarious that they are still teaching it with those useless examples though. You’d have thought they could come up with something better by now. I mean, I get why you’d chose something obvious, but in my experience CS students seem to understand polymorphism perfectly well without making a duck quack and a dog go woof. But what do I know, I can’t even make it work.
- mjburgess 7y agoI doubt there's any programme you've ever written that makes no use of polymorphism (the contextual resolution between multiple semantics to a term). Even 1 + 1 is polymorphic, ie., "1" + "1" selects for a different behaviour. Method overriding may rely on inheritance, and the problem is usually the inheritance not the polymorphism.
- nightski 7y agoThey did not specifically state it but I believe he/she was referring to subtype polymorphism. Parametric polymorphism as you describe is far more useful imho.
- mjburgess 7y agoThere are many types -- it is phrased generally and may lead readers to believe that there is some issue with polymorphism. I still object on the subtype grounds though -- because the issue is not the polymorphism (that is useful and usually a good idea). It's the inheritance relation, which is not the subtype relation -- eg., you can do subtype polymorphism with just implementing interfaces and there shouldn't be any problems. This comment is actually expressing issues which have arisen because of inheritance and confusing it with polymorphism.
- Floegipoky 7y agoI have far fewer problems with the Car than I do with the rest of the example. > The problem comes when you want to add continually new methods all the time This is not a real problem! Violating encapsulation to avoid dealing with the occasional merge conflict is probably the worst use of pattern matching I've ever seen. The tug-of-war between OO and FP is greatly exaggerated.
- mysonytv 7y agoand the other are still using Foo and Bar :-/