Some programmers actually hate OOP languages? WHAT?!

Started by
91 comments, last by Washu 9 years, 2 months ago

There IS such a thing as over-engineering a program (or project of multiple programs) and the clue here might be the original source being someone talking about programming games. A blanket statement that all OOP is bad is bunk as 'OOP' isnt a fixed definition - and it can be a matter of degree it is used (and frequently abused).

I'm an old school programmer who writes C++ programs as if they were C for my own stuff (hundreds of thousand of lines of code), but had no problem with using a a number of OOP styled libraries (DirectX is organized OOP after all, and I used that for the graphical parts of MY projects).

When you are creating a game, you may NOT have it all designed out to a fine detail, and often WILL have to add/modify things and even rethink the program's processing almost completely, when it didn't work the way you expected or expanded what it was to be. Alot of OOP stuff does add alot of extra formal coding to implement that style heavily and it takes time that the programmer has little enough of to get the game working (Ive gotten the evil eye from programmers when I called their programs 'prototypes' when I knew from experience that what they thought was sufficient fell well short of what the product had to be).

So perhaps that original comment came from someone whose programming work WAS largely 'prototyping', where OOP might NOT be right for what they are doing (timewise) and don't realize that for bigger projects it has advantages (I recall when OOP was newly out that there were comments/recommendations that for organized projects the few people who controlled the Class sets were critical. To keep from having every other programmer on the project (and his brother) go every which way in the design and willy-nilly change/add Class things because it was convenient.

--------------------------------------------[size="1"]Ratings are Opinion, not Fact
Advertisement

One of the more recent common reasons is that OOP or, more specifically, OOD (object-oriented design) often produces code that is not optimal for today's architectures (where the CPU-memory gap starts to widen). An example is a typical "OOP-style" update/render loop, which would go like:


for every entity:
    entity.Update();

for every entity:
    entity.Render();


However, that is really bad for a variety of reasons: virtual function calls are comparatively costly on today's architectures, and the "Array of Structures"-(AoS)-style that is typical for OOP is not optimal for architectures where the CPU speeds have greatly exceeded memory access speeds, so every memory access might, in worst case, stall the CPU for hundreds of cycles. Usually that is where CPU caches come in, but to optimally use CPU caches, memory layout and memory access patterns are vital. For most cases in games (especially concerning game objects/entities), a "Structure of Arrays"-style (SoA) is preferrable, cache-wise.

The performance improvements are not neglegible! (though in some specific game cases, like simpler casual, you may still ignore them since they do not weigh in as much as in more complex games and game worlds)

SoA-style programming is more reminiscent of C-style (non-OOP) programming.

However, obviously you can still use OOP aspects when programming in this more "data-oriented" way. Just don't assume the OOP patterns you've learned in school are silver bullets for everything.

More interesting articles on data-oriented programming:

https://molecularmusings.wordpress.com/2011/11/03/adventures-in-data-oriented-design-part-1-mesh-data-3/

Essentially: don't be shocked, nothing is ever a silver bullet or a solution for everything, and good developers will make use of the tools they know with conscious design decisions and weighing in pros and cons. OOP definitely is not a silver bullet for everything, neither is C++.

Especially, for OOP-trained (I don't want to use the word "brainwashed") people right out of college, getting to know some languages with completely different paradigms, such as functional languages such as Haskell, can be incredibly beneficial in avoiding the OOP "tunnel vision" that is so easy to get nowadays.

Honestly just reading through the thread and all the links provided by you guys, I'm actually started to get anxious. Its like when I was a kid and some teacher starts screaming at me for doing something wrong, when I didn't know it was wrong, and instead of teaching me that this is the wrong way of doing things, they just keep screaming at me and telling me how stupid I am (probably not a good teacher to learn from him, but still).

After reading this thread, I'm honestly more scared to share my source code with the public than ever. Because I might be doing something stupid and someone will just come along and start bashing me for writing shit code. Problem is, I will never learn the right way to code from the wrong way if I don't share my code and no one explains it to me.

TL;DR - unless you've been telling everyone that you're the greatest software engineer who's ever lived, you should never feel like that.

Often this is something that goes away with age, but it's also a cultural issue - the importance placed on protecting one's ego.
E.g. In America it's common for people to not want to admit they don't know something - from lying to your friends, saying you've heard of [obscure band]... to dancing around your co-workers questions with qualified stalling like:
"Now I would say... that this system X probably works similar to system Y"
instead of being straightforward with:
"I haven't used system X. Greg wrote it. You should ask him, or I can look at it with you to try and figure it out".

It's ok to not know things. It's good to know that you don't know things!
"Ignorant" is not an insult, except when it's used to mean that you're choosing not to learn.
If you discover that you're ignorant of something, and then follow up with more learning, then you're now a better person.
Without first admitting and accepting that you need to learn, this self-improvement is impossible.

The internet (and professional software studios) are amazing as they can surround you with lots of really knowledgeable programmers. That's an amazing resource that you can use to become an amazing programmer yourself.
The only catch, is you've got to first admit that you're a shitty programmer. Even me, now, with over a decade making games, I'm willing to humble myself before other programmers if they're more knowledgeable in an area than me. Hell, even if they're a newbie student who knows some neat trick that I don't, it's worthwhile letting them momentarily be the master and giving them your full attention as an eager-to-learn student.

The second part is learning to accept criticism. The Wikipedia page for that word is a good start in explaining it - that a critique is not a personal attack and can/should be objective. If you get defensive when provided with a critique of you're work, then you're choosing to be a bad student, choosing permanent ignorance over learning.
Sometimes people are bad at providing critique / some people are lacking in tact. These people's critiques may sound offensive, may sound like they're attacking you personally. Just remember that they're really only there to show you where you can continue learning. If they've done this in a seemingly hurtful way, it is not your problem to deal with - it's actually their own problem, their own bad interpersonal skills. They need to learn how to interact with people better ;)
Always assume good faith and mentally translate people's words into the best meaning before taking them to heart. This can mean translating "OMG U SUCK! Why is this code 100 lines?" to "You could have done this with less lines. Ask me how." :lol:

Also, when people suck at communication like this, keep in mind that (ironically) it's usually tactful not to tell them, even though without this feedback, they themselves are being robbed of an opportunity to learn/improve their communication skills :lol:

Honestly just reading through the thread and all the links provided by you guys, I'm actually started to get anxious. Its like when I was a kid and some teacher starts screaming at me for doing something wrong, when I didn't know it was wrong, and instead of teaching me that this is the wrong way of doing things, they just keep screaming at me and telling me how stupid I am (probably not a good teacher to learn from him, but still).

After reading this thread, I'm honestly more scared to share my source code with the public than ever. Because I might be doing something stupid and someone will just come along and start bashing me for writing shit code. Problem is, I will never learn the right way to code from the wrong way if I don't share my code and no one explains it to me.

TL;DR - unless you've been telling everyone that you're the greatest software engineer who's ever lived, you should never feel like that.

Often this is something that goes away with age, but it's also a cultural issue - the importance placed on protecting one's ego.
E.g. In America it's common for people to not want to admit they don't know something - from lying to your friends, saying you've heard of [obscure band]... to dancing around your co-workers questions with qualified stalling like:
"Now I would say... that this system X probably works similar to system Y"
instead of being straightforward with:
"I haven't used system X. Greg wrote it. You should ask him, or I can look at it with you to try and figure it out".

It's ok to not know things. It's good to know that you don't know things!
"Ignorant" is not an insult, except when it's used to mean that you're choosing not to learn.
If you discover that you're ignorant of something, and then follow up with more learning, then you're now a better person.
Without first admitting and accepting that you need to learn, this self-improvement is impossible.

The internet (and professional software studios) are amazing as they can surround you with lots of really knowledgeable programmers. That's an amazing resource that you can use to become an amazing programmer yourself.
The only catch, is you've got to first admit that you're a shitty programmer. Even me, now, with over a decade making games, I'm willing to humble myself before other programmers if they're more knowledgeable in an area than me. Hell, even if they're a newbie student who knows some neat trick that I don't, it's worthwhile letting them momentarily be the master and giving them your full attention as an eager-to-learn student.

The second part is learning to accept criticism. The Wikipedia page for that word is a good start in explaining it - that a critique is not a personal attack and can/should be objective. If you get defensive when provided with a critique of you're work, then you're choosing to be a bad student, choosing permanent ignorance over learning.
Sometimes people are bad at providing critique / some people are lacking in tact. These people's critiques may sound offensive, may sound like they're attacking you personally. Just remember that they're really only there to show you where you can continue learning. If they've done this in a seemingly hurtful way, it is not your problem to deal with - it's actually their own problem, their own bad interpersonal skills. They need to learn how to interact with people better ;)
Always assume good faith and mentally translate people's words into the best meaning before taking them to heart. This can mean translating "OMG U SUCK! Why is this code 100 lines?" to "You could have done this with less lines. Ask me how." laugh.png

Also, when people suck at communication like this, keep in mind that (ironically) it's usually tactful not to tell them, even though without this feedback, they themselves are being robbed of an opportunity to learn/improve their communication skills laugh.png

Thank you. That was really helpful happy.png

OOP allows you to organize the code in rational segments that when properly encapsulated represent black boxes you can interconnect while keeping code coupling at a minimum. It is an invaluable tool for writing maintainable and easy to understand code because the objects we create translate nicely to the concepts in our head.
It is not a perfect tool for every situation though, and most definitely not the best performing solution. However when building large systems the ability to easily modify and quicky understand them becomes increasingly more important and quickly outweights the performance implications. I could not have imagined making Banshee Engine (which now has little over 200k LOC) using anything else but OOP.
Data oriented programming has been getting a lot of traction recently as it makes good use of processor cache and make it easier to work with vector extensions - both of which can offer significant performance benefits. However it makes your code very hard to maintain and understand but it is sometimes the only solution if performance is absolutely critical. It's not something I would ever use for building an engine but I will use it in performance critical systems (like a raytracing renderer) but even then I will encapsulate it in an OOP abstract interface.
Therefore don't let anyone tell you OOP is flat out bad. It has plenty of uses, and so do other paradigms. For me from a perspective of an engine developer it has proven invaluable.

I get the feeling this is going to be a long thread. wacko.png


Hell, even if they're a newbie student who knows some neat trick that I don't, it's worthwhile letting them momentarily be the master and giving them your full attention as an eager-to-learn student.

I can make annoying sounds using only my armpit. :)

(I am joking now.)

Problem is, I will never learn the right way to code from the wrong way if I don't share my code and no one explains it to me.

TL;DR - unless you've been telling everyone that you're the greatest software engineer who's ever lived, you should never feel like that.

. . .

+1!

To add to that:

- Egoless Programming: http://blog.codinghorror.com/egoless-programming-you-are-not-your-job/

- You Are Not Your Code: http://www.hanselman.com/blog/YouAreNotYourCode.aspx

This article sums up my thoughts about OOP: http://www.smashcompany.com/technology/object-oriented-programming-is-an-expensive-disaster-which-must-end

For an original contribution to this discussion, OOP has all the same problems that global variables and functions acting on them have. Only in OOP instead of a big universe of global, mutable state, you have little microcosms of it. From inside of an instance, how is it any different than global variables whose values can be changed at any moment?

And don't even get me started on abominations like the Singleton Pattern...

Languages like C# have been improving drastically in recent years because they've been incorporating functional programming ideas into themselves. Everything I like about Ruby, it turns out, comes from functional programming.

OOP relies entirely on mutable state, and dealing with mutable state introduces all sorts of headaches, and for no real gain.

And yet, at some point every program does need to deal with mutable state (database, writing to the screen, etc). This talk does a good job of describing a way to deal with that: https://www.destroyallsoftware.com/talks/boundaries.

Edit: change "feelings" to "thoughts" since I don't actually *feel* anything about OOP.

An example is a typical "OOP-style" update/render loop, which would go like:


for every entity:
    entity.Update();
for every entity:
    entity.Render();

Cute, but strawman. Set up in order to be easily torn down.

Thinking of clusters of data as objects is one direction. Thinking of data as a continuous stream of sources and filters is another direction. Thinking of verbs primarily as you do in SQL, rather than mostly nouns and operations on nouns, is another direction.

A better, less strawman condition I encountered recently: When we had a 12 GB data source to rip through and modify, if your thinking is like my co-worker who spends his day in Java, thinking that you need to load a chunck, parse it, make a bunch of objects, then serialize the objects in the other stream, you're doing it wrong. Instead open your toolbox, grab "sed" spend some time figuring out how to code your modifications, and let it work its magic.

Some processing tasks are far easier in other languages or with other tools or with different paradigms. There is good reason Fortran is still the king of numerical computing and the benchmark language/tool for supercomputers. Not because you can use assembler blocks to fine tune performance section, not because it tries to be like C and become a close abstraction of the metal, but because for that type of problem the language is really good at making efficient machine code.

Use the right tool for the job. If the only tools you know are Java, C++, and C#, your collection of tools is too small.

An example is a typical "OOP-style" update/render loop, which would go like:


for every entity:
    entity.Update();
for every entity:
    entity.Render();

Cute, but strawman. Set up in order to be easily torn down.

Thinking of clusters of data as objects is one direction. Thinking of data as a continuous stream of sources and filters is another direction. Thinking of verbs primarily as you do in SQL, rather than mostly nouns and operations on nouns, is another direction.

A better, less strawman condition I encountered recently: When we had a 12 GB data source to rip through and modify, if your thinking is like my co-worker who spends his day in Java, thinking that you need to load a chunck, parse it, make a bunch of objects, then serialize the objects in the other stream, you're doing it wrong. Instead open your toolbox, grab "sed" spend some time figuring out how to code your modifications, and let it work its magic.

Some processing tasks are far easier in other languages or with other tools or with different paradigms. There is good reason Fortran is still the king of numerical computing and the benchmark language/tool for supercomputers. Not because you can use assembler blocks to fine tune performance section, not because it tries to be like C and become a close abstraction of the metal, but because for that type of problem the language is really good at making efficient machine code.

Use the right tool for the job. If the only tools you know are Java, C++, and C#, your collection of tools is too small.

I believe I wrote pretty much exactly the same things you said, and yes, it's a very naive example, but believe me, in my years as lead programmer in various projects, I did encounter that multiple times, both in junior programmers' code, as well as student code (in my time as lecturer).

The link I posted provides a more thorough overview on data-oriented programming and some of the "stumbling blocks" naive OOP might have (also taken from real life, seen as implemented by less experienced developers).

This topic is closed to new replies.

Advertisement