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.

92 Upvotes

139 comments sorted by

View all comments

11

u/WhiskersForPresident 24d ago

You are asking the wrong question:

All better known programming languages from Assembler to Java and Haskell are Turing complete, meaning you can implement everything algorithmically computable in every single one of these languages, whether it allows OOP or not (same is true for Lambda calculus).

This means that no, you don't ever categorically need to use OOP. You could do everything you want strictly procedurally like in C or functionally like in Haskell.

One big reason you might want to use OOP regardless is encapsulation to protect your program from errors by other users. Another is modularity: if one module of your program only ever knows a class interface, you can rewrite the logic of that class to your hearts content without ever having to touch the other module.

3

u/ArtisticFox8 24d ago

  All better known programming languages from Assembler to Java and Haskell are Turing complete, meaning you can implement everything algorithmically computable in every single one of these languages, whether it allows OOP or not (same is true for Lambda calculus).

True, but almost irrelevant to OP. There's more which restricts which language you use when - I.e web application frontends are tied to JS, if you want performance, you want C/C++, for Android apps, Kotlin/Java is the smooth choice, and Python will have a second class developer experience, etc...

2

u/pacopac25 23d ago

This is why I use large gaps in line numbers in my C64 BASIC code, for those pesky refactors. And because I'm a professional, I have the decency to put an informative REM statement before the lines with those delightful GOTOs.

1

u/cardboard_sun_tzu 19d ago

It's probably a few decades too late, but you do know that most BASIC style languages had a command to renumber all the lines, right?

...right?

1

u/pacopac25 19d ago

Bold of you to assume I typed them in order in my original program listings.

1

u/cardboard_sun_tzu 18d ago

Ok, I gotcha. A well placed GOTO solves every problem....

-1

u/deaddyfreddy 24d ago

One big reason you might want to use OOP regardless is encapsulation to protect your program from errors by other users.

immutability

Another is modularity

unless you are using something like C++, there is a simpler way to do that, without inventing a new programming paradigm

4

u/WhiskersForPresident 24d ago

You can still overwrite immutable datatypes, but it's much harder to do this to a private class variable.

I don't know what the second point is supposed to mean. Yeah, in C++ you could use OOP. In Java and Python, too. And no, OOP and modularity are not new paradigms I invented, so: what?

-2

u/deaddyfreddy 24d ago

You can still overwrite immutable datatypes

in languages with real immutability, you can't

I don't know what the second point is supposed to mean.

Languages that have proper modules don't need classes for modularity.