Major Physical Design Rules



  1. Keep class data private

  2. Avoid data with external linkage at file scope

  3. Avoid free functions (except operator functions) at file scope in .h files;
    avoid free functions with external linkage (including operator functions) in .c files.

  4. Avoid enumerations, typedefs, and constants at file scope in .h files.

  5. Avoid using preprocessor macros in header files except as include guards.

  6. Only classes, structures, unions, and free operator functions should be declared at files scope in a .h file;
    only classes, structures, unions, and inline (member or free operator) functions should be defined at file scope in a .h file.

  7. Place a unique and predictable (internal) include guard around the contents of each header file.

  8. Logical entities declared within a component should not be defined outside that component.

  9. The .c file of every component should include its own .h file as the first substantive line of code.

  10. Avoid definitions with external linkage in the .c file of a component that are not declared explicitly in the corresponding .h file.

  11. Avoid accessing a definition with external linkage in another component via a local declaration;
    instead, include the .h file for that component.

  12. Prepend every global identifier with its package prefix.

  13. Prepend every source file name with its package prefix.

  14. Avoid cyclic dependencies among packages.

  15. Only the .c file that defines main is authorized to redefine global new and delete.

  16. Provide a mechanism for freeing any dynamic memory allocated to static constructs within a component.