Share this Page URL

Chapter 17 . Debugging and Troubleshooting > Some useful tips - Pg. 445

Debugging and Troubleshooting 445 Some useful tips Before we go on to the troubleshooting guide, you need to consider a few serious hints about writing your code and debugging your programs. If you follow these four guidelines, you will make your programming and debugging experience a whole lot simpler. · Include comments. --You really can't add too many comments in your code. When you or someone else needs to inspect your code to track down a bug, these comments can save days of work. The hours you spend trying to decipher what some arcane code is doing (or supposed to be doing), when you just want to fix some small bug, may be some of the most unpleasant hours you'll ever spend programming. · Use meaningful variable names. --Whenever possible, give variables names that reflect their functions: lastName is much more meaningful than ln or x23. For global variables, it's a good idea to use a lowercase g as the first letter--for instance, glastName. That way, you won't inadvertently use a local variable when you think you are using a global variable. · Change one thing at a time. --While debugging, don't fall into the trap of making a number of possible fixes all at once. Instead, make the one change that will most likely fix the problem. If that doesn't work, change the code back before trying a new possibility. If you try to make a number of changes at once, you'll probably end up introducing more bugs than you are fixing. · Work from a backup. --Always make a copy of your movies before you start making serious changes in an attempt to fix bugs. If you don't like the direction your changes have taken, you can always revert to the original. If you are forced to try to undo all your changes, you will often miss something and end up introducing additional bugs or complications. A troubleshooting guide