C++核心指导原则: 其他杂项

C++ Core Guidelines 整理目录

  1. 哲学部分
  2. 接口(Interface)部分
  3. 函数部分
  4. 类和类层次结构部分
  5. 枚举部分
  6. 资源管理部分
  7. 表达式和语句部分
  8. 性能部分
  9. 并发和并行
  10. 错误处理
  11. 常量和不可变性
  12. 泛型编程
  13. 源文件
  14. 命名和布局建议
  15. 标准库
  16. 其他规则

CPL: C 风格编程

CPL.1: Prefer C++ to C

CPL.2: If you must use C, use the common subset of C and C++, and compile the C code as C++

CPL.3: If you must use C for interfaces, use C++ in the calling code using such interfaces

A: 结构性考虑

A.1: Separate stable code from less stable code

A.2: Express potentially reusable parts as a library

A.4: There should be no cycles among libraries

Non-Rules and myths

NR.1: Don’t insist that all declarations should be at the top of a function

NR.2: Don’t insist on having only a single return-statement in a function

NR.3: Don’t avoid exceptions

NR.4: Don’t insist on placing each class definition in its own source file

NR.5: Don’t use two-phase initialization

NR.6: Don’t place all cleanup actions at the end of a function and goto exit

NR.7: Don’t make all data members protected