Ada 95 Quality and Style Guide Chapter 8

Chapter 8: Reusability - TOC - 8.1 UNDERSTANDING AND CLARITY

8.1.1 Application-Independent Naming


  • Select the least restrictive names possible for reusable parts and their identifiers .
  • Select the generic name to avoid conflicting with the naming conventions of instantiations of the generic.
  • Use names that indicate the behavioral characteristics of the reusable part, as well as its abstraction.

  • example

    General-purpose stack abstraction:

       type Item is private;
    package Bounded_Stack is
       procedure Push (New_Item    : in     Item);
       procedure Pop  (Newest_Item :    out Item);
    end Bounded_Stack;

    Renamed appropriately for use in current application:

    with Bounded_Stack;
       type Tray is ...
       package Tray_Stack is 
          new Bounded_Stack (Item => Tray);


    Choosing a general or application-independent name for a reusable part encourages its wide reuse. When the part is used in a specific context, it can be instantiated (if generic) or renamed with a more specific name.

    When there is an obvious choice for the simplest, clearest name for a reusable part, it is a good idea to leave that name for use by the reuser of the part, choosing a longer, more descriptive name for the reusable part. Thus, Bounded_Stack is a better name than Stack for a generic stack package because it leaves the simpler name Stack available to be used by an instantiation.

    Include indications of the behavioral characteristics (but not indications of the implementation) in the name of a reusable part so that multiple parts with the same abstraction (e.g., multiple stack packages) but with different restrictions (bounded, unbounded, etc.) can be stored in the same Ada library and used as part of the same Ada program.

    < Previous Page Search Contents Index Next Page >
    1 2 3 4 5 6 7 8 9 10 11
    Appendix References Bibliography