Why not include all the standard headers always?

Besides

  • namespace pollution
  • compilation time (although reducable by precompiled headers, it will hurt those compiling a large project once because they actually want to use it, and not develop – also you want to think about rebuilds which are necessary once in a while)

you named “Less figuring out which headers I need and in which header a certain function is” as a benefit. I agree so far as this can be true for well designed libraries and headers.

In practice however I experienced (at least with MFC/ATL) some errors which could be solved by figuring out the correct order of includes. On the other hand one day you want to resolve an issue which makes you travel across the included headers – now imagine yourself looking at tons of headerfiles actually having nothing to do with your code file.

My conclusion is: The time you save by including a bunch of unnecessary headers do not pay off if you have to maintain a large project later on. The more time you invest before starting including any headers, the more time you will safe afterwards – but mostly without actually recognizing it.

Leave a Comment