I write games in C (yes, C) (2016)
Source: Hacker News
Why I Write Games in C (yes, C)
I am an unusual beast. All my solo‑project games I’ve been making recently have been written in vanilla C. Nobody does this, so I think it might be interesting to explain why I do.
Dry programming language opinions incoming, you have been warned.
What I need from a language
There are some non‑negotiable requirements.
- Reliability – I can’t afford to spend my time dealing with bugs I didn’t cause myself.
- Longevity – A lot of my games were written for Flash, and now Flash is dying. I do not want to spend my time porting old games to new platforms; I want to make new games. I need a platform that I am confident will be around for a while.
- Portability – I want to avoid tying myself to a particular OS, and ideally I’d like the option of developing for consoles. So it’s important that my programming language is portable and that it has good portable library support.
What I want from a language
The strongest item on my desired (but not required) list is simplicity. I find looking up language features and quirky “clever” APIs incredibly tiring. The ideal language would be one I can memorize and then never have to look things up.
- Strict typing & static analysis – fewer bugs, strong warning messages, and tools that help find issues quickly.
- Good debuggers & dynamic analysis – makes bug hunting less of a creative drain.
- Performance – I’m not after high‑def realism, but more cycles broaden the palette of things you can do, especially on modern, powerful computers.
- Fast compilation – Waiting 10+ seconds breaks my flow; I need a compiler that keeps up with my thoughts.
- Data‑centric approach – I’m not an OOP convert. I prefer handling data as data and writing code that fits the situation, rather than forcing everything into classes and objects.
The Alternatives
- C++ – Still the most common language for games and not without reason. I do almost all of my contract work in it, but I dislike it intensely. It covers my needs but fails my wants badly: it is desperately complicated, easy to create insidious bugs, and slower to compile compared to C.
- C# and Java – Verbose and complex beasts that railroad programmers into a strongly OOP style I oppose. They hide complexity in a way that doesn’t actually prevent it from biting you.
- Go – Appealing as a modern take on C, but stop‑the‑world garbage collection is a big pain for games, library support is poor, and I worry about its long‑term relevance.
- Web development – A terrifyingly fast‑moving environment, especially after Flash’s death. I really dislike JavaScript; it is so loose that I marvel people can write large software in it, and I have no interest in trying.
- Haxe – More promising than most alternatives, with some good library support, but I’m concerned about its relative youth and longevity. I’ve only dabbled with the surface.
- Write my own language – I admire that idea and sometimes toy with it, but throwing away existing library support and taking full responsibility for future compatibility feels like too much. It is also very difficult, and I would rather be making games than programming languages.
Why C is still my best fit
- C is dangerous, but it is reliable—a very sharp knife that can cut fingers as well as veg, yet simple enough to learn to use carefully.
- It is fast, and when it comes to compilation I can’t think of anything faster.
- It can be made to run on just about anything, usually with relatively easy effort. It is hard to imagine a time when this won’t be the case.
- The library and tooling support is strong and ongoing.
I say this with some sadness, but it is still the language for me.
I absolutely do not mean to say “hey, you should use C too.” My preferences are pretty specific and unusual. I have also already written more vanilla C code than most, and that certainly is part of my comfort.
So yeah, that’s it :-)