Game Development Reference
In-Depth Information
It is my sincerest wish that you take an analytical approach to debugging. Ask yourself
“Why?” constantly. As a programmer, you have the rare fortune to work with a determin-
istic system where the same conditions always lead to the exact same outcome. Given
logs, assertions, breakpoints, and stepping through code, you have all the tools needed to
analyze where your code is going wrong.
But don't forget the compiler has a say in this, too—which is to say: don't ignore compiler
warnings. They, too, inform you of potential, and sometimes actual, issues. Ignoring them
should be done only if you understand the reason for the warning and the implications of
not fixing it.
The worst thing you can do when you encounter a problem is to become angry. I know
that's easier said than done. Especially, when you're already stressed out, there's a deliv-
ery date to meet, and you're working on code that you just don't feel comfortable with.
But being angry and eventually frustrated seriously impacts your ability to approach a
problem analytically, which will increase the time it takes you to locate and fix the bug,
possibly tenfold. So the best advice I can give when it comes to debugging is to
keep...your...calm. Whether you meditate, take a stroll, get a cup of coffee, go shopping,
play a game, anything that lets you get away from a really annoying problem is frequently
a very good way to solve the problem more easily at a later time.
Where you depend on other code—for instance, when using Cocos2D classes and calling
their methods, and they behave unexpectedly—you need to use different tools. The other
tools you can use are the class or API references. Class references contain short descrip-
tions of classes and their methods. A good class reference will tell you whether your as-
sumptions about a given class or method and its parameters are indeed correct, and under
which conditions the method returns what values. More often than not, you'll find your
assumptions about how the class or method works were wrong to begin with.
Tip The Cocos2D class reference can be found here:
http://www.cocos2d-swift.org/docs/api/index.html . The
Apple class references are easily Googled by using the name of the class fol-
lowed by class reference—for instance “NSArray class reference”.
Nevertheless, if you find that a Cocos2D method is at fault—say, it returns nil where
you expect it to return an object reference—you can use the Step Into command to wade
through the code in Cocos2D. You may be surprised how much you can learn from step-
ping through Cocos2D code and what assumptions it makes. You might not understand all
of it, but you may still be able to get a good grasp of what it does and where exactly it
Search WWH ::




Custom Search