next up previous
Next: Using the Debugger Up: Debugging Java Programs with Previous: Debugging Java Programs with

Perspective

A good interactive debugger, which allows you to run your program a few statements at a time and observe the values of variables, is an invaluable tool for finding problems and verifying that a program works.

But a debugger is no substitute for thinking. The best way to eliminate errors (bugs) is to not create them in the first place. Time spent carefully designing a program is more than repaid in time saved during testing and debugging. Before you start writing detailed code, be sure you understand the problem and the algorithms you plan to use to solve it. After you've written the code, carefully check it (proofreading, tracing, etc.) before you try running it.

Don't rush to get something on the computer. You may be tempted to type in the first thing that comes to mind and start tinkering with it, because it sometimes feels like no progress has been made until the machine is involved. But if you hack before you know what you are doing, it will take much longer to get a correct program and the code will be much worse.

Rather than tinkering with your code, randomly changing things in the hope that bugs will go away, get away from the computer and think.

Take advantage of all error-detecting features provided by CodeWarrior. Turn on any options that you can find to generate warning messages. Use any available software tools to look for potential bugs. Don't waste your time on problems the computer could have caught for you.

Once you have carefully designed and typed your program, your task is to verify that it works as expected. The debugger can be a great help with this, allowing you to stop execution at ``interesting'' places and check that variables have their expected values, that expected output has been produced, and that nothing unexpected has happened.


next up previous
Next: Using the Debugger Up: Debugging Java Programs with Previous: Debugging Java Programs with
Kiri Wagstaff
2001-07-18