Reflection

While reviewing and studying for my exam, I can’t help but reflect back on the subject of “sanity checks” in game code. These are the “if-then” statements that look for null pointers, variables with values outside of their domain, etc. — in other words: bad code. For a small game such as “Maxwell’s Demon”, such checks really don’t make much sense because each of those possibilities is essentially going to be an unrecoverable error that needs to get fixed anyway, and the sanity checks only serve to slow down the code.

When the sanity checks become important is when the code gets re-used or repurposed. “Engines” and “libraries”, especially those meant to be used by teams of programmers or released to the public for inclusion in multiple projects, absolutely need this stuff. You always want the programmer using your code to know the problem is his code and not yours. Toward that end, it makes sense that your library code throws meaningful and helpful error messages whenever possible. Because these error messages are usually not meaningful to the end user though, it is a good idea to let the programmer who is using your code to toggle whether error messages are displayed or not. In fact, you might even want to provide two versions of the code: one with sanity checks and error messages (for ease of programming) and one version stripped of all such checks and compressed such that it takes up a minimum of space and time.

I regret that my code lies on neither extreme at this point. It has not been optimized for re-use, nor has it been optimized for speed. As such, I really don’t recommend trying to use it at this time (even though I have made it available). Typically i write much better code, but the time constraints and the desire to use the existing code from the course have resulted in the less-than-ideal code on this project.

Leave a Reply

Your email address will not be published. Required fields are marked *