Saturday, March 12, 2016

Why I don't love OOP

Why I don't love OOP

Welcome to my first blog post! My name is Daniel Trey Hilburn, but I go by Trey. This is the first blog post of many for Trey Talks Tech. I want to begin by thanking you for reading and without further ado, let's get started.


Object Oriented Programming has taken over much of the developer space ever since languages like Java and C# have come around. The idea of making everything an object makes a lot of sense in some cases, but as many things tend to do, it gets out of hand. You might ask me why that I'm not a fanboy of OOP and might comment that I just haven't had enough experience in the dev space to be able to say something like this. If we're being honest with ourselves, though, anyone who has learned to program is a developer. That being said, I'm currently trying to finish up my Computer Science degree, having already learned Python, Java, and C++. I also tinker with other languages in my spare time like C#.

Now to the point...


Now that I have established myself as someone who knows what I'm talking about, we can
start a real discussion about OOP and why I'm not a fan of it. In OOP, every class is an object, and if you want the class to do something different than it already does, then you probably need to make another class. That is just a general overview of the matter, but we can get to the details pretty quickly. I have a great example with what I'm currently working on for my Software Engineering class. We are creating an argument parser that parses command line arguments for the values and allows the developer using our library to handle those values however he or she wishes. We created the class for the parser, then realized we needed to make a thing that was an "argument", which meant that we needed to create a whole new class for that object. Then this evolved to the point where we're parsing an XML document, so we also needed a class for that. This quickly turns into a case where you start to feel like as a developer that you need to "Object all the things" or however you want to word it.

My argument


Objects are very useful, which is why OOP is so successful in the dev space, but some prob-
lems don't even warrant the developer to use an object to solve the problem. That's really what programmers are, we're problem solvers, and sometimes we overthink our problems. Quite frankly, we tend to do that most of the time. Many times I find myself trying to make a huge thing out of something that is a much simpler problem to solve. This is where I have to say that I don't mind using OOP, and in some cases it's very good to "Object all the things", but I don't enjoy being forced into that paradigm without a choice. What I'm saying, is that I prefer a language like Python, which is the first language I learned, simply because it gives me freedom of choice. I can make a class, but do I always have to? Not really. I can just make a program that does what I want without having to fear if I instantiated all the objects correctly or whatever. I like this freedom because it doesn't restrict my thinking so that I feel like I need to make a new object for each new feature I add to a program. Granted, I can add features as methods to the class that I created initially, but I have to think about how I want to go about it. I'm going to have to do some planning anyway, but having limited options makes it more difficult.

I'm free to do what I want

I love being able to just make my application and have it just work without having to worry
about all those weird errors that objects give. Also, I can always just have functions that work together to do a similar task that would require an object with several methods in OOP. In C++ you can just have the main function that does all of the stuff that I want without having to instantiate an object that I created or whatever, but the most freeing thing is in Python when I can just write out my programs without even having to have a main function, while it is advised to do so. The more things I can do without having to limit my frame of mind and way of thinking, the more I love the language that I'm working in. 

OOP is situational

As I was mentioning before, I feel that OOP is "situational", meaning that in some situations
my programs require me to think in terms of OOP. All of the other times, though, I may spend more time setting up a class structure in OOP languages, and miss out on being able to jump into the program headfirst. My ideology on programming is "Use the right tools for the job." I really think that it makes a difference being able to switch between whatever language will work best, while not being so broad that you only know the basics in several languages.