OOP Is Still The Best Software Design Method Ever Created. Period.

Using OOP Language Features, Does Not Mean A Project Is Using OOP Correctly. The Principles Come First.

As a famous dude once said, “the rumors of my demise have been greatly exaggerated.” I think the same holds true for OOP. Developers are piling on in their disdain for OOP. OOP is a giant mistake! Paradigm X is better. So here’s a mixed list of facts and nonsense claims about OOP.

You Don’t Know OOP

When OOP is taught it usually starts with conceptual and abstract explanations. OOP is an extremely complex topic so starting with the technical details or code samples would be hard for anyone to digest. The problem is that since we are humans we can make all sorts of assumptions or draw incorrect conclusions based on high level explanations.

This is one of the most digestible technically accurate explanations of OOP I’ve ever seen, https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/. I won’t even attempt to do it better because I cannot. Please review even if you think you know OOP.

The reason I’m suggesting you review it is because I recently watched a Youtuber video, with over a million views, and was surprised to see their explanation for Encapsulation. Basically this Youtuber explained Encapsulation’s main purpose as being the grouping of related object data. This is unfortunately not correct. Encapsulation’s main purpose is access control of member data. That is to hide member data so that it is strictly under the control of the class that it belongs to.

My point is this, there is a lot of incorrectly implemented OOP code out there, because developers misunderstand it. Just like there’s a lot of incorrectly implemented code in Functional Programming and just about any other major paradigm. OOP is an easy target because it is so ubiquitous, not because its bad.

Your Language Actually Does Not Do OOP

Let me lay it out flatly if you’re dissatisfied with the results of OOP, it may be that your chosen language does not really support it. Doh! I’ll say it another way if your language does not support static typing, access modifiers, and interfaces (or abstract classes), it can only mimic OOP and does not truly support it.

If you read through the link I had provided explaining OOP, you will see that without the core features I mentioned you simply cannot fully achieve most of the principles of OOP design. Some JavaScript people may believe that you can. For example it is possible to attain some Encapsulation, by embedding functions inside of constructor functions, to create member privacy and not expose them outside of the class. But so what? This is not a language feature, this is a work around for a missing feature that adds more code and more complexity. Developers have to know how to do it and other developers have to understand what this code means and so on. Is it a wonder that OOP is seen as too complex? But wait ECMAScript 2020 will soon allow for private fields. OK then what about more subtle access modifiers like protected and internal? I guess we can wait another 10 years for those.

For the other main principles of OOP it’s pretty much the same story. Abstraction requires a way to separate code interfaces from implementations. This is how we are able to dumb down a complex object so that we can hide its implementation and loosely couple our code. This is how dependency injection and true test mocking work. JavaScript and other dynamically typed languages again do not support interfaces or abstract classes. Sure it’s possible to simulate Abstraction. Maybe you use a facade pattern or adapter to mimic a reduced interface so that the internal complexity of an object can be hidden, but once again it’s not fluid and the direct language facilities are missing.

So then in the end what do you get? A lot of very clever complex code that may achieve some adherence to OOP principles but at what cost?

OOP Is Too Hard

My programming language supports OOP but it’s too hard. News flash programming is hard. It’s really really hard to do well. But that’s why we get paid the big bucks. Going to work every morning is hard. Working out is hard. But they all have their benefits when done properly. Trying to do anything well is hard. Don’t conflate poor OOP implementations with the idea that OOP sucks.

In my last job I would be the guy to interview candidates on their JavaScript skills. It always surprised me how many candidates had little understanding of some of the fundamental concepts of JavaScript. Prototypes, what this means under certain contexts, scoping rules (pre ES6), etc.

If you don’t know the tool you’re using you will use it poorly. This is just as true for programming paradigms as it is for languages.

There’s lots of different programming paradigms. For example I find Rust’s Trait based programming to be quite promising. It’s not at all OOP in my opinion. But having said that it has huge potential, both the language and the design style. As Rust develops further and more software is built using it, this style of programming may become the preferred way of coding large apps. However as of right now OOP is still king. It has the sophisticated tooling, the language support, and the developer mind share and experience. I suspect OOP will continue to be used for decades to come.

As always if you like helping other devs try DzHaven.com

Published by David Choi

Developer Lead DzHaven.com. Where devs help devs and make money.

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

Create your website with WordPress.com
Get started
<span>%d</span> bloggers like this: