C++.Coding.Standards.1918.Rules.Guidelines [Electronic resources]

Herb Sutter, Andrei Alexandrescu

نسخه متنی -صفحه : 521/ 3
نمايش فراداده

Table of Contents
C++ Coding Standards: 101 Rules, Guidelines, and Best Practices
By Herb Sutter, Andrei Alexandrescu
Publisher: Addison Wesley Professional
Pub Date: October 25, 2004
ISBN: 0-321-11358-6
Pages: 240

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