Summary of Google C/C ++ programming style

Source: Internet
Author: User

Some time ago I read the Google C/C ++ programming style and extract some important points. Please give us some advice.

For the sake of clarityGoogle C ++Programming specifications:

Pascal case: When an identifier is composed of two or more words, no other symbols are added between words, and each word must be capitalized, such as pascalcase.

Camel case: When an identifier is composed of two or more words, no other symbols are added between words. The first word starts with lowercase, And the other words start with uppercase. For example, camelcase.

Unix/LinuxVariable naming method: WhenProgramWhen it is composed of two or more words, the words start with lowercase and are connected.

Below isGoogle C ++Some content of programming specifications:

I. Naming

1) Common variables:LinuxNaming rules. For example:StringTable_name;

2) constants:K +Pascalcase. For example, const int kdayinaweek = 7;

3) class private members: Linux naming rules+_. For example:IntParament_count _;

4) Name of a common function: pascalcase. For example:Addtableentry ().

5) storage functions:LinuxNaming method. For example:

Int num_entries () const {return num_entries _};

Void set_num_entries () {int num_entries };

6) enumeration: The value is a word in uppercase. Words are separated by underscores. For example, my_enum_value

7) Class Name and structure Name:Pascalcase

Ii. Function Parameters

The input parameter is money, and the output parameter is later.

Iii. Sorting of header files

CSystem header file

C ++System header file

Other library header files

Header files in this project

Iv. File comments

1. creator of Creation Time

2. Modify the time modifier to modify the function list.

3. In the header file, the role of this class is first defined, and the function usage is briefly described.

V. Other conventions

1, Each line should not exceed80Characters, excluding long paths or header file protection;

2, Set the editorTabConvert to space, preferably4Space;

3And empty loop body usage{},ContinueInstead of a semicolon;

4Do not use the Hungarian naming method.

 

the most important thing is to be consistent with the programming style of your team, even if your team's programming style conflicts with the one described above.

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.