-
-
Notifications
You must be signed in to change notification settings - Fork 894
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A case against UPPERCASE constants #96
Comments
I confirm the |
Sure, there's a case against upper case constants, but how else are you going to specify global scope immutables immediately? You need to come up with a solution, because it is very annoying trying to figure out where a variable I'm looking at comes from only to find out it was defined in a header file I'm including, and isn't a part of the class I'm looking at. Enums can be upper camel case because you think of the values almost as types in their own right, but using enum classes disambiguates where they come from anyway, so signifying with caps isn't needed. Global constants, on the other hand, need to be something that's signified exists outside of the current scope and isn't going to be modified underneath you. Capitalization was the easiest way to signify this, but I agree, this does conflict with macros. There needs to be something to replace it if you are going to make that argument. |
Actually I have an idea for a replacement. Given the Always Use Namespaces rule, how about we change the rule for global constants to always scope with at least first namespace? ie:
This wouldn't apply to local constants, as you know exactly where they are defined. This could apply to class static constants used internally in a class, but regardless they are already forced to use the class namespace when used outside of a class. Non static class constants are essentially local constants, so again they wouldn't need to be scoped. Now you know the global constant comes from a different scope, and you can understand that it is a constant by usage, rather than second guessing where it came from. Outside the namespace you already have to scope, so it doesn't create more code for the user of your API, just internally. |
My argument is that avoiding all-uppercase for all non-macros avoids those hard to understand errors you get when you use a constant or enum value that was already defined in some external header.
Ever had to do
#undef ERROR
after including Windows.h ?The text was updated successfully, but these errors were encountered: