r/cpp • • Jul 02 '26

Why use c++ over c for game development?

Isn't c++ overkill for most games? I think with good architectural decisions you can make decent 2d and 3d games using only what's available in c without the higher level concepts introduced in c++? Do you think I'm being stupid here? Am I missing something? I'm only just starting to learn c making simple games leaning heavily on Raylib and ECS architecture.

0 Upvotes

117 comments sorted by

View all comments

39

u/gokufan300 Jul 02 '26

games really like being object oriented

1

u/[deleted] Jul 03 '26 edited Jul 05 '26

[removed] — view removed comment

2

u/HolidayNo84 Jul 08 '26

You think modularity is exclusive to OOP?

-1

u/GrimbaldTheBrutish Jul 03 '26

...what?

If anything games are one of the few areas in which I think OOP is a very poor paradigm. Performance wise games like to be data oriented, which is often in complete opposition to many OOP designs.

There's nothing wrong with OOP, but I don't see how you'd correlate it to games specifically.

10

u/serviscope_minor Jul 03 '26

Performance wise games like to be data oriented

Well, the 0.001% of AAA games, sure. So many games are written in OO style in C# using unity.

1

u/GrimbaldTheBrutish Jul 03 '26

Of course, i'd argue that almost everything is written in OO style. OO langauges are the norm, you almost can't find a job that isn't about OO.

The question is whether games really like being object oriented, as they put it.

I don't see how you're at a better advantage to write a game using OO than you are any other piece of software. Most software, say websites or apps, really have no advantage from being data oriented. Games at least are one of the very few places where you actually see a movement away from OOP.

You'll actually find the majority of game engines aren't written in an OO manner. Neither are a lot of supporting code like shaders or the common libraries used in gaming. Go to say, web dev, and almost everything is OO. Game developers probably have at least heard of ECS, if you ask a web developer they'll probably have never heard of a data oriented paradigm in web development because of extreme speed concerns on hardware.

So yes, OO is fine for writing games there's nothing wrong with it, but there's nothing special about games that make it better off being written in OO compared to any other common software program.

-12

u/HolidayNo84 Jul 02 '26

I know that's the typical choice, thing is I don't like being object oriented.

14

u/DACOOLISTOFDOODS Jul 02 '26

OOP is a tool, it shouldn't be pushed everywhere, it shouod be used where it's the right tool for the right job. For games, it is for the most part

-2

u/HolidayNo84 Jul 03 '26

I don't like the tool.

5

u/therealjerseytom Jul 03 '26

I think this is an opportunity to step back and really ask yourself why you "don't like it", and if there's some perspective that you might be missing.

Different approaches in programming, are to me, literally like you'd look at a hammer, screwdriver, wrench, or saw. I don't have particular sentiments towards any one of them. Like, "Ugh, screwdrivers just suck." They're all good at certain things and not good at others.

If all you've ever been doing is pounding nails, a screwdriver probably seems like it's not worth bothering with.

That all to say, it's worth keeping an open mind to.

1

u/HolidayNo84 Jul 03 '26

I do understand and agree with your message. However I have developed a preference for composition over inheritance because of how easy it is for me to reason about. I find that concepts explained in a functional paradigm are easier for me to learn. Obviously this is entirely personal preference and some people probably have the opposite experience. I think both experiences are entirely valid.

6

u/oracleoftroy Jul 03 '26

Good news! "Favor composition over inheritance" has been an OOP mantra for at least a quarter century!

I don't know why OOP only seems to mean inheritance these days, since many objects don't use or need it at all to provide useful functionality. Inheritance is great to use when you need it and should be used. But it really isn't something one needs all that often. Even in a fully OO project, you may only need it in a handful of places.

1

u/[deleted] Sep 06 '26

OOP has been pushed because on paper it looks like a logical paradigm, ideal for architectural design. Yet it is quite the opposite, for games OOP is a very poor design choice.

Ofcourse it works for average games and for the average problem it feels natural because they haven't learned how to think of that design in different ways.

By bundling data and logic OOP by its design breaks one of the most fundamental laws of programming which is separation of concern.

Once you start exploring you'll see that there are better ways to the mountain.

1

u/oracleoftroy Sep 06 '26

What exactly do you mean by this? Because frankly, a lot of the time when I hear the anti-OO crowd say stuff like this, I picture the following meme:

The compiler needs you to to spot the difference between these two pictures:

foo.bar();  

C Programmer: "boo hiss! That's OOP! It's slow, and confusing and no one could possibly tell what it is doing!"

bar(&foo);  

C Programmer: "Yay! That's great code! So fast, and simple. I know exactly what its doing down to the last instruction!"

Assembler: "It's the same picture."

A rather long-standing bit of C++ advice for good class design is: "Prefer non-member non-friend functions to member functions." That's item 23 in Effective C++, 3rd edition, 2005 (Meyers) and item 44 from C++ Coding Standards, 2004 (Sutter, Alexandrescu). I think this originates from Meyer's Dr. Dobbs article "How Non-Member Functions Improve Encapsulation" from 2000. All are very good reads.

So in short, it's been a C++ OOP best practice to not make everything a member function for about 26 years at least. C++ is not like Java or C#, it doesn't force you to put everything in classes. And that's a good thing. Free functions are great.

Moreover, most objects won't have virtual methods, and most should behave like value types and avoid pointer indirections where possible. Objects can encapsulate SoA style data.

To be honest, a lot of the anti-OOP arguments are based on things OOP programmers already recognize as bad practice. But for some reason they seem to think all OOP amounts to deep inheritance hierarchies, run time pointer chasing graphs of data, and all sorts of other things that are simply bad design and independent of OOP or Procedural or Functional, etc. Bad practice doesn't become good because the slow pointer chasing isn't done in a OOP paradigm.

1

u/[deleted] Sep 06 '26

Bar(&foo) is also wrong if the function is designed to operate for a single instance of an object. Ideally in data driven C we want functions to work on arrays of structs. This is the number one issue with OOP.

→ More replies

1

u/[deleted] Sep 06 '26

And if you have to prefer non member functions, then that effectively advocates an anti oop standpoint. C++ is multi paragdim it is not OOP. It can be whatever you need it to be.

→ More replies

2

u/Raknarg Jul 07 '26

whys that? Do you just mean you hate inheritance, or what? Cause just the concept of "grouping related information together with transforming member functions" which is more or less the core of OOP is kinda just integral in most languages, C used to be considered "object oriented" it was just very limited in terms of actual polymorphism. You'd even have single-parent non-virtual inheritance by having the first member of your class the parent object.

If you hate inheritence, join the club. I avoid inheritance when I can, in most cases my objects tend to be glorified structs with constructors and maybe handy member functions and a destructor if needed, and polymorphism is achieved through composition or templates.

8

u/StickyDeltaStrike Jul 02 '26

You can do C but most people won’t be doing that, so they won’t want to hire you.

If you do your own project just do it in whatever you love :)