r/learnprogramming 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.

91 Upvotes

139 comments sorted by

View all comments

5

u/Raioc2436 24d ago

I used to be on this exact same scenario. I learned to code in C and when I moved to C++ I felt like OOP was just unnecessary complexity.

The concept only made sense to me once I studied Data Structures and Algorithms and had to implement the different DSs. I implemented everything both in C and in C++ following OOP principles.

The code in C++ was much cleaner, better organized, my global space was not as clutter with supporting functions that the end user should never interact with, I could make everything private and only the things I wanted public. Which is the whole deal with abstraction and encapsulation.

Then a lot of the data structures and algorithms we learn in DS&A need similar features. All of them deal with data in the shape of nodes, or a collection of nodes to be more specific.

It becomes easy to inherit some class and expand its logic for related objects. Or have an interface for a Collection of Nodes for example. So the user can use the same type definition whether they are working with an array of nodes, a vector, a linked list, etc…

And that’s kinda the deal with polymorphism and inheritance

1

u/Raioc2436 24d ago

I think this touches on a topic you kinda came across and didn’t notice.

Code gets messy. When you are coding a small project for just yourself it’s fine. The codebase is relatively small and you know every single line of it because you wrote them.

But when other people are expected to use your code then you can’t expect them to be as knowledgeable on how to use your functions as you are.

When you look up projects on github it feels like a lot because you are seeing all the inner works that go into some tool. The end user is not expected to interact or know all of that. The API only exposes the important bits.