关于c++风格 code style
- Header files should be self-contained.
- All header files should have #define guards to prevent multiple inclusion. The format of the symbol name should be <PROJECT>_<PATH>_<FILE>_H_.
- You may forward declare ordinary classes in order to avoid unnecessary #includes. A "forward declaration" is a declaration of a class, function, or template without an associated definition. #include lines can often be replaced with forward declarations of whatever symbols are actually used by the client code.
- Use standard order for readability and to avoid hidden dependencies: Related header, C library, C++ library, other libraries' .h, your project's .h.
- dir2/foo2.h.
- C system files.
- C++ system files.
- Other libraries' .h files.
- Your project's .h files.
- In dir/foo.cc or dir/foo_test.cc, whose main purpose is to implement or test the stuff in dir2/foo2.h, order your includes as follows:
- Do not make nested classes public unless they are actually part of the interface, e.g., a class that holds a set of options for some method.
- Variables needed for if, while and for statements should normally be declared within those statements, so that such variables are confined to those scopes. E.g.:
- while (const char* p = strchr(str, '/')) str = p + 1;
- Constructors should never call virtual functions or attempt to raise non-fatal failures. If your object requires non-trivial initialization, consider using a factory function or Init() method.
- Use the C++ keyword explicit for constructors callable with one argument.
- Use delegating and inheriting constructors when they reduce code duplication.
- Inheriting constructors allow a derived class to have its base class's constructors available directly, just as with any of the base class's other member functions, instead of having to redeclare them. This is especially useful if the base has multiple constructors.
- Only very rarely is multiple implementation inheritance actually useful. We allow multiple inheritance only when at most one of the base classes has an implementation; all other base classes must be pure interface classes tagged with the Interface suffix. Multiple inheritance allows a sub-class to have more than one base class. We distinguish between base classes that are pure interfaces and those that have an implementation.
- All parameters passed by reference must be labeled const.
- Use streams only for logging.
- Use prefix form (++i) of the increment and decrement operators with iterators and other template objects.
- document that a variable is non-negative using assertions. Don't use an unsigned type.
- 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_. Data members of structs, both static and non-static, are named like ordinary nonmember variables. They do not have the trailing underscores that data members in classes have.
- 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.
- Regular functions have mixed case; accessors and mutators match the name of the variable: MyExcitingFunction(), MyExcitingMethod(), my_exciting_member_variable(), set_my_exciting_member_variable().
- Use a k followed by mixed case, e.g., kDaysInAWeek, for constants defined globally or within a class.const int kDaysInAWeek = 7;
- Enumerators should be named either like constants or like macros: either kEnumName or ENUM_NAME.
- Empty loop bodies should use {} or continue, but not a single semicolon.
- both of the && logical AND operators are at the end of the line.
摘自:http://google-styleguide.googlecode.com/svn/trunk/cppguide.html
关于c++风格 code style的更多相关文章
- intelij IDEA设置goole code style风格
1.安装google-java-format 插件 file ->Setings... ->pligins 输入上诉插件安装 2.下载IntelliJ Java Goog ...
- Java Code Style
近期困惑于团队成员代码风格迥异,代码质量不可控,作为一名老司机,忧患于后期服务的可维护性,多次一对一的代码Review,耗时耗力不说,效果也不明显.痛定思痛,多次反思之后得出结论:无规矩不成方圆,可靠 ...
- 与你相遇好幸运,The Moe Node.js Code Style Guide
The Moe Node.js Code Style Guide By 一个最萌的开发者 @2016.9.21 >>代码是人来阅读的,格式规范的代码是对编程人员最好的礼物 :) > ...
- Eclipse setting Java code style and codetemplate
1.open the eclipse tool window First click the Window menu,then check the children's menu which name ...
- 【Idea】idea code style配置eclipse code formatter
在eclipse中有自动配置code style的功能 ,但是idea上却没有,这个时候需要自己手工配置 1. 在idea中找到Preference->Plugins->Browse re ...
- checkstyle.xml Code Style for Eclipse
1. Code Templates [下载 Code Templates] 打开 Eclipse -> Window -> Preferences -> Java -> Cod ...
- _rqy's Code Style for OI
_rqy's Code Style for OI Inspired by Menci's Code Style for OI 本文介绍_rqy的OI中的代码规范.其来源主要为_rqy的长期积累及参考G ...
- Javascript Code Style Guide
本指南采用的Airbnb发布的基于ES5的JavaScript Code Style. ES5 英文版:https://github.com/airbnb/javascript/tree/es5-de ...
- 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键
google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...
随机推荐
- MATLAB plot函数的一些参数
直接从帮助文档中抓图,注意是颜色.线型什么的.
- 服务器控件和 viewstate
//不会产生处理回发事件的方法.类似客户端html Repeater rep = new Repeater(); DataList dtl = new DataList(); FileUpload f ...
- Ubuntu Mono 运行 Helloworld
Ubuntu Mono 运行 Helloworld ref: http://www.mono-project.com/docs/getting-started/install/linux/#usage ...
- BZOJ4684 : Company Organization
二分答案,转化为判定问题. 建立有向图,$a->b$连边表示$a$是$b$的子集,至此可以处理掉$1$和$2$. 对于$5$,则往对应点的集合塞一个元素,即可满足$5$. 首先求出强连通分量进行 ...
- ubuntu server下建立分区表/分区/格式化/自动挂载(转)
link:http://www.thxopen.com/linux/2014/03/30/Linux_parted.html 流程为:新建分区-->格式化分区-->挂载分区 首先弄明白分区 ...
- POJ2104 & 主席还是可持久化还是 函数式
题意: 区间第K大. SOL: 非常有意思的树,尽管我搞不清楚名字. 原理参见clj的可持久化数据结构研究. wa了整整一天,然后重打,然后1a... code: /*================ ...
- <构建之法>3-5章感想
提示:(下面的总结我会按照每章发现的问题,自己的回答,感想来陈述) 3章. 在阅读3.2.4职业成长-自我评估的时候,说到CRUD需要一些核心技术和许多控扩展的知识,那么作为软件工程的学生,在学校除了 ...
- CSS3 transform rotate(旋转)锯齿的解决办法
-moz-transform: rotate(5deg);-webkit-transform: rotate(5deg); 把图片旋转了5度.本以为轻而易举,可遇到了问题.在Fireofx中显示正常, ...
- 20145304 刘钦令 Java程序设计第二周学习总结
20145304 <Java程序设计>第2周学习总结 教材学习内容总结 java可区分基本类型和类类型(即参考类型)两大类型系统. 基本类型主要可区分为整数.字节.浮点数.字符与布尔. 整 ...
- ACM Same binary weight
Same binary weight 时间限制:300 ms | 内存限制:65535 KB 难度:3 描述 The binary weight of a positive integer ...