Hacker News new | past | comments | ask | show | jobs | submit login

> If you can find me one C project out there which has headers with zero #includes and forces each compilation unit including the header to include all the prerequisites needed for that header I would be genuinely interested.

A whole OS does this: Plan 9 from Bell Labs :)

For details see the paper by Rob Pike: How to Use the Plan 9 C Compiler

http://doc.cat-v.org/plan_9/4th_edition/papers/comp

Also the Plan 9 libraries are much cleaner and leaner than those in 'modern' *nix systems, which makes keeping track of includes much easier: http://man.cat-v.org/plan_9/2/intro




Well it stands to reason that the Plan 9 code would work that way if Rob Pike made the comment. I'm just wondering if anyone else found this way of coding attractive. Everything I've seen points to "no".


There is even a relatively popular piece of software dedicated to helping developers use this style: http://code.google.com/p/include-what-you-use/


That is not the stated purpose of the tool (to write code in the aforementioned style):

  "Include what you use" means this: for every symbol (type,  
  function variable, or macro) that you use in foo.cc, either 
  foo.cc or foo.h should #include a .h file that exports the 
  declaration of that symbol.
I agree 100% with that statement. According to the style, foo.h can never #include anything.


That's not true - you can't forward-declare types used in class member variables for instance.


Dennis Ritchie, creator of C? Ken Thompson, creator of Unix?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: