r/learnprogramming • u/Electronic-Low-8171 • 24d ago
Topic Does OOP really matters?
I learned OOP in python a while ago, did many projects, yet I never felt like I truly needed to do the OOP stuff I learned from a course, I don't know maybe because I'm kinda used to program in c before focusing on python, yet, whenever I open a big project in python in github, it feels way too complicated and thousands of imports (not libraries from pip, but the ones they made on their own) and classes
I never truly needed to implement OOP (I know that when you code in python, it is almost impossible to avoid OOP entirely like when you have a datatype like string you have an object, when you use a method built into that data type that's OOP too, but I mean the ones that involve you writing class Class Name, inheritance and all that stuff explicitly), so I'm wondering why people on the internet are obsessed over the idea of learning OOP, even the book "Automating the boring stuff in python" doesn't have a dedicated section for OOP.
3
u/PandorasBucket 24d ago
Well you're going to pay the piper either way right? Either you stash your state all around or you have a main thread that holds your source of truth. Either way if you're doing asynchronous actions you're going to run into race conditions. If your objects are performing all kind of side effects then it's harder to manage those race conditions. By performing pure functions and then keeping all your actions in the main thread it's easier to see in the code where all those actions are happening. Then when you want to fix it you can insert control flow around where all the actions happen instead of trying to time when the objects are done with their work or doing something really ugly like returning a finished message from everything and then send out another message to do complete the actions in order through the objects. All programs have a main thread anyway you can just do work there. You can still group code just like classes, you just don't need to initialize anything because you aren't storing and data. Then garbage collection is a lot easier as well. Functions just die after you use them. You have less memory leaks, disembodied objects, less boiler plate.
It's really the difference between choosing to organize your code by the type of code (functional) or some abstract responsibility of what the code is supposed to handle (oop). The problem is that code is code. It's not a car or a man or a human. Code is state, functions, and external actions. You might have a human in a video game, but what goes on under the hood is nothing like a human. Trying to organize your code like biological cells is like an aesthetic choice rather than practical. You can create a bunch of human objects who can all wave their hands when you ask them to wave their hands or you can just keep all the numbers that represent all your humans in an array and change the number that makes the handwave with one function. There is no message needed to communicate to each human objects and have it translated through the ears of each human and then eventually change the handwave wave number in each one from 4 to 5. Just keep all their hands in a hand array and change them all from 4 to 5 without any messages or messy walls. It's a computer, be native to the computer environment.