E-Book, Englisch, 491 Seiten
Roth Clean C++20
2. Auflage 2021
ISBN: 978-1-4842-5949-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
Sustainable Software Development Patterns and Best Practices
E-Book, Englisch, 491 Seiten
Reihe: Professional and Applied Computing (R0)
ISBN: 978-1-4842-5949-8
Verlag: Apress
Format: PDF
Kopierschutz: 1 - PDF Watermark
- Gain sound principles and rules for clean coding in C++
- Carry out test-driven development (TDD)
- Better modularize your C++ code base
- Discover and apply C++ design patterns and idioms
- Write C++ code in both object-oriented and functional programming styles
Autoren/Hrsg.
Weitere Infos & Material
1;Table of Contents;5
2;About the Author;12
3;About the Technical Reviewer;13
4;Acknowledgments;14
5;Chapter 1: Introduction;15
5.1;Software Entropy;17
5.1.1;Why C++?;18
5.2;Clean Code;20
5.3;C++11: The Beginning of a New Era;20
5.4;Who This Book Is For;21
5.5;Conventions Used in This Book;22
5.5.1;Sidebars;23
5.5.2;Notes, Tips, and Warnings;23
5.5.3;Code Samples;23
5.5.3.1;Coding Style;24
5.5.3.2;C++ Core Guidelines;25
5.6;Companion Website and Source Code Repository;25
5.7;UML Diagrams;26
6;Chapter 2: Build a Safety Net;27
6.1;The Need for Testing;27
6.2;Introduction to Testing;30
6.3;Unit Tests;33
6.4;What About QA?;35
6.5;Rules for Good Unit Tests;36
6.5.1;Test Code Quality;36
6.5.2;Unit Test Naming;36
6.5.3;Unit Test Independence;38
6.5.4;One Assertion per Test;39
6.5.5;Independent Initialization of Unit Test Environments;40
6.5.6;Exclude Getters and Setters;41
6.5.7;Exclude Third-Party Code;41
6.5.8;Exclude External Systems;42
6.5.9;What Do We Do with the Database?;42
6.5.10;Don’t Mix Test Code with Production Code;43
6.5.11;Tests Must Run Fast;46
6.5.12;How Do You Find a Test’s Input Data?;47
6.5.12.1;Equivalence Partitioning;47
6.5.12.2;Boundary Value Analysis;49
6.5.13;Test Doubles (Fake Objects);50
7;Chapter 3: Be Principled;54
7.1;What Is a Principle?;54
7.2;KISS;55
7.3;YAGNI;56
7.4;DRY;57
7.4.1;It’s About Knowledge!;57
7.4.2;Building Abstractions Is Sometimes Hard;58
7.5;Information Hiding;61
7.6;Strong Cohesion;66
7.7;Loose Coupling;69
7.8;Be Careful with Optimizations;73
7.9;Principle of Least Astonishment (PLA);74
7.10;The Boy Scout Rule;75
7.10.1;Collective Code Ownership;76
8;Chapter 4: Basics of Clean C++;77
8.1;Good Names;78
8.1.1;Names Should Be Self-Explanatory;80
8.1.2;Use Names from the Domain;82
8.1.3;Choose Names at an Appropriate Level of Abstraction;84
8.1.4;Avoid Redundancy When Choosing a Name;85
8.1.5;Avoid Cryptic Abbreviations;86
8.1.6;Avoid Hungarian Notation and Prefixes;87
8.1.7;Avoid Using the Same Name for Different Purposes;88
8.2;Comments;89
8.2.1;Let the Code Tell the Story;89
8.2.2;Do Not Comment Obvious Things;90
8.2.3;Don’t Disable Code with Comments;91
8.2.4;Don’t Write Block Comments;92
8.2.4.1;Don’t Use Comments to Substitute Version Control;96
8.2.5;The Rare Cases Where Comments Are Useful;96
8.2.5.1;Documentation Generation from Source Code;98
8.3;Functions;101
8.3.1;One Thing, No More!;105
8.3.2;Let Them Be Small;106
8.3.2.1;“But the Call Time Overhead!”;107
8.3.3;Function Naming;108
8.3.4;Use Intention-Revealing Names;109
8.3.5;Parameters and Return Values;110
8.3.5.1;Number of Parameters;110
8.3.5.2;Avoid Flag Parameters;112
8.3.5.3;Avoid Output Parameters;115
8.3.5.4;Don’t Pass or Return 0 (NULL, nullptr);116
8.3.5.5;Strategies for Avoiding Regular Pointers;119
8.3.5.5.1;Choose simple object construction on the stack instead of on the heap;119
8.3.5.5.2;In a function’s argument list, use (const) references instead of pointers;122
8.3.5.5.3;If it is inevitable to deal with a pointer to a resource, use a smart one;123
8.3.5.5.4;If an API returns a raw pointer...;123
8.3.5.6;The Power of const Correctness;124
8.4;About Old C-Style in C++ Projects;126
8.4.1;Choose C++ Strings and Streams over Old C-Style char*;127
8.4.2;Avoid Using printf(), sprintf(), gets(), etc.;129
8.4.3;Choose Standard Library Containers over Simple C-Style Arrays;134
8.4.4;Use C++ Casts Instead of Old C-Style Casts;137
8.4.5;Avoid Macros;140
9;Chapter 5: Advanced Concepts of Modern C++;143
9.1;Managing Resources;144
9.1.1;Resource Acquisition Is Initialization (RAII);146
9.1.2;Smart Pointers;147
9.1.2.1;Unique Ownership with std::unique_ptr




