3 ms·
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
by keithflower 15y 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 http://sunland.gsfc.nasa.gov/info/cstyle.html
European Molecular Biology Open Software Suite (EMBOSS)
http://emboss.sourceforge.net/developers/c-standards_new.html http://emboss.sourceforge.net/developers/c-standards_new.htm...
Atacama Large Millimeter Array (astronomy):
http://www.alma.nrao.edu/development/computing/docs/joint/0009/2001-02-28.pdf 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 http://staff.washington.edu/jon/cnts/impl.pdf
- tptacek 15y agoI 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.
- keithflower 15y ago> 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/ http://www.python.org/dev/peps/pep-0020/ /irrelevant quote
- apaprocki 15y agoTo 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.