I. Stability
1 parameter detection
2. After the memory is released, set it to null.
3 if statements always have else branches
4. The switch statement always has a default branch, and each case has a break, which must be explained.
5. Write as few as possible. It is best to have only one return at the end of the function.
6. brackets are added to each part of the ternary operator.
7 if-Else, the branch in switch-case must have braces {}
Binary readable
1 Note, which generally includes: function description, parameter explanation, modification record (modification time, modifier, modification content description)
2. Function Name: meaningful verb-object phrase, hump-Type COMMAND
3 long statement branch writing, line feed indent, operator line first
4. Generally, the function body must not exceed one screen.
5. There is only one empty row between function bodies.
Only one variable is declared in one row.
7. * near type when declaring pointer, such as int * P;
8. input parameters before
9 if-Else, switch-case, etc.
10 switch. Each case has only one empty row.
Three Efficiency
1. The parameter initialization list is more efficient than the constructor's in-body replication.
2. Declare a variable for storage using a value that remains unchanged for multiple times to avoid repeated acquisition.
3. The pre-auto-increment operator is more efficient than the post-auto-increment operator.
4 if the string is null, strlen is not used, but if (! Pstr |! (* Pstr ))
Appendix 4: Three programming naming rules (Hungary, small hump, and big hump)
1 Hungary Name:
The START letter is the abbreviation of the variable type, and the rest is the abbreviation of the variable in English or English. The first letter of the word must be capitalized.
For example, long lsum = 0; "L" is the abbreviation of the type;
2. Small CAMEL: (little camel-case)
The first letter is lowercase, and the first letter is uppercase.
Example: String firstname = string. empty;
3 big camel-case: (big camel-case)
The first letter of each word is capitalized;
Example: String firstname = string.
How to write beautiful functions? (Appendix: three most common command Rules)