Need help organizing code... its a complete mess.

Started by
1 comment, last by rip-off 12 years, 9 months ago
I was hoping someone might know a good book or resource for me to study up on that'll teach me how to better organize my game code. I've been working on Pacman and it feels like the code is all over the place. I've resorted to using Global variables everywhere and i'm not sure if i've created the most optimal classes.

Anyone know a good book? Generally, the examples in most of these XNA books are simple games and they put all the logic into the Game1.cs file. I'm looking for a better structure than that...
Advertisement
Learning pure functional programming is a good way to learn how to divide a giant routine with side effects into many small well defined functions that are thread safe and can be tested out of context.
Forcing yourself to remove global variables will be part of it. Applying the Single Responsibility Principle will help too. Reducing dependencies is another powerful tool. Inverting the dependencies or introducing some kind of pure abstract "mapping" layer (often in the form of callbacks, or delegates).

Personally, this is something I learned by writing bigger and bigger programs, to the point where I couldn't maintain my older style so I was forced to abandon globals and really start separating things out into smaller units. Even then, it wasn't until I was working where I learned the value of unit testing, and totally minimising the dependencies so everything can be tested in isolation.

That is my excuse for not having many good resources to point you to. However, here are some excellent articles on programming design principles:

This topic is closed to new replies.

Advertisement