Minimize Including Header Files

One of the most important techniques for making C++ code compile quickly is minimizing unnecessary inclusion of header files.

Header files can create deep chains of dependencies. For example, one header includes five others. Those five each include another five. Before long, a single #include can drag in dozens—or even hundreds—of files that the compiler now needs to process.

This not only increases compilation time but also adds unnecessary complexity to your project.

A common mistake is to lazily include a header file every time you declare a function that uses a type. In many cases, that's completely unnecessary.

C++ allows you to forward declare many types. If your function only takes a pointer or reference to a type, the compiler doesn't need to know the definition—just that the type exists.

For example:

class BASstring;

void APPprocess(const BASstring& Value);

You don’t need to include BASstring.h in your header for this. The full definition is only required in the .cpp file where you use the type's data members or need its full definition.

This habit can have huge cumulative effects. Instead of headers pulling in a cascade of other headers, you've contained the dependency graph and prevented it from exploding. As a result, the compiler reads much less code, incremental builds are much faster, and your project remains more maintainable and understandable.

Reducing compilation time is more than just a convenience. Fast compile times help you stay in the flow, encourage experimentation, and make you a more productive developer overall.

So, when you write headers, prefer forward declarations whenever possible, and only include headers when absolutely necessary. This simple practice makes a big difference, especially in larger codebases.