Google Style Guide
https://google.github.io/styleguide/cppguide.html
I really like this style guide. Very standard in industry.
Pascal:
Camel:
Include What You Use
If a source or header file refers to a symbol defined elsewhere, the file should directly include a header file which properly intends to provide a declaration or definition of that symbol. It should not include header files for any other reason.
Do not rely on transitive inclusions. This allows people to remove no-longer-needed #include
statements from their headers without breaking clients. This also applies to related headers - foo.cc
should include bar.h
if it uses a symbol from it even if foo.h
includes bar.h
.
Naming
Filenames
Filenames should be all lowercase and can include underscores (_
) or dashes (-
).
- prefer ā
_
ā
Examples of acceptable file names:
my_useful_class.cc
my-useful-class.cc
myusefulclass.cc
myusefulclass_test.cc // _unittest and _regtest are deprecated.
What about folder names?
Seems like they donāt have a convention for folder names. I think using the same convention as the file names makes sense.
Personal Preference
Since the classes themselves donāt have underscores in between, I also donāt have underscores in between for the filenames.
Type Names (Classes, Structs)
Type names follow PascalCase. Ex: MyExcitingClass
,Ā MyExcitingEnum
.
Variable Names
Variables (including function parameters) and data members areĀ snake_case
.
- data members of classes (but not structs) additionally have trailing underscores
_
Non-Class Member Variables
Class Data Members
Data members of classes (but not structs) additionally have trailing underscores _
.
Struct Data Members
Data members of structs, both static and non-static, are named like ordinary nonmember variables. They do not have the trailing underscores that data members in classes have.
Constant Names
Variables declaredĀ constexpr
Ā orĀ const
, and whose value is fixed for the duration of the program, are named with a leading ākā followed by mixed case. Underscores can be used as separators in the rare cases where capitalization cannot be used for separation. For example:
Method / Function Names
Functions are named with PascalCase.
- accessors and mutators may be named like variables.
Regular functions have mixed case;
Method names
Enum Names
Enumerators (for both scoped and unscoped enums) should be named likeĀ constants, not likeĀ macros. That is, useĀ kEnumName
Ā notĀ ENUM_NAME
.