It’s a dirty little secret in game development. The actual finished code of most games sucks. It’s barely maintainable, often riddled with special cases, and the code authors are often embarrassed to have their code seen in public.
I’ve been a senior engineer for over a decade, I’ve mentored new programmers, I’ve written long articles about how to write good code. But I have to admit that a lot of my game code is crap. And I’m willing to bet that by the end of your project, your code will be too. Why is that?
- The goals of a game are too vague to properly plan around. You can’t use a “waterfall” development model with any reliability
- The “agile” development method with a multi-discipline team tends to focus less on code cleanliness and more on making a fun game, which is an incredibly hard task all by itself
- Traditional refactoring approaches don’t work well because the GUI requirements are extremely detailed and intricate
- Your time constraints are manic and often impossibly short
I’ve heard all the arguments for how to fix this problem; everything from “be a better programmer” to “use more extreme programming” to “just plan things better.” But these don’t reflect the reality of the situation. The reality is this: if you show me a game that has really clean and maintainable code, I’ll show you some other game that beat them to market and quite possibly took some of their sales.
This isn’t unique to indie gamers, either. Except for a few cases (the engine code at Turbine is reasonably clean), the game code I’ve seen everywhere has basically sucked. Even when the developers use Scrum. Hell, especially when using Scrum methodologies, because game functionality seems to win out over code cleanliness in those situations. Sure, it shouldn’t, yadda yadda, but it does.
So we have to live in the real world where game code sucks. But our code has to be maintainable! We have to keep this code working for years after the game ships. We will quite possibly want to use the code for a sequel. It can’t be entirely throw-away code. Where do we draw the line, and how? I’ll offer my thoughts on that next time.