Skip to main content
GameDev.net gamedev.net
🔒 Locked

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

Started by alphster Jun 28, 2011 at 5:04 AM 1 replies 1.8k views
Original Post
alphster
alphster
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...
Dawoodoz
Dawoodoz
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.
rip-off
rip-off
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:

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.