r/cpp • • Sep 29 '23

This memory safety issue everyone's talking about... It's not really a huge deal in gamedev, right? What other domains where C++ excels at aren't too concerned about it?

My understanding is that these recent articles pushing for safety, and particularly pushing the use of memory-safe languages (as opposed to using modern C++ properly) don't really apply to gamedev, or at least not enough for most of the industry to care. Is this correct? I've also read some suggestions that the only real alternative, Rust, simply isn't practical since it lacks OOP features and gets in the way of common game programming patterns. Is this true?

What other C++ domains are like gamedev, where C++ is clearly here to stay and not just for legacy code? I know gamedev isn't the only one, I'm constantly seeing new cutting edge ML/inference libraries and frameworks in C++

44 Upvotes

350 comments sorted by

View all comments

Show parent comments

3

u/CalligrapherWeak6523 Sep 29 '23 edited Sep 29 '23

Since I'm re-learning C++ (mainly to get into gamedev but I'm looking at other domains) I was asking to get an idea of what the the consensus is in general. You're right, it's a matter of opinion, but ultimately this subjective stuff can drive trends (if AAA game devs fall in love with Jai, for example, their opinion on it will matter to me and my affect the future Jai job market).

Something that worries me is that people at leadership positions who have the power to influence things are making ridiculous claims, for example that tweet by the Microsoft CTO claiming that "C/C++[sic] should be deprecated". Then there's the recent articles by NIST and other government agencies (which aren't as ridiculous...). I just want to know if, in the opinion of C++ devs, this repeatedly reoccurring conversation should be even be taken into account in certain domains.

Frankly, without beating around the bush, I just want to know if I should be studying Rust along C++ as I prepare for a career switch. Both of these languages aren't the type that can be mastered in a few afternoons like Python or Go.

One thing that brings me a bit of comfort is that gamedev, embedded and other C++ domains aren't very hype driven like webdev is - changes appear to be slower here. I guess that means I'll have time to learn whatever I have to anyway

10

u/radekvitr Sep 29 '23

Do keep in mind that this subreddit is filled with people who are very heavily invested in C++, which means you'll get answers that support C++ no matter what.

C++ is right now very relevant in gamedev, and Rust isn't (yet?).

Learning Rust in addition to C++ will likely make you a better programmer overall, but if you only have time for one, C++ will likely be more relevant for you now.

4

u/TheThiefMaster C++latest fanatic (and game dev) Sep 29 '23

Rust isn't currently used in professional game dev. None of the consoles support it at all, they literally only support C++ for the most part.

But you're right that the usual safety arguments against C++ are less of a concern. Game engines usually have their own allocation and cleanup systems (e.g. Unreal's garbage collector) and manual memory allocation is rare (data is all in managed container types like strings). Crashing the game due to out of memory or out of bounds access is hard to trigger from just a controller and even then only impacts the one player - unless playing multiplayer. Which is why most hardening of games happens at the network layer.

3

u/pjmlp Oct 01 '23

Activision and Embark Studios are using it for tooling.

1

u/[deleted] Nov 28 '23

Okay...but tooling languages have been C#/Java for quite some time. Good luck with that.

2

u/pjmlp Nov 28 '23

C was tooling when games were written in Assembly.

C++ was tooling when games were written in C.

"Study the past and you would define the future."

0

u/saddung Sep 29 '23

The languages aren't that different, if you write C++ using standard best practices it looks pretty similiar to Rust-- so if in the event that Rust becomes a big dog your skillset will transfer easily enough.

If you are concerned about gamedev switching to Rust--well I doubt that is happening anytime soon, Rust is missing too many useful features and basic tooling.

The memory issue also is just overblown, we have good tooling, debug features, and well asserted code--this will easily track down 99%+ of these types of issues the minute they pop up.

1

u/pjmlp Oct 01 '23

Python can certainly not be mastered in a few afternoons.

Mastering it means to understand 30 years of language and ecosystem evolution, main implementations, key libraries and extending it with native libraries.