Top-Down Design (Introduction to Statistical Computing)
Three-Toed Sloth 2013-09-17
Summary:
Lecture 6: Top-down design is a recursive heuristic for solving problems by writing functions: start with a big-picture view of the problem; break it into a few big sub-problems; figure out how to integrate the solutions to each sub-problem; and then repeat for each part.
- The big-picture view: resources (mostly arguments), requirements (mostly return values), the steps which transform the one into the other.
- Breaking into parts: try not to use more than 5 sub-problems, each one a well-defined and nearly-independent calculation; this leads to code which is easy to understand and to modify.
- Synthesis: assume that a function can be written for each sub-problem; write code which integrates their outputs.
- Recursive step: repeat for each sub-problem, until you hit something which can be solved using existing functions alone.
Exemplification: how we could write the lm function for linear regression, if it did not exist and it were necessary to invent it.
Additional optional reading: Herbert Simon, The Sciences of the Artificial.