CMPU 101 § 55

Coding Style

These are notes on good coding style, both general and specific to Racket. They will be updated through the semester.

Keep lines short

No line should span more than 80 characters.

Design concise functions

A general guideline is “one task, one function”. Ideally no function should span more than five to eight lines.

Don’t dangle parentheses

Good:

(define f
  (lambda (l)
    (cond ((empty? l) 0)
          (else (f (rest l))))))

Bad:

(define f
  (lambda (l)
    (cond ((empty? l) 0)
          (else (f (rest l)))
    )
  )
)

Acknowledgments

Based in part on notes by Marc Smith.