关于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 ...
随机推荐
- 制作一个访问量很高的大型网站,你会如何来管理所有HTML、CSS、JS与图片?
1.先确定全局样式和编码方式. 2.编写习惯,标注样式. 3.文件夹存放,命名.
- sql server 2008 跨服务器查询
exec sp_addlinkedserver 'ITSV','','SQLOLEDB','192.168.202.53' exec sp_addlinkedsrvlogin 'ITSV','fals ...
- Delphi 2009 泛型容器单元(Generics.Collections)[1]: TList<T>
Delphi 2009 新增了泛型容器单元: Generics.Collections, 同时还有一个 Generics.Defaults 单元做支持. Generics.Collections 包含 ...
- Delphi7 客户端调用WebService(天气预报)
客户程序:第一步:新建一个Application. 第二步:File----->New----->Other------>WebServices----->WSDL Impor ...
- JS实现选择不同select标签option值的验证
js实现不同select标签option值的验证 功能描述: 选择中文时,匹配中文的正则表达式,选择英文选项是匹配英文的表达式,并且有对应的提示信息. html代码片段: <select id= ...
- Codeforces 343D Water Tree(DFS序 + 线段树)
题目大概说给一棵树,进行以下3个操作:把某结点为根的子树中各个结点值设为1.把某结点以及其各个祖先值设为0.询问某结点的值. 对于第一个操作就是经典的DFS序+线段树了.而对于第二个操作,考虑再维护一 ...
- SPFA 的两个优化
From NOCOW SPFA算法有两个优化算法 SLF 和 LLL: SLF:Small Label First 策略,设要加入的节点是j,队首元素为i,若dist(j)<dist(i),则将 ...
- ACM: 限时训练题解- Travelling Salesman-最小生成树
Travelling Salesman After leaving Yemen, Bahosain now works as a salesman in Jordan. He spends mos ...
- Android -- EditText方法
1. 选择需要的内容 final EditText myEditText=(EditText)findViewById(R.id.editText1); //编辑框对象 myEditText.setT ...
- children和childNodes的区别
children和childNodes 1,childNodes 属性,标准的,它返回指定元素的子元素集合,包括HTML节点,所有属性,文本.可以通过nodeType来判断是哪种类型的节点,只有当no ...