Eliminating Magic Numbers: When is it time to say “No”?
https://softwareengineering.stackexchange.com/questions/56375
-
31-10-2019 - |
Question
We're all aware that magic numbers (hard-coded values) can wreak havoc in your program, especially when it's time to modify a section of code that has no comments, but where do you draw the line?
For instance, if you have a function that calculates the number of seconds between two days, do you replace
seconds = num_days * 24 * 60 * 60
with
seconds = num_days * HOURS_PER_DAY * MINUTES_PER_HOUR * SECONDS_PER_MINUTE
At what point do you decide that it is completely obvious what the hard-coded value means and leave it alone?
No correct solution
Licensed under: CC-BY-SA with attribution
Not affiliated with softwareengineering.stackexchange