C++编程规范

C++编程规范 pdf epub mobi txt 电子书 下载 2026

出版者:人民邮电出版社
作者:(美)萨特 亚历山德莱斯库
出品人:
页数:220
译者:
出版时间:2005-9
价格:42.00元
装帧:平装
isbn号码:9787115137708
丛书系列:图灵原版计算机科学系列
图书标签:
  • C++
  • C/C++
  • C++编程规范
  • 程序设计
  • 计算机
  • 编程规范
  • 编程
  • 拥有
  • C++
  • 编程规范
  • 代码风格
  • 软件工程
  • 可读性
  • 维护性
  • 最佳实践
  • 编程指南
  • 代码质量
  • C++开发
  • 代码规范
想要找书就要到 本本书屋
立刻按 ctrl+D收藏本页
你会得到大惊喜!!

具体描述

在本书中,两位知名的C++专家将全球C++团体的集体智慧和经验凝结成一套编程规范。这些规范可以作为每一个开发团队制定实际开发规范的基础,更是每一位C++程序员应该遵循的行事准则。书中对每一条规范都给出了精确的描述,并辅以实例说明;从类型定义到差错处理,都给出了最佳的C++实践。即使使用C++多年的程序员也会从中受益匪浅。

  本书适合于各层次C++程序员,也可作为高等院校C++课程的教学参考书。

作者简介

Herb Sutter,ISO C++标准委员会主席,C++ Users Journal杂志特邀编辑和专栏作家;他目前在微软公司领导NET环境下C++浯言扩展的设计工作除本书外.他还撰写了三本广受赞誉的图书:Exceptional C++ Style、Exceptional C++和More Exceptional C++。 .

Andrei Alexandrescu,世界顶级的C++专家.“C++ Users Journal杂志的专栏作家,他的Modem C++ Design—书曾荣获2001年最佳C++图朽称号.书中所开发的Loki已经成为最负盛名的C++程序库之一。

目录信息

Organizational and Policy Issues 1
0. Don't sweat the small stuff. (Or: Know what not to standardize.) 2
1. Compile cleanly at high warning levels. 4
2. Use an automated build system. 7
3. Use a version control system. 8
4. Invest in code reviews. 9
Design Style  11
5. Give one entity one cohesive responsibility. 12
6. Correctness, simplicity, and clarity come first. 13
7. Know when and how to code for scalability. 14
8. Don't optimize prematurely. 16
9. Don't pessimize prematurely. 18
10. Minimize global and shared data. 19
11. Hide information. 20
12. Know when and how to code for concurrency. 21
13. Ensure resources are owned by objects. Use explicit RAII and smart pointers. 24
Coding Style 27
14. Prefer compile- and link-time errors to run-time errors. 28
15. Use const proactively. 30
16. Avoid macros. 32
17. Avoid magic numbers. 34
18. Declare variables as locally as possible. 35
19. Always initialize variables. 36
20. Avoid long functions. Avoid deep nesting. 38
21. Avoid initialization dependencies across compilation units.  39
22. Minimize definitional dependencies. Avoid cyclic dependencies. 40
23. Make header files self-sufficient. 42
24. Always write internal #include guards. Never write external #include guards. 43
Functions and Operators 45
25. Take parameters appropriately by value, (smart) pointer, or reference. 46
26. Preserve natural semantics for overloaded operators. 47
27. Prefer the canonical forms of arithmetic and assignment operators. 48
28. Prefer the canonical form of + + and --. Prefer calling the prefix forms. 50
29. Consider overloading to avoid implicit type conversions. 51
30. Avoid overloading &&, ¢ò, or, (comma). 52
31. Don't write code that depends on the order of evaluation of function arguments. 54

Class Design and Inheritance 55
32. Be clear what kind of class you' re writing. 56
33. Prefer minimal classes to monolithic classes. 57
34. Prefer composition to inheritance. 58
35. Avoid inheriting from classes that were not designed to be base classes. 60
36. Prefer providing abstract interfaces. 62
37. Public inheritance is substitutability. Inherit, not to reuse, but to be reused 64
38. Practice safe overriding. 66
39. Consider making virtual functions nonpublic, and public functions nonvirtual. 68
40. Avoid providing implicit conversions. 70
41. Make data members private, except in behaviorless aggregates (C-style structs). 72
42. Don't give away your internals. 74
43. Pimpl judiciously. 76
44. Prefer writing nonmember nonfriend functions. 79
45. Always provide new and delete together. 80
46. If you provide any class-specific new, provide all of the standard forms (plain, in-place, and nothrow). 82
Construction, Destruction, and Copying 85
47. Define and initialize member variables in the same order. 86
48. Prefer initialization to assignment in constructors. 87
49. Avoid calling virtual functions in constructors and destructors. 88
50. Make base class destructors public and virtual, or protected and nonvirtual. 90
51. Destructors, deallocation, and swap never fail. 92
52. Copy and destroy consistently. 93
53. Explicitly enable or disable copying. 95
54. Avoid slicing. Consider Clone instead of copying in base classes. 96
55. Prefer the canonical form of assignment. 99
56. Whenever it makes sense, provide a no-fail swap (and provide it correctly). 100
Namespaces and Modules 103
57. Keep a type and its nonmember function interface in the same namespace. 104
58. Keep types and functions in separate namespaces unless they're specifically intended to work together. 106
59. Don't write namespace usings in a header file or before an #include. 108
60. Avoid allocating and deallocating memory in different modules. 111
61. Don't define entities with linkage in a header file. 112
62. Don't allow exceptions to propagate across module boundaries. 114
63. Use sufficiently portable types in a module's interface. 116
Templates and Genericity 119
64. Blend static and dynamic polymorphism judiciously. 120
65. Customize intentionally and explicitly. 122
66. Don't specialize function templates. 126
67. Don't write unintentionally nongeneric code. 128
Error Handling and Exceptions 129
68. Assert liberally to document internal assumptions and invariants. 130
69. Establish a rational error handling policy, and follow it strictly. 132
70. Distinguish between errors and non-errors. 134
71. Design and write error-safe code. 137
72. Prefer to use exceptions to report errors. 140
73. Throw by value, catch by reference. 144
74. Report, handle, and translate errors appropriately. 145
75. Avoid exception specifications. 146
STL: containers 149
76. Use vector by default. Otherwise, choose an appropriate container. 150
77. Use vector and string instead of arrays. 152
78. Use vector (and string::c_str) to exchange data with non-C++ APIs. 153
79. Store only values and smart pointers in containers. 154
80. Prefer pushback to other ways of expanding a sequence. 155
81. Prefer range operations to single-element operations. 156
82. Use the accepted idioms to really shrink capacity and really erase elements. 157
STL: Algorithms 159
83. Use a checked STL implementation. 160
84. Prefer algorithm calls to handwritten loops. 162
85. Use the right STL search algorithm. 165
86. Use the right STL sort algorithm. 166
87. Make predicates pure functions. 68
88. Prefer function objects over functions as algorithm and comparer arguments. 170
89. Write function objects correctly. 172
Type Safety 173
90. Avoid type switching; prefer polymorphism. 174
91. Rely on types, not on representations. 176
92. Avoid using reinterpret_cast. 177
93. Avoid using static_cast on pointers. 178
94. Avoid casting away const. 179
95. Don't use C-style casts. 180
96. Don't memcpy or memcmp non-PODs. 182
97. Don't use unions to reinterpret representation. 183
98. Don't use varargs (ellipsis). 184
99. Don't use invalid objects. Don't use unsafe functions. 185
100. Don't treat arrays polymorphically. 186
Bibliography 187
Summary of Summaries 195
Index 209
· · · · · · (收起)

读后感

评分

比较轻量级的一本书。如果你已经看过 effective c++ ,exceptional c++系列,那这本书只用翻翻目录就行了。  

评分

其实我想看个实践,别人的方法。 副标题叫Best Practices,但是Practice很少。 这本书的内容都缺少实践,站着说话不腰疼,对于我这样的菜鸟感觉是这样的。 比如这条,比如有个巨类: CHugeClass { function0(); function1(); function2(); function3(); .... f...  

评分

其实我想看个实践,别人的方法。 副标题叫Best Practices,但是Practice很少。 这本书的内容都缺少实践,站着说话不腰疼,对于我这样的菜鸟感觉是这样的。 比如这条,比如有个巨类: CHugeClass { function0(); function1(); function2(); function3(); .... f...  

评分

名字起的很有吸引力,其实内容很多章节讲的东西,都是<<effective c++>>里面的,我不知道原版书的文采怎么样?所以我不好妄加评论,但这本中文版的译者的翻译水平,我真的不敢苟同,翻译的僵硬,晦涩,缺乏灵活性,估计就是逐字翻译的,唉,浪费了我几十块钱,买了一本多余的书!  

评分

名字起的很有吸引力,其实内容很多章节讲的东西,都是<<effective c++>>里面的,我不知道原版书的文采怎么样?所以我不好妄加评论,但这本中文版的译者的翻译水平,我真的不敢苟同,翻译的僵硬,晦涩,缺乏灵活性,估计就是逐字翻译的,唉,浪费了我几十块钱,买了一本多余的书!  

用户评价

评分

这本《C++编程规范》的作者显然在软件工程领域有着深厚的造诣,从我对这本书的初步浏览来看,它不仅仅是一本枯燥的规则集合,更像是一本精心编排的“武功秘籍”。首先,我得说,书中对现代C++特性的理解和应用非常到位。例如,它对移动语义(Move Semantics)在性能优化中的作用阐述得极其透彻,远超我之前阅读过的几本老牌经典教材。作者没有停留在“为什么要做”的层面,而是深入到了“如何做得更优”的细节,通过大量的代码示例对比,直观地展示了遵循规范与不遵循规范在实际运行效率上的巨大差异。我特别欣赏它对“零成本抽象”原则的坚持,书中很多看似繁琐的规范,最终都能追溯到如何最大限度地榨取硬件性能,同时保持代码的可读性和可维护性。这种对底层原理的深刻洞察,让这本书的价值瞬间提升了一个档次,它教给读者的不仅是写代码的格式,更是编写高效、健壮系统的核心思想。如果说有什么遗憾,那就是对于某些前沿的并发模型,如C++20的Ranges库在规范层面的集成度还可以再加强一些,但瑕不掩瑜,这已然是一部值得反复研读的案头必备之作。

评分

坦白讲,我原本以为这会是一本非常枯燥、需要硬啃的书,因为“规范”二字听起来就和“无聊”挂钩。然而,这本书的叙事方式非常具有吸引力。作者似乎非常懂得读者的心理,他没有采用那种居高临下的说教口吻,而是用一种分享经验、共同进步的姿态来引导我们。比如,在讲解异常安全性的章节时,作者没有直接抛出RAII的定义,而是先描述了一个经典的资源泄漏场景,让读者亲身体会到不规范操作的痛苦,然后再顺理成章地引出规范要求,这种“痛点引导”的教学方法,极大地增强了知识的记忆深度。而且,书中的插图和流程图设计得非常精美且富有启发性,它们有效地将复杂的控制流和内存管理逻辑可视化了。这对于我这种更偏爱视觉学习的程序员来说,简直是福音。它将复杂的C++特性“翻译”成了易于理解的视觉语言,使得原本可能需要花费数小时理解的抽象概念,在几分钟内就能豁然开朗。这使得学习过程本身变成了一种享受,而不是负担。

评分

作为一名资深的C++开发者,我对语言特性的掌握自认为已经相当深入,但阅读《C++编程规范》的过程中,仍然不断有“原来如此”的瞬间。这本书的价值在于它对那些“大家都知道,但很少人能写对”的边缘情况进行了极其细致的打磨。举个例子,书中关于模板元编程的规范部分,它没有仅仅停留在模板的语法层面,而是深入到如何利用SFINAE(Substitution Failure Is Not An Error)原则来构建类型萃取器,并给出了业界公认的最佳实践模板结构。这对于我日常工作中需要处理复杂泛型库和框架的情况来说,提供了直接可用的、经过实战检验的蓝图。此外,书中对内存模型和原子操作的规范部分,清晰地区分了不同编译器和平台下的潜规则,指明了如何才能真正写出跨平台且线程安全的底层代码。很多其他资料只是简单提及了`std::atomic`,但这本书却详细探讨了内存顺序(Memory Ordering)对性能和正确性的双重影响,其深度令人叹服。

评分

我是一名刚刚从脚本语言转向C++的初学者,我购买这本书的初衷是希望能快速掌握C++的“规矩”,避免养成坏习惯。这本书的结构设置非常友好地兼顾了我们这类新人的需求。虽然它讨论的主题非常深入,但其章节的逻辑组织非常清晰,总能让人知道当前学习的内容在整个编程体系中所处的位置。最让我感到惊喜的是,它在介绍完一个规范后,通常会附带一个“反面教材”的对比区,明确指出如果不遵守该规范会导致哪些安全漏洞或性能瓶颈,这种对比教学法对我理解“为什么需要规范”至关重要。它没有用深奥的术语来吓退新手,而是用贴近实际问题的例子来展示规范的力量。这本书就像一位经验丰富的前辈,没有直接扔给我复杂的算法,而是先教会我如何安全、整洁地搭建我的“工具箱”和“工作台”。这套基础打得扎实,让我对未来深入学习更复杂的C++特性充满了信心,它真正做到了“授人以渔”,而非仅仅“授人以鱼”。

评分

我是一名资深的系统架构师,过去十年里,我见证了无数团队因为缺乏统一的编码标准而陷入“代码孤岛”和“技术债”的泥潭。因此,我带着一种近乎挑剔的眼光来审视这本《C++编程规范》,而这本书的表现,完全超出了我的预期。它最突出的特点在于其“面向团队协作”的设计哲学。书中关于命名约定、头文件依赖管理以及宏使用的部分,简直可以作为我们公司新员工入职培训的指定教材。我尤其赞赏作者对于“防御性编程”的强调,书中用了一个专门的章节来讨论如何在编译期和运行期捕获潜在的错误,特别是那些在大型跨平台项目中极易被忽视的边界条件处理。这种前瞻性的设计思维,使得代码在投入维护阶段后,其生命周期成本大大降低。与市面上其他侧重于语法层面的指南不同,本书的视野更宏大,它将编程规范提升到了架构设计的高度,强调规范是实现长期软件健康的关键基石。这种高度的系统性,让我确信,这本书将成为未来我们代码审查流程中的重要参考手册。

评分

技巧比较实用

评分

现代c++程序员必读。

评分

现代c++程序员必读。

评分

技巧比较实用

评分

技巧比较实用

本站所有内容均为互联网搜索引擎提供的公开搜索信息,本站不存储任何数据与内容,任何内容与数据均与本站无关,如有需要请联系相关搜索引擎包括但不限于百度google,bing,sogou

© 2026 onlinetoolsland.com All Rights Reserved. 本本书屋 版权所有