๐”– Scriptorium
โœฆ   LIBER   โœฆ

๐Ÿ“

C++ coding standards: 101 rules, guidelines, and best practices

โœ Scribed by Sutter, Herb;Alexandrescu, Andrei


Publisher
Addison-Wesley Professional
Year
2004;2011
Tongue
English
Leaves
239
Series
The C++ in-depth series
Edition
10. print
Category
Library

โฌ‡  Acquire This Volume

No coin nor oath required. For personal study only.

โœฆ Synopsis


Every software development team should have and follow a coding standard.It's even better when what the coding standard requires is actually consistent, reasonable, and correct.Coding standards have many advantages: They improve code quality. This happens automatically when following agood, simple set of guidelines.They improve development speed, because the programmer doesn't need toalways make decisions starting from first principles.They enhance teamwork by eliminating needless debates on inconsequentialissues and by making it easy for teammates to read and maintain each other'scode.The coding standards introduced by this book are a collection of guidelines forwriting high-quality C++ code.**They are the distilled conclusions of a rich collective experience of the C++community. Until now, this body of knowledge has been available only asfolklore or spread in bits and pieces throughout books.

โœฆ Table of Contents


Cover......Page 1
Contents......Page 8
Preface......Page 12
Organizational and Policy Issues......Page 18
0. Don't sweat the small stuff. (Or: Know what not to standardize.)......Page 19
1. Compile cleanly at high warning levels.......Page 21
2. Use an automated build system.......Page 24
3. Use a version control system.......Page 25
4. Invest in code reviews.......Page 26
Design Style......Page 28
5. Give one entity one cohesive responsibility.......Page 29
6. Correctness, simplicity, and clarity come first.......Page 30
7. Know when and how to code for scalability.......Page 31
8. Don't optimize prematurely.......Page 33
9. Don't pessimize prematurely.......Page 35
10. Minimize global and shared data.......Page 36
11. Hide information.......Page 37
12. Know when and how to code for concurrency.......Page 38
13. Ensure resources are owned by objects. Use explicit RAII and smart pointers.......Page 41
Coding Style......Page 44
14. Prefer compile- and link-time errors to run-time errors.......Page 45
15. Use const proactively.......Page 47
16. Avoid macros.......Page 49
17. Avoid magic numbers.......Page 51
18. Declare variables as locally as possible.......Page 52
19. Always initialize variables.......Page 53
20. Avoid long functions. Avoid deep nesting.......Page 55
21. Avoid initialization dependencies across compilation units.......Page 56
22. Minimize definitional dependencies. Avoid cyclic dependencies.......Page 57
23. Make header files self-sufficient.......Page 59
24. Always write internal # include guards. Never write external # include guards.......Page 60
Functions and Operators......Page 62
25. Take parameters appropriately by value, (smart) pointer, or reference.......Page 63
26. Preserve natural semantics for overloaded operators.......Page 64
27. Prefer the canonical forms of arithmetic and assignment operators.......Page 65
28. Prefer the canonical form of ++ and --. Prefer calling the prefix forms.......Page 67
29. Consider overloading to avoid implicit type conversions.......Page 68
30. Avoid overloading &&, ||, or, (comma).......Page 69
31. Don't write code that depends on the order of evaluation of function arguments.......Page 71
Class Design and Inheritance......Page 72
32. Be clear what kind of class you're writing.......Page 73
33. Prefer minimal classes to monolithic classes.......Page 74
34. Prefer composition to inheritance.......Page 75
35. Avoid inheriting from classes that were not designed to be base classes.......Page 77
36. Prefer providing abstract interfaces.......Page 79
37. Public inheritance is substitutability. Inherit, not to reuse, but to be reused.......Page 81
38. Practice safe overriding.......Page 83
39. Consider making virtual functions nonpublic, and public functions nonvirtual.......Page 85
40. Avoid providing implicit conversions.......Page 87
41. Make data members private, except in behaviorless aggregates (C-style structs).......Page 89
42. Don't give away your internals.......Page 91
43. Pimpl judiciously.......Page 93
44. Prefer writing nonmember nonfriend functions.......Page 96
45. Always provide new and delete together.......Page 97
46. If you provide any class- specific new, provide all of the standard forms ( plain, in-place, and nothrow).......Page 99
Construction, Destruction, and Copying......Page 102
47. Define and initialize member variables in the same order.......Page 103
48. Prefer initialization to assignment in constructors.......Page 104
49. Avoid calling virtual functions in constructors and destructors.......Page 105
50. Make base class destructors public and virtual, or protected and nonvirtual.......Page 107
51. Destructors, deallocation, and swap never fail.......Page 109
52. Copy and destroy consistently.......Page 111
53. Explicitly enable or disable copying.......Page 112
54. Avoid slicing. Consider Clone instead of copying in base classes.......Page 113
55. Prefer the canonical form of assignment.......Page 116
56. Whenever it makes sense, provide a no-fail swap (and provide it correctly).......Page 117
Namespaces and Modules......Page 120
57. Keep a type and its nonmember function interface in the same namespace.......Page 121
58. Keep types and functions in separate namespaces unless they're specifically intended to work together.......Page 123
59. Don't write namespace usings in a header file or before an #include.......Page 125
60. Avoid allocating and deallocating memory in different modules.......Page 128
61. Don't define entities with linkage in a header file.......Page 129
62. Don't allow exceptions to propagate across module boundaries.......Page 131
63. Use sufficiently portable types in a module's interface.......Page 133
Templates and Genericity......Page 136
64. Blend static and dynamic polymorphism judiciously.......Page 137
65. Customize intentionally and explicitly.......Page 139
66. Don't specialize function templates.......Page 143
67. Don't write unintentionally nongeneric code.......Page 145
Error Handling and Exceptions......Page 146
68. Assert liberally to document internal assumptions and invariants.......Page 147
69. Establish a rational error handling policy, and follow it strictly.......Page 149
70. Distinguish between errors and non-errors.......Page 151
71. Design and write error-safe code.......Page 154
72. Prefer to use exceptions to report errors.......Page 157
73. Throw by value, catch by reference.......Page 161
74. Report, handle, and translate errors appropriately.......Page 162
75. Avoid exception specifications.......Page 163
STL: Containers......Page 166
76. Use vector by default. Otherwise, choose an appropriate container.......Page 167
77. Use vector and string instead of arrays.......Page 169
78. Use vector (and string::c_str) to exchange data with non-C++ APIs.......Page 170
79. Store only values and smart pointers in containers.......Page 171
80. Prefer push_back to other ways of expanding a sequence.......Page 172
81. Prefer range operations to single-element operations.......Page 173
82. Use the accepted idioms to really shrink capacity and really erase elements.......Page 174
STL: Algorithms......Page 176
83. Use a checked STL implementation.......Page 177
84. Prefer algorithm calls to handwritten loops.......Page 179
85. Use the right STL search algorithm.......Page 182
86. Use the right STL sort algorithm.......Page 183
87. Make predicates pure functions.......Page 185
88. Prefer function objects over functions as algorithm and comparer arguments.......Page 187
89. Write function objects correctly.......Page 189
Type Safety......Page 190
90. Avoid type switching; prefer polymorphism.......Page 191
91. Rely on types, not on representations.......Page 193
92. Avoid using reinterpret_cast.......Page 194
93. Avoid using static_cast on pointers.......Page 195
94. Avoid casting away const.......Page 196
95. Don't use C-style casts.......Page 197
96. Don't memcpy or memcmp non-PODs.......Page 199
97. Don't use unions to reinterpret representation.......Page 200
98. Don't use varargs (ellipsis).......Page 201
99. Don't use invalid objects. Don't use unsafe functions.......Page 202
100. Don't treat arrays polymorphically.......Page 203
Bibliography......Page 204
Summary of Summaries......Page 212
A......Page 226
C......Page 227
D......Page 229
F......Page 230
I......Page 231
M......Page 232
O......Page 233
Q......Page 234
S......Page 235
U......Page 236
Z......Page 237

โœฆ Subjects


Computer Science;Programming;Science;Technical;Nonfiction;Software;Reference;Computers;Technology;Coding;Engineering


๐Ÿ“œ SIMILAR VOLUMES


C++ Coding Standards: 101 Rules, Guideli
โœ Herb Sutter, Andrei Alexandrescu ๐Ÿ“‚ Library ๐Ÿ“… 2004 ๐Ÿ› Addison-Wesley Professional ๐ŸŒ English

Consistent, high-quality coding standards improve software quality, reduce time-to-market, promote teamwork, eliminate time wasted on inconsequential matters, and simplify maintenance. Now, two of the world's most respected C++ experts distill the rich collective experience of the global C++ communi

C++ Coding Standards: 101 Rules, Guideli
โœ Herb Sutter, Andrei Alexandrescu ๐Ÿ“‚ Library ๐Ÿ“… 2004 ๐Ÿ› Addison-Wesley Professional ๐ŸŒ English

The authors cover virtually every facet of C++ programming: design and coding style, functions, operators, class design, inheritance, construction/destruction, copying, assignment, namespaces, modules, templates, genericity, exceptions, STL containers and algorithms, and more. Each standard is descr