If you have never used C++ you may have heard or seen some code that looks particularly complex, but don’t worry: this is not the default! It is one of the older languages that’s been around forever and still widely used, why is that?

Why is C++ the most used language in game programming?

C++ main use case is for writing code that needs to perform well. Games generally tend to have a real time requirement, for example running a game that draws fancy 3D scenes at more than 60 frames per second. In order to achieve that we need to have code that runs fast and have control over almost all aspects, more on that in the next section.

Besides performance reasons we can look at platform compatibility. Most languages have limited use cases or are very specific on which platforms they run. C++ can run on any platform as long as you have a compiler to generate the machine code for it. That is also the main difference between C++ and other languages like C#, Java or Python. C++ compiles down to machine code which are the literal instructions for the CPU to execute. C# or Java compile your code to an intermediary language that will be translated to CPU instruction at runtime by a virtual machine!

What good is there to learn from using C++?

C++ gives you an understanding of the inner workings of a computer. Since it’s possible to manually allocate memory and work with pointers, you will understand more of how to use it efficiently. This knowledge remains even when using other programming languages afterwards! When you start to optimize code, you will find out how the CPU works. An example is optimizing the size of a struct so it can fit better in the caches of the CPU. The applications are endless: transferring large files between the hard drive and RAM, uploading textures to the GPU and many more.

You can have direct control over hardware using C++. There are already tons of libraries out there, but you can always write your own code for them. This low level access can’t be replicated by most other languages. Rendering operations are hardware operations on the graphics card. There operations are usually done through a C++ program that is compiled out to a Dynamic Link Library (DLL). This DLL can then be loaded in your language of choice to access the functions stored inside. This is perfectly fine for everyday use cases, but if you want to do anything that’s unorthodox you’re out of luck. That’s where C++ comes in.

Some downsides of C++

C++ can be very verbose, and it has to be because we have to be very precise. This can sometimes lead to a lot of boilerplate code that can be avoided compared to using other languages.

It’s still very easy to write code that’s slower than something written in other languages. This is usually because the other languages translate basic operations very efficiently by default. You could still get close if not faster by writing C++ code, but why invest the time to reinvent the wheel?

Choose your tool for game creation wisely!

Usecase

Personally I tend to combine C++ with a scripting language for game development. My own game engine Ryne runs on C++ and I use C# as a scripting language that users can use to write the high level gameplay code. Of course this comes with some pain points where some parts have to be written in C++ and some in C#, but I think it’s a good mix for quick development cycles.

How to use the C++ course

In the C++ course we’ll look at many aspects of C++. Depending on your experience with programming in other languages you can start at different levels. I will try to cover all the basics and slowly tackle more complex subjects so you should learn something new regardless of your current skill level with C++.