Hardware Reference
In-Depth Information
delayby1ms(1);
// display one digit for 1 ms
}
}
}
}
V
ERTICAL
A
LIGNMENT
It is often helpful to align similar elements vertically, to make typo-generated bugs more
obvious. Compare the array definitions given in Figure 5.39; it is obvious that the reader will be
able to locate any missing elements more easily with version b than with version a.
(a) non-vertically aligned array
// values to generate 1 cycle of sine wave
unsigned rom char upper[60] = {0x38, 0x38, 0x39, 0x3A, 0x3B, 0x3C,
0x3C, 0x3D, 0x3D, 0x3E, 0x3E, 0x3F, 0x3F, 0x3F, 0x3F,
0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3E, 0x3E, 0x3D, 0x3D,
0x3C, 0x3C, 0x3B, 0x3A, 0x39, 0x38, 0x38, 0x37, 0x36, 0x35, 0x34, 0x34,
0x33, 0x32, 0x32, 0x31, 0x38, 0x37, 0x36, 0x35, 0x34, 0x34,
0x30, 0x30, 0x30, 0x30, 0x30, 0x31, 0x31, 0x32, 0x32, 0x33,
0x34, 0x34, 0x35, 0x36, 0x37};
(b) vectically aligned array
// values to generate 1 cycle of sine wave
unsigned rom char upper[60] = {
0x38, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3C, 0x3D, 0x3D, 0x3E,
0x3E, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F, 0x3F,
0x3E, 0x3E, 0x3D, 0x3D, 0x3C, 0x3C, 0x3B, 0x3A, 0x39, 0x38,
0x38, 0x37,0x36,0x35,0x34,0x34,0x33,0x32,0x32,0x31,
0x31, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30,
0x31, 0x31, 0x32, 0x32, 0x33, 0x34, 0x34, 0x35, 0x36, 0x37};
Figure 5.39
■
Influence of vertical alignment of array on readability
The names of variables, constants, and functions should spell out their meaning or
purpose.
A variable name may have one word or multiple words. Use lowercase when the name con-
tains only one word. For example,
sum
,
limit
, and
average
are examples of single-word variable
names. A multiple-word variable name should be in mixed case starting with lowercase. For
example,
inBuf, outBuf, squareRoot, arrayMax
Search WWH ::
Custom Search