Object-Oriented Programming is Bad
Video Statistics and Information
Channel: Brian Will
Views: 932,463
Rating: 3.9597459 out of 5
Keywords: OOP, Object-Oriented Programming, programming
Id: QM1iUe6IofM
Channel Id: undefined
Length: 44min 35sec (2675 seconds)
Published: Mon Jan 18 2016
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.
The downvotes indicate one of two things:
I'm in the second camp. I actually agree with his overall point - that OOP is overused, and that other approaches are more appropriate in many cases. I agree that procedural code is not only perfectly valid, but even more appropriate than OO code in a lot of situations. But everything in his "Why does OOP not work" section seems to hinge on the idea that you can't include object references in messages... which as far as I can tell, is just a completely made-up requirement.
Even Erlang, which embodies shared-nothing message passing perhaps best of all, allows object references (in the form of process IDs) to be passed in messages.
He further argues that an object is solely responsible for its own collaborators, so an object must instantiate its own dependencies and (due to the first made-up rule) must never share them with anybody else. This reduces the object graph to an object tree, and he goes on to show how ludicrous that sort of system would be. He justifies this with the statement "The moment objects are shared, encapsulation flies out the window".
Wait, what? Where does that claim come from? So, if I pass a single logger instance around in my code, I've thrown encapsulation out completely? If I have one thread-safe, mutable list that is written to by multiple producers, I'm breaking some sacred rule and not doing "true" object-oriented programming?
The sharing of objects is a technique for managing and limiting the use of shared state. A given scope (function or object) can only access the shared state if it's been explicitly given a reference to that shared state. It's reasonable, and indeed common, to have functions that act as coordinators, instantiating objects and deciding which of those objects is to be shared with which other objects. Objects share state because somebody with a broader view of the world decided that they should share state.
I think the speaker tried to make too strong a point. If he had stuck to "OO Programming isn't the universal solution to all problems", I think his point would be readily accepted. But he reached too far, and tried to make his more general argument "OO is the wrong solution to nearly all problems". But to argue that point, he had to argue against a made-up and limited notion of what OOP is - he made a strawman argument.
I would have liked to see more concrete arguments. Show the kinds of state-sharing problems that OO encourages or exacerbates, and talk about how non-OO approaches avoid or resolve these problems. Don't argue from theory, argue from practice.
I actually agree with most of what he said... except for basically everything in the "Why does OOP not work" section, which appears to be the central point of the overall presentation. OK, I'd also argue that long functions should be broken up; if you feel a need to put section headers in a long function body, that's a smell, and there's a decent chance that those sections could be extracted into supporting functions with no loss of readability.
So this post is getting a lot of downvotes and I don't think it's fair. He makes a number of very important points.
I remember when Java first came out and he is absolutely right on why it was adopted so eagerly. It never proved itself better than the 40 year old patterns that everyone used, it was because Java had so many features and libraries built in to the SDK and because of Intellisense.
Anyone who's worked on large object oriented systems can see the cluster fucks that can occur. Procedural programming has it's own cluster fucks, but OOP is not immune from them.
Oh boy, do I hate titles like this.
Regardless of how right or wrong the anti-OOP stance may be, I think it is very healthy to have the entire paradigm publicly challenged like this. I think OOP carries a lot of value, but it causes problems when left unchecked. So, it's actually refreshing to hear that good software is written without obsessing over perfectly encapsulating every bit of data in the program.
I have developed the following observations after many years of pushing through OO code. I'm not presenting them as indisputable truths. They're just how I feel so far.
struct
basically) or all private (data to uphold the overall object). Any other mixtures are questionable at best.protected
opens data up and encourages inheritance.Download
,Thread
, etc. I grew tired of always having to make-and-invoke. It made more sense to just call a function to kick everything off. I canasync
it if I want to; I don't need every single class to be clever about its usage.obj.get_parent()
orobj.get_neighbor()
orobj.get_container()
. This results in horrifying dependencies/hierarchies. It is much better to have higher level managers:container.get_neighbor(obj)
I'll add more as I think of them.
TL;DR OOP is never the right answer. "Encapsulation does not work at a fine-grained level". So why did OOP take over? Java with GC, Namespaces/No headers, Exceptions and other reasons. OOP leads to essentially shared state. Structuring OO programs is really hard and leads to a mess. Instead, write well organized procedural code, preferring pure functions and using ADTs when appropriate.
Uh... TL;DR the major points for those of us at work right now? (It's a 45min video...)
Several questions broken into different threads here:
Honest question here: is unit testing just out in this approach? That always seemed like the biggest plus to breaking out functionality into smaller functions. I mean, you could just break up the functions into "subfunctions" as the video seems to suggest for organization and to have the same automated testing functionality, but the video seems to suggest "just shove everything into the god function" is better, and my immediate reaction is "what the hell are you smoking and where do I get some". I get his argument about that usually meaning tracking functionality across multiple files, etc. being tedious, and I agree with that, but having dealt with god functions in various places, I've always found them less maintainable than the alternative.
Am I missing something there?
The proposed use construct:
can be implemented with C++11 lambdas:
I have been refactoring some code I have into one gigantic data struct(2k lines struct and 6k fields, AKA god object) plus functions that take either portion or entire struct by pointer. It turned out to be quite more manageable compare to smaller data structures spreading all over the code in hundreds different places.
A portion of programming became designing that data structure and minimizing dependencies, since it is a lot easier to see what references what in the program by finding all occurrences of pointer to a particular field, this led to simpler and shorter program. The functions became easier to reason about as well, a function that takes the entire struct is clearly more complicated and perhaps unnecessary, a function that takes a field of the struct containing a reference to other field is potentially problematic.
The important take away for me is program complexity is dictated entirely by data complexity not code. OOP encourages mixing of data and code to the point of making it impossible to visualize the data.