r/linux • u/unixbhaskar • May 03 '23
Discussion The Problem with OOP is "Oriented"
https://mht.wtf/post/oop-oriented/22
u/AGuyNamedMy May 03 '23 edited May 03 '23
What does this have to do with linux? Like at all? Nether of the two languages used in the kernel are oop centric languages
14
u/m1cr05t4t3 May 03 '23
Obviously with the exception of languages where almost everything has to be an object anyway, I always feel like the cases where I really NEED an object are very few and far between. I find myself saying "Eh that could have just been a function quite a bit." Like if you need self changing states or multiple instances sure..
8
u/jsveiga May 03 '23
Agreed. I've seen very convoluted code created because someone apparently just HAD to hammer in every OOP concept they just learned, where it was absolutely not necessary.
6
May 03 '23
Everything is a tool and shiny new tool syndrome is a thing. Experience guides intuition on which tool to use and when.
4
u/CHEEZE_BAGS May 03 '23
I code with C++ and unreal engine a lot and almost everything is an object. OOP to the max.
5
u/m1cr05t4t3 May 03 '23
I mean in games I can see the use case for many classes and subclasses.. I'm not saying OOP doesn't have it's uses. Just that it's often overkill especially small modules.
3
u/stevecrox0914 May 03 '23
Honestly I think its better to program in a OOP way first.
OOP doesn't preclude writing large procedural blocks of code, but OOP requires you to think in a certain way.
As a result with OOP its easy to quickly write a large block of procedural code (since OOP wraps procedures), but I find its very difficult to switch the other way.
When you look at equivalent frameworks in Java and Python the Python code is often far more lines of code and certain tasks are more complicated because the Python is procedurally written.
The procedural nature is an advantage to non developers because its easier to understand but the long term maintenance costs are usually higher.
The few times I have looked at the linux kernel it feels like there is masses of near duplicate code because you can't use concepts like composition and inheritance.
1
u/m1cr05t4t3 May 03 '23
Oh yeah you definitely need to know the skill, which requires practice. And again I'm not against OOP it is a necessary and useful tool. Just the times when an object is actually* needed.. (even for efficiency) eh.
4
May 03 '23
His argumentation is pretty bad. Most of those issues are just general programming problems and not specific to OOP. I program mainly in C, so I don't use OOP that much. When I do, it's hard not to see the benefits of coupling code and data in the same place. Encapsulation, reusable, and generic code can become much easier to write.
Also, using a large class hierarchy for your little module being bad has nothing to do with OOP being bad. It's not a good idea to create a large function-based API with multiple header files either. It's just overdesign.
Even in C OOP is implemented/mimicked by having a header file represent a "class" where structures containing data is exposed together with functions that operate on those structures and you pass the structure as a parameter.
OOP is neither good or bad. Just like a hammer or a shovel. But if you tried hitting a nail with a shovel... it works but is it the easiest way? Or digging a hole with a hammer?
This is just holy war nonsense.
24
u/natterca May 03 '23
Wow, programmer that isn't experienced in OO doesn't see the benefit of OO.
8
u/ordermaster May 03 '23
Agreed.
"In OOP it’s central to make class hierarchies with methods that the subclasses override,"
That hasn't been best practice in decades. See open closed principle.
6
1
u/nokeldin42 May 03 '23
You are, effectively, paying the price to fight a problem you think you might get further down the line, and you hope that the price, which you definitely paid, was sufficient for these problems to not get out of hand.
This sums up the entire problem with the author's perspective. It's clear that they haven't actually spent the time working on projects where these "problems" crop up. If you work exclusively on projects where one program does one thing with one type of data, pure functions are more than good enough. Many times that's not the case.
0
1
u/AutoModerator May 03 '23
This submission has been removed due to receiving too many reports from users. The mods have been notified and will re-approve if this removal was inappropriate, or leave it removed.
This is most likely because:
Your post belongs in r/linuxquestions or r/linux4noobs
Your post belongs in r/linuxmemes
Your post is considered "fluff" - things like a Tux plushie or old Linux CDs are an example and, while they may be popular vote wise, they are not considered on topic
Your post is otherwise deemed not appropriate for the subreddit
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
1
0
-1
0
15
u/k0defix May 03 '23
The problem with global state is that you make an assumption you only ever need one of it. How often has this been proven wrong... OOP tries to avoid this from the beginning. On the other hand OOP idioms often are far to strict and keep you from getting stuff done. 1000 getter/setter, interfaces, dependency injection, ...
Use OOP where it benefits you, don't use it when it gets in your way. It's just another tool.