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
- 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.
- 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.
- 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.
- 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.










