The three-legged debugging stool
There are three tools I have frequently used to help me debug programs: logging, symbolic debugging, and print statements.
Each has its own strengths and weaknesses. The advantage of logging is that it is always there. When something goes wrong in your program, It should already have been writing out a log file. If you have chosen what to log with some care, occasionally simply looking at the log file will be enough to determine what went wrong.
Symbolic debugging it's great because you can walk through your the program line by line, and examine anything in scope at the point in the code.
What, then, would be the use of print statements? Let me give an example: I had a bug that occurred somewhere around the 80th iteration of a model, and would become worse over the next 40 or so iterations. I knew exactly which variables were involved in what was going on. Rather than set a breakpoint in the offending code, and then repeatedly examine the same four or five values while stopping at the breakpoint dozens of times, it was much simpler to just put a print statement in the problem lines and let the program go. Then I could just scroll through the output and watch the variables change.
Each has its own strengths and weaknesses. The advantage of logging is that it is always there. When something goes wrong in your program, It should already have been writing out a log file. If you have chosen what to log with some care, occasionally simply looking at the log file will be enough to determine what went wrong.
Symbolic debugging it's great because you can walk through your the program line by line, and examine anything in scope at the point in the code.
What, then, would be the use of print statements? Let me give an example: I had a bug that occurred somewhere around the 80th iteration of a model, and would become worse over the next 40 or so iterations. I knew exactly which variables were involved in what was going on. Rather than set a breakpoint in the offending code, and then repeatedly examine the same four or five values while stopping at the breakpoint dozens of times, it was much simpler to just put a print statement in the problem lines and let the program go. Then I could just scroll through the output and watch the variables change.
Comments
Post a Comment