next up previous
Next: Definitions Up: Physical Design Rules Previous: Introduction

Rules

  1. Place a unique and predictable internal include guard around the contents of each header file.
  2. The following rule may be useful if preprocessor efficiency is a concern:
    Place a redundant external include guard around each preprocessor include directive in each header file.
  3. The .cc file of every component should include the corresponding .hh file as the first substantive line of code.
  4. Prepend every global identifier with its package prefix.
  5. Avoid data with external linkage at file scope.
  6. For similar reasons as for rule 5, also avoid (global) functions, enumerations, and typedefs at file scope. In general allow only classes, structs, unions, and definitions for overloaded operators at file scope.

  7. If an entity is defined in a .cc file, it should be declared in the corresponding .hh file.
  8. Obtain the declaration for a function by including the .hh file of the component in which the function is defined.
  9. When using a class, declare the class locally and only include the header file for that class if the compiler requires it.
  10. Put inline functions into a separate .icc file which is then #included into the .hh file.

  11. Large components can be broken up into many .cc files to improve compiler and linker efficiency.

  12. Put classes with their friend classes and functions in the same component.
    • Prevents other components from violating encapsulation by defining local versions of friends.
    • Friends are useful for iterators and global operator functions.
    • In general, minimize friend declarations, for maintenance reasons.

  13. Avoid cyclic dependencies between components.
    Especially avoid cyclic dependencies between packages.
    • If two classes are interdependent, either break the dependency or put them in the same component.

next up previous
Next: Definitions Up: No Title Previous: Introduction

Fritz DeJongh
Wed Nov 6 11:11:14 CST 1996