Search code examples
c++include

At what point should I fight deep #include trees


I am currently working on a C++ project and am quite often using templates. Now I wonder if I should start worrying more about / cleaning up deep #include trees.

After removing not-needed includes, the code size after running the C preprocessor gcc -E on my .cpp files is:

  • 50% of the files: ~40k lines,
  • 30% of the files: between 40k and 80k lines,
  • 20% of the files: between 80k and 180k lines.

Is there some standard if these are large/small line counts? At what point does it become worth being more aggressive in reducing the #includes?


Solution

  • It doesn't matter how many lines of code there are. What matters is whether you feel build times are tolerable. If it takes too long to compile, then you need to speed it up, for example by eliminating unneeded includes.

    But as long as you don't have a problem with build times, why bother worrying about whether you include too much?