Where OOP falls apart, and why OOP cultism is bad
Object-Oriented programming, an interesting solution to scalable and reasonable code. It is by far the most common type of code you find in the wild, beating Functional Programming and Procedural Programming by quite a wide margin. But, of course, just because it‘s popular doesn‘t necessarily mean it is good. Now I‘m not here to bash OOP, I think overall it is foolish to claim that one way of solving a problem is objectively worse than another, especially when considering tooling, etc. But I am going to explain why I try to avoid OOP, and where it falls flat for me. Perhaps this can enlighten folks to learning new stuff!
The first most glaring problem with OOP is when there is some code that doesn‘t necessarily fit within a Class. In Java, you end up making a static ball of code and name it something or other utility. Then, this code is pulled into everyone and anyone who needs it, creating a nice tangled mess that OOP was supposed to be preventing. Another way to do this is to make it on static, and segregate it behind an interface. But, then you‘ll quickly learn that now EVERY SINGLE CLASS depends on this interface. Interfaces in the OOP world are touted as a way to decrease coupling, but what happens when the underlying implementation does change? What happens when we need a new feature? What happens if we need to deprecate or change the interface? It just makes more work that no-one wants to do.
Just the muttering of the phrase "Global State" makes most enterprise developers shudder. But, there is nothing wrong with it, especially if that state is immutable. We can go out of our way to hide global state behind Classes and Interfaces and Abstractions but in reality, I can guarantee that code you use, has some sort of global state (whether you know it‘s there or not). So why not embrace this fact? If you‘re solving your problem, and you can verify that your code works, why should you make it more complex? Where and when does the value of abstract code come in?
Unfortunately, the world of the OOP devout is quite captivating for new developers. They often find themselves thinking that OOP is the ONLY way to solve a problem. Heck, I‘ve even been made fun of for mentioning that I write LISP, OCaml, or Raku. Is this the sort of culture that we should be pushing? OOP is popular, sure, but if we stick to things that are popular we will never innovate, we will never inspire people to get better (because they think they‘re already the best!) Elitism is fine in moderation, but don‘t let it get to your head.
OOP can be powerful for solving problems but, it isn‘t the only way to skin a yak. Never, ever let yourself get an ego to the point that you think one way of solving a problem is inherently better than another. If you solve your a problem, and it doesn‘t adhere completely to your design-patterns, or to OOP, or whatever, do not freak out. If someone is telling you that your code needs to be more Object-Oriented, calmly ask them how those changes would actually increase the quality and value of the code. Once again, this post is to increase thought and expression, not to beat on OOP, I use OOP for encapsulation when it makes sense, classes are good for making structs with simple, understandable methods. Thanks for reading!