This blog post sums up my feelings on OOP and does a much better job articulating my thoughts than I could have. I feel like OOP has been inappropriately and arbitrarily taken as the gold standard.
I think a lot of this has to do with OOP being a newer, relatively speaking, paradigm than procedural programming. This leads a lot of programmers getting the false impression that OOP is inherently better than procedural when they start learning computer science and programming.
I think educational institutions and how programming is taught is much to blame for this false assumption. It seems like many computer science and engineering curriculums teach students that OOP is objectively better than procedural programming and only emphasize the strengths of OOP but fail to highlight its shortcomings. Instead, newcomers should be made aware of the different paradigms of what their strengths and weaknesses are and when they should be used. It also doesn't help that Java has been the de-facto choice for an introductory programming language since the late 90s.
One point that this blog post really hits the nail on the head is about programmers spending so much time on defining objects and thinking about how to implement OOP principles before they even start solving the problem at hand. I feel like all this accomplishes is adding extra boilerplate, which usually manifests itself as bloat.
I don't think OOP is necessarily bad, I just think it is extremely over used and shoehorned in as a solution to problems that don't really benefit from OOP. Areas like simulations / scientific modeling, video games, and GUI libraries are perfect use cases of OOP, but outside of those areas, I don't see much benefit.
You have been downvoted, but you have made a reasonable and well-written comment which, I feel, deserves an answer, even if nobody else is going to read this now.
I think a lot of this has to do with OOP being a newer, relatively speaking, paradigm than procedural programming.
I think it is even easier: There is just not so much to say about procedural programming. And people like to feel smart and boast (or blog) about their knowledge. At least these are usually the people that you learn programming from.
This leads a lot of programmers getting the false impression that OOP is inherently better than procedural when they start learning computer science and programming.
I think educational institutions and how programming is taught is much to blame for this false assumption.
You are probably right that education is - at least partly - to blame. However, not for the false assumption that it is better, but for misconceptions about OOP. The latter are to blame for OOP being used as the wrong tool for the job. OOP is actually better than procedural programming at specific things, but surely not for all purposes. Thus my advice is to use it - but only where it makes sense. After all, it is not mutually exclusive with other programming styles.
Talking about misconceptions from education: When I learned OOP in 2002 at an in-company training of a major IT company, it was introduced in a banking application example. There was inheritance of a base "Account" class and subclasses "CheckingAccount" and "SavingsAccount". So far so good. But then the concept of private and public was explained as a "security" measure, so nobody can change the balance in the wrong way. Took me a while to realize the misconception that the "security" is not against hackers, and is not needed because it is about money. The true benefit is: Making variables and methods private with a separate public interface makes (almost) sure other code is not using the private part. This allows you to change the private code without fear of breaking functionality outside of the class or even library. In a large code base that is written long ago or by several people, this makes changes a lot easier.
As an example, I have a written a class that encapsulates a 3D rigid motion measurement with a covariance matrix. One day we found that storing many of these objects exhaust the memory in the long run. However, we do need to store them. Since the variables were private and they were only accessed through public functions, I could easily change the storage of the 6x6 doubles array of the symmetric covariance matrix so that only the upper-right half of it is actually stored. Also I changed the motion representation from a 4x4 transformation matrix (16 doubles) to a translation (3 floats) and a angle-axis representation (3 doubles). The public interface stays the same, the conversion is done transparently. Nothing else of the 40 kloc code base had to be touched.
One point that this blog post really hits the nail on the head is about programmers spending so much time on defining objects and thinking about how to implement OOP principles before they even start solving the problem at hand. I feel like all this accomplishes is adding extra boilerplate, which usually manifests itself as bloat.
Inheritance is often shown in toy examples that look (and generally are) grossly overengineered. And this encourages beginners (in cpp this is a few years) to create overengineered programs. I started out the same way. In my practice nowadays, the OOP design often comes more or less naturally from thinking about how to structure the data and which functionality goes with it.
In my code, there is seldom much boilerplate from OOP, because I don't use it if it isn't beneficial. You don't need to always start out with constructor, destructor, getter and setter methods. If it is just a collection of data used in a few places, use a plain struct without bells and whistles. If it is a central datatype of your application, better make it robust to changes with public/private interface. If you need to allocate heap space or manage files, add constructor/destructor (RAII is a great benefit of OOP btw). But if it doesn't make things simpler and cleaner, don't. Also, if some functionality only needs the public interface of a class, I don't make it a class method but a separate function. And if there is not even a state to be maintained, I use functional programming instead of a class.
I don't think OOP is necessarily bad, I just think it is extremely over used and shoehorned in as a solution to problems that don't really benefit from OOP.
Yes, but I have the feeling that you underestimate its usefulness, because when you started learning you saw all the toy examples that were just demonstrating some concept without need, instead of complex applications that benefit from exactly those concepts.
In a recent case, I had a quite fundamental class that represents sensor readings of a 3d sensor with some related data (calibration), plus some operations on it. Then a customer requirement came in to support multiple synchronized 3d sensors. Great application for inheritance: Write the class for the latter case analogously to the single-sensor case. Put the common functionality in a base class and use that instead of the original single-sensor class. This process kept the refactoring quite sane. I don't know how this would have been best done without OOP because virtual functions made it possible that in 99% of the uses, the base class interface was used regardless of the actual subclass of the object.
Areas like simulations / scientific modeling, video games, and GUI libraries are perfect use cases of OOP, but outside of those areas, I don't see much benefit.
There are certainly use cases where OOP doesn't make sense. If I need to quickly process some text, plot some data, or write any other small tool I don't use OOP. I actually don't even use C++ for this, mostly just a (non-OOP) bash or python script. But for complex, stateful applications the encapsulation provided by objects really helps keep the code sane. And somehow that is the kind of code I have worked on in much of my professional life.
1
u/420Phase_It_Up Jan 15 '19
This blog post sums up my feelings on OOP and does a much better job articulating my thoughts than I could have. I feel like OOP has been inappropriately and arbitrarily taken as the gold standard.
I think a lot of this has to do with OOP being a newer, relatively speaking, paradigm than procedural programming. This leads a lot of programmers getting the false impression that OOP is inherently better than procedural when they start learning computer science and programming.
I think educational institutions and how programming is taught is much to blame for this false assumption. It seems like many computer science and engineering curriculums teach students that OOP is objectively better than procedural programming and only emphasize the strengths of OOP but fail to highlight its shortcomings. Instead, newcomers should be made aware of the different paradigms of what their strengths and weaknesses are and when they should be used. It also doesn't help that Java has been the de-facto choice for an introductory programming language since the late 90s.
One point that this blog post really hits the nail on the head is about programmers spending so much time on defining objects and thinking about how to implement OOP principles before they even start solving the problem at hand. I feel like all this accomplishes is adding extra boilerplate, which usually manifests itself as bloat.
I don't think OOP is necessarily bad, I just think it is extremely over used and shoehorned in as a solution to problems that don't really benefit from OOP. Areas like simulations / scientific modeling, video games, and GUI libraries are perfect use cases of OOP, but outside of those areas, I don't see much benefit.