How to Hand Trace Through Software Code

Tracing through your code can be a helpful way to debug your program. Unfortunately, it is tedious and often very boring. These tips will hopefully help you quickly complete the task and move on.

[edit] Steps

  1. Divide a sheet of paper into columns. Each column is a variable the code you are tracing through will use. Write the name of the variable at the top of each column.
  2. Write the starting value of each variable as the first item in its column. Don't write a value if the variable isn't initialized right away.
  3. Go through each statement in your code and whenever the value of a variable is changed, write the new value underneath the old value in its column. Hopefully, this will help you see what is wrong with your program.
  4. Fix your program's problem and recompile the code. Test the code, and if it still contains the bug, retrace through the code if nothing else works.


[edit] Tips

  • Use a pencil so that you can erase if you make a mistake in your trace. You can also erase the sheet of paper so that you can reuse it to trace another time.
  • Trace through one section of code at a time so that it doesn't become confusing.
  • If you have any other way of debugging your code, use it before hand tracing through the program, because this method can be slow and painful.
  • Some IDE's have built in debuggers that can step through code, imitating a hand trace. This is much faster and can prevent errors when writing by hand.


[edit] Warnings

  • Double check the values you write down, or your entire trace will be wrong, and you will think you have caught the bug when you haven't.


Embed this: Republish this entire article on your blog or website.

Was this article accurate? Yes No

Edit This Page E-mail this to a Friend Printable version
Discuss This Page Thank the Authors Write an Article
Categories:Programming

Authors

Andy C Zhang, Maluniu, Anonymous, OhioMike
Thanks to all authors for creating a page that has been read 3,638 times.

Related wikiHows

Hide These Ads - Why?


Hide These Ads - Why?
Show Ads

Navigation

Editing Tools

My Pages