Magic Numbers Your code should not have any numeric constants
in it with the possible exception of 0 and 1. The reason for this is
best shown by example:
for (int i = 0; i < 100; i++)
{
m[i] *= 100;
}
Edit the above code to change units from centimeters to millimeters.
Or, edit the following:
for (int i = 0; i < NUM_MEASUREMENTS; i++)
{
m[i] *= METERS_TO_CENTIMETERS;
}
Another nice reason is when you decide to change things later on, you
only have one place to look, and can avoid possibly-inaccurate
search/replace schemes. Imagine the headache when increasing the
number of measurements your lab-helper program can handle from 100 to
10000 when you have the following line of code:
for (int i = 0; i <= 99; i++)
Rather than
for (int i = 0; i <= NUM_MEASUREMENTS - 1; i++)