Magic Numbers, Semantics, and Compiler Errors
![Image](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEirRy0QhsUCyTdr0C59uQqn0byPMpQ5tGuQ6bPyp657hy2Z_cVD9EF68Ez1P4wOo8Mud9bMrHj6NQ5VbO2WwJHi46o091BY77IQaLQOYx23fNUxFaE10x-YgJnDbrsca5Nv2wVu82mttwc4/s1600/255-percent.png)
Magic numbers are considered such a scourge upon code bases that there tools out there to automatically find them and root them out. After all, who knows what setValue(6); really means? There are also many approaches to giving better names to magic numbers. Not all of them are good, though. For example, we have a callback that sets a completion percentage on a status: void callback(Status status) { status.updateProgress(0, "Starting"); // Do some stuff... status.updateProgress(25, "Some stuff done"); // Do some more stuff status.updateProgress(50, "More stuff done"); // Reticulating splines status.updateProgress(75, "Splines reticulated"); // Validate everything status.updateProgress(100, "Complete"); } Those percentages would get flagged as magic numbers by the automatic tools. The developer would need to extract those out to constants to make that tool happy. A thoughtful developer would create