没有合适的资源?快使用搜索试试~ 我知道了~
首页C++ Coding Standards,101 Rules,Guidelines and Best Practices
资源详情
资源评论
资源推荐
C++ Coding Standards - 101
Rules, Guidelines, and Best
Practices @Team LiB
C++ Coding Standards - 101 Rules, Guidelines, and Best Practices @Team LiB
1
Table of Contents
1. C++ Coding Standards: 101 Rules, Guidelines, and Best Practices ................................................ 14
2. Table of Contents ........................................................................................................................... 15
3. Copyright ....................................................................................................................................... 27
4. The C++ In-Depth Series ................................................................................................................ 29
4.1 Titles in the Series ................................................................................................................ 29
5. Preface ........................................................................................................................................... 30
5.1 How to Use This Book .......................................................................................................... 31
5.2 Coding Standards and You ................................................................................................... 32
5.3 About This Book ................................................................................................................... 33
5.4 Acknowledgments ............................................................................................................... 34
6. Organizational and Policy Issues .................................................................................................... 35
6.1 Chapter 0. Don't sweat the small stuff. (Or: Know what not to standardize.) .................. 35
6.1.1 Summary ................................................................................................................... 36
6.1.2 Discussion ................................................................................................................. 36
6.1.3 Examples ................................................................................................................... 37
6.1.4 References ................................................................................................................ 38
6.2 Chapter 1. Compile cleanly at high warning levels ........................................................... 38
6.2.1 Summary ................................................................................................................... 38
6.2.2 Discussion ................................................................................................................. 38
6.2.3 Examples ................................................................................................................... 39
6.2.4 Exceptions ................................................................................................................. 41
6.2.5 References ................................................................................................................ 42
6.3 Chapter 2. Use an automated build system...................................................................... 42
6.3.1 Summary ................................................................................................................... 42
6.3.2 Discussion ................................................................................................................. 42
6.3.3 References ................................................................................................................ 43
6.4 Chapter 3. Use a version control system .......................................................................... 43
6.4.1 Summary ................................................................................................................... 43
6.4.2 Discussion ................................................................................................................. 43
6.4.3 Exceptions ................................................................................................................. 44
6.4.4 References ................................................................................................................ 44
6.5 Chapter 4. Invest in code reviews ..................................................................................... 44
6.5.1 Summary ................................................................................................................... 44
6.5.2 Discussion ................................................................................................................. 45
6.5.3 References ................................................................................................................ 45
7. Design Style ................................................................................................................................... 46
7.1 Chapter 5. Give one entity one cohesive responsibility ................................................... 46
7.1.1 Summary ................................................................................................................... 47
7.1.2 Discussion ................................................................................................................. 47
7.1.3 Examples ................................................................................................................... 47
7.1.4 References ................................................................................................................ 48
C++ Coding Standards - 101 Rules, Guidelines, and Best Practices @Team LiB
2
7.2 Chapter 6. Correctness, simplicity, and clarity come first................................................. 48
7.2.1 Summary ................................................................................................................... 48
7.2.2 Discussion ................................................................................................................. 48
7.2.3 Examples ................................................................................................................... 49
7.2.4 References ................................................................................................................ 49
7.3 Chapter 7. Know when and how to code for scalability ................................................... 50
7.3.1 Summary ................................................................................................................... 50
7.3.2 Discussion ................................................................................................................. 50
7.3.3 References ................................................................................................................ 52
7.4 Chapter 8. Don't optimize prematurely ............................................................................ 52
7.4.1 Summary ................................................................................................................... 52
7.4.2 Discussion ................................................................................................................. 52
7.4.3 Examples ................................................................................................................... 54
7.4.4 Exceptions ................................................................................................................. 54
7.4.5 References ................................................................................................................ 54
7.5 Chapter 9. Don't pessimize prematurely .......................................................................... 54
7.5.1 Summary ................................................................................................................... 55
7.5.2 Discussion ................................................................................................................. 55
7.5.3 References ................................................................................................................ 56
7.6 Chapter 10. Minimize global and shared data .................................................................. 56
7.6.1 Summary ................................................................................................................... 56
7.6.2 Discussion ................................................................................................................. 56
7.6.3 Exceptions ................................................................................................................. 57
7.6.4 References ................................................................................................................ 57
7.7 Chapter 11. Hide information ........................................................................................... 57
7.7.1 Summary ................................................................................................................... 57
7.7.2 Discussion ................................................................................................................. 58
7.7.3 Exceptions ................................................................................................................. 58
7.7.4 References ................................................................................................................ 58
7.8 Chapter 12. Know when and how to code for concurrency ............................................. 59
7.8.1 Summary ................................................................................................................... 59
7.8.2 Discussion ................................................................................................................. 59
7.8.3 References ................................................................................................................ 62
7.9 Chapter 13. Ensure resources are owned by objects. Use explicit RAII and smart pointers
................................................................................................................................................... 62
7.9.1 Summary ................................................................................................................... 62
7.9.2 Discussion ................................................................................................................. 62
7.9.3 Exceptions ................................................................................................................. 64
7.9.4 References ................................................................................................................ 64
8. Coding Style ................................................................................................................................... 64
8.1 Chapter 14. Prefer compile- and link-time errors to run-time errors ............................... 65
8.1.1 Summary ................................................................................................................... 65
8.1.2 Discussion ................................................................................................................. 65
8.1.3 Examples ................................................................................................................... 66
C++ Coding Standards - 101 Rules, Guidelines, and Best Practices @Team LiB
3
8.1.4 Exceptions ................................................................................................................. 67
8.1.5 References ................................................................................................................ 67
8.2 Chapter 15. Use const proactively .................................................................................... 67
8.2.1 Summary ................................................................................................................... 67
8.2.2 Discussion ................................................................................................................. 68
8.2.3 Examples ................................................................................................................... 69
8.2.4 References ................................................................................................................ 69
8.3 Chapter 16. Avoid macros ................................................................................................. 70
8.3.1 Summary ................................................................................................................... 70
8.3.2 Discussion ................................................................................................................. 70
8.3.3 Examples ................................................................................................................... 71
8.3.4 Exceptions ................................................................................................................. 72
8.3.5 References ................................................................................................................ 72
8.4 Chapter 17. Avoid magic numbers .................................................................................... 72
8.4.1 Summary ................................................................................................................... 72
8.4.2 Discussion ................................................................................................................. 72
8.4.3 Examples ................................................................................................................... 73
8.4.4 References ................................................................................................................ 73
8.5 Chapter 18. Declare variables as locally as possible ......................................................... 74
8.5.1 Summary ................................................................................................................... 74
8.5.2 Discussion ................................................................................................................. 74
8.5.3 Exceptions ................................................................................................................. 75
8.5.4 References ................................................................................................................ 75
8.6 Chapter 19. Always initialize variables .............................................................................. 75
8.6.1 Summary ................................................................................................................... 75
8.6.2 Discussion ................................................................................................................. 75
8.6.3 Examples ................................................................................................................... 76
8.6.4 Exceptions ................................................................................................................. 77
8.6.5 References ................................................................................................................ 77
8.7 Chapter 20. Avoid long functions. Avoid deep nesting ..................................................... 78
8.7.1 Summary ................................................................................................................... 78
8.7.2 Discussion ................................................................................................................. 78
8.7.3 Exceptions ................................................................................................................. 79
8.7.4 References ................................................................................................................ 79
8.8 Chapter 21. Avoid initialization dependencies across compilation units ......................... 79
8.8.1 Summary ................................................................................................................... 79
8.8.2 Discussion ................................................................................................................. 79
8.8.3 References ................................................................................................................ 80
8.9 Chapter 22. Minimize definitional dependencies. Avoid cyclic dependencies ................. 80
8.9.1 Summary ................................................................................................................... 81
8.9.2 Discussion ................................................................................................................. 81
8.9.3 Exceptions ................................................................................................................. 82
8.9.4 References ................................................................................................................ 82
8.10 Chapter 23. Make header files self-sufficient ................................................................. 83
C++ Coding Standards - 101 Rules, Guidelines, and Best Practices @Team LiB
4
8.10.1 Summary ................................................................................................................. 83
8.10.2 Discussion ............................................................................................................... 83
8.10.3 Examples ................................................................................................................. 83
8.10.4 References .............................................................................................................. 84
8.11 Chapter 24. Always write internal #include guards. Never write external #include guards
................................................................................................................................................... 84
8.11.1 Summary ................................................................................................................. 84
8.11.2 Discussion ............................................................................................................... 84
8.11.3 Exceptions ............................................................................................................... 85
8.11.4 References .............................................................................................................. 85
9. Functions and Operators ............................................................................................................... 86
9.1 Chapter 25. Take parameters appropriately by value, (smart) pointer, or reference ....... 86
9.1.1 Summary ................................................................................................................... 86
9.1.2 Discussion ................................................................................................................. 86
9.1.3 References ................................................................................................................ 87
9.2 Chapter 26. Preserve natural semantics for overloaded operators .................................. 87
9.2.1 Summary ................................................................................................................... 88
9.2.2 Discussion ................................................................................................................. 88
9.2.3 Exceptions ................................................................................................................. 88
9.2.4 References ................................................................................................................ 89
9.3 None 27. Prefer the canonical forms of arithmetic and assignment operators .................. 89
9.3.1 Summary ................................................................................................................... 89
9.3.2 Discussion ................................................................................................................. 89
9.3.3 Examples ................................................................................................................... 90
9.3.4 Exceptions ................................................................................................................. 91
9.3.5 References ................................................................................................................ 91
9.4 Chapter 28. Prefer the canonical form of ++ and --. Prefer calling the prefix forms ........ 91
9.4.1 Summary ................................................................................................................... 91
9.4.2 Discussion ................................................................................................................. 92
9.4.3 Exceptions ................................................................................................................. 92
9.4.4 References ................................................................................................................ 93
9.5 Chapter 29. Consider overloading to avoid implicit type conversions ............................. 93
9.5.1 Summary ................................................................................................................... 93
9.5.2 Discussion ................................................................................................................. 93
9.5.3 References ................................................................................................................ 94
9.6 Chapter 30. Avoid overloading &&, ||, or , (comma) ....................................................... 94
9.6.1 Summary ................................................................................................................... 94
9.6.2 Discussion ................................................................................................................. 95
9.6.3 Examples ................................................................................................................... 96
9.6.4 Exceptions ................................................................................................................. 97
9.6.5 References ................................................................................................................ 97
9.7 Chapter 31. Don't write code that depends on the order of evaluation of function
arguments .................................................................................................................................. 97
9.7.1 Summary ................................................................................................................... 97
剩余308页未读,继续阅读
夜行歌
- 粉丝: 15
- 资源: 94
上传资源 快速赚钱
- 我的内容管理 收起
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
会员权益专享
最新资源
- c++校园超市商品信息管理系统课程设计说明书(含源代码) (2).pdf
- 建筑供配电系统相关课件.pptx
- 企业管理规章制度及管理模式.doc
- vb打开摄像头.doc
- 云计算-可信计算中认证协议改进方案.pdf
- [详细完整版]单片机编程4.ppt
- c语言常用算法.pdf
- c++经典程序代码大全.pdf
- 单片机数字时钟资料.doc
- 11项目管理前沿1.0.pptx
- 基于ssm的“魅力”繁峙宣传网站的设计与实现论文.doc
- 智慧交通综合解决方案.pptx
- 建筑防潮设计-PowerPointPresentati.pptx
- SPC统计过程控制程序.pptx
- SPC统计方法基础知识.pptx
- MW全能培训汽轮机调节保安系统PPT教学课件.pptx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0