You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Avoid the use of numerical values in code ("magic numbers") when possible. Reasons for this include, appropriately named symbolic constants make code more readable rather than checks against a specific number. For portability reasons also if a specific number needs to be changed reassigning a symbolic value is much easier than replacing a specific number in the code since each case has to be checked specifically.
Non Compliant Code:

if(age>=18)
{
        printf("Of legal voting age");
}

Compliant Code:

if(age>=VOTING_AGE)
{
        printf("Of legal voting age");
}

Source: http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap10.html

  • No labels