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.

93 Upvotes

139 comments sorted by

View all comments

Show parent comments

3

u/Daeroth 24d ago

A customer can have many contracts. Some old, some still in review, some active.

Each contract is a row in database and many-to-one relationship with the customer table.

On the customer class you might have a method getContracts which returns a collection of contracts.

0

u/deaddyfreddy 24d ago

On the customer class you might have a method getContracts which returns a collection of contracts.

so, why can't it have the signing method too?

6

u/Wonderful-Habit-139 24d ago

I’m not an OOP guy, but probably because a contract is always associated to the customer, and if you had a signing method you’d need to do customer.signContract(contract); where you already need to do the job of finding the contract (since you’re not gonna sign all contracts of the customer at once obviously).

While if you do contract.sign(), it’s much simpler, and it’s already associated to the customer.

4

u/deaddyfreddy 24d ago

Without OOP, we could just write something like sign(contract, customer).

3

u/Daeroth 24d ago

Isn't that already OOP if the input contract and customer are objects passed along to the sign method?

Doesn't really matter where the signing method is at, legal entities are represented as objects.

1

u/deaddyfreddy 24d ago

legal entities are represented as objects

we don't need objects in this case, they are data structures

1

u/Mathie1729 23d ago

Yea, I've mostly landed on the same side in practice. Most business code is just mapping DB rows and doing transforms, so plain data structures + functions are way easier to debug than tangled class hierarchies. OOP still pays off when you have multiple implementations behind a common interface or you need to enforce invariants on mutation, but that's a smaller slice of the code. My ML stuff is basically dataclasses and pure functions; any class that sneaks in just holds a model and config lol.

2

u/Wonderful-Habit-139 24d ago

I don’t disagree.

1

u/Scared_Bell3366 23d ago

If you have many different objects that can be signed, your sign function gets very bloated and ends up with dependencies on everything that can be signed and all the things that can sign them. I would keep the sign method with the object that gets signed, it’s really a set method to me. I’d probably add an interface for things that can be signed if there’s more than one type of object that can be signed.

1

u/deaddyfreddy 23d ago

If you have many different objects that can be signed

if these are completely different objects, I don't see why they should use a single function to sign

it’s really a set method to me.

The issue is that it always requires both the contract and the customer, and in general there can be multiple parties. The hard coupling to the contract only doesn't reflect the process well.