Home Segments Index Top Previous Next

289: Mainline

The look-it-up principle: Whenever practicable, a program should look up a frequently needed answer, rather than computing that answer.

For example, in Segment 269, the fCalories, cCalories, and pCalories instance variables reside in the Food class, whereas in Segment 272, the fGrams, cGrams, and pGrams instance variables appear. The right choice depends on whether you are more likely to be interested in calories or in grams.