Hacker News new | ask | show | jobs
by keithflower 5301 days ago
Our experiences don't match. Avoiding nested includes has been a part of the rigorous and useful standards of a lot of important, mission-critical, large-scale projects, and is something I try to enforce in my own code.

There are numerous examples of projects which follow that recommendation. I'm told, for example, that the recommendation on the excellent Blender 3-D graphics system is to avoid nested includes. Other examples:

NASA: http://sunland.gsfc.nasa.gov/info/cstyle.html

European Molecular Biology Open Software Suite (EMBOSS) http://emboss.sourceforge.net/developers/c-standards_new.htm...

Atacama Large Millimeter Array (astronomy): http://www.alma.nrao.edu/development/computing/docs/joint/00...

Clinical Neutron Therapy System (for radiation oncology): http://staff.washington.edu/jon/cnts/impl.pdf

2 comments

I take your point, but I'm not sure you're really taking his. As another data point, I just did a find/xargs-grep across my "~/codebase/3p" tree, which has ~5500 .h files for projects ranging from MongoDB to Ruby and Python to OpenSSL to valgrind. Virtually all of them have nested includes. Many of them are components of mission-critical software.

He's right; nested includes are a modern C idiom.

> In all my years writing C, I have never seen a C/C++ header which does not include the other headers it needs in order to compile cleanly.

> He's right; nested includes are a modern C idiom.

No doubt they are found a lot. The request was for counterexamples. Fashion/style vs engineering practice assertions may be passing like ships on a nighttime C here.

>...for projects ranging from MongoDB to Ruby and Python...

Python....why, even Tim Peters asserts that "Flat is better than nested"...wink...

http://www.python.org/dev/peps/pep-0020/

/irrelevant quote

To be fair here, NASA does say to avoid nesting headers. But then it follows up with this ridiculous statement:

  In extreme cases, where a large number of header files are 
  to be included in several different source files, it is 
  acceptable to put all common #includes in one include file. 
I would not trust anything else the author of that guide writes. EMBOSS says not to nest. The Atacama code suggests not nesting but then says:

  To avoid nested includes, use #define wrappers as follows:
The last pdf states:

  This prevents including the same item more than once when 
  a .c file includes several .h files (we rejected
  alternatives involving conditional compilation as too 
  complicated).
I guess it boils down to preference since the language allows you to do either, I just don't put a lot of stock in these style guides.