Random Thoughts

Are debuggers crutches ?

Advertisements

As every programmer knows debuggers are useful tools to step through
the program execution.

Some of the scenarios where debuggers are quite helpful are:

Given the value debuggers would provide to a developer why would
experienced developers have mixed opinions about them.

Here is what some of the experts say about debuggers:

“As a personal choice, we tend to not use debuggers beyond getting a
stack trace or the value of a variable or two. One reason is that it
is easy to get lost in details of complicated data structures and
control flow; we find stepping through a program less productive than
thinking harder and adding output statements and self-checking code at
critical places. Clicking over statements take longer than scanning
the output of judiciously-placed displays. It takes less time to
decide where to put print statements than to single-step to critical
section of code, even assuming we know where that is. More important,
debugging statements stay with the program; debugger sessions are transient.

Blind probing with a debugger is not likely to be productive. It is
more helpful to use the debugger to discover the state of the program
when it fails, then think about how the failure could have happened. “

Kernighan and Pike, The Practice of Programming

“Given the enormous power offered by modern debuggers, you might be
surprised that anyone would criticize them. But some of the most
respected people computer science recommend not using them. They
recommend using your brain and avoiding debugging tools
altogether. Their argument is that debugging tools are a crutch and
that you find problems faster and more accurately by thinking about
them than by relying on tools. They argue that you, rather than the
debugger, should mentally execute the program to flush out defects.”

Steve McConnell, Code Complete

“An interactive debugger is an outstanding example of what is not
needed — it encourages trial-and-error hacking rather than systematic
design, and also hides marginal people barely qualified for precision
programming”

Harlan Mills (Quote from Code Complete)

Like many programmers I also used the debugger very frequently.  While
programming with Perl I had used ptkdb and while working with Java I
used Eclipse which has an excellent visual debugger. But things got
changed when I started programming with Python. I got bitten while
debugging some Python code, which made heavy use of decorators, using
visual debugger that came with the IDE (it was not Eclipse). After
wasting a considerable amount of time I realized that the code flow
using the debugger (probably due to a bug in it) was different than
how the program would behave when it was executed. With that
experience I dropped the IDE and switched back to world’s most
customizable editor 🙂 and also stopped depending on the debugger
altogether.

Ever since then I have used the debugger very sparingly. At the same
time there have been no dearth of issues I faced with the code I
worked, developed.

These are some of my learning I got ever since I stopped being
over-dependent on debuggers:

Does this mean that one should never use a debugger as they prevent
one from getting a bigger picture. I don’t think so and I don’t go as
far as to suggest that one should avoid debugger at all costs. I think
use of debugger in moderation , not using as one’s first line of
action when faced with a problem and always trying to view the problem
one is facing at the right context (with or with out debugger) are
better approaches to debugging.

If you are frequently using the debugger, stop reaching for the
debugger and see if that makes you a better developer.

Also see an interesting discussion in StackOverlflow about debuggers:
Debugger mother of all evils

Advertisements

Advertisements