[Go] program Development Basic Learning II (C + + Google Style naming convention)

Source: Internet
Author: User
Tags naming convention

No rules inadequate surrounding area, the new position will need to obey the code rules of the team. Very happy that the team is using Google's C + + coding rules, probably looked at Google's coding rules, as nine days off said: "Google's C + + style guide is far more than a traditional code writing style guidance, for C + + All aspects of Google's interpretation and use of suggestions, including each rule given, in more detail on the good side of the rule and the bad side, the most radical rule even has to disable C + + exception, and in addition to the Google specification interface as the base class, disable multiple inheritance, In most cases, the default parameters are disabled, and so on. To a large extent, Google is trying to make C + + a highly efficient Java to use ~ ~ ~. The Chinese version of Google C + + Style guide has more than 50,000 words, and today summarizes the most common naming conventions.

1. File naming rules

Because in writing the program when the first to create a file, good file name can clearly see the file will be hosted content, Google gives the rule is:"file name to all lowercase, can contain an underscore (_) or hyphen (- ). According to the project contract, for example: Cmd_save_player_info "

I like the naming rules of the underlined way, and we should prevent the conflict with the function names in the standard library when naming them.

2. Class naming rules

Class is a user-defined data type, the rules that Google gives are:"The first letter of each word of the type name is capitalized and does not contain underscores: Modplayermanager"

The same convention is used for all type naming-classes, structs, enumerations, type definitions (typedef).

3. Variable naming rules

The rules given by Google are:"variable names are all lowercase, and the words are connected with underscores." The class's member variable ends with an underscore, such as: player_id.

What is special is that the member variable is followed by an underscore, for example: Player_name_. Global variables are added g_, such as G_system_time.

4. Constant naming rules

For constants, the rules that Google gives are:" K followed by the words beginning with capital letters, for example: Kplayername".

5. Function naming rules

For a function, Google gives the rule:"The general function uses the case mix, the value and the Set value function is required to match the variable name."

General function words start with uppercase, for example: Checkplayercookie ().

Member variable settings and get functions are a bit special, see the following code:

[CPP]View Plaincopy
    1. Class Player
    2. {
    3. Public
    4. void set_player_id (const int player_id) {return player_id_ = player_id;}
    5. int get_player_id () const{return player_id_;}
    6. Private
    7. int player_id_;
    8. };

6. Namespace naming rules

For namespaces, Google gives the rule: "Namespaces arenamed in lowercase letters and based on the project name and directory structure: google_awesome_project."

7. Enumeration naming rules

For enumerations, the rule given by Google is:"The name of the enumeration should be consistent with constants or macros : kenumname or enum_name."

8. Macro variable naming rules

For macro variables, Google gives the following rule: " you're not going to use a macro , are you?" if you're going to use it, name it like this: My_macro_that_scares_small_ Children. ".

Naming rules are often used, of course, I have not really practiced this naming convention, relative to the previous use of the Hungarian nomenclature, do not see the advantages there. But since Google does this should give them the truth, regardless of the style, and the team to maintain unity is a good style.

Reference article: 1, Google C + + style guide-Chinese version

2. Boost libraries allowed in Google C + + style (1)

[Go] program Development Basic Learning II (C + + Google Style naming convention)

Related Article

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.