IfSQ logo


SPM-1—Magic Numbers

Defect Indicators: Numeric literals (other than 0 or 1) have been embedded directly into the source code. For example “34” or “86400”.

Risks: If numbers are embedded in code in this way, it increases the time needed to make maintenance changes, and increases the risk of error.


Remedy: Isolate a single copy of the number and refer to it. For example, isolate the number into:

Note: If your programming language does not support constants, simulate this—for example, by declaring a variable and initialising it at the beginning of the program.


Research Findings: