Why all the hating on OO?

I think I finally figured out why there is so much disdain if not outright hate for Object-Oriented techniques these days. TLDR; OO is not well-suited to the prevailing need for client-server (i.e. web) applications.

OO is essentially an extension of the idea of abstract data types (ADTs). Originally ADTs were implemented with a combination of a static structure definition and a set of procedures/functions that could manipulate them, but the data and algorithms were separate things and had no syntactic or semantic link. OO came along and bundled the two in one syntactic/semantic unit — the class. (It also added in polymorphism, inheritance, et. al. but these features aren’t critical to the issue at hand.)

An OO class combines both data and functionality. But here is the killer issue in today’s world: functionality cannot be expressed in a language-neutral way — it can’t cross the programming language barrier. If I have a C# or C++ class definition, I cannot use that class in Javascript or Ruby. Sure, there are sometimes awkward binding techniques available but there is a fundamental mismatch between the way things are expressed in different languages that always interfere. The data part of a class definition could be expressed in a limited, standards-based way (e.g. XML or JSON), but the algorithms cannot.

But the most common client-server scenario in our day is a web application, where the server code is written in one language and the UI in another. It’s no wonder that OO doesn’t work well in that case — the same class definitions can’t be used on both the client and server side! Trying to shoe-horn OO into a web app design leads to duplication of algorithmic code and the use of dumb DTO “objects” in between. Not much of a win from OO…

But even supposing you could use the same class definitions — suppose you had UI in Javascript and were using Node.js on the server — you still have a mismatch between what the algorithmic part of the class needs to do on the client vs. the server. On the client, you may need to make a call to the server, but on the server you’d need to persist or fetch data from a store. So even in this case much of your code would have an “if client do this, else if server do that” flavor to it. (This mismatch is not unique to web apps — it affects all client-server applications.)

So unsurprisingly, web developers have never been fond of OO and for good reason. I would also suggest that due to this mismatch the web community may never have developed a real appreciation for the substantial strengths of OO when applied to the right problem, or even a comprehensive understanding of the underlying notion of ADTs. Especially when you add in the fact that ostensibly OO languages (Javascript) really are not, the waters are very muddied and impede a developers ability to really learn and understand OO.

Now, all that said, you may still decide to use a class definition on either the client and/or the server in the appropriate language. But the client-server barrier limits the amount that you can leverage that work across a vertical slice of the application.



About jeffkotula

Software engineer, musician, and so on...
This entry was posted in design, software engineering and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s