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 fi开发者_如何学编程les 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?
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?
Size after running the preprocessor is truly unimportant; be concerned with the size BEFORE running the preprocessor. And only if your inclusion tree is very confusing should you be particularly concerned; if it's of a reasonable depth and complexity, you should spend your time working on something that has more of an impact on your code.
精彩评论