The first tweet below reminded me that few people seem to realise that const expressions are evaluated by the compiler/interpreter into the actual const value. Often this is called constant folding (though that can happen outside constant definitions too!)
Truckloads of source code I have come across in all kinds of languages where people put the calculated values in the expression like described here:
[Wayback/Archive] Kevlin Henney on Twitter: “For example:
const int secondsInDay = 24 * 60 * 60;There is no need to calculate it yourself:const int secondsInDay = 86400;Or, related to what I’ve just seen:const int secondsInDay = 86400; // 24 * 60 * 60“.
In languages that support rich enough types, you can even pass a typed constant like timespan, duration or period around:
[Wayback/Archive] David Kerr on Twitter: “@KevlinHenney The general point is well made of choir course. In
java, etc you can pass aDurationobject around, no need to interpret an in. Type safety, self documenting.”
My recommendation is to use an expression like the first and maybe document the calculated value (for instance for ease of bug hunting) like here





