Sustainable Software Development With Clean C++
This book is 60% complete
Last updated on 2016-04-09
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.
- About The Author
- Why C++?
- Who this book is for
Conventions used in this book
- 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
- Information hiding
- High cohesion
- Loose coupling
- Be careful with optimizations
- Principle of Least Astonishment (PLA)
- The Boy Scout Rule
3. Basics of clean C++
- 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
- Avoid comments
- Do not comment obvious things
- Documentation generation from source code
- Don’t disable code with comments
- Don’t write block comments
- 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,
- Strategies to avoid regular pointers
- Const correctness
- Write exception-safe code
- Don’t allow undefined behaviour
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
- 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
- Sorting and output of a container
- Comparing two sequences
- Take advantage of Boost
- Good names
4. Object Orientation
- Object-Oriented Thinking
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
- Template Method
- Command Processor
- Factory Method
- Money Class
- Special Case Object
- Fluent Interface
- What is an idiom?
Common C++ Idioms
- Function-like objects (Functor)
- Virtual constructor
- 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
- 5. Test Driven Development
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. Free App. 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), EPUB (for phones and tablets), MOBI (for Kindle) and in the free Leanpub App (for Mac, Windows, iOS and Android). 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.