Magic Numbers
Learn what magic numbers are, what they look like, and how to eliminate them.
We'll cover the following
Magic numbers (and strings)
Magic numbers are literals scattered in the code that have no explicit meaning. They harm our code because they affect code management in the long run.
Note: Magic numbers also refer to
strings
. They’re treated the same way as magic numbers. To be consistent, we’re going to only use the term “magic numbers” for both of them for the rest of the course.
Let’s look at a trivial example:
Get hands-on with 1400+ tech skills courses.