Discussion
Team LiB
Previous Section Next Section

Discussion

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 to later replace 42 with another constant.

Prefer replacing hardcoded strings with symbolic constants. Keeping strings separate from the code (e.g., in a dedicated .cpp or resource file) lets non-programmers review and update them, reduces duplication, and helps internationalization.

    Team LiB
    Previous Section Next Section