In the old days, programmers would perform the debugging confirmation process by temporarily inserting print
statements into their code and rerunning the program to see what printed out. For example, to confirm that x = 3
in our previous code, we would insert into our code a statement that printed the value of x
and do something similar for the if-else
, like this:
x <- y^2 + 3*g(z,2) cat("x =",x,"\n") w <- 28 if (w+q > 0) { u <- 1 print("the 'if' was done") } else { v <- 10 print("the 'else' was done") }
We would rerun the program and inspect the feedback printed out. We would then remove the print
statements and put in new ones to track down the next bug.
This manual process is fine for one or two cycles, but it gets really tedious during a long debugging session. And worse, all that editing work distracts your attention, making it harder to concentrate on finding the bug.
So, debugging by inserting print
statements into your code is slow, cumbersome, and distracting. If you are serious about programming in any particular language, you should seek a good debugging tool for that language. Using a debugging tool will make it much easier to query the values of variables, check whether the if
or the else
gets executed, and so on. Moreover, if your bug causes an execution error, debugging tools can analyze it for you, possibly providing major clues as to the source of the error. All of this will increase your productivity substantially.