OO & Functional Programming
Some readings and my opinion on OO and Functional Programming
Goodbye OO
https://medium.com/@cscalfani/goodbye-object-oriented-programming-a59cda4c0e53
A scathing critical of OO. Main points:
- Inheritance fails
- "implicit environment that they carry around with them, you wanted a banana but what you got was a gorilla holding the banana and the entire jungle" - I didn't really buy this point. NPM packages also may bring a lot of dependencies into the project. The point is to control dependency. I don't think this is particularly an OO issue.
- Diamond Problem - yes, this is legitimate
- Fragile Base Class Problem - code that inherite from base class depends on the particular implementation (internal) of base class - yes this is legitimate. Inheritance has it's evil side. Either should be used with careful planning & best done by one (don't inherit someone else's code, or that there is clear structure...., best not. "Prefer composition than inferitance" (https://en.wikipedia.org/wiki/Composition_over_inheritance)
- Hierarcgy Problem - "categorical hierarchy" vs "containment" / "interface" like hash tag... the logic in the article is a bit confusing but I agree "interface like hash tag" and is better in organisation. This is basically the idea "composition / interface over inheritance".
- Encapsulation fails
- I think the article confused the concept "encapsulation". Encapsulation is to encapsulate the internal state of object. Object being held by someone who should not hold it or manipulate it... not a problem of encapsulation but a misuse of the object. Anyway, not agree with the author.
- Polymorphism fails
- "It's just you don't need OO to get this" - well, not really something wrong with OO.
So the take home to me from this article - not anything new. It's just be caution with inheritance. That's a rightful one. Composition over inheritance - yes I agree. Inheritance still can be used - but needs a good plan.
This article sounds more emotional than objective. OO still has its merits. Like any tool, there needs caution and not to misuse...
Rise and fall of OO
https://medium.com/machine-words/the-rise-and-fall-of-object-oriented-programming-d67078f970e2
Yes, I have same feeling with this article. OO makes sense in certain domain... but not necessarily all domains. Think carefully when to use it. Where to place some codes... don't be dogmatic.
- The "platypus" effect - egg laying mammal, where to put in the class hierarchy? (category always break somewhere in real world...)
- Deep class hierarchies - yes this is a problem. Base class try to handle too much. The root of this problem is still that the single category hierarchy does not work well in real world. Multiple inheritance has the diamond problem. So "composition > inheritance"
- Encapsulation: only own methods change states.... then when some data (noun) needs to be passed multiple passes in various procedures (think of MISO), process belonging to a single pass seeps into objects... result: the logic of a process is broken into different pieces and put into different classes..... "
- OOP - complex objects ("noun") - result: verbs (process) is broken into classes "noun", also resulting these objects difficult to setup (dependencies, for example, even a data source?) difficult to test
- FP - dumb objects (just data), passes (processed) by functions - object easy to setup, all logics in a function, easy to test
- ORM - object-relational-mapping, yes I know....
- Functional Programming:
- OOP - interacting or communicating with objects (objects talk to each other)
- FP - transforming objects (focus on verb, dumb objects)
- Do not change input
- "pure" functional programming - all objects are immutable... a bit dogmatic