-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Description
I always ensure that the header defining the interface is included as the first one, as this automatically tests for SF.11, ensuring that the header file is self-contained.
I have read issue #366, were a similar rule is rejected with:
Components are not always neatly divided into A.h/A.cxx one-to-one correspondence. Furthermore, if A.h contains the interface of component A, then it should be self-contained.
But it is a long time ago (10 years). And I am NOT suggesting a rule that require the "name" (name as in <name>.<ext>) to be the same, for the .h and .cpp file.
What I suggest is that rule SF.5 is updated so that is requires or at least recommends that the header file that defines the interface is put first in the .cpp file, with the reason that it implicitly tests for rule SF.11.
Especially in cases where there is only one .h file.
Additionally I suggest a rule [SF.?23?] that every .h file in the project is included as the first file in at least 1 (one) .cpp file.
Whether this rule belongs as an enforcement or a note to rule SF.11, or as a rule in itself I have no strong opinion about.
Applying the rule of "my own interface first" means that in all the cases (in my experience the major part) where there is only one .h file defining the interface, Rule SF.5 is fulfilled, Rule SF.11 is tested, and rule SF.?23? is fulfilled for most files in the project, so only the cases with multipli interface files, or other .h files need a dedicated test .cpp that just include that file to test for rule SF.11.