A suggestion about:

"Method bodies may only appear in the class definition if they are very short, 
no more than five lines. Otherwise the method body should be defined outside of 
the class definition."

To avoid dependency explosions that increase compile times and allow for 
link-time substitutability, I would suggest that method bodies should very 
rarely appear in header files. In my experience, this dramatically improves the 
likelihood that complex and/or user-defined types can be forward-declared and 
therefore can improve encapsulation and lower compilation times. This is also 
critical for link-time injection of mocks for unit testing, which is often the 
first step when transitioning a non-OO codebase toward OO. 

Classically, the main reason to put small functions into header files was to 
allow for inlining of small functions. With LTO, this point should be somewhat 
moot. In our internal testing of mega-compilation (a poor man's LTO where 
source files for a given binary module are #included into a single compilation 
unit), clearing header files of almost all method bodies resulted in a 20% 
decrease in compilation times and an 11% performance improvement at the system 
level. These improvements were icing on the cake, as our primary goal was to 
improve unit-testability by way of better encapsulation (and other OO 
principles).


Reply via email to