|
Re: Debuggers are a wasteful Timesink
|
Posted: Nov 30, 2003 10:33 AM
|
|
> Only a couple of days back, I was diagnosing a bug: "Error > while reading AFM file in PDF generator." Now, I have no > clue what an AFM file is. I figured out it's an ascii file > containing some font kerning information for PDF > documents. Next, I don't know how the code works. I grep > for the "AFM" and "read" in the code, and find a function > called "ReadAFMFile" somewhere. Since I don't know the > file format, I get lost in all the for and > while loops. Print statements galore, but it > makes little sense. Finally, I do manage to figure out the > reason by "guessing" that it's a UNIX vs. MS-DOS format > issue with the ascii file. I strip off all the carriage > returns in the file, and bingo, it works! > > So this turned out to be simple. What if it wasn't, and if > I had to actually find out the file format and how the > parsing works?!
Wouldn't it have been nice if the code had been written in a clean and expressive way so that it told you how it worked? Wouldn't it have been nice if the code had been instrumented with unit tests that helped you understand it? Don't you think it is our professional duty to write code that eliminates the need for others to have to use debuggers to understand it?
> I think debuggers are very, very essential > tools. I'd really like to hear how a debugger has ever > wasted your time. Honestly, just how?
Simple. By trying to breakpoint my way into the failing context. I've spent hours trying to get to just the right point in the execution thread. I've spent hours in the wrong place, convinced it was the right place. I've spent hours backtracking from a context, not quite sure exactly how I got there. Only to find that the bug was stupdily obvious and I could have easily found it simply by reading the code that I was breakpointing through.
Note, I am not saying that there is not a place for debuggers. I just think that they should be considered a tool of last resort.
> > Check out this article on "code spelunking": > http://www.acmqueue.com/modules.php?name=Content&pa=showpag > &pid=67
|
|