3 ms·
The problem with OOP isn't the concept itself. IMHO, the problem seems to stem the fact that people use a "Class" as both a means of organizing code and as a st
by choiway 7y ago
The problem with OOP isn't the concept itself. IMHO, the problem seems to stem the fact that people use a "Class" as both a means of organizing code and as a state machine. When you confuse the two, problems just get exponentially worse.
- AnimalMuppet 7y agoThat is the concept of OOP - that you package together the data (state) and the functions that can operate on that data.
- gmueckl 7y agoYes, but it does not make sense to take this mantra to religious extremes. As soon as you have different objects of different classes involved in the same state transition, you have a problem: where do you put the method that orchestrates everything? Usully, neither of the objects involved in the transition are the right place, but people shove it in there anyway.
- madhadron 7y agoUsers of multiple dispatch OOP languages (Common Lisp, Dylan, CLOS, C++ STL) would disagree vehemently with this characterization.
- AnimalMuppet 7y agoWell, I'm a C++ STL user, and I agree with me... Could you be more specific about 1) in what sense you call C++ STL multiple dispatch, and 2) why you think it disagrees with what I said?
- madhadron 7y agoIf you bundle functions and data, you end up implementing M functions each on N types, or M*N. If you can separate your functions and your data, you implement M functions and N types, or M+N. This is an explicit design goal of the STL and Stepanov's research that led to it. Similarly, Stepanov was explicitly trying to be able to write a polymorphic max function `T max(T a, T b)`. That is, the instance of the max function actually used is chosen based on all the arguments, not solely on the first, which is the definition of multiple dispatch. C++ also has a single dispatch object system, and the STL even mixes them, putting things like vector::push on the class with the single dispatch system and the STL algorithms in the multiple dispatch system.
- pjmlp 7y agoFor example via template meta-programming, or free functions with overloading.
- choiway 7y agoAgreed. What I'm saying is that I think you avoid a host of problems if you distinguish between data and state.
- thisiszilff 7y agoYou don't need to modify that data. The methods can produce other objects in which case OOP starts to look very functional, the main difference being that you lead with the data (a.to_foo() instead of food(a)). There's a lot of different definitions of OOP and some of that is willy nilly state modification everywhere, but other parts of it are encouraging you to see what data is coupled together and to treat that as a unit, therefore helping you think at a higher level about what you're doing.
- snidane 7y agoTotally agree. The case for organising code should be named 'module' instead of a class. It's very nicely visible in Python where class and module are the same thing - a dict essentially.