To OOP, or not to OOP?

Started by
40 comments, last by johnstanp 14 years, 1 month ago
Many people i talked to seem to HATE Object oriented programming. They say that OOP code takes more space than 'normal' code, is unnecessarily complicated and requires greater processing power and time to use/compile. I would really appreciate it if you could tell me why you chose to use/not to use OOP. Thanks :)
"Spending your life waiting for the messiah to come save the world is like waiting around for the straight piece to come in Tetris...even if it comes, by that time you've accumulated a mountain of shit so high that you're fucked no matter what you do. "
Advertisement
Use OOP if it fits your problem (and thus simplifies your design and implementation). Don't try to fit absolutely everything in an OO framework just because you think "OO" implies "good".

Further reading: "Why C++ isn't just an object-oriented language" by Bjarne Stroustrup.
It sometimes depends on the language though too. I found when I was doing a tetris clone in java one day, that using more OO made my life easier. However, doing a pong clone with SFML and C++, I had about half the code OO, the rest just procedural with some helper functions. The reusable object I had in Pong, was just a Piece class, that stored various float variables, and had getters/setters. X & Y position, height, width, etc. Other than that I just used helper methods to work with the SFML framework.
Quote:Original post by agm_ultimatex
The reusable object I had in Pong, was just a Piece class, that stored various float variables, and had getters/setters.

Many purists will argue that getters and setters are the antithesis of OO.
Whether or not you should "use" OOP is a meaningless argument, devoid of context. Your goal in writing software is to write it in a readable, debuggable, testable, performant manner. You should use whatever techniques are appropriate for that. The important concepts for solid code apply whether you are writing OOP, imperative, or functional software.

That being said, saying broadly that "OOP code takes more space than 'normal' code, is unnecessarily complicated and requires greater processing power and time to use/compile" is flat-out wrong. While this is true of bad OOP code, there also exists good OOP code which is efficient, small, and readable.
Quote:Original post by DevFred
Quote:Original post by agm_ultimatex
The reusable object I had in Pong, was just a Piece class, that stored various float variables, and had getters/setters.

Many purists will argue that getters and setters are the antithesis of OO.


Haha, hence why I said my Pong clone wasn't very OO. I suppose for what I did, one could almost use a struct. I did create a couple class methods that did some quick math, just to keep it somewhat DRY.
OOP is not in the class keyword in itself. You can write object oriented code without it all together. The Win32 API is object oriented though it is written in C (though it's not necessarily the best designed framework).
An observation I have made in my own progression in projects and interleaved progression of such has been that:
1 - The end product can tend to be imperative especially when it's done over a short period of time.
2 - Refactoring causes code to be more object oriented.
3 - General purpose (or highly reusable code) is better suited to be object oriented.

It is in my preference to use "OO designed frameworks" (like DirectX) rather than "state machine designed frameworks" (like OpenGL) - as far as I have last checked, which has been for a while (OGL2 I believe)

My one and a half cent
[ my blog ]
Quote:Original post by DevFred
Quote:Original post by agm_ultimatex
The reusable object I had in Pong, was just a Piece class, that stored various float variables, and had getters/setters.

Many purists will argue that getters and setters are the antithesis of OO.


Yes, in fact getters and setters are one of the enabling techniques of OO development (you can for example extend the getter/setter methods to read/write from/to a file/database/whatever without changing any code using the getter/setters at all!).

I think the "purists" are just saying that so that newbies don't immediately turn away from OO with the feeling "OOP is bullshit, I'll just keep using structs".
Quote:Original post by arithma
3 - General purpose (or highly reusable code) is better suited to be object oriented.

When I read "general purpose" and "highly reusable", I tend to think of templates, not OO.
Its a matter of opinion. You cant provide any logical arguments for this at all. OOP and procedural both have a style to them and over time you learn which you prefer.

Just watch out for the "purists". These people are religiously driven to use their One True Paradigm and regard the other as inefficient, slow, confusing, complicated, simplistic or whatever else. Don't let those people make your decisions for you.
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!

This topic is closed to new replies.

Advertisement