This, from Computational Mathematics by B. P. Demidovich and I. A. Maron:
To illustrate the compilation of a computational scheme, suppose
it is required to compute the values of the analytically specified
function
for certain values of the argument:
. If the number of these values is great, it ‘is not advisable to compute them separately, first
, then
, and so on, each time performing the whole sequence of operations indicated by the symbol
. It is much better to separate
into elementary operations
and carry out the computations as repeated operations:
performing one and the same operation
for all values of the argument under consideration.
Although this comes from the era of hand calculations, it’s good advice for programming as well. It’s always better to break down the problem into smaller portions and work your way through. Not only is the code easier to debug but frequently it decreases the computational cost.