Sustainable Software Development With Clean C++

Retired

This book is no longer available for sale.

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)

About the Author

Stephan Roth
Stephan Roth

Stephan is coach, consultant and trainer for systems and software engineering with German consultancy company oose Innovative Informatik eG located in Hamburg. Before he joined oose, he worked for many years as a software developer, software architect and systems engineer in the field of radio reconnaissance and communication intelligence systems. He has developed sophisticated applications, especially in a high performance system environment, and graphical user interfaces using C++ and other programming languages. Stephan is an active supporter of the Software Craftsmanship movement and is concerned with principles and practices of Clean Code Development (CCD).

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
      • 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
      • Type-rich programming
      • Take advantage of <algorithm>
        • Sorting and output of a container
        • Comparing two sequences
      • Take advantage of Boost
      • Logging
    • 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
  • 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
    • Bibliography

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...

80% Royalties. Earn $16 on a $20 book.

We pay 80% royalties. That's not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earnedover $13 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

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub