1. Stupid Human TricksDavid Letterman 1980s: The Programming Cycle
There has never been an unexpectedly short debugging period in the history of computers.
--Steven Levy
  1. Welcome to Debugging
  2. A programmer is a human trying to do a machine's job. Unlike computer execution, which occurs in the blink of an eye, the programming cycle occurs at our time scale. In the cycle, the programmer (or programmers) repeatedly modifies human-readable code. The hope is that the code can be converted to, or handled by, machine instructions that execute on a processing unit. And besides running, the hope is that the code will run correctly: it will do the job intended by the programmer.

    The poor human gets feedback from the system when the code does not translate to machine actions (a "compiler error"), or the machine actions fail to execute (an "execution error"), or the output is not correct (a "mistake"). All the while, the programmer cycles through the psychological states displayed below: In professional programming this job is done by a team of people who follow practices and standards.

    Exhibit 1. Manic Depression: The Five Stages of Grief Programming

    Programming can be satisfying and occasionally exciting when the machine finally does what you want (apparently). But it also tedious and frustrating because the machine and its programs cannot read the programmer's mind. Humans often forget how simple and dumb machines are. However, rest assured. The humans are still firmly in control. The machines and their program masters do not appear to have their own objectives yet. Instead, they are maids and chauffeurs waiting for us to want them to do something for us in a language they understand.

    We will expand on some of these stages, but below is the arc that you should expect to follow when setting out to do economic computation. When you are actually writing the program we will call it CodingTime. When you think the program does what you want you try to run it. This requires the computer to understand the instructions and then carry them out. We break this up into two stages: CompileTime (translating the code into machine instructions) and RunTime (carrying out the machine instructions by loading them into RAM and adding the first instruction to the running program list). In some languages these stages are very distinct, but in many languages the user may not be aware of these separate stages.

    Exhibit 2. The Waiting is the Hardest Part

    All progress in programming leads to more code writing and debugging. The human programmer is thinking/working at the teal-colored stages: coding, checking output, coming up with new ideas. At all the other stages the computer is attempting to compile or execute the human's code. Errors always lead back to more coding which starts the cycle again.
  3. Stages of the Programming Cycle
  4. A programming cycle for a modified "hello world" program.
  5. Here is an example of writing a program, finding syntax errors, then finding semantic errors and finally having correct output.
    PROGRAM                         COMPILER SAYS        RTE SAYS        OUTPUT
    ====================================================================================
    include "oxstandard.h"           include
    main() {                          not understood
      decl x,v="hello worl";
      println(x);
    
    Oops. Forgot the # which must start a precompiler directive:
    PROGRAM                         COMPILER SAYS        RTE SAYS        OUTPUT
    ====================================================================================
    #include "oxstandard.h"          file not found
    main() {
      decl x,v="hello worl";
      println(x);
    }
    
    Oops. That's not the name of the standard library file.
    PROGRAM                         COMPILER SAYS        RTE SAYS        OUTPUT
    ====================================================================================
    #include "oxstd.h"               OK!                  x has no value
    main() {
      decl x,v="hello worl";
      println(x);
    }
    Oops, meant to print the other variable.
    PROGRAM                         COMPILER SAYS        RTE SAYS        OUTPUT
    ====================================================================================
    #include "oxstd.h"               OK!                  OK!              hello worl
    main() {
      decl x,v="hello worl";
      println(v);
    
    Oops, spelling error only I can catch.
    PROGRAM                         COMPILER SAYS        RTE SAYS        OUTPUT
    ====================================================================================
    #include "oxstd.h"              OK!                  OK!              hello world
    main() {
      decl x,v="hello world";
      println(v);
      }
    
    The point is that you have to fix bugs in order to find and discover all the bugs in your program. Get used to looking at the output Ox produces to see where it detects the bug and then try to understand the cause. Often the cause is not as obvious as the bugs here. Sometimes you will not understand the error message. At this point you can ask me and I will try to respond quickly. I won't try to find all your bugs but I will try to fix the one that is stopping you from getting any further.

Exercises