Naming conventions are like most standards: the great thing about them is that there are so many to choose from. Most people agree that a project should have one and use it consistently, but there is little agreement on what the rules should be. Here are three possibilities, for example:
- Macros, constants, and enumerands in all caps:
- Type names in Pascal case:
- Structure names in Pascal case with a leading underscore:
- Functions and member/variable names in lower case with words separated by underscores:
- Variables in camel case:
- Namespaces, Types, Methods, Members, and Enumerators in Pascal case:
- Type names in Pascal case with no underscores:
- Variables and Members in lowercase with underscores between words
Variables declared constexpr or const, and whose value is fixed for the duration of the program, named with a leading “k” followed by mixed case:
- Functions in Pascal case with no underscores, capitalizing acronyms as single words (i.e.
- Namespace names all lower case.
- Enumerators (for both scoped and unscoped enumerations) named either like constants or like macros: either
- Macros upper cased with words separated by underscores:
My own preferences, which I typically follow in code I’m writing for myself, have a lot in common with the standards we followed in the SXE project. They are now documented on my programming blog: Programming with Jim: Jim’s C Naming Conventions.