I second the extra specification of compile-time
constants and the exclusion of run-time
constants
This PR is trying to drop the phrase “compile-time” because it doesn’t have an obvious and clear meaning (see discussion in opening comments above), and because being “compile-time” seems less relevant to how a variable should be used or named compared to other attributes like mutability, scope, and lifetime. Also, I don’t think in this document it is worth trying to be very technical or make detailed rules about how everything needs to be named. For local variables, it seems fine to just let developers have freedom to emphasize constness with caps where it seems better. Global variables are different because global variables are declared and accessed in different places, often far away, and if you are using one you almost always need to be aware if it has a constant value or if the value can change. Whether the value is initially evaluated at preprocessing time, compile time, link time, or perhaps early init can be interesting to know, but probably less relevant than knowing whether the value changes. A capitalized name is a good way to indicate that the value will not change.
Re: class constants, if it would help I could replace “global constants” with “global constants and other constants with static duration including namespaced and class-scope constants” here. But I don’t think developer guidelines need to be so procedural or legalistic. I wouldn’t expect someone just reading the updated text to be confused by it, and I wouldn’t expect someone familiar with C++ to think of ::MY_CONSTANT
, my_namespace::MY_CONSTANT
, and MyClass::MY_CONSTANT
much differently by default. Also, it seems fine to me if someone wants to use normal variable names for non-global constants. I think the benefit of using ALL_CAPS
in a symbol name is to communicate the fact that the symbol’s value will not change. If a developer chooses to not indicate or emphasize constness in some symbol name, it doesn’t seem like a problem.