CppCoreGuidelines icon indicating copy to clipboard operation
CppCoreGuidelines copied to clipboard

ES.9 lacks example

Open jzarl opened this issue 4 years ago • 1 comments

"ES.9: Avoid ALL_CAPS names" has an "Example" section, but that should be labeled "Example, bad" to be consistent with other guidelines.

After renaming the existing example section I propose a positive example section to at least provide something like the following:

// example, better:
// no danger of name-clashes with ALL_CAPS macros:
// consider "enum class", though
enum Coord { North, NorthEast, NorthWest, South, SouthEast, SouthWest, East, West };

The lack of a positive example allows newcomers to come to the conclusion that instead of "SOME_NAME" they should use the same naming conventions for local variables and for global ones. While nowhere as bad as having an accidental macro substitution wreak havoc in a seemingly harmless peace of code, this could still lead to unintended hiding. Ex.:

namespace {
constexpr int SPECIAL_VALUE = 42; // bad, all caps
constexpr int specialValue = 42; // better
constexpr int c_specialValue = 42; // even better, visualizes global scope
}

My examples may not be the best, but I hope I've made my point...

jzarl avatar Sep 28 '20 21:09 jzarl

General point taken.

On this specific example:

constexpr int c_specialValue = 42; // even better, visualizes global scope

I wouldn't recommend it as "even better".

gdr-at-ms avatar Sep 29 '20 16:09 gdr-at-ms