3 ms·
People don't like (implementation) inheritance, for good reason. But that's not the core of OOP, that's some weird crap people piled on top of OOP in the 90's.
by kentonv 6y ago
People don't like (implementation) inheritance, for good reason. But that's not the core of OOP, that's some weird crap people piled on top of OOP in the 90's.
Object-oriented programming, fundamentally, is about associating code with the data it manipulates. Code + data = object. Two essential follow-ons:
* Encapsulation: Your object provides an interface composed of methods, without allowing callers to reach in and mess with the data inside except by calling those methods. This allows your implementation to evolve without breaking callers.
* Abstraction/polymorphism: Objects with different implementations can implement the same interface thus making them interchangeable. This enables code which operates on such objects to be reused across wildly different use cases.
These fundamentals exist in basically all large systems. Example: Linux file descriptors are objects. Different kinds of file descriptors (e.g. disk files vs. sockes) implement the same interface (syscalls, e.g. read/write), and you cannot reach directly into their implementation from userspace, which allows the kernel implementation to evolve over time. You really can't not use OOP in these scenarios.
The opposite of OOP is separating code from data. In anti-OOP, you declare your data structure completely transparently, without declaring any kind of "methods" that apply to it. Code modules interoperate by operating on the same underlying structure. This tends to lead to sclerosis as adding new features to the data structure without breaking existing code can be quite difficult.
My hot take: The philosophy of REST (though less often the actual implementation) is disturbingly anti-OOP.
- mwcampbell 6y agoYou say inheritance was added to OOP in the 90s. I don't know the history here, but I know Smalltalk has inheritance. So was that a late addition to Smalltalk? I'd also like to know why you think REST is disturbingly anti-OOP. It does impose a separation between the implementation of a resource and its representation, right? So multiple implementations could have the same representation and the same verbs. So in that sense, it's like OOP, isn't it?
- kentonv 6y ago> You say inheritance was added to OOP in the 90s. Looking it up, I think I was wrong about that. Early OOP did in fact have implementation inheritance. I guess what I should have said is, OOP originally had three legs. One of them turns out to be bad but the other two seem fundamental to large-scale systems programming. > I'd also like to know why you think REST is disturbingly anti-OOP. So, this is pretty abstract, but REST philosophy seems to put a lot of emphasis on representations of data while discouraging communication of operations on the data. The way to operate on the data is to GET the representation, modify it, and then PUT it back -- not to POST a message saying "please perform operation F". I've heard several hardcore REST advocates specifically argue against communicating operations, deriding it as "RPC" (which I guess they see as derogatory?). In practice I think most people only follow this philosophy when it makes a reasonable amount of sense and ignore it when it doesn't.