Bad Code

Wednesday, January 12th, 2011

A friend sent me this xkcd comic the other day:

Good Code

Pretty funny… since it seems to happen a lot in the game industry. But then I started thinking about “bad” code in general. Is it really all that bad?

None of the games that I’ve worked on have had perfect code. That includes the professional ones as well as the one man side projects. There’s always bad code somewhere. Always a section that could be rewritten better or faster. Always a global that someone threw in there at the 11th hour to fix a bug. Always a magic number somewhere. Always a piece of code that you look back on and say, “What the @#$!?” Always!

It’s inevitable! Games aren’t something you can really fully pre-plan. Nobody really knows exactly how the game is going to turn out and what path it’s going to take before you begin. You’ve got a studio full of really creative people all working toward a common goal and a rough idea of the game they’re trying to make, but they all have different ideas of how to get there and the game is naturally going to evolve and change at least a little bit over the course of development. Nothing works out exactly as it’s planned on paper. Especially a video game! Until you actually make it, you’ve got no idea if it’s going to pan out the way it’s working in your head ( or in your publisher’s head! ). How do you plan code for something like that?

On top of the creative and ever-changing nature of game development, a game is a ridiculously complex piece of software. This isn’t a word processor or a spreadsheet tool. These programs have to juggle everything from graphics to input to sound to AI to physics to UI to memory management to streaming to particle effects to everything in between… and it’s gotta run at a decent frame rate… and oh yea… it’s gotta be fun! It’s gonna be pretty damn tough to pre-plan a perfect architecture of code to handle all of that in addition to the constantly changing design decisions and tweaks that result in a finished product. It’s just never going to be all rolled up in a neat little package.

If that wasn’t enough, there are always time constraints. The game / feature / system / whatever always needs to done yesterday. Whether that’s pressure from a publisher or from a manager or from a launch date you need to hit, it doesn’t matter. There’s always going to be time limitations, which usually require some “clever” or “interesting” coding to get stuff done on time. Admit it, there’s no doubt been a time when you’ve been crunching for weeks and aren’t seeing or thinking straight ( let alone coding straight ). How tempting is that “quick fix” at 3am that might not result in the prettiest code or the most elegant solution ( read: hack )?

But is all this really such a bad thing? I’m obviously not in favor of ugly, bad, spaghetti, wrong, hack, global ridden, duct tape code… no one is. I’m just thinking that it might simply come with the territory… at least a little. It might just be something we shouldn’t be getting too upset over, because everyone’s written some bad code ( and even some god awful code ) from time to time. No one’s perfect and every game in the history of mankind ( please correct me if I’m wrong ) has some bad code in it somewhere. Par for the course?

I’m sure you have ( I know I have ) looked at someone else’s code and thought, “What the hell was this dude thinking? That’s some of the worst code I’ve ever seen! How is this even working?!” The usual follow up is something along the lines of, “Man, if I wrote this thing it’d be soooo much <insert awesomely positive blue sky thought here such as “better”, “faster”, or “cleaner”>! Why didn’t they just do <xyz>?! There’s NO way I would have let the code get to this point! Not me!”

Maybe. But maybe not.

I just did a search on the original DOOM source code and found 32 references to the word “hack”. Who cares? I certainly don’t! And at the end of the day, we’re making games! We’re not writing code to win awards, we’re writing code to make something fun!

Your finished game should always have the final word, not your code. If your game is fun, then congratulations… you win!


There is 1 comment in this article:

  1. Wednesday, January 12th, 2011TheLucidGamer says:

    SHHHHHH! You’re not supposed to tell them!!!

    Also my code is ALWAYS \\ insert awesome positive blue sky thought here such as “better”, “faster”, or “cleaner” !

Write a comment: