C++ Core Guidelines Explained: Best Practices for Modern C++
- Length: 403 pages
- Edition: 1
- Language: English
- Publisher: Addison-Wesley Professional
- Publication Date: 2022-03-25
- ISBN-10: B09NSGQ4JK
- ISBN-13: 9780136875758
- Sales Rank: #0 (See Top 100 Books)
Write More Elegant C++ Programs and Improve Legacy Code
“We are very pleased to see Rainer Grimm applying his teaching skills and industrial background to tackling the hard and necessary task of making the C++ Core Guidelines accessible to more people.”
— Bjarne Stroustrup and Herb Sutter, co-editors, C++ Core Guidelines
The official C++ Core Guidelines provide consistent best practices for writing outstanding modern C++ code, but they aren’t organized for easy usage by working developers. In C++ Core Guidelines Explained, expert C++ instructor Rainer Grimm has distilled them to their essence, removing esoterica, sharing new insights and context, and presenting well-tested examples from his own training courses.
Grimm helps experienced C++ programmers use the Core Guidelines with any recent version of the language, from C++11 onward. Most of his code examples are written for C++17, with added coverage of newer versions and C++20 wherever appropriate, and references to the official C++ Core Guidelines online.
Whether you’re creating new software or improving legacy code, Grimm will help you get more value from the Core Guidelines’ most useful rules, as you write code that’s safer, clearer, more efficient, and easier to maintain.
- Apply the guidelines and the underlying programming philosophy
- Correctly use interfaces, functions, classes, enum, resources, expressions, and statements
- Optimize performance, implement concurrency and parallelism, and handle errors
- Work with constants, immutability, templates, generics, and metaprogramming
- Program in C++ style, manage source files, and use the Standard Library
Cover Page Title Page Table of Contents Contents Foreword Preface Conventions Why guidelines? Pantha rhei How to read this book? Acknowledgments About the Author Part I. The Guidelines Chapter 1. Introduction Target readership Aim Non-aims Enforcement Structure Major sections Distilled Chapter 2. Philosophy P.1. Express ideas directly in code P.2: Write in ISO Standard C++ P.3: Express intent P.4: Ideally, a program should be statically type safe P.5: Prefer compile-time checking to run-time checking P.6: What cannot be checked at compile-time should be checkable at run-time P.7: Catch run-time errors early P.8: Don’t leak any resources P.9: Don’t waste time or space P.10: Prefer immutable data to mutable data P.11: Encapsulate messy constructs, rather than spreading through the code P.12: Use supporting tools as appropriate P.13: Use support libraries as appropriate Distilled Chapter 3. Interfaces I.2: Avoid non-const global variables I.3: Avoid singletons Making good interfaces I.13: Do not pass an array as a single pointer I.27: For stable library ABI, consider the Pimpl idiom Related rules Distilled Chapter 4. Functions Function definitions Parameter passing: in and out Parameter passing: ownership semantic Value return semantics Other functions Related rules Distilled Chapter 5. Classes and Class Hierarchies Summary rules Concrete types Constructors, assignments, and destructors Class hierarchies Overloading and overloaded operators Unions Related rules Distilled Chapter 6. Enumerations Enum.1: Prefer enumerations over macros Enum.2: Use enumerations to represent sets of related named constants Enum.3: Prefer enum classes over “plain” enums Enum.5: Don’t use ALL_CAPS for enumerators Enum.6: Avoid unnamed enumerations Enum.7: Specify the underlying type of an enumeration only when necessary Enum.8: Specify enumerator values only when necessary Related Rules Distilled Chapter 7. Resource Management General rules Allocation and deallocation Smart pointers Related Rules Distilled Chapter 8. Expressions and Statements General Declarations Expressions Statements Arithmetic Related Rules Distilled Chapter 9. Performance Wrong optimizations Wrong assumptions Enable optimization Related Rules Distilled Chapter 10. Concurrency General guidelines Concurrency Parallelism Message passing Lock-free programming Related Rules Distilled Chapter 11. Error Handling Design Implementation If you can’t throw Related Rules Distilled Chapter 12. Constants and Immutability Con.1: By default, make objects immutable Con.2: By default, make member functions const Con.3: By default, pass pointers and references to consts Con.4: Use const to define objects with values that do not change after construction Con.5: Use constexpr for values that can be computed at compile-time Distilled Chapter 13. Templates and Generic Programming Use Interfaces Definition Hierarchies Variadic templates Metaprogramming Other rules Related Rules Distilled Chapter 14. C-Style Programming CPL.1: Prefer C++ to C CPL.2: If you must use C, use the common subset of C and C++, and compile the C code as C++ CPL.3: If you must use C for interfaces, use C+ + in the calling code using such interfaces Distilled Chapter 15. Source Files Interface and implementation files Namespaces Distilled Chapter 16. The Standard Library Containers Text In- and output Related Rules Distilled Part II. Supporting Sections Chapter 17. Architectural Ideas A.1: Separate stable code from less stable code A.2: Express potentially reusable parts as a library A.4: There should be no cycles among libraries Chapter 18. Non-Rules and Myths NR.1: Don’t insist that all declarations should be at the top of a function NR.2: Don’t insist to have only a single return-statement in a function NR.3: Don’t avoid exceptions NR.4: Don’t insist on placing each class declaration in its own source file NR.5: Don’t use two-phase initialization NR.6: Don’t place all cleanup actions at the end of a function and goto exit NR.7: Don’t make all data members protected Chapter 19. Profiles Pro.type: Type safety Pro.bounds: Bounds safety Pro.lifetime: Lifetime safety Chapter 20. Guideline Support Library Views Ownership pointers Assertions Utilities Part III. Appendix Appendix A. Enforcing the C++ Core Guidelines Visual Studio clang-tidy Appendix B. Concepts Appendix C. Contracts
Donate to keep this site alive
1. Disable the AdBlock plugin. Otherwise, you may not get any links.
2. Solve the CAPTCHA.
3. Click download link.
4. Lead to download server to download.