1. Problem Analysis and Data Definition: What kind of information is involved? Create data definitions for data that represents the information. If they look complex, construct examples according to the data definitions, just to make sure they work.
  2. Contract and Purpose Header: What kind of data does the function consume? Which kind does it produce? And what is its purpose? (in one line). Each function should work on one kind of data and do exactly one thing.
  3. Examples: Make up examples of inputs. What should the function produce for these inputs?
  4. Template: Construct the template.
    1. Does the data definition (of the main argument) have multiple clauses? If so, use a cond with as many cases as there are clauses in the data definition.
    2. How can you distinguish these kinds of data with conditions involving the main parameter?
    3. Are structs involved? If so, write down all the selector expressions. (Do so on a per-clause basis.)
    4. Does the data definition involve any self-references (or cross-references)? If so, use recursion in the template to express these "arrows".
  5. Function Definition: Now we are finally ready to code. Use the items in the template to produce the desired results in each case:
    1. Can you deal with the simple cond cases? Your examples should cover those cases directly.
    2. What do the expressions in the recursive cases compute? Use the purpose statement of the function to figure out what the recursive function application computes.
    3. How can you combine the results of these expressions so that the function returns the desired value? Use the examples to tabulate the values of the intermediate expressions and the desired output for the given input. This will usually suggest an expression for combining the intermediate results, though admittedly this is the one and only "deep" step of design and you won't get away without some real thinking here.
  6. Tests: Turn the examples into tests using check-expect. You should have at least one test for each cond clause. You may want to do this as you develop functional examples. As you debug your function, create additional tests.

Mitchell Wand
College of Computer and Information Science, Northeastern University
360 Huntington Avenue #202WVH,
Boston, MA 02115
Internet: wand @ ccs.neu.edu
Phone: (617) 373-2072 / Fax: (617) 373-5121

Last modified: Sun Dec 21 16:39:48 Eastern Standard Time 2008