Top-Down Design (Introduction to Statistical Computing)
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.
Top-down design forces you to think not just about the problem, but also about
of solution, i.e., it forces you to think algorithmically;
this is why it deserves to be part of your education in the liberal arts.
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.
Introduction to Statistical Computing
Posted at September 16, 2013 10:30 | permanent link