3 ms·
Because variables have identifiers, and the identifier can allow the programmer to be more expressive and explicit about what the number means. Then, in the con
by partycoder 10y ago
Because variables have identifiers, and the identifier can allow the programmer to be more expressive and explicit about what the number means. Then, in the context of the code, you use the variable instead of just the value, making the code more readable.
https://en.wikipedia.org/wiki/Magic_number_(programming)#Unnamed_numerical_constants https://en.wikipedia.org/wiki/Magic_number_(programming)#Unn...
- detaro 10y agoI'm aware of the principle, but that does not answer how that would have helped them here or how this indicates anything about the quality of the entire code base. Nothing in the writeup suggests that they had difficulty understanding this particular piece of code or that they were searching for something specific but didn't find it due to bad naming. Exposing this value as an external configuration parameter in a place that is more often looked at might have helped someone to realize caching might be an issue earlier, but it could easily have been ignored as well.
- partycoder 10y agoExplicitly saying "I want 10 years" is different than saying "a large number. Do the math to know more". This is how identifiers can help understanding the programmer intention. Then, you can define the time length as an arithmetic operation. Such as 10 * (60 * 60 * 24) * 365. These might be still considered magic numbers to certain extent, but it's simpler to recognize numbers such as 60, 24 and 365.