CH01 -- IntroductionCH02 -- Build a Safety NetCH03 -- Be PrincipledCH04 -- Basics of Clean C++CH05 -- Advanced concepts of modern C++CH06 -- Object OrientationCH07 -- Functional ProgrammingCH08 -- Test Driven DevelopmentCH09 -- Design Patterns and IdiomsAppendix A -- Small UML GuideBibliography.;Wri
Clean C++ Sustainable Software Development Patterns and Best Practices with C++ 17
β Scribed by Roth, Stephan
- Publisher
- Apress
- Year
- 2017
- Tongue
- English
- Leaves
- 299
- Edition
- 1st edition
- Category
- Library
No coin nor oath required. For personal study only.
β¦ Synopsis
Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++,Clean C++is exactly what you need. It is written to help C++ developers of all skill levels and shows by example how to write understandable, flexible, maintainable, and efficient C++ code. Even if you are a seasoned C++ developer, there are nuggets and data points in this book that you will find useful in your work.
If you don't take care with your code, you can produce a large, messy, and unmaintainable beast in any programming language. However, C++ projects in particular are prone to be messy and tend to slip into bad habits. Lots of C++ code that is written today looks as if it was written in the 1980s.
It seems that C++ developers have been forgotten by those who preach Software Craftsmanship and Clean Code principles. The Web is full of bad, but apparently very fast and highly optimized C++ code examples, with cruel syntax that completely ignores elementary principles of good design and well-written code. This book will explain how to avoid this scenario and how to get the most out of your C++ code. You'll find your coding becomes more efficient and, importantly, more fun.
What You'll Learn
Gain sound principles and rules for clean coding in C++
Carry out test driven development (TDD)
Discover C++ design patterns and idioms
Apply these design patterns
Who This Book Is For
Any C++ developer and software engineer with an interest in producing better code.
β¦ Table of Contents
Contents at a Glance......Page 5
Contents......Page 6
About the Author......Page 12
About the Technical Reviewer......Page 13
Acknowledgments......Page 14
Chapter 1: Introduction......Page 15
Software Entropy......Page 16
Clean Code......Page 17
C++11 β The Beginning of a New Era......Page 18
Sidebars......Page 19
Coding Style......Page 20
UML Diagrams......Page 21
The Need for Testing......Page 22
Introduction into Testing......Page 24
Unit Tests......Page 26
What about QA?......Page 27
Unit Test Naming......Page 28
Unit Test Independence......Page 29
One Assertion per Test......Page 30
Exclude Third-Party Code......Page 31
Donβt Mix Test Code with Production Code......Page 32
Test Doubles (Fake Objects)......Page 35
What Is a Principle?......Page 39
YAGNI......Page 40
Information Hiding......Page 41
Strong Cohesion......Page 44
Loose Coupling......Page 47
The Boy Scout Rule......Page 51
Good Names......Page 53
Names Should Be Self-Explanatory......Page 55
Use Names from the Domain......Page 56
Choose Names at an Appropriate Level of Abstraction......Page 57
Avoid Cryptic Abbreviations......Page 58
Avoid Hungarian Notation and Prefixes......Page 59
Comments......Page 60
Do Not Comment Obvious Things......Page 61
Donβt Write Block Comments......Page 62
Donβt Use Comments to Substitute Version Control......Page 64
The Rare Cases Where Comments Are Useful......Page 65
Documentation Generation from Source Code......Page 66
Functions......Page 68
One Thing, No More!......Page 70
βBut the Call Time Overhead!β......Page 71
Function Naming......Page 72
Arguments and Return Values......Page 73
Number of Arguments......Page 74
Avoid Flag Arguments......Page 75
Avoid Output Arguments......Page 77
Donβt Pass or Return 0 (NULL, nullptr)......Page 79
Prefer simple object construction on the stack instead of on the heap......Page 80
The Power of const correctness......Page 82
Prefer C++ Strings and Streams over Old C-Style char*......Page 84
Avoid Using printf(), sprintf(), gets(), etc.......Page 86
Prefer Standard Library Containers over Simple C-style Arrays......Page 89
Use C++ casts Instead of Old C-Style Casts......Page 92
Avoid Macros......Page 94
Managing Resources......Page 96
Smart Pointers......Page 98
Unique Ownership with std::unique_ptr
Shared Ownership with std::shared_ptr
No Ownership, but Secure Access with std::weak_ptr
Managing Proprietary Resources......Page 104
We Like to Move It......Page 105
What Are Move Semantics?......Page 106
The Matter with Those lvalues and rvalues......Page 107
rvalue References......Page 108
Donβt Enforce Move Everywhere......Page 109
The Rule of Zero......Page 110
The Compiler Is Your Colleague......Page 113
Automatic Type Deduction......Page 114
Computations during Compile Time......Page 117
Variable Templates......Page 119
Donβt Allow Undefined Behavior......Page 120
Type-Rich Programming......Page 121
Know Your Libraries......Page 127
Take Advantage of
Easier Parallelization of Algorithms Since C++17......Page 129
Sorting and Output of a Container......Page 131
Comparing Two Sequences......Page 132
Take Advantage of Boost......Page 133
Proper Exception and Error Handling......Page 134
Prevention Is Better Than Aftercare......Page 135
Strong Exception-Safety......Page 136
The No-Throw Guarantee......Page 137
An Exception Is an Exception β Literally!......Page 139
Define User-Specific Exception Types......Page 140
Pay Attention to the Correct Order of Catch-Clauses......Page 142
Object-Oriented Thinking......Page 144
Principles for Good Class Design......Page 146
Keep Classes Small......Page 147
Open-Closed Principle (OCP)......Page 148
The Square-Rectangle Dilemma......Page 149
Favor Composition over Inheritance......Page 158
Interface Segregation Principle (ISP)......Page 160
Acyclic Dependency Principle......Page 161
Dependency Inversion Principle (DIP)......Page 164
Donβt Talk to Strangers (Law of Demeter)......Page 169
Tell, Donβt Ask!......Page 174
Avoid Static Class Members......Page 176
Chapter 7: Functional Programming......Page 178
What Is Functional Programming?......Page 179
What Is a Function?......Page 180
Pure vs. Impure Functions......Page 181
Functional Programming with C++ Templates......Page 182
Generator......Page 184
Predicates......Page 187
Binders and Function Wrappers......Page 190
Lambda Expressions......Page 192
Generic Lambda Expressions (C++14)......Page 194
Higher-Order Functions......Page 195
Map, Filter, and Reduce......Page 196
Filter......Page 197
Reduce (Fold)......Page 198
Fold Expressions in C++17......Page 199
Clean Code in Functional Programming......Page 200
Chapter 8: Test-Driven Development......Page 202
The Drawbacks of Plain Old Unit Testing (POUT)......Page 203
The Workflow of TDD......Page 204
TDD by Example: The Roman Numerals Code Kata......Page 207
Preparations......Page 208
The First Test......Page 210
The Third Test and the Tidying Afterwards......Page 212
More Sophisticated Tests with a Custom Assertion......Page 216
Itβs Time to Clean Up Again......Page 218
Approaching the Finish Line......Page 221
Done!......Page 222
The Advantages of TDD......Page 224
When We Should Not Use TDD......Page 226
Design Principles vs. Design Patterns......Page 227
Dependency Injection (DI)......Page 228
The Singleton Anti-Pattern......Page 229
Dependency Injection to the Rescue......Page 232
Adapter......Page 240
Strategy......Page 241
Command......Page 245
Command Processor......Page 249
Composite......Page 252
Observer......Page 255
Simple Factory......Page 260
Facade......Page 263
Money Class......Page 264
Special Case Object (Null Object)......Page 267
What Is an Idiom?......Page 270
The Power of Immutability......Page 271
Substitution Failure Is Not an Error (SFINAE)......Page 272
The Copy-and-Swap Idiom......Page 275
Pointer to Implementation (PIMPL)......Page 278
Class......Page 282
Interface......Page 284
Association......Page 287
Generalization......Page 289
Dependency......Page 290
Components......Page 291
Stereotypes......Page 292
Bibliography......Page 293
Index......Page 295
β¦ Subjects
Science;Computer Science
π SIMILAR VOLUMES
Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++,<i>Clean C++</i>i
<div><div>Write maintainable, extensible, and durable software with modern C++. This book, updated for the recently released C++20 standard, is a must for every developer, software architect, or team leader who is interested in well-crafted C++ code, and thus also wants to save development costs. If
Write maintainable, extensible, and durable software with modern C++. This book, updated for the recently released C++20 standard, is a must for every developer, software architect, or team leader who is interested in well-crafted C++ code, and thus also wants to save development costs. If you want
<p>Write maintainable, extensible, and durable software with modern C++. This book is a must for every developer, software architect, or team leader who is interested in good C++ code, and thus also wants to save development costs. If you want to teach yourself about writing clean C++, <i>Clean C++<