Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
if (age >= 18) {
  takevote(personID);
}
... 
if (age <= 18) {
  checkSchoolEnrollment(personID);
}

Compliant Solution

Code Block
bgColor#ccccff
enum { ADULT_AGE=18 };
... 
if (age >= ADULT_AGE) {
  takevote(personID);
}
... 
if (age <= ADULT_AGE) {	
  checkSchoolEnrollment(personID);
}  

In the compliant code it is easy to check if the user is an adult and process accordingly. If the definition of adult changes during iterations of the codebase it is much simpler to replace the value for ADULT_AGE then search for instance of 18 and see if they're appropriate for change.

When declaring immutable values such as ADULT_AGE it is best to use const or enum as explained in

DCL00-A. Declare immutable values using const or enum 

Risk Assessment

Mistakes regarding numeric values can cause unintended consequences if changes are not made uniformly

...