[plt-scheme] running an MzScheme debugger in Emacs?

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Apr 26 11:30:28 EDT 2008

Debuggers have a role in programming, no question asked.

I don't think, however, they have a role in freshman programming or,  
if they do, only a minor role. This is just another point where I  
deeply disagree with Gerry and Hal's approach to teaching freshmen.

HtDP pushes (1) simple functions as in "one task, one function" and  
(2) examples/tests for each function. If you follow this advice, a  
debugger becomes unnecessary for the first five chapters. What is  
necessary -- and what I have failed to include in HtDP/1e -- is to  
teach 'debugging testing', meaning:

  when you discover a failure, formulate a test T for the function F  
that fails.

Then extract tests from T for all those functions that F calls  
during. Reformulate T for G, H, etc called from F. Eventually you  
discover the source of the problem and you fix it.

;; ---

Why does this not work for chapter VI, or better put, why does it not  
work well? In chapter VI HtDP introduces accumulators AND this  
demands that programmers understand the 'invariant relation' between  
the local parameter X, the initial parameter X0 and the accumulator A:

  ;; X -> Y
  (define (foo X0)
    (local (;; X AccuType -> Y
            ;; *****   A represents some memory of the "stuff"  
between X0 and X ******
            (define (foo-accu X A) ...))
     (foo-accu X0 A0)))


Putting foo-accu at the top level is the first step. But translating  
a test case
   (check-expect (foo X1) Y1)
into one for
   (check-expect (foo-accu X1 A0) Y1)
and deeper into the call chain is difficult.

I have found that 'tracing' (via printf) tends to work just fine in  
revealing a break in A ~ X ~ X0

;; ---

For chapters VII and VIII, all bets are off. Once you use set! and  
*set*!, your program communicates values not just via function calls  
but also via 'side channels.' For that, you need debuggers to inspect  
the current state of the world.

;; ----

Why does SICP suggest the use of debuggers early on? Because SICP  
does NOT pay attention to the systematic construction of programs but  
uses 'playful programming' to explore computational ideas (a new  
epistemology). This is a fine thing to do -- but not if your  
department is responsible (on the average) for the preparation of  
students to become contributing programmers on reasonably large  
projects.

If SICP paid attention to program DESIGN, the debugger question could  
be postponed.
If they had, Scheme would still be regarded as the 'right entry  
option' and wouldn't have been just a fad, like everything else the  
freshman year goes through.
If so, HtDP wouldn't exist.

-- Matthias








Posted on the users mailing list.