Explanation of Google C ++ programming specifications

Source: Internet
Author: User
Tags coding standards

Explanation of Google C ++ programming specifications

I personally think that google's C ++ coding standards are highly practical, and the code standards that come with Microsoft are simpler and clearer. I personally code them according to google's C ++ coding standards.

I. File Name

The file name must be in lowercase. It can contain underscores (_) or hyphens (-).

my_useful_class.ccmy-useful-class.ccmyusefulclass.cc
Ii. type commands

Type name: each word starts with an uppercase letter and does not contain underscores (_): MyExcitingClass or MyExcitingEnum.

All types of names-class, struct, type definition (typedef), enumeration-use the same conventions, for example:

// classes and structsclass UrlTable { ...class UrlTableTester { ...struct UrlTableProperties { ...// typedefstypedef hash_map
 
   PropertiesMap;// enumsenum UrlTableErrors { ...
 
Iii. variable naming

All variable names are in lowercase, And the words are underlined and connected.

3.1. Name common variables

String table_name;

3.2. Name the class data member, ending with a line below

String name _;

3.3. structure data member name. It can be the same as a common member and does not end with an underscore like a class:
struct UrlTableProperties {   string name;   int num_entries;}
3.4. global variable name, prefixed with g _

String g_name;

3.5. Constant name, k followed by a word starting with an uppercase letter

Const int kDaysInAWeek = 7;

Iv. function name 4.1. A common function. The function name starts with an uppercase letter. Each word is capitalized and is separated by an underscore.
int AddTableEntry()bool DeleteUrl()
4.2. The access function must match the name of the accessed variable.
class MyClass {public:...   int num_entries() const { return num_entries_; }   void set_num_entries(int num_entries) { num_entries_ = num_entries; }private:   int num_entries_;};
V. namespace

The namespace name is in all lowercase, and its name is based on the project name and directory structure: google_awesome_project

6. Enumeration naming

All the enumerated values are in uppercase, And the words are separated by the following strip. The enumerated names belong to the type, so the uppercase values are mixed:

enum UrlTableErrors {   OK = 0,   ERROR_OUT_OF_MEMORY,   ERROR_MALFORMED_INPUT,};

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.