Deciding on a Programming Language for Game Dev
Tags: gamedev, c, emscripten
Published: 2022-04-05 12:24:21

Our first step in learning how to make games was to decide on which programming language to use. I am an experienced software developer, so I guided this decision.

This is _Game Dev From Scratch_, and we want to learn about programming. We don't want to use a game maker tool or a third-party engine, at least not in the beginning. We would like our game to run in the browser, so that people can discover and play it easily. We have lofty goals, so we want to use a high-performance language.

1. Typically browser games are written in JavaScript. I don't mind JavaScript, and I use it for front-end web development. JavaScript has dynamic typing, but I believe that static typing is advantageous for all but the smallest projects. [This stackoverflow page](https://stackoverflow.com/questions/1517582/what-is-the-difference-between-statically-typed-and-dynamically-typed-languages) explains the difference. JavaScript is not a slow language, but it's not the quickest either.

2. TypeScript is JavaScript with static typing bolted on. The transpiler is slow. It was developed by Microsoft. Call me a bigot, but I don't like Microsoft, and I don't like TypeScript!

3. I do much of my professional work in Python. I really like the light-weight syntax, without all those pesky braces and semicolons. Python is great for experiments, and has been adopted by the scientific and artificial intelligence communities. Although Python has some excellent and very fast libraries for mathematics, scientific computing, and AI, the Python language itself is much slower than JavaScript, and for that reason I don't think that it's ideal for game development.

4. Mainstream stand-alone games are often written in C++. C++ has been described as an octopus made by nailing extra legs onto a dog. When invited to reflect on whether he should have written git in C++, Linus Torvalds retorted that:
> C++ is a horrible language. It's made more horrible by the fact that a lot of substandard programmers use it, to the point where it's much much easier to generate total and utter crap with it. Quite frankly, even if the choice of C were to do *nothing* but keep the C++ programmers out, that in itself would be a huge reason to use C.

5. If C is a dog, it's a good old dog. The C programming language was [created by Dennis Ritchie](http://www.linfo.org/c.html) in the early 1970s. In my opinion, just about every programming language that has come after C is largely inferior to C, and none is wholly superior to it. It is not so easy to get started with C compared to Python for example, but I believe that I can make up for that with some helpful libraries and syntactic sugar.

Can we make a browser game written in C? According to [Mozilla's Game development page](https://developer.mozilla.org/en-US/docs/Games), yes we can. We can compile C or C++ to WebAssembly using a tool called [emscripten](https://emscripten.org/), and WebAssembly runs much faster than JavaScript in the browser.

As I understand, the popular SDL2 library has been ported to work with emscripten. Using SDL2 and OpenGL, we can build a browser version of our game, and native versions for the major platforms, all from the same code base. I have some prior experience with SDL2 and OpenGL.

In summary, we considered several different programming languages for learning about game development, and we decided to use C:

1. JavaScript – good for web, dynamic typing, not the quickest.
2. TypeScript – I don't like it.
3. Python – beautiful syntax, but it's too slow.
4. C++ – Linus doesn't like it.
5. C is the worst programming language – except for all the others that have been tried.

{% embed https://www.youtube.com/watch?v=H4YRPdRXKFs %}

Next post: [My Simple Programs](https://dev.to/gamedev/my-simple-programs-3g97), by Thalia
Previous post: [Creating Games](https://dev.to/gamedev/creating-games-4dpj), by Sean
Contents: [Game Dev From Scratch](https://dev.to/gamedev/game-dev-from-scratch-2do1)