Java Reference
In-Depth Information
When you let the code run (and click the Go button in the application to get the drawing started),
you get the set of variables shown in Figure 11-9 after a very short wait:
Figure 11-9. Variables at conditional breakpoint:
As you can see, it stopped when currentStep got to 15.
Debugging Tips and Tricks
Now that you know the basics of using the Eclipse debugger, here are a few tips and tricks to help you
along when you use any debugger:
Be especially watchful in loops. By nature, loops repeatedly check and define a
small set of values. So, examine those variables as you work through a loop. I can't
tell you how often a badly set looping variable has been the source of my troubles,
but it's a large percentage of the time.
Use conditional breakpoints in loops. Often, a problem doesn't surface until a
particular value is reached. It's not much fun to watch the same set of values, and
boredom can dull your focus and make you miss the actual problem, so use
conditional breakpoints to skip over the things you know aren't problems.
Watch for “copy and paste” errors. If you're using code you got from somewhere
else (including this topic), it's very easy to neglect to change a variable to the value
you need from whatever was in the example you borrowed. It may look right,
because it's what you read when you went looking for an example, but it's wrong
because it's not what your program needs.
Take the time to understand the code. I'm a great one for rushing through things I
think are simple, only to discover they're not so simple. Painful experience has
taught me to take the time to fully understand the code I'm using (whether from a
library or a sample or my own code). Only by understanding the code in all its
detail can you understand the results the debugger is giving you.
That last one is actually the hardest things developers do, by the way. Getting all the relationships
within a codebase into your head so that you have a clear idea of how it works, usually called
visualization, is a tough task. Good developers are good at visualization. It's also why so many
Search WWH ::




Custom Search