C ++ programming naming convention 0 Preface
Based on years of work experience and other naming rules, my personal experience is more standard and is now applied to my development team.
1 Naming rules The file name, function name, and variable name should be descriptive and should not be excessively abbreviated. type variables are nouns, and function names are verbs or Verbs + nouns. The function name must be directive and can be abbreviated to be very general. 2 File Name
The C ++ file should end with. cpp, And the header file should end with. H. All file names should be in lower case, and the file names should be the same as the class names.
Example:
Publictools. h
Publictools. cpp
3 Type name
Types include class, struct, typedef, and enum.
Type name: the first letter of each word is capitalized.
Example:
Class ):
Class testclass
{
};
Struct (struct ):
Struct teststruct
{
};
Type Definition (typedef ):
Typedef struct testtype
{
};
Enumeration (Enum ):
Enum testenum
{
};
4 Variable name
The first letter of a common variable is lowercase, the member variable ends with "_", and the function parameter starts. Start with the global variable g _ and start with the static variable S.
Example:
Common variables:
Int index;
Char type;
String name;
Member variables:
Int index _;
Function Parameters
Void setindex (INT _ index)
{
};
Global variables:
Int g_count;
Static variables
Int s_number;
5 Constant name
All uppercase letters are separated by underscores.
Example:
Const string max_filename255;
6 Function Name
The first letter is capitalized. The value matches the set-value function with the variable name.
Example:
Int index _;
Int getindex ()
{
Returnindex _;
};
Void setindex (INT _ index)
{
Index _ = _ index;
};
7 Namespace
All lowercase letters.
Example:
Namespace mynamespace
{
};
8 Type name
The first word is fully written, and the first letter of the next word is capitalized.
Example:
Struct teststruct
{
Int number,
String studentname
};
Enum testenum
{
Errorin,
Errorout
};
9 Macro name
All uppercase letters are separated by underscores.
Example:
# Define pi_raud3.14159265
10 # Define header file protection naming
All uppercase.
Example:
# Ifndef foo_bar_baz_h _
# Define foo_bar_baz_h _
...
# endif // foo_bar_baz_h _;