CSC324H Programming Languages

Fall 2009 -- Scheme Coding Guideline



In the assignments of functional programming in Scheme, you should NOT use any of the imperative features, such as iteration, do, begin and all functions ending with "!" (e.g. set!, set-car!, vector-set!...). However, you are allowed to define helper procedures.

Coding guidelines

  1. Comments

    Each procedure you write, including all helper procedures, should have a concise and clear description of the procedure, the arguments, preconditions, and return values.

  2. Indentation

    We should be able to tell the structure of your procedure simply by looking at it. I.e. it should be very clear what is a procedure call, what are the arguments to a procedure, what is the condition in the if (or cond) statement, and what is the consequent.

    For example:

    Bad:
      (define (length x)(if (null? x) 0 (+ 1 (length (cdr x)))))

    Good:
    (define (length x)
       (if (null? x) 0
            (+ 1 (length (cdr x))))))

    You are encouraged to use a good editor (e.g. Emacs) that indents the code for you.
  3. Efficiency

    You do not have to go out of your way to optimize your algorithms. However, your code should be reasonable. You should not be evaluating the same thing multiple times, for example. You should not traverse lists unnecessarily.

  4. Style

    Your code should be nice. Of course, it is difficult to say what "nice code" is. Use your judgment.

    if condition then do A
    else do A

    is not a "nice" piece of code.

    if x >= 0 do A
    if x < 0 do B
    else do C

    is not a "nice" piece of code either.

    It should be clear to the reader that your code does not work by some magic simply because you tried 10000 different versions and one of them finally worked. It should be clear that you know what you are doing.

    Your should pick informative names for your helper procedures, as well as for all arguments.

  5. Things NOT to do


General coding guidelines

[Home|Assignments]