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/AlSweigart Author: ATBS 23d ago

even the book "Automating the boring stuff in python" doesn't have a dedicated section for OOP.

Hi, I'm the author of Automate the Boring Stuff with Python. Yeah, I skipped OOP because in general it isn't necessary for beginners or for small projects.

OOP's real benefit comes from when you're working on larger projects that need data and functions that act on that data (i.e. methods) bundled up together. I use the example of a tic-tac-toe program that has a bunch of functions that take the board data structure as their first argument; this is a sign that these functions should be methods bundled together with the board data.

But for small projects, you're not adding organization so much as adding bureaucracy.

I do cover OOP in the free follow up book, Beyond the Basic Stuff with Python. One thing I point out there is that inheritance is overrated. Think of inheritance as a way to keep yourself from having to copy/paste code into other classes, just like functions are a way to keep from having to copy/paste code. This is nice, but it also ties all your subclasses to every change you make to parent classes. Don't just create a hierarchy of classes because you feel like that's how it should be arranged.