Is C++ worth it, for video games?

I really like the viewpoint that this guy takes to using C++:

Really clever and hard working C/C++ programmers can beat higher-level languages by a wide margin given enough time. However, their code will typically become less portable and harder to maintain.

Conclusion: If your sole reason for using C++ is speed, and you lack the budget for intensive optimization, you might be misguided.

Especially that last line. I conjecture that the thought pattern for people resisting moving to higher-level languages looks like this:

  1. Write some code in Python (Lua, C#, Ruby, etc.)
  2. Runs slow
  3. Write same code in C/C++
  4. Compile with -O3, runs fast!
  5. Conclusion: Python (Lua, C#, Ruby) is too slow.

Of course, the conclusion only follows if the premises are true, and here I think low-level language people get caught on step 1. Often C/C++ programmers write their Python code as if they were writing C, but if you write Python like this:

in_list = [1,2,3,...]
sum = 0
ix = 0
while ix < len(in_list):
    sum += in_list[ix]

Then of course you shouldn't expect it to run fast. I agree with @lemire on his general conclusion: if you're not going to seriously micro-optimize, think about using something else. For most realistic-sized projects (say, more than 10k lines), you'll end up saving yourself time and effort.

But what about video games?

Unfortunately it's hard to get away from C++ when you're writing video games. Why? All the useful libraries (Ogre, for example) are in C++. The Python port of Ogre is hairy, and Ogre isn't built for non-compiled languages anyways (it's very hard to test Ogre code in Python). It's even difficult to access the low-level APIs (e.g. OpenGL) in high-level languages, due to their reliance on C-isms.

What can we high-level language users do about this? Write more game engines, game middleware, and game libraries in your language of choice! Personally, I am recently enamoured of Go and am thinking about writing a video game-focused DSL based on Go. There are some things (vectors, matrices, the concept of space and time) which are common to almost all video games and should be made first-class in a language. If this sounds cool, let me know!


comments powered by Disqus