• Advertisement

C vs C++, Objected Oriented Programming vs Data Oriented Programming

Recommended Posts

As someone new and planning on getting into Graphics Programming and possibly Game Development, the following topics/paths always leave me wondering as to which route I should take. Now, I know some of these subjects are a little controversial and might create much debate, but still, I would love to hear about your personal view and experience in the industry and hopefully get a better perspective.

As someone who is planning on getting into Graphics Programming or Game Development, would it be better to :

1. C or C++

2. Object Oriented Programming or Data Oriented Programming

After researching around on the internet, there seems to be two schools of thoughts. One that prefer to use C with perhaps a few features from C++ such as operator overloading, etc. (Casey Muratori, Mike Acton....) Who value performance and the Data Oriented approach and see Object Oriented as an unnecessary evil.  And, those who use C++ and Object Oriented Programming (responsibly).

Now, as a relatively new programmer with only python experience, I'm really having a hard time deciding which road to take; especially when it comes to the initial decision of deciding which language to learn.

Both sides seem to make a good case, yet the undeniable fact is that majority of the people do seem to use C++ (but perhaps someone in the industry could shed some light on this subject), while some use a Cish C++, and relatively few using only pure C. Even John Carmack -- Quake's developer who used to code in pure C have recently decided to use C++ for their new and recent installment of Quake 3.

After years in the industry, what would you recommend to newcomers who are interested in Graphics Programming, making their own engine, or Game Development in terms of C, C++, OOP, DOD?

Thanks in advance :)

 

Share this post


Link to post
Share on other sites
Advertisement

These questions feel like asking whether one should use a hammer or a screwdriver.  Really each solves a different problem.

As far as OOP vs DOP... I'm gonna say something a bit controversial here, but I feel C++ is actually more of a DOP than an OOP language.  Now hold off on the flames, I do have good reasons.  Sure you can create objects in C++, and you have inheritance... to a degree.  But most of what people consider OOP, is not really OOP (classes, encapsulation, RIAA, are all awesome tools, but are not really OOP).  C++ lacks things like virtual constructors, multi-dispatch, and a slew of other minor things that are really useful for OOP, but you don't really know is missing until you've stepped away from C++ OOP.  Now I'm not saying that C++ isn't OOP (there are a myriad of OOP definitions, and you can do OOP in assembly if you like...) just that C++ OOP can be awkward in some situations (like trying to force a square peg into a round hole).

In fact, modern C++ has stepped away from OOP in favor of meta-programming/templates.  Where-as most of the classes in a C++ program are just glorified structs with a few member functions attached (no inheritance, no virtual dispatch, etc...), you will find extensive use of template/meta programming in nearly every modern C++ program.  From containers to iterators, and all the algorithms that use them, these are all DOP in function if not form.  Despite their terrible syntax, they are an amazing tool, and IMHO are what separates C++ from many of the other languages out there (or at least at one time, many languages now have or are getting generics or something similar, which I think is a testament to how effect/useful they are).  I really do think that Stepanov was a genius when he brought DOP into C++ with the STL.

But in the end, you should learn and use both techniques, OOP and DOP.  Then when you have a problem to be solved you can be confident in your choice of algorithms, patterns, and design decisions.

Share this post


Link to post
Share on other sites

Depending on the face of project, I see myself more often write C-Style global functions than diving into the OOP (if correct or not may be at any onse choice) syntax. But on the other side OOP(ish) style code makes life a little easier over plain C code. Classes as data containers with extra functions are in some way better to handle than the good old plain data with argument overloaded API calls have been for there encapsulation of proeprties.

I think it is the possibility of both, C_Style mixed with OOP(ish) code that makes C++ (dont forgetting about the power of templates and preprocessor macros)

Share this post


Link to post
Share on other sites

You can do OOP with C (check out gobject as an (over engineered) approach).

Likewise you can do procedural development with C++ but still benefit from safety and convenience (i.e smart pointers, STL / vectors)

Most of my middleware work is in C (eases binding to other languages and the hardware) but I would classify more than 90% of my code to be Object Oriented in design.

i.e C:

struct Player *p = PlayerCreate();
PlayerDamage(p, 13);
PlayerDestroy(p);

vs (non-exception safe) C++

Player* p = new Player();
p->damage(13);
delete p;

As for which one is better... people generally agree that breaking things up into objects makes a project easier to navigate because you have a common design that you can make assumptions upon.

Edited by kop0113

Share this post


Link to post
Share on other sites

Thanks so much for all the wonderful replies. I'm currently learning C++ and planning to read Effective C++ once I am done with the first book.

Are there any good books you guys would recommend? on algorithms, data structures, etc? or any other related subjects that might be helpful beyond the basics of C++ ? :)

Share this post


Link to post
Share on other sites

The original objectmentor PDFs about SOLID are now hosted here: http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod

Definitely read them.

Understanding SOLID is the beginning of a journey away from just being able to write code in C++ and towards being able to architect software and software components. Then to do so on a larger scale without even getting hung up on the specifics of any particular language.

SOLID is often touted as modern pillars of OO and the PDFs are certainly presented from an OO perspective. In actuality you will find that a number of the lessons there can and should be applied to other programming paradigms too!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Advertisement