Richard said:
Eric Sosman said:
Richard said:
Richard wrote:
[...]
“Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are, by
definition, not smart enough to debug it.†– Brian W. Kernighan
This quote is maybe sometimes applicable. But not always.
Debugging well structured and documented code is generally quite
easy. [...]
The only empirical study I'm aware of came to the opposite
conclusion. A bunch of computer science students were handed
an existing program and told to debug it. Half received the
program as originally written, half received the same program
minus all its comments. The comment-less group found more of
the bugs and found them faster. So much for documentation.
I think the experiment was described in "The Psychology of
Computer Programming," but I can't remember for sure. The authors
speculated that the comments led the readers down the same paths
of fallacious reasoning that the original code writers followed
when they wrote the bugs in the first place.
Depends on your familiarity with the code and how well you know how to use
a debugger. Some people are just good at it - binary chop and gut
instinct.
Debuggers are vastly overrated. They are sometimes useful
when you have little idea of what's going on and don't know where
to look, but all they can really do is provide grist for the
reasoning mill. In many "interesting" scenarios, debuggers
distort the progress of the program so much that they are of
How do they distort the progress? They distort it much less than adding
printfs!
<OT> Never debugged a multi-threaded program? </OT> Never
seen a program that misbehaves when run on its own but runs
fine and produces correct results when run under a debugger?
Never seen a timing-dependent program that goes completely
blooey when a breakpoint retards its progress? "You are young.
Life has been kind to you. You will learn." -- S. Todd
I disagree 100% with most of the above. They are very useful when you
use them in a properly structured manner. It is almost impossible to
"deduce" error conditions in a huge code base where the bugs occur 23
hours into execution for example.
Please tell us about the last time you sat in front of a
debugger's screen for twenty-three hours, and then had any
semblance of a neuron still firing when the bug finally struck.
If, that is, you were lucky enough to have put your breakpoints
in useful places.
In the real world people maintain SW who never wrote an original
function in that code.
The debugger is invaluable in stepping through with live data and
demonstrating the call flows. That in conjuction with a profile of
course.
You make it sound like using a debugger is replacement for
"reasoning". it isn't of course. It is a utility to utilise your
reasoning and to check the program at crucial error prone times.
I said a debugger could only provide "grist for the reasoning
mill," and I stand by it. With the debugger you may observe that
variable `x' is mysteriously set to 42, and this is what eventually
causes the program to print the ten million dollar water bill.
But the 42 is clearly a symptom of something unidentified that
has already gone wrong, and you need to reason about that earlier
fault. At a minimum, you need to reason about where to set the
breakpoints for your next twenty-three-hour run.
Call stack at the point of the crash. Almost as good.
Nowhere near as good. Back to that mysterious 42: The great
question is "Hunh? How did *that* happen?" With a call stack
(a static snapshot, somewhat less informative than a core dump)
you are completely on your own. With a reversible program you
could back-step until you see the 42 revert to something more
reasonable, then see that the bad `x' really derives from a
bad `y' elsewhere, and then back-step to find where `y' got
polluted. Or let that issue go for a bit, stuff a good value
into `y' and forward-step again, this time along a different
path ... No, Richard, a call stack cannot do this.
I'm not sure what you mean by "commented" - where did this come from?
From the experiment I described, above, in the part you seem
to have read with little attention.
Note : of course it is better to get it right first time. But in the
real world there will always be bugs.
2nd note : if a system crashes I can guarantee that i can debug it to
the point of the crash quicker than you can read and understand 500000
lines of C code and run it through in your head with all possible data
input and come to a guess at where it might crash .....
A program that crashes is a blessing to the programmer who
is trying to debug it. A program that runs successfully all the
way to completion but prints the ten million dollar water bill
along the way, or a program that runs for twenty-three hours
when you needed it to complete in eighteen -- those are the
problems that the grownups tackle.