Comment your Code

Comment all of your code. Specifically, there are two things you need to add to each function: a contract and a purpose.

A contract tells us what kind of data (or, what type of data) each function consumes, and what kind of data it returns. 

For example, the function square might look something like this:

(define (square n)
  (* n n))

The contract for square might look like:

;; CONTRACT
;; square : number -> number

The contract tells us the name of the function (which comes before the colon) and the types of data that are passed to the function (before the arrow) and the type of data that is returned from the function (after the arrow).

The purpose statement is a human readable description of what the function does.

;; PURPOSE
;; Multiply a number by itself.
;; CONTRACT
;; square : number -> number

(define (square n)
  (* n n))

This way, someone can look at your code and understand (1) what you intend for the function to do (the purpose), (2) the name of the function, and (3) what kinds of information go in and out of the function. This is typically all another programmer needs to understand your code.

Turn this in via Sakai.

Creative Commons License This work is licensed under a Creative Commons BY-SA 3.0 License.