Tracing What, How, and Why Copyright © Curt Hill, 2004-2006
What? Tracing is the simulation of a computer program or part of a computer program We “play computer” The results should be the same as if the program were executed on a real machine The simulation needs to cover every relevant aspect of the computation Copyright © Curt Hill, 2004-2006
Elbonian Computers Copyright © Curt Hill, 2004-2006
Why? Essential debugging tool Important learning technique A correct trace demonstrates that you understand the fundamentals We will have tracing exercises in class and on tests Copyright © Curt Hill, 2004-2006
How? Find the first statement to be executed Write down all the variables Used to record their current value As new variables are encountered they may be added to the list For each statement that is encountered: Determine its action Record changes to any variables Show the final values when execution is complete Copyright © Curt Hill, 2004-2006
An example Java Console C++ Java Window Copyright © Curt Hill, 2004-2006
Right and Wrong There is a right way and a wrong way to do tracing The right way is this The wrong way is to attempt to analyze this algebraically That approach does not allow for a change in variables Copyright © Curt Hill, 2004-2006