I've seen it as normal in most C++ code to name constants in capitals with underscores, LIKE_THIS
.
Usually, all-caps identifiers are used for macros, to avoid confusion with "real" compiler names. Since in earlier C macros were the only way to have constants usable e.g. in array sizes, some people adopt this style for all constants (or at least for enum
values). Personally, I just leave them for macros, where it's actually useful to make a distinction.
However, when I see C++ code (not that I've seen much of it), it looks immediately different from C#. Aside from the generic abundance of pointers and less formally-named/abbreviated stuff like WndProc
and the Hungarian notation, half of the stuff is in all-capitals.
That would be the Windows API style, which comes from the late eighties, so it's normal that it looks nothing like .NET.
Windows-related types are typically all-caps, I suspect that comes from the fact that they too were macros (although currently they are all typedef
s) actually, I just checked the windows.h
from the Windows 1 SDK, and they were typedef
s even then, so probably it was some kind of stylistic choice; constants are still macros, though.
Hungarian notation was invented in Microsoft by Charles Simonyi, and was widely adopted (and misunderstood) internally in the early years of Windows.
As for the abbreviations, that's typical of older APIs (look at the C standard library or the POSIX APIs, they are even terser), and I think that it can be justified both by technical and practical arguments:
- older compilers and linkers had length limits for identifiers, which means that they wouldn't distinguish identifiers differing only from - say - the sixth letter onwards; so, you want to keep the meaningful letters at the beginning (incidentally, this seems to have influenced the C standard library - I heard that
strncmp
, strncat
& co. have the n
in the middle because of this);
- when you work on an 80x25 terminal, you don't want to continue to scroll to read a single line, so names like, say,
AttachedPropertyBrowsableWhenAttributePresentAttribute
don't strike you as a stellar idea;
- also, people worked in C++ way before Visual Studio and IntelliSense. I'm sure that some editors had autocompletion even way back then, but in simpler editors you don't want to spend the day writing
ListViewVirtualItemsSelectionRangeChangedEventHandler
by hand.