It is almost ubiquitous knowledge among educated and/or experienced programmers that “magic numbers” (i.e. hard-coding specific numeric values in multiple different locations in code) is generally highly damaging to code quality, readability, and maintainability.
It is a lot harder to change code that uses a lot of magic numbers, because every time you need to change one of those numbers you not only have to remember (or find) all the places where that number is, you have to also make sure that each instance of that number that you do find is actually related to the other ones that you are changing and not merely coincidentally the same. This can quickly become nightmarishly tedious, error prone, time consuming, and inflexible. Thus, it is common to instead use named constants so that it is easy to change all the related number instances at once in a much more foolproof way.
Continue reading Most programmers know that “magic numbers” tend to degrade code quality, but are they aware that hard-coding types (i.e. “magic typing”) often does too?