GotW #7a Solution: Minimizing Compile-Time Dependencies, Part 1—Herb Sutter

The solution to the latest GotW problem is now available. In this Item, the focus is on analyzing and managing compile-time dependencies.

    GotW #7a Solution: Minimizing Compile-Time Dependencies, Part 1

    by Herb Sutter

From the article:

Managing dependencies well is an essential part of writing solid code. C++ supports two powerful methods of abstraction: object-oriented programming and generic programming. Both of these are fundamentally tools to help manage dependencies, and therefore manage complexity. It’s telling that all of the common OO/generic buzzwords—including encapsulation, polymorphism, and type independence—along with most design patterns, are really about describing ways to manage complexity within a software system by managing the code’s interdependencies.

When we talk about dependencies, we usually think of run-time dependencies like class interactions. In this Item, we will focus instead on how to analyze and manage compile-time dependencies. As a first step, try to identify (and root out) unnecessary headers.

Guideline: Never #include unnecessary header files.

Guideline: Prefer to #include <iosfwd> when a forward declaration of a stream will suffice.

Guideline: Never #include a header when a forward declaration will suffice.

Continue reading...

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.