Constants - No Magic

Constants - No Magic

Constant values are values that cannot be changed throughout your software. Software in general should not have magic numbers, either that they are not documented properly or used in multiple locations.

An example of magic numbers would be like:

totalArea = 3.14 * radius * radius;
taxes = 0.13 * price;

Which in large programs can make it very difficult to read properly, now to solve this issue we can use constants.

const double PI = 3.1415;
const double TAX_RATE = 0.13;
const int MAX_NUMBER_OF_COURSES = 5;

As you may of noticed with the naming conventions, it is also important to have the const variable names fully capitalized as well as separated using underlines