90 likes | 992 Views
Debugging Watch and Text Output. Alice. Debugging Techniques. Several techniques are helpful in eliminating errors (bugs) in programs. careful design incremental development In this session we look at two additional techniques: Watch Text output. Watch.
E N D
Debugging Techniques • Several techniques are helpful in eliminating errors (bugs) in programs. • careful design • incremental development • In this session we look at two additional techniques: • Watch • Text output
Watch • Variables are elusive and a bit magical because they exist somewhere in the murky depths of the computer's memory and we can't see what is going on inside them. • To help you "see" the inner workings of a variable, Alice provides a watch -- a small window where the value of a variable can be displayed at runtime.
Creating a Watch • Select the object in the Object tree and then the variable you want to watch. • Then right click on the variable and select watch this variable. • In this example, we selected the corvette and then right clicked on its direction variable.
Demo • Every time the value changes, it is immediately updated in the window. • Setting a watch on a variable thus allows you to see whether the value is changing as expected. If not, you can then change your code to make it work correctly.
Text Output • Using a print instruction is another way to keep an eye on the value stored in a variable at runtime. • The print instruction causes the animation to be displayed in a split window. • One pane displays the animation • A second pane is a text console where text output is displayed.
Modified methods • Here is the modified left method: • Note that a print instruction is added to both the left and right turn methods.
Demo • The major difference between a watch window and text output is that text output provides a history of the values as the program runs.