I wish I could read this article with a clear mind, but the author's stance is just so... bloody arrogant that I have a hard time doing it. How can you say that object orientation is "objectively bad" when most of the best software in the world is written using object-oriented principles? I dunno — maybe the decades of research starting all the way from Smalltalk have actually been conducted by very intelligent computer scientists who knew what they were talking about? In my experience, it seems that it's mostly old-school programmers in their 40s who prefer the described imperative approach. Given the absolute cornucopia of fascinating new programming paradigms out there today, I feel that they're a bit stuck in the past.
Additionally, I know of literally zero programmers who write things out on index cards and create rigid Employee/Manager/Contractor-like hierarchies.
(With that said, enough smart people have complained about OO that I'm willing to give it more thought.)
How can you say that object orientation is "objectively bad"
Where did the author say that? I did a CTRL+F for "objectively bad" and only found this:
But despite the fact that many programmers out there have gone through bad phases like this and eventually come to smart conclusions about how to actually write good code efficiently, it seems that the landscape of educational materials out there still overwhelming falls into the “objectively bad” category.
Of course the author is taking things to the extreme to show his point, but that doesn't mean his point is invalid, or that these issues aren't real. I've seen a plethora of horrible code over the years in the enterprise...code you wouldn't even believe that came from "professional" developers from big name companies (IBM and AMD as my most recent examples)...I've had the great displeasure of going through code (usually in Java) that has come out of Indian and Chinese "code shops" where 10$ an hour developers crank out code for the enterprise which is absolutely OOP to the extreme. I've had management at various client offices try to do "agile" by pre-defining everything through requirements documents turned into code objects which are heavily abstracted. And these are all multi-billion dollar corporations. I've been tempted to start a blog just to show examples of what not to do that I find on a daily/weekly basis at large enterprises in their software. The point is, there are pros and cons to most programming techniques, and all of them can be abused. Less experienced developers (or experienced shitty developers) are given tools without an understanding of when they are appropriate. OO is a tool, and as the saying goes...when you're holding a hammer, every problem looks like a nail. Not every code problem is best solved with objects. :)
Don't focus on the negative. Developers love to bitch and moan about bad code, but will never show mediocre or good code to others. I've seen bad code and I've seen code that looked bad until I actually understood what it accomplished.
The point being: read a lot of code. Corporate code, open source code, game code, microchip controller code. Each has its quirks and requirements that don't make sense when looked at from a different perspective.
I guess I didn't make it clear that I consider good examples to be part of "ways to avoid". Like you, I see a lot of examples of bad code, but not a lot of examples of how to fix it or how to avoid it. I think that needs to change if these "don't do this" bits are to be taken seriously.
Thanks :) I was thinking more of an educational focus for those who aren't already aware of why things are bad...as opposed to showing it to others who already can recognize things are stupid. But I'm sure I have stuff I can submit to that site too :D
But he's not describing object oriented design. The point is invalid.
My job is developing and maintaining a payroll system in Smalltalk, does it get any more object oriented?
We have a Person class. Whether they are a manager or a contractor is decided by a has-a relation inside the Employment the Person has.
All customers have different types of employees, it's not something we can know beforehand so it would just be silly of us to create a class hierarchy over those things. Also, anybody starting to create that tree of classes would soon see they are being stupid when they realise they will have hundreds of leaf classes with no meaningful difference.
maybe the decades of research starting all the way from Smalltalk have actually been conducted by very intelligent computer scientists
You are definitely overestimating the amount of "research" that has gone on. Most research is about introducing new concepts, and finding a solid mathematical basis for those concepts. There's very little research that attempts to answer whether one methodology is better than another one. Instead we have millions of practitioners each doing incremental trial-and-error to eventually settle on the best practices (which is useful too).
FWIW, I'm not an old school programmer in my 40s and I agree with their anti-OOP attitude. The problem with OOP is that it's overprescribed. Ever since Java there has been a trend of "everything should be represented with inheritance", which leads to some ridiculous code.
I'd call the developers of C#, Cocoa, Ember.js/Angular.js, etc. "reserachers". They're professional computer scientists with decades of experience who've determined that OO (of a particular flavor) is the way to go, at least for their domains. Why wouldn't I trust their expertise?
Here's practical example. Maybe you could help me figure it out. Let's say you're building a little app for scheduling events for a group of people. The main screen for this app is a scrollable view that shows all the currently scheduled events (x = time, y = person). You add events by "painting" them on with your finger on the x axis. The app has to have the following features:
Whenever anything changes the scheduling data, the view has to update immediately to reflect those changes. The data could change through network sync, another app, another view, etc.
The changes have to animate. If you scheduled something for 11:00am—12:00pm in the app and then somebody adds 5 minutes through the web client, you have to see the scheduled event animate in the app to expand its width by 5 minutes. It can't just get replaced immediately by an 11:00am—12:05pm event. (This animation should continue if you're scrolling the view with your finger.)
Undo/redo functionality. Also has to animate.
The scrollable view has to decelerate with the appropriate speed when let go, and bounce a little when it hits the edge of the timeline.
If you're adding an event and you accidentally overlap with the next event in your timeline, the screen should shake slightly, the event you're currently "painting" should blink red, and the width should animate backwards until it's no longer overlapping. These animations should continue even if you lift your finger and then scroll the view.
Some of the buttons should animate and "expand" to add additional UI when held down for 1 second.
When the buttons are held down, the hold should cancel when the user moves their finger outside of a certain radius from the button center.
Finally, the scheduling view should be usable in other places with other data. Side-by-side editing of two different schedule files? Offline thumbnail rendering of the scheduling timeline? A popover with the scheduler view in another part of the app? All these things should be as easy as instantiating another scheduling view and hooking it up with the appropriate scheduling data.
I'm trying to wrap my mind around how to deal with all these overlapping animations, timers, and events in the imperative style and all I see is spaghetti code. My gut feeling is that when you have lots of "juice" in your app, it just makes sense to keep that state squared away in separate objects.
What's more, if you're writing software for a particular ecosystem, it's likely that the frameworks will all be object oriented. You might not even get control of your own run loop! And since much, if not most, development these days is done for iOS and Android, I think it's silly to say that imperative is the "one true way" when it won't even work for those platforms (unless you drop down to the C++ layer, which... ugh).
Finally, here's what I posted on the blog where I found this article:
I’ve heard from some smart people that OO is overused, so I’m very willing to look into the argument, but flame wars in programmer circles around the internet have shown that there’s no real consensus on the issue. One person on HN framed it as “thinking about code as nouns vs. verbs”, which makes sense to me. Yes, computers are just a series of sequential commands under the hood, but that’s just an implementation detail. Our users think about our software as a series of objects: a button here, a bit of text there, a thing that plays sound and a screen that shows some pictures. Why shouldn’t we code with the same mindset? Isn’t it best to work on the highest conceptual level possible?
So I'm pretty sure that at the end of this, it's going to turn out that we meant different things by the term OOP and it turns out that we agree all along.
For that app you're talking about, I would definitely prefer an entity-component system. One component would receive the latest server data, and it would create entities as needed, and assign a "targetLocation" field. Another module would store the animation time, another component would keep track of the current touch/drag state, another component would figure out the final renderable metrics from all that information, and etc for the other features.
I'm trying to wrap my mind around how to deal with all these overlapping animations, timers, and events in the imperative style and all I see is spaghetti code.
I think when you say "imperative style" you're probably referring to immediate-mode GUI which Casey used in his blog post. He's written more about IMGUI in the past, it's a fun topic to google. For the level of complexity you're talking about with your app, IMGUI would be a pretty bad fit, and Casey would surely agree.
So anyway in your juicy app there would surely be some data structures that act like objects and some code that looks like classes. The blog post (and I) aren't saying "never write anything that looks like an objects" because that's effectively impossible in a complicated program. They're saying: don't spin out new structs/classes until necessary. If you can get something done with a simple function instead of a class, then do it.
Also when I say I hate OOP, other things I'm specifically talking about are:
Inheritance is awful and should be avoided as much as possible. There are better ways to share behavior.
Classes/structs are fine if needed. Interface-based polymorphism is also fine (also only if needed).
Class-private data is bad. Encapsulation & information-hiding are good things in general, but class-private data usually ties you into awkward designs that are more trouble than help. Instead do encapsulation by convention (make up your own rules for data visibility and stick to them).
Our users think about our software as a series of objects: a button here, a bit of text there, a thing that plays sound and a screen that shows some pictures.
That's definitely a fine philosophy that goes all the way back to the Smalltalk days. I don't personally agree.. I think the way that the end user perceives the software is usually not the most effective way to organize the implementation. Buttons aren't really buttons, they are just textures and click areas and event handlers.
Isn’t it best to work on the highest conceptual level possible?
If you change that to "most effective conceptual level" then I will agree :)
I have to say I agree I mean he takes OOP to the extreme while anyone who's had the misfortune to work on code that's heavily 'compressed' to the extreme could say the same. I mean who doesn't love going though n levels of abstractions to find out what a function actually does.
Properly compressed code doesn't have many layers of abstractions. Each layer means more code, so they really have to pay off. Too many layers doesn't mean less code, it means more.
If you want to compress your code to the extreme, you would use few layers of abstractions, and maximize their power instead. For instance, you could implement and use an external DSL. It's just one layer, but a potentially very powerful one.
5
u/archagon May 28 '14 edited May 28 '14
I wish I could read this article with a clear mind, but the author's stance is just so... bloody arrogant that I have a hard time doing it. How can you say that object orientation is "objectively bad" when most of the best software in the world is written using object-oriented principles? I dunno — maybe the decades of research starting all the way from Smalltalk have actually been conducted by very intelligent computer scientists who knew what they were talking about? In my experience, it seems that it's mostly old-school programmers in their 40s who prefer the described imperative approach. Given the absolute cornucopia of fascinating new programming paradigms out there today, I feel that they're a bit stuck in the past.
Additionally, I know of literally zero programmers who write things out on index cards and create rigid Employee/Manager/Contractor-like hierarchies.
(With that said, enough smart people have complained about OO that I'm willing to give it more thought.)