Google C++ Style Guide学习笔记——命名
来源:互联网 发布:邪恶漫画知子继母 编辑:程序博客网 时间:2024/04/28 10:44
1、一般性规则
函数名、变量名、文件名应当是描述性的,避免使用缩写词。
2、文件名
文件名应当全部小写,可以使用下划线'_'或者破折号'-',优先使用下划线。
C++文件应当以.cc结尾
3、类型名
类型名(包括classes、structs、typedefs、enums)以大写字母开头,每个单词首字母大写,不要使用下划线。
4、变量名
变量名全部使用小写,单词与单词之间使用下划线。类的成员变量使用trailing underscores。举例:
Common Variable names
For example:
string table_name; // OK - uses underscore. string tablename; // OK - all lowercase.
string tableName; // Bad - mixed case.
Class Data Members
Data members (also called instance variables or member variables) are lowercase with optional underscores like regular variable names, but always end with a trailing underscore.
string table_name_; // OK - underscore at end.string tablename_; // OK.Struct Variables
Data members in structs should be named like regular variables without the trailing underscores that data members in classes have.
struct UrlTableProperties { string name; int num_entries;}See Structs vs. Classes for a discussion of when to use a struct versus a class.
Global Variables
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.
以字母'k'开头,后接首字母大写的大小写混合单词。如:kDaysInAWeek.
6、函数名
常规函数名:常规函数名应该首字母大写,每个单词以大写字母开头,不使用下划线。如
AddTableEntry() DeleteUrl() OpenFileOrDie()
Accessors and Mutators
Accessors and mutators (get and set functions) should match the name of the variable they are getting and setting. This shows an excerpt of a class whose instance variable is
num_entries_
.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_;};You may also use lowercase letters for other very short inlined functions. For example if a function were so cheap you would not cache the value if you were calling it in a loop, then lowercase naming would be acceptable.
7、枚举命名:
像consts或macros一样命名。尽量像consts。
- Google C++ Style Guide学习笔记——命名
- Google C++Style Guide【C++编程风格指南解读】——命名约定
- Google C++ style guide——命名约定
- Google Objective-C Style Guide
- Google C++ Style Guide之命名规则
- Google C++ Style Guide之命名规则
- 笔记:Google C++ Style Guide
- Google C++ style guide——格式
- IOS的学习笔记之Objective-C style guide.
- Google C++Style Guide【C++编程风格指南解读】——注释
- Google C++Style Guide【C++编程风格指南解读】——C++代码格式
- Google C++Style Guide【C++编程风格指南解读】——Windows代码规则
- Google C++Style Guide【C++编程风格指南解读】——规则的根本目标
- Google Objective-C Style Guide 中文版
- Google Objective-C Style Guide 中文版
- Google Objective-C Style Guide 中文版
- Google Objective-C Style Guide 中文版
- Google Objective-C Style Guide 中文版
- project euler problem 11:Largest product in a grid
- PADS2007下快速布局布线PCB_本人总结
- 敏捷开发纵横谈(1)——敏捷那些事儿
- ssh 连接linux
- php编程,windows记事本转utf8编码,response开头出现乱码字符的解决办法
- Google C++ Style Guide学习笔记——命名
- 互联网协议入门
- 802.11n 速率计算方法
- 1-Click PC Tuneup软件-破解实录-[上]
- 怎样做一个好用扩展性好的网站管理系统?分享经验
- Tutorial 01 - Create a window
- os内存管理之页式存储管理 http://blog.163.com/he_haoyi/blog/static/118698376200991542415238/
- 基础操作
- 个人研究得出生成HTML的静态页