معرفی کتاب «C [plus plus] coding standards: 101 rules, guidelines, and best practices» نوشتهٔ Herb Sutter & Andrei Alexandrescu، منتشرشده توسط نشر Addison-Wesley Professional در سال 2004. این کتاب در 3 صفحه، فرمت pdf، زبان انگلیسی ارائه شده است. «C [plus plus] coding standards: 101 rules, guidelines, and best practices» در دستهٔ برنامهنویسی قرار دارد.
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. 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
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++ Community Into A Set Of Coding Standards That Every Developer And Development Team Can Understand And Use As A Basis For Their Own Coding Standards.
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 Described Concisely, With Practical Examples. From Type Definition To Error Handling, This Book Presents C++ Best Practices, Including Some That Have Only Recently Been Identified And Standardized-techniques You May Not Know Even If You've Used C++ For Years. Along The Way, You'll Find Answers To Questions Like
- what's Worth Standardizingand What Isn't?
- what Are The Best Ways To Code For Scalability?
- what Are The Elements Of A Rational Error Handling Policy?
- how (and Why) Do You Avoid Unnecessary Initialization, Cyclic, And Definitional Dependencies?
- when (and How) Should You Use Static And Dynamic Polymorphism Together?
- how Do You Practice Safe Overriding?
- when Should You Provide A No-fail Swap?
- why And How Should You Prevent Exceptions From Propagating Across Module Boundaries?
- why Shouldn't You Write Namespace Declarations Or Directives In A Header File?
- why Should You Use Stl Vector And String Instead Of Arrays?
- how Do You Choose The Right Stl Search Or Sort Algorithm?
- what Rules Should You Follow To Ensure Type-safe Code?
whether You're Working Alone Or With Others, C++ Coding Standards Will Help You Write Cleaner Codeand Write It Faster, With Fewer Hassles And Less Frustration.
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++ community into a set of coding standards that every developer and development team can understand and use as a basis for their own coding standards. 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 described concisely, with practical examples. From type definition to error handling, this book presents C++ best practices, including some that have only recently been identified and standardized-techniques you may not know even if you've used C++ for years. Along the way, you'll find answers to questions like What's worth standardizing--and what isn't? What are the best ways to code for scalability? What are the elements of a rational error handling policy? How (and why) do you avoid unnecessary initialization, cyclic, and definitional dependencies? When (and how) should you use static and dynamic polymorphism together? How do you practice "safe" overriding? When should you provide a no-fail swap? Why and how should you prevent exceptions from propagating across module boundaries? Why shouldn't you write namespace declarations or directives in a header file? Why should you use STL vector and string instead of arrays? How do you choose the right STL search or sort algorithm? What rules should you follow to ensure type-safe code? Whether you're working alone or with others, C++ Coding Standards will help you write cleaner code--and write it faster, with fewer hassles and less frustration Covering the facets of C++ programming, this book discusses: design and coding style, functions, operators, class design, inheritance, construction/destruction, copying, assignment, namespaces, modules, templates, genericity, exceptions, and STL containers and algorithms. Each standard is described concisely, with practical examples.