谷歌c++代码规范(1)---命名

通用命名规则

原文

Function names, variable names, and filenames should be descriptive; eschewabbreviation.
Give as descriptive a name as possible, within reason. Do not worry about saving horizontal space as it is far more important to make your code immediately understandable by a new reader. Do not use abbreviations that are ambiguous or unfamiliar to readers outside your project, and do not abbreviate by deleting letters
within a word.```
一句话,就是不要担心浪费内存空间,命名少用缩写,语义明确才是最重要的。

## 文件名 ##
原文

Filenames should be all lowercase and can include underscores () or dashes (-).Follow the convention that your project uses. If there is no consistent local pattern to follow, prefer ““.

规则:字母全部小写,可以使用下划线‘_' 或者扩折号 '-'。另外,文件名最好多加一些定义。例如 http_server_logs.h 而不是logs.h.


## 类型名 ##

Type names start with a capital letter and have a capital letter for each new word,with no underscores: MyExcitingClass, MyExcitingEnum. The names of all types — classes, structs, typedefs, and enums — have the same naming convention. Type names should start with a capital letter and have a capital
letter for each new word. No underscores.

类型名包括类名,结构体,枚举,以及typedef。其命名方式符合大驼峰法,也就是名字由一个或者多个单词组成,每个单词首字母大写。

## 变量名 ##

The names of variables and data members are all lowercase, with underscores between words. Data members of classes (but not structs) additionally have trailing underscores. For instance: a_local_variable, a_struct_data_member,a_class_data_member_

变量名字母全部小写,字母间使用下划线联接。类成员变量需要在名称后增加一个尾下划线,例如 a_local_variable,而类成员变量 a_class_data_member_.

## 全局变量名##

There are no special requirements for global variables, which should be rare in any case, but if you use one, consider prefixing it with g_ or some other marker to easily distinguish it from local variables.

在谷歌规范中并没有对全局变量的具体限制,只是建议我们为全局变量起一个明显的区别相对于其他,比如在名字前加个统一的前缀例如g_。

##常量名##

Use a k followed by mixed case, e.g., kDaysInAWeek, for constants defined globally or within a class.As a convenience to the reader, compile-time constants of global or class scope follow a different naming convention from other variables. Use a k followed by
words with uppercase first letters
“`
常量名字的规范是混合型即前缀k+驼峰法,例如 const int kDaysInAWeek=3.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值