Sustainable Software Development With Clean C++
Sustainable Software Development With Clean C++
About the Book
This book has been retired!
After a full revision and completion during the last year, the completely revised and updated book will be published by Apress Media LLC under the title "Clean C++ - Sustainable Software Development With C++17" (http://www.apress.com/la/book/9781484227923). The publishing date will be approximately at the end of 2017/beginning of 2018. The book will be proofread and edited by professionals, thus it will provide a much better reading experience. Furthermore, it will be updated according to the latest developments in the C++ domain and takes also a few of the newest C++17 features into account.
I would like to take this opportunity to thank all readers for purchasing its predecessor here.
Best regards,
Stephan
(July 2017)
Table of Contents
-
- Foreword
- About The Author
-
Introduction
- Why C++?
- Who this book is for
-
Conventions used in this book
- Sidebars
-
Code samples
- Coding style
- Source code repository
- UML diagrams
-
This book is work in progress
- Outlook: upcoming chapters and topics
-
Part 1: Principles and Rules
-
1. Build a safety net!
- The need for testing
-
Introduction into testing
- Unit Tests
- What about QA?
-
Rules For Good Unit Tests
- Test code quality
- Unit test naming
- Unit test independence
- One assertion per test
- Independent initialization of Unit Test environments
- Exclude getters and setters
- Exclude 3 party code
- Exclude external systems
- And what about the database?
- Don’t mix test code with production code
- Tests must run fast
- Test doubles (Fake objects)
- C++ Test frameworks
-
2. Be principled
- What is a principle?
-
Important basic principles
- KISS
- YAGNI
- DRY
- Information hiding
- High cohesion
- Loose coupling
- Be careful with optimizations
- Principle of Least Astonishment (PLA)
- The Boy Scout Rule
-
3. Basics of clean C++
-
Good names
- Names should be self-explanatory
- Choose names at an appropriate level of abstraction
- Avoid redundancy when choosing a name
- Avoid cryptic abbreviations
- Avoid Hungarian notation and prefixes
- Avoid using the same name for different purposes
-
Comments
- Avoid comments
- Do not comment obvious things
- Documentation generation from source code
- Don’t disable code with comments
- Don’t write block comments
-
Functions
- One thing, no more!
-
Let them be small
- “But the call time overhead!”
- Function naming
- Use intention-revealing names
-
Arguments and return values
- Number of arguments
- Avoid flag arguments
- Avoid output arguments
-
Don’t pass or return 0 (NULL,
nullptr
) - Strategies to avoid regular pointers
- Const correctness
- Write exception-safe code
- Formatting
- Don’t allow undefined behaviour
-
Resource management
-
Resource Acquisition Is Initialization (RAII)
- STL smart pointers
-
Resource Acquisition Is Initialization (RAII)
-
About old C-style in C++ projects
-
Prefer C++ strings and streams over old C-style
char*
- Avoid using printf(), sprintf(), gets(), etc.
- Prefer STL containers over simple C-style arrays
-
Use C++ casts instead of old C-style casts
- reinterpret_cast and dynamic_cast are bad!
- Avoid macros
-
Prefer C++ strings and streams over old C-style
- Type-rich programming
-
Take advantage of
<algorithm>
- Sorting and output of a container
- Comparing two sequences
- Take advantage of Boost
- Logging
-
Good names
-
4. Object Orientation
- Object-Oriented Thinking
- Classes
-
Rules for good class design
- Keep classes small
- Single Responsibility Principle (SRP)
- Open-Closed Principle (OCP)
- Liskov Substitution Principle (LSP)
- Interface Segregation Principle (ISP)
- Dependency Inversion Principle (DIP)
- Misuses of classes
-
1. Build a safety net!
-
Part 2: Practices and Patterns
-
5. Test Driven Development
- The workflow of TDD
- TDD By Example: Roman Numerals
- When we should not use TDD
-
6. Design Patterns and Idioms
- What is a design pattern?
-
Some patterns, and when to use them
- Strategy
- Template Method
- Composite
- Command
- Command Processor
- Decorator
- State
- Observer
- Factory Method
- Prototype
- Adapter
- Facade
- Money Class
- Special Case Object
- Actor-Role
- Fluent Interface
- Pipeline
- What is an idiom?
-
Common C++ Idioms
- Function-like objects (Functor)
- Virtual constructor
- Traits
- Curiously Recurring Template Pattern (CRTP)
- (Private) Pointer To Implementation (PIMPL)
- Resource Acquisition Is Initialization (RAII)
- The Barton–Nackman trick
- Non-copyable Mixin
-
Appendix A: Small UML Guide
-
Class Diagrams
- Class
- Interface
- Association
- Generalization
- Dependency
- Stereotypes
-
Class Diagrams
- Bibliography
-
5. Test Driven Development
The Leanpub 60 Day 100% Happiness Guarantee
Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.
(Yes, some authors have already earned much more than that on Leanpub.)
In fact, authors have earnedover $14 millionwriting, publishing and selling on Leanpub.
Learn more about writing on Leanpub
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
Learn more about Leanpub's ebook formats and where to read them