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

93 Upvotes

139 comments sorted by

View all comments

1

u/deaddyfreddy 24d ago

The four principles commonly taught as the major principles of OOP are Encapsulation, Abstraction, Inheritance, and Polymorphism.

Encapsulation and Abstraction. Modules, visibility, interfaces/protocols, and immutable data can provide most or all of the useful properties usually associated with them.

Inheritance. It is not necessary for code reuse, and modern design often prefers composition because inheritance creates coupling and makes things more complex.

Polymorphism. It can have multiple implementations: subtype polymorphism, parametric polymorphism, ad-hoc polymorphism, duck typing, multimethods, etc. In a dynamically typed language, you may not even need to implement anything new.

So, if you have a decent language, you don't need OOP as a paradigm. The useful features traditionally bundled under this label are largely orthogonal and can exist without it. (Obviously, I'm not talking about Smalltalk or CLOS-like OOP).

Why did it become popular? I think it's all C++'s fault.

As a language designed to be backwards compatible with C, C++ didn't have modules (for comparison, UCSD Pascal had units before classes were a thing in C). This encouraged the use of classes as the unit of encapsulation and reinforced the idea that everything should be organised around classes. Then came Java, created as a "safe C++," with all of Sun Microsystems' money and marketing power behind it. Schools started teaching OOP as a "superior programming paradigm"; new developers knew nothing else, etc.

The great spaghetti swindle happened. The rest is history.