Picking a Programming Language - Part 3: Common Languages

Now that we’ve talked about the big features of languages that can impact your game, we can look at specific languages and what they have to offer a game engine. This is not a complete list of the only languages you can write games in, just some of the more common ones (and the ones I know well enough to speak to). Chances are, you can find game development tools and libraries for pretty much any programming language.

C

Type: Compiled
Memory: Manual

C is a (relatively) low-level programming language and the language of choice for the Linux kernel. C’s low-level status and manual memory management means it runs very lean, using a minimum of system resources for non-program related activities. For games, this means being able to make better use of system resources for a game that runs better or offers more features on a lower-end system. However, C also has a steep learning curve. You’ll need to learn about how C’s manual memory management works, as well as pointers, and ensure both are properly managed to avoid memory leaks. C isn’t object-oriented so if you’re coming from an object-oriented background, the change can be a bit of an adjustment. The lack of object-oriented-ness is likely the biggest reason C isn’t one of the bigger languages used in game development, but it’s still perfectly possible to make games in C.

There are plenty of great libraries available for game development in C, with two of the biggest being SFML and SDL2.

C++

Type: Compiled
Memory: Manual

C++ is an extended version of C, adding some big features such as support for object-oriented programming and a huge host of commonly-used data types, containers, and algorithms through the Standard Template Library (STL). The object-oriented design does add some overhead compared to C, but it’s still a very lean language that makes good used of its resources. These features make C++ extremely common for console game development because it allows developers to squeeze as much performance out a console’s fixed hardware as possible. That means bigger, better-looking, more complex games on more limited hardware. C++ does have a steep learning curve as well for most of the same reasons as C.

Because C++ is an extended version of C, everything in C is available in C++ (the reverse isn’t true though) including libraries. It’s very common to use libraries designed for C in C++, so SFML and SDL2 both work in C++ as well. C++ is also the language of choice for the Unreal game engine so if you plan to use it, it’s worth learning C++.

Java

Type: Compiled/Interpreted
Memory: Automatic

Java’s biggest selling point is portability. It sits between a compiled and interpreted language. Java code is compiled to a file that can be executed by a Java Virtual Machine (JVM). The nice thing is that unlike C or C++, this compiled file is completely portable because any system that has a JVM can run it. This feature makes Java a little quicker than purely interpreted languages, but still slower than purely compiled languages. Another issue with Java is it’s memory management.

More knowledgeable people have written entire articles on just the subject of how Java manages memory, so I won’t go into extreme detail here. The important thing to know about Java’s memory management for game development is that it’s automatic and that the minimum and maximum heap size is set for Java programs. They can either be specified when running a java program using the -Xms and -Xmx flags, or if they are omitted then some default values will be used based on your system configuration. If your game needs more memory than the minimum, but less than the maximum, your game may stall as the JVM allocates more memory. If your game asks for more memory than the maximum, there’s a good chance it will simply crash when it runs out of memory.

Despite this, Java is a perfectly respectable language for game development (just look at Minecraft). Java is also the language of Android, so if you plan to develop mobile games, Java is a good language to know. The Lightweight Java Game Library (LWJGL) is a popular choice for game development in Java and as long as you aren’t trying to manage tons of data or do a lot of heavy processing, then Java will meet your needs.

C#

Type: Compiled/Interpreted
Memory: Automatic

C# actually shares a lot in common with Java, but was developed by Microsoft for its .NET platform. Like Java, it compiles to a executable that can be executed by the .NET framework. This executable is fully portable between any system that has the correct version of the .NET framework. However, the .NET framework handles this executable very differently than the JVM in Java. Instead of the virtual machine processing these instructions, the .NET framework compiles them into machine code and loads them into memory. This means we actually get the benefits of fully compiled code in terms of performance. C# also uses a slightly different version of memory management that avoids the memory limits present in Java, so the memory limits will only be those that exist for the system in general. Automatic memory management does still add some overhead to your game, but games written in C# will generally run quicker than in Java.

Although C++ dominated the console market for a long time, cheaper hardware has allowed for consoles with better specs. This gives developers more room to develop their games without worrying quite so much about optimization and helped make C# a more viable language despite its automatic memory management. C# has become a major player in the world of game development for both consoles and PC, and popular engines such as Monogame and Unity use C# for their scripting.

Python

Type: Interpreted
Memory: Automatic

Python was developed as a language to be easy to learn, but being an interpreted language with automatic memory management means it won’t handle complex games with a lot of heavy processing very well. You won’t be writing the next Borderlands in it, but it’ll handle simpler games like platformers or graphic novels perfectly fine. It makes for a great way to get into game development and learn programming at the same time. For people who want to start making games with “real code” instead of an engine, Python can be a good first step before moving on to other languages.

The Pygame library is a pretty popular choice for game development in Python.

JavaScript

Type: Interpreted
Memory: Automatic

JavaScript is the language of game development on the web. Thanks to enhancements to the language over the years, and the addition of the canvas element in the HTML5 spec, JavaScript has dethroned Adobe Flash for browser games. If you’re new to the world of programming languages, I should point out the Java and JavaScript are two completely different languages. JavaScript is an interesting one because the virtual machine that runs it is a web browser instead of your typical virtual machine that’s hidden away as a process. It suffers from many of the same problems as Python, but its availability online makes it a very popular choice overall. It can even do 3D thanks to WebGL.

One consideration worth mentioning for JavaScript is the fact that it runs through a browser, which means its code must be downloaded to your user’s computer to run. JavaScript is sent as plain text, so anyone who plays your game will have access to its source code. There are a couple of ways to get around this if you’re concerned.

The first is to run the code through an obfustigator. This is usually done to shrink the size of JavaScript program to make it easier to send to the client, but also has the side effect of making the code understandable to a machine, but virtually unreadable to a human. The code is still there though, and it can be reverse engineered if someone is determined enough. It’s more of a deterrent than a solution.

The second is to split your game into a client and server. The client’s job would be to handle the rendering and input while the server would contain the actual logic for your game. Only the client would be downloaded and visible to the user while the game itself would exist on a server. The server source code would be protected. However, this requires you to have a server up and running for people to play your game and the code for the client would still be visible. It would protect part of your code, but not all of it.

A quick search will yield plenty of libraries for game development through JavaScript. GDevelop and MelonJS are two of the bigger ones I’ve heard about personally, but there are plenty of others as well.

Hopefully this helps highlight some of the features of programming languages that can affect the development of a game engine. The issues I’ve highlighted here will generally only crop up when you try to push a game to its limits by having either a lot of data or heavy processing, and even then some clever algorithms can circumvent some of this. If you read this article because you’re agonizing over what language to learn, then I hope the information here helped you make the choice. Remember: you’re not locked into a programming language forever. You can start learning another at any time and each language you learn makes the next one even easier.