File name#
- fully lower-case
- word separation expressed as
_
(underscore)
1
2
|
file_name.txt
very_good_source_code.c
|
Type name#
- start with capital letter
- next letters are lower-case
- word separation expressed as upper-cased first letter
1
2
|
class SuperDuperClass{};
struct TypeNameExpressedLikeThis{};
|
Variable name#
Constant name#
- start with
k
- word separation expressed as upper-cased first letter
- if you can’t use uppercase spacing,
_
(underscore) is allowed that time
1
2
|
const int kMagicNumber = 42;
const int kAndroid8_0_0 = 24;
|
Function name#
- start with capital letter
- word separation expressed as upper-cased first letter
- some functions like accessors and mutators can be named like variable.
1
2
3
4
5
|
MoveToThere();
ScoreCount();
get_name();
set_name();
size();
|
NameSpace name#
- fully lower-case
- word separation expressed as
_
(underscore)
1
2
|
namespace countryside_bus {}
namespace project_goo {}
|
Enumerator name#
- enum follows Constant naming rule
- not Macro naming rule
1
2
3
4
5
|
enum Fruits {
kBanana,
kApple,
kCherry
};
|
Macro name#
- fully CAPITAL LETTER
- word separation expressed as
_
(underscore)
1
2
|
#define PI 3.14
#define ARRAY_SIZE 32
|
Some Exceptions#
If you are naming something that is analogous to an existing C or C++ entity then you can follow the existing naming convention scheme.
- bigopen()
- function name, follows form of open()
- uint
- bigpos
- struct or class, follows form of pos
- sparse_hash_map
- STL-like entity; follows STL naming conventions
- LONGLONG_MAX
- a constant, as in INT_MAX