CSC151.01 2006S, Class 18: Documentation, Preconditions and Postconditions Admin: * The Joe Rosenfield '(25 center) * Q&A on Exam? * Reminder: No CS Extra tomorrow. * I'll try to do less introductory lecture today. * Reading for Tuesday: Testing (ready after noon) * Lab partners: Choose your own, keep for the week Overview: * Quick summary of topics: * Documentation * The error procedure * Husk and Kernel * Lab * (1) It is important to document your code: It helps others, it helps you * (2) Think about preconditions, particularly "for what values will my code work?" * (3) When the parameters are wrong, you might (error "You idiot, you called this procedure incorrectly") * (4) It may be inefficient to repeatedly check parameters, so use "The Iowa Method" ; The Husk (define proc (labmda (params) (if (the-client-chose-bad-parameters param) (error "You idiot") (kernel params)))) ; The Kernel (define proc-kernel (lambda (params) (go-ahead-with-your-business-without-checking params))) /Reflection/ (define all-real? (lambda (lst) (if (not (list? lst)) (error "all-real?: expected a list, received something else") (all-real-kernel? lst)))) (define all-real-kernel? (lambda (lst) (or (null? lst) (and (real? (car lst)) (all-real-kernel? (cdr lst))))))