关于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 ...
随机推荐
- node.js整理 01代码的组织和部署
模块 require(函数) 用于在当前模块中加载和使用别的模块,传入一个模块名,返回一个模块导出对象. 模块名可使用相对路径(以./开头),或者是绝对路径(以/或C:之类的盘符开头:注意单个模块名默 ...
- 工具:使用jekyll生成静态网站
在使用前端框架构建网页而不使用后端平台与数据库,即没有服务器的条件下读取文件夹其他文件,浏览器可能会阻止访问.对于这种静态构建可以使用简单的生成工具jekyll.它主要适用于将静态文件生成静态网站,在 ...
- [工作中的设计模式]观察者模式observer
一.模式解析 观察者模式定义了一种一对多的依赖关系,让多个观察者对象同时监听某一个主题对象.这个主题对象在状态上发生变化时,会通知所有观察者对象,使它们能够自动更新自己. 观察者模式又叫订阅发布模式, ...
- 转:Delphi 回调函数及例子
http://anony3721.blog.163.com/blog/static/5119742010866050589/ { http://anony3721.blog.163.com/blog/ ...
- http://blog.csdn.net/jyw935478490/article/details/51233931
http://blog.csdn.net/jyw935478490/article/details/51233931
- linux TCP Wrappers
1. TCP Wrapper简介 (出处:http://www.softpanorama.org/Net/Network_security/TCP_wrappers/) (维基百科)TCP Wrapp ...
- 使用Maven构建Android项目
http://www.ikoding.com/build-android-project-with-maven/ 之前一直在做WEB前端项目,前段时间接手第一个Android项目,拿到代码之后,先试着 ...
- Hive 实现HBase 数据批量插入
HBase 数据的插入可以使用Java API 来写Java 程序逐条倒入,但是不是很方便.利用Hive自带的一个Jar包,可以建立Hive和HBase的映射关系 利用Hive 的insert可以将批 ...
- POJ3084 Panic Room(最小割)
把某点与某几点分开的最小花费,当然想到最小割.具体怎么建图,可以画个简单的情况,然后就清楚了: 0到1不受控制,建立0->1容量为INF的边: 1到0受在0一边的一个控制面板的控制,建立1-&g ...
- Hadoop 分布式环境搭建
一.前期环境 安装概览 IP Host Name Software Node 192.168.23.128 ae01 JDK 1.7 NameNode, SecondaryNameNode, Data ...