Wednesday, January 13, 2010
Interface vs. implementation dependencies
Every c/c++ programmer knows the difference between a *.h file and a *.c file. The h file is for the interface and the c file for the implementation. That is basic c. However many people miss one important aspect of this. That is classifying the module's dependencies based on whether they are dependencies of the interface or the implementation.
Where the rubber meets the road is in how you include your header files. Many developers do not take the time to separate their include directives into interface vs. implementation dependencies. Interface dependencies should be included in the header file, implementation dependencies in the source file. While violating this rule will not cause compile stopping problems (usually) it slows your compilation waaaay down.
I will admit this issue is about knee deep into the realm of nit-picking but every little bit helps. So next time you feel compelled to say #include in a header file think: is this really an interface dependency?
P.S. This applies to c++ too but the situation is somewhat more complicated.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment