Program design techniques? (debugging)
Wayne Throop
throopw at rtp47.UUCP
Mon Aug 5 03:55:51 AEST 1985
I am a top-down, design-by-refinement advocate. However, that isn't
what I wanted to post about. A paragraph in the referenced posting made
me think of a debugging/development technique that is familiar to Lisp
users, but less so to C users. It might be useful, so I'll describe it.
> This last is fraught with opportunity: Implementing from the top down can
> produce an interim situation in which you have an elaborate control
> structure or driver which is untestable because it's not hooked to anything
> that does anything; implementing from the bottom up can result in lots of
> little primitives that are untestable because there is no way to coordinate
> their activities cooperatively.
Given a moderately good debugger, you can set breakpoints on stubs, and
"do them by hand", allowing the control structures to be excersized.
For example, say that a stub is supposed to fill in a data structure
from input text, and return the data structure. If the input routines
aren't fleshed out yet, one can simply write the stub to return a local
data item, and fill it in using the debugger when the breakpoint on that
stub is taken.
The same idea works for bottom-up design, but in reverse. One can write
a top-level stub which simply calls each of the primitives you are
trying to check out. The debugger can be used to direct control to each
primitive in the proper order "by hand".
This technique is very usefull when building a prototype, or in testing
a partially completed implementation. It is what is sometimes refered
to as "debugging a program into existance". It's main advantage is
that, having tested part of the program, whan an addition breaks what
used to work, one knows where to look for the bug (in the newly added
code). All existing code is (fairly well) debugged already.
My appologies if this technique is already well-known, or passe.
--
Wayne Throop at Data General, RTP, NC
<the-known-world>!mcnc!rti-sel!rtp47!throopw
More information about the Comp.lang.c
mailing list