As I started typing a supposedly-simple post on header files, I realized that what I was explaining could easily be split into various posts and significantly extended with additional content, so here comes a new (short) series on these special little files in the need of careful attention.

Quoting the Wikipedia:

A header file is a file that allows programmers to separate certain elements of a program’s source code into reusable files. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required. This is to keep the interface in the header separate from the implementation.

Header files are mostly used in C and C++ and are a really poor alternative to a proper modules system (which both of these programming languages lack). However, they are a fact of life and handling them properly is a prerequisite for having a sane code base that is readable and quick to build.

In this series we will see a few tricks on good header file design both for C and C++, including topics like why should header files be self-contained, how to handle C++ inline definitions or a more elaborate description of why they are not a good modules system.

Stay tuned! And keep in mind that this introductory post is your best chance to answer this question: are there any specific topics in this area that you’d like to see covered?