Dave Doyle

Learning Programming through code animation (1998)

It seems obvious in many ways that computers should be used to teach computer programming. However with few exceptions, this is rarely the case. Traditional programming is taught from books, and books are obviously static in nature and allow only a linear format. This presentation of a programming concept generally involves giving an overview, showing a snippet of code and then explaining what the code does. To illustrate this with a short FORTRAN example:

      DO 10 I = 1, 5
         ARRAY[I] = I+1
10    CONTINUE
      ARRAY[1] = 10
      ARRAY[4] = 3
      DO 20 I = 1, 5
         IF (MOD(ARRAY[I],2).EQ.0)
            ARRAY[I] = ARRAY[I] / 2
         ENDIF
20    CONTINUE

Let's step through this code ...
[ text explaining it to the reader ]

The problem with this method is that it requires the user to jump back and forth between the code and the write-up. If the user gets lost, or doesn't understand the language being used to describe the problem, they are pretty much out of luck.

An alternative to this approach is to use animated code tutorials rather than static text. Using a simple applet, this code could be shown as such:

Notice that the explanation is now embedded within the program itself and each step is outlined in detail. All variables of interest show their immediate values at that step, helping to demystify why the program works the way it does. Also, the user is shown how to break the program as a whole into simpler substructures in order to understand it better. Breaking a program down is a step performed by advanced programmers automatically, but how to do so is rarely shown within computer textbooks.

Just like a book, the user has control over when they're ready to advance to the next line of code. They can spend time analyzing each part of the code, and looking at the variables and the help text as long as they need. They could even step away from the computer and return later, if need be. A more advanced version of this program might have the ability for users to step forward and back, or to jump to interesting steps within the process.

Binary Search Tree animationAnimations have also been applied to other computer science subjects as well. Binary Search Trees (BST) are a commonly used data structure that are often difficult for an incoming programmer to fully understand. Other instructional developers have successfully created animations that demonstrate how these work.

The example in the picture here shows a pre-created BST that the user can interact with. Each node can be clicked on to get its value. Nodes can be added, removed or found, and the process of how this occurs is followed in detail, noting each decision made during the process.

These dynamic visualizations can be invaluable to a developer being introduced to new concepts. While it takes longer to develop programming concepts in this way, it would not be difficult to develop a suite of tools that make it fairly easy for programmers to adapt the problem they are trying to teach into a well-presented and effective interactive tutorial.

Hopefully within the near future, learning programming from textbooks will be considered an archaic tradition.