How to write beautiful functions? (Appendix: three most common command Rules)

Source: Internet
Author: User
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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.