4 ms·
> I didn't fully grok OOP until I saw how composition and dynamic dispatch can be used in real code to create abstractions and flexibly swap out different imple
by PaulStatezny 4y ago
> I didn't fully grok OOP until I saw how composition and dynamic dispatch can be used in real code to create abstractions and flexibly swap out different implementations for your interfaces.
> You could build a chatbot that supports Discord, Slack, and IRC dynamically at runtime...
As a counter-point, OOP isn't necessary for dynamic dispatch.
None of these dynamic features you describe are necessarily any harder in non-OOP languages — or easier in OOP languages.
You can do the same kind of dynamic dispatch in Elixir, Go, etc.
OOP really is a preference, not a differentiator.
Source: I cut my teeth on OOP and used it for many years. Been using Elixir for the last half a decade, and have zero loss of ability to do things like this.
- Transfinity 4y agoI agree. IMO, Java-style OOP conflates 2 different concepts, polymorphism and inheritance. Polymorphism (including dynamic dispatch and duck typing) is a game changer, in that it encourages simple, stable interfaces, enables testing, encourages encapsulation, etc. It's a key technique for building big projects. Inheritance is a tool for reducing the amount of code written by a human, among many others (things like code generation and composition) I haven't seen it unlock other important conceptual domains the way polymorphism does. Unfortunately many undergraduate curriculums get overly excited about inheritance when teaching OOP. I guess animal-cat-dog is an easy example (though totally unrealistic), but the problems polymorphism solves don't often show up in classroom-sized projects.
- czx4f4bd 4y agoYes, the general applicability of these concepts is exactly why they should be emphasized when teaching OOP rather than wasting time on uselessly contrived examples of inheritance. However, I'm not really sure why your comment is framed as a counterpoint to mine. I explained what it took for me to grok OOP, but I never said OOP alone provides composition and dynamic dispatch. It seems needlessly antagonistic to make this some kind of programming paradigm pissing contest when that has nothing to do with anything I said.