October 2004
Intermediate to advanced
240 pages
6h 22m
English
Programming isn’t magic, so don’t incant it: Avoid spelling literal constants like 42 or 3.14159 in code. They are not self-explanatory and complicate maintenance by adding a hard-to-detect form of duplication. Use symbolic names and expressions instead, such as width * aspectRatio.
Names add information and introduce a single point of maintenance; raw numbers duplicated throughout a program are anonymous and a maintenance hassle. Constants should be enumerators or const values, scoped and named appropriately.
One 42 may not be the same as another 42. Worse, “in-head” computations made by the programmer (e.g., “this 84 comes from doubling the 42 used five lines ago”) make it tedious and error-prone ...