Jump to content
  • Advertisement
Sign in to follow this  
Waaayoff

To OOP, or not to OOP?

This topic is 3149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 :)

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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".

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!