--::::::::::
--apsetool.doc
--::::::::::




 
 















                              SELECTED TAXONOMIES
                                        
                                    from the
                                        
                       E&V REFERENCE MANUAL, VERSION 1.0
                                   July, 1988
                     Interim Report for Period 6/85 - 3/88




                                 Prepared for:
                            Ada Software Repository


                                  Prepared by:
                                  Richard Conn




          The  information  in  this  document  is, for the most part,
          extracted  literally  from the E&V___ Reference_________ Manual,______, Version_______
          1.0._._.















 
 




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                                1. INTRODUCTION



               From the Executive Summary of the E&V Reference Manual:

               "The Ada community, including government, industry, and
          academic  personnel,  needs  the  capability to assess APSEs
          (Ada  Programming Support Environments) and their components
          and  to  determine their conformance to applicable standards
          (e.g.,  DOD-STD-1838,  the  CAIS  standard).  The technology
          required to fully satisfy this need is extensive and largely
          unavailable;   it   cannot   be   acquired   by   a   single
          government-sponsored,   professional  society-sponsored,  or
          private  effort.   The  purpose  of  the APSE Evaluation and
          Validation  (E&V)  task  is  to  provide  a  focal point for
          addressing the need by:

                 "(1)  Identifying  and defining specific technology
            requirements,

                 "(2)  Developing  selected elements of the required
            technology,

                 "(3)  Encouraging  others to develop some elements,
            and

                 "(4)  Collecting  information  describing  existing
            elements.

          "This  information will be made available to DoD components,
          other government agencies, industry and academia.

               "The   purpose   of  the  E&V  Reference  Manual  (this
          document) is to provide information that will help users to:

                 "(1)  Gain  an  overall  understanding of APSEs and
            approaches to their assessment,

                 "(2)   Find  useful  reference  information  (e.g.,
            definitions)  about  specific elements and relationships
            between elements, and

                 "(3)  Find criteria and metrics for assessing tools
            and   APSEs,   and   techniques   for   performing  such
            assessment.

          "The  latter  are to be found (or referenced) in a companion
          document called the E&V Guidebook."


 
                                       1




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                   2. APSE DEFINITIONS and ALTERNATIVE NAMES






          2.1.  PSE___

               PSE  stands  for "Programming Support Environment," and
          is  defined  in  the  "IEEE  Standard  Glossary  of Software
          Engineering Terminology" (dated 1983) as:
               "An  integrated collection of tools accessed via a
               single  command  language  to  provide programming
               support   capabilities   throughout  the  software
               life-cycle.   The  environment  typically includes
               tools  for  design,  editing,  compiling, loading,
               testing,  configuration  management,  and  project
               management."




          2.2.  APSE____

               APSE  stands for "Ada Programming Support Environment."
          It  is a programming support environment for the development
          of   software   written  in  the  Ada  computer  programming
          language.

               The  "E&V Reference Manual" goes on to describe various
          ways  of viewing an APSE from various perspectives.  It also
          describes key attributes of an APSE.


















 
                                       2




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                              3. LIFE CYCLE PHASES



               The life cycle phases recommended in the "E&V Reference
          Manual" are:

             - System Concepts

             - System Requirements Analysis

             - Software Requirements Analysis

             - Preliminary Design

             - Detailed Design

             - Coding and Unit Testing

             - CSC Integration and Testing

             - CSCI Testing

             - System Integration and Testing

             - Operational Testing and Evaluation

             - Change Requirements

             - Global




          3.1.  System______ Concepts________




          3.2.  System______ Requirements____________ Analysis________











 
                                       3




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          3.3.  Software________ Requirements____________ Analysis.________.
          "Those  activities  of  the  life  cycle  pertaining  to the
          establishment  of  system requirements and a complete set of
          functional, performance, and interface requirements for each
          CSCI."




          3.4.  Preliminary___________ Design.______.
          "Those  activities  in  the  life  cycle  pertaining  to the
          development of a modular, top-level design of each CSCI from
          the software requirements."




          3.5.  Detailed________ Design.______.
          "Those  activities  in  the  life  cycle  pertaining  to the
          development  of a modular, detailed design of each CSCI from
          the preliminary design."




          3.6.  Coding______ and___ Unit____ Testing._______.
          "Those activities in the life cycle pertaining to the coding
          and testing of each unit comprising the detailed design."




          3.7.  CSC___ Integration___________ and___ Testing._______.
          "Those  activities  in  the  life  cycle  pertaining  to the
          integration of units of code and the performance of informal
          tests on aggregates of integrated units."




          3.8.  CSCI____ Testing._______.
          "Those  activities  in  the  life  cycle  pertaining  to the
          conduct   of   formal   tests   on   each   CSCI   and   the
          recording/analysis of test results."









 
                                       4




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          3.9.  System______ Integration___________ and___ Testing._______.
          "Those  activities  in  the  life  cycle  pertaining  to the
          successive  integration  and  testing  of CSCIs and HWCIs to
          validate that the complete system is properly integrated and
          satisfies system requirements."




          3.10.  Operational___________ Testing_______ and___ Evaluation.__________.
          "Those  activities  in  the  life  cycle where the system is
          tested   and   evaluated   in   surroundings  which  are  as
          operationally  realistic  as  possible to determine that the
          system  will satisfactorily perform the mission for which it
          was designed."




          3.11.  Change______ Requirements.____________.
          "Those  activities  in  the  life  cycle  pertaining  to the
          support  (error detection/correction) and enhancement of the
          operational  CSCIs.   Often,  this activity will result in a
          series  of  software developments potentially requiring tool
          features   (besides  Global  features)  different  from  all
          preceding life cycle activities."




          3.12.  Global.______.
          "Represents  those  general  support  features which include
          common  (in  implementation  and  use)  software elements or
          functions.   Global  features  can  be included in each life
          cycle activity."


















 
                                       5




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                             4. APSE TOOL TAXONOMY



               "APSEs are the highest levels of toolset.  APSEs should
          contain  all  the  tools  and toolsets needed to support the
          full spectrum of project activities."




          4.1.  Computer________ Management__________ System.______.
          "Those  tools  needed  to  access,  use,  and  maintain  the
          hardware  and  software  which  consists of the APSE and the
          system on which it runs."

          4.1.1.  Command_______ Language________ Processor_________

          4.1.2.  Archive,_______, Backup,______, and___ Retrieval_________ System______

          4.1.3.  Security________ System______

          4.1.4.  Job___ Scheduler_________

          4.1.5.  Resource________ Controller__________

          4.1.6.  File____ Manager_______

          4.1.7.  Import/Export_____________ System______

          4.1.8.  On-Line_______ Assistance__________ Processor_________

          4.1.9.  Data____ Base____ Manager_______




          4.2.  Project_______ Management__________ System.______.
          "Those  tools  needed  to  plan,  develop,  and  maintain an
          applications system."

          4.2.1.  Cost____ Estimator_________

          4.2.2.  Quality_______ Analyzer________

          4.2.3.  Scheduler_________

          4.2.4.  Work____ Breakdown_________ Structure_________

          4.2.5.  Resource________ Estimator_________

 
                                       6




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          4.2.6.  Tracking________

          4.2.7.  Configuration_____________ Manager_______

          4.2.8.  Problem_______ Report______ Analyzer________

          4.2.9.  Change______ Request_______ Analyzer________




          4.3.  Compilation___________ System.______.
          "Those tools needed to produce and run software systems."

          4.3.1.  Program_______ Library_______ Manager_______

          4.3.2.  Syntax-Directed_______________ Editor______

          4.3.3.  Compiler________

          4.3.4.  Assembler_________

          4.3.5.  Linker______

          4.3.6.  Loader______

          4.3.7.  Interpreter___________

          4.3.8.  Runtime_______ Library_______




          4.4.  Document________ System.______.
          "Those tools needed to develop and produce documents."

          4.4.1.  Document________ Manager_______

          4.4.2.  Word____ Processor_________

          4.4.3.  Spell_____ Checker_______

          4.4.4.  Graphics________ Generator_________

          4.4.5.  Formatter_________








 
                                       7




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          4.5.  Desktop_______ System.______.
          "Those  tools  needed  to  do  the every-day, administrative
          tasks of business."

          4.5.1.  Spreadsheet___________

          4.5.2.  Calculator__________

          4.5.3.  Address_______ Book____

          4.5.4.  Electronic__________ Mail____

          4.5.5.  Phone_____ Book____

          4.5.6.  Electronic__________ Conferencing____________

          4.5.7.  Calendar________

          4.5.8.  Dictionary__________




          4.6.  Static______ Analyzer________ System.______.
          "Those  tools  needed  to  do  analysis  of software systems
          without actually executing the program(s) being analyzed."

          4.6.1.  Comparator__________

          4.6.2.  Data____ Flow____ Analyzer________

          4.6.3.  Functional__________ Analyzer________

          4.6.4.  Interface_________ Analyzer________

          4.6.5.  Traceability____________ Analyzer________

          4.6.6.  Testability___________ Analyzer________

          4.6.7.  Test____ Condition_________ Analyzer________

          4.6.8.  Quality_______ Analyzer________

          4.6.9.  Complexity__________ Measurer________

          4.6.10.  Correctness___________ Checker_______

          4.6.11.  Completeness____________ Checker_______

          4.6.12.  Consistency___________ Checker_______

          4.6.13.  Reusability___________ Analyzer________

 
                                       8




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          4.6.14.  Syntax______ and___ Semantics_________ Checker_______

          4.6.15.  Reachability____________ Analyzer________

          4.6.16.  Cross_____ Referencer__________

          4.6.17.  Maintainability_______________ Analyzer________

          4.6.18.  Invocation__________ Analyzer________

          4.6.19.  Scanner_______

          4.6.20.  Structured__________ Walkthrough___________ Tool____

          4.6.21.  Auditor_______

          4.6.22.  Error_____ Checker_______

          4.6.23.  Statistical___________ Analyzer________

          4.6.24.  Statistical___________ Profiler________

          4.6.25.  Structure_________ Checker_______

          4.6.26.  Type____ Analyzer________

          4.6.27.  Units_____ Analyzer________

          4.6.28.  I/O___ Specification_____________ Analyzer________

          4.6.29.  Sizing______ Analyzer________




          4.7.  Dynamic_______ Analyzer________ System.______.
          "Those tools needed to do analysis of software systems while
          actually  executing the program(s) or some representation of
          the system being analyzed."

          4.7.1.  Requirements____________ Simulator_________

          4.7.2.  Requirements____________ Prototype_________

          4.7.3.  Simulation__________ and___ Modelling_________ Tools_____

          4.7.4.  Design______ Prototype_________

          4.7.5.  Debugger________

          4.7.6.  Executable__________ Assertion_________ Checker_______

          4.7.7.  Constraint__________ Evaluator_________
 
                                       9




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          4.7.8.  Coverage/Frequency__________________ Analyzer________

          4.7.9.  Mutation________ Analyzer________

          4.7.10.  Testing_______ Analyzer________

          4.7.11.  Regression__________ Testing_______ Analyzer________

          4.7.12.  Resource________ Utilization___________ Analyzer________

          4.7.13.  Emulator________

          4.7.14.  Timing______ Analyzer________

          4.7.15.  Tuning______ Analyzer________

          4.7.16.  Reliability___________ Analyzer________

          4.7.17.  Real____ Time____ Analyzer________

          4.7.18.  Formal______ Verification____________ System______

          4.7.19.  Symbolic________ Execution_________ System______






























 
                                      10




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                            5. ATTRIBUTES of an APSE



               "Attributes  are the characteristics of tools or "whole
          APSEs"  which  the E&V user evaluates (or validates) to make
          assessments  and  comparisons." At the top level, three main
          attributes are of concern:

             - Performance: how well does it function?

             - Design: how well is it designed?

             - Adaptation - how adaptable is it?

             - Software-Oriented Criteria





          5.1.  Performance.___________.
          "Performance  quality  factors deal both with the ability of
          the  software  to  function  and with error occurrences that
          affect  software  functioning.   Low quality factors predict
          poor software performance."

          5.1.1.   Efficiency.__________.   "Efficiency deals with utilization of
          resources.   The  extent  to  which a component fulfills its
          purpose  using a minimum of computing resources.  Of course,
          many  of  the ways of coding efficiently are not necessarily
          efficient  in  the  sense  of  being  cost-effective,  since
          transportability,  maintainability, etc., may be degraded as
          a result."

          5.1.2.   Integrity._________.  "Integrity deals with software failures
          due to unauthorized access.  The extent to which access to a
          component  or associated data by unauthorized persons can be
          controlled."

          5.1.3.   Reliability.___________.   "Reliability  concerns  any software
          failure.  The extent to which a component can be expected to
          perform its intended functions in a satisfactory manner."

          5.1.4.    Survivability._____________.    "Survivability  deals  with  the
          continued performance of software (e.g., in a degraded mode)
          even when a portion of the system has failed."

          5.1.5.   Usability._________.   "Extent to which resources required to
          acquire,  install,  learn,  operate,  prepare input for, and
          interpret output of a component are minimized."
 
                                      11




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          5.2.  Design.______.
          "Design  quality  factors  deal mainly with software failure
          and  correction.   Low  quality  levels  usually  result  in
          repeating  a  portion  of  the  development  process  (e.g.,
          redesign, recode, reverify); hence the term design."

          5.2.1.   Correctness.___________.   "The extent to which software design
          and  implementation conform to specifications and standards.
          Criteria  of  correctness  deal  exclusively with design and
          documentation  formats.   Agreement  between  a  component's
          total  response  and  the  stated response in the functional
          specification  (functional  correctness), and/or between the
          component   as   coded  and  the  programming  specification
          (algorithmic correctness)."

          5.2.2.   Maintainability._______________.   "The  ease of effort in locating
          and  fixing  software  failures.   The  extent  to  which  a
          component  facilitates  updating to satisfy new requirements
          or to correct deficiencies.  This implies that the component
          is understandable, testable, and modifiable."

          5.2.3.    Verifiability,_____________,   Testability.___________.    "Software  design
          characteristics  affecting  the  effort  to  verify software
          operation  and performance.  The extent to which a component
          facilitates  the  establishment of verification criteria and
          supports  evaluation  of its performance.  This implies that
          requirements  are matched to specific modules, or diagnostic
          capabilities are provided, etc."




          5.3.  Adaptation.__________.
          "Adaptation  quality factors deal mainly with using software
          beyond  its  original  requirements,  such  as  extending or
          expanding  capabilities  and  adapting  for  use  in another
          application  or  environment.   Low  quality  levels predict
          relatively high costs for new software use."

          5.3.1.    Expandability,_____________,   Flexibility.___________.    "The   effort  in
          increasing   software  capabilities  or  performance  or  to
          accommodate  changes in requirements.  The extent to which a
          component  allows  new capabilities to be added and existing
          capabilities to be easily tailored to user needs."

          5.3.2.   Interoperability.________________.  "The effort in coupling software
          of one system to software of one or more other systems.  The
          ability  of  APSEs  to  exchange data base objects and their
          relationships   in  forms  usable  by  components  and  user
          programs  without  conversion.  Interoperability is measured
          by  the  degree  to  which this exchange can be accomplished
          without conversion."

 
                                      12




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          5.3.3.   Reusability.___________.   "The extent to which a component can
          be adapted for use in another application."

          5.3.4.   Transportability.________________.  "The extent to which a component
          can  be  adapted  for  use  in  another  environment  (e.g.,
          different  host or target hardware, operating system, APSE).
          The  ability  of  a component to be installed on a different
          APSE  without  change in functionality.  Transportability is
          measured  in  the  degree  to which this installation can be
          accomplished without reprogramming."




          5.4.  Software-Oriented_________________ Criteria________

          5.4.1.   Accuracy.________.  "Those characteristics of software which
          provide the required precision in calculations and outputs."

          5.4.2.    Anomaly_______  Management,__________,  Fault_____  or__  Error_____  Tolerance,_________,
          Robustness.__________.    "Those   characteristics  of  software  which
          provide for continuity of operations under and recovery from
          non-nominal  conditions.  The protection of a component from
          itself,  user  errors,  and  system  errors.  The ability to
          recover  and  provide meaningful diagnostics in the event of
          unforeseen  situations.  A robust routine will avoid failing
          for  input  values where the desired output is well-defined,
          but   the   intermediate   results   of   a  straightforward
          implementation may cause the routine to fail."

          5.4.3.  Application___________ Independence.____________.  "Those characteristics of
          software  which  determine  its  non-dependency  on database
          system, microcode, computer architecture, and algorithms."

          5.4.4.   Augmentability.______________.  "Those characteristics of software
          which  provide for expansion of capability for functions and
          data."

          5.4.5.   Autonomy.________.  "Those characteristics of software which
          determine its non-dependency on interfaces and functions."

          5.4.6.   Capacity.________.   "The  upper  and  lower  limits  of the
          functions implemented by a tool."

          5.4.7.    Commonality___________   (Data_____  and___  Communication).______________.   "Those
          characteristics  of  software  which  provide for the use of
          interface   standards  for  protocols,  routines,  and  data
          representations.    The  set  of  assumptions  made  by  the
          component  and  made  about  the  component by the remaining
          components  and  the  system  in which it appears.  Software
          components  have  control,  data,  and  service  interfaces.
          Included  in  this  attribute is conformance to any existing
          pertinent interface standards such as the CAIS.
 
                                      13




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          5.4.8.  Communication_____________ Effectiveness._____________.  "Those characteristics
          of  the  software  which  provide for minimum utilization of
          communications resources in performing functions."

          5.4.9.   Completeness.____________.   "The  extent  to  which a component
          provides the complete set of operations necessary to perform
          a function."

          5.4.10.   Consistency.___________.   "Those  characteristics of software
          which   provide   for   uniform  design  and  implementation
          techniques and notation."

          5.4.11.   Cost.____.   "The  cost  of a complete component or the
          costs  of  features of a component.  The cost of a component
          may  vary  depending  on delivery with source code or object
          code  only  (for  example).   Other  cost considerations are
          installation, user assistance, and maintenance support."

          5.4.12.    Distributedness._______________.    "Those   characteristics   of
          software  which  determine  the  degree  to  which  software
          functions  are  geographically or logically separated within
          the system."

          5.4.13.   Document________ Accessibility._____________.  "Those characteristics of
          software  which  provide  for  easy  access  to software and
          selective use of components."

          5.4.14.   Functional__________  Overlap._______.   "Those  characteristics  of
          software which provide common functions to both systems."

          5.4.15.    Functional__________   Scope._____.   "Those  characteristics  of
          software   which  provide  commonality  of  functions  among
          applications."

          5.4.16.   Generality.__________.   "Those  characteristics  of software
          which  provide  breadth  to  the  functions  performed  with
          respect to the application."

          5.4.17.   Granularity.___________.  "The degree to which a component has
          separate   limited   functions  that  are  composible,  user
          selectable, and communicate through a common data base."

          5.4.18.   Maturity.________.   "The  extent  to which a component has
          been  used  in  the  development  of deliverable software by
          typical  users  and  to which the feedback from that use has
          been reflected in modifications to the component."

          5.4.19.   Modularity.__________.   "Those  characteristics  of software
          which provide a structure of highly cohesive components with
          optimum  coupling.   The  extent  to  which  a  component is
          implemented   in   a   hierarchical   structure   in   which
          identifiable  functions are isolated in separate compilation
          units."
 
                                      14




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          5.4.20.      Operability,___________,     Communicativeness._________________.      "Those
          characteristics  of  software which determine operations and
          procedures  concerned  with  operation of software and which
          provide  useful inputs and outputs which can be assimilated.
          The   user/component   dialog  established  to  control  the
          execution  of  the  component.  This is driven by the set of
          assumptions  made  by  the  component  and  made  about  the
          component by the persons who use it."

          5.4.21.   Power._____.   "The  extent  to  which  a  component has
          capabilities,   such   as  default  options  and  wild  card
          operations,  that  contribute  to  the  effectiveness of the
          user."

          5.4.22.    Processing__________   (Execution)___________  Effectiveness._____________.   "Those
          characteristics  of  the  software which provide for minimum
          utilization of processing resources in performing functions.
          The  choice  between  alternative  algorithms based on those
          taking the least amount of time."

          5.4.23.   Proprietary___________ Rights.______.  "Restrictions on the release,
          distribution,  or  use  of  a  component.   This includes so
          called "data rights" restrictions."

          5.4.24.    Reconfigurability._________________.    "Those  characteristics  of
          software  which  provide  for continuity of system operation
          when one or more processors, storage units, or communication
          links fails."

          5.4.25.   Rehostability._____________.   "The ability of an APSE component
          to  be  installed on a different host or different operating
          system  with  needed reprogramming localized to the KAPSE or
          machine dependencies."

          5.4.26.   Required________  Configuration._____________.  "The amount and types of
          hardware  or software facilities needed for the operation of
          a  component.   This  includes primary and secondary storage
          and any other required resources."

          5.4.27.  Retargetability._______________.  "The ability of an APSE component
          to  accomplish  its function with respect to another target.
          The component may require modification."

          5.4.28.   Self-Descriptiveness.____________________.   "Those  characteristics of
          software  which provide explanation of the implementation of
          functions.    The   technical   data,   including   on-line,
          documentation,  listings,  and  printouts,  which  serve the
          purpose   of   elaborating   the  design  or  details  of  a
          component."

          5.4.29.   Simplicity.__________.   "Those  characteristics  of software
          which provide for definition and implementation of functions
          in the most non-complex and understandable manner.  A simple
 
                                      15




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          program  style  is  one which makes the program, as a whole,
          easy  to understand.  Other things being equal, the style is
          concise  and  straightforward.   It  makes  use  of process,
          procedural, and data abstraction, as appropriate, to present
          a clear exposition of the intent."

          5.4.30.      Software________     Production__________    Vehicle(s).__________.     "The
          methodology(ies),  language(s),  and  technique(s)  used  to
          produce the software related to a component."

          5.4.31.   Storage_______  Effectiveness._____________.  "Those characteristics of
          the  software  which  provide  for  minimum  utilization  of
          storage  resources  in  performing  functions.   The  choice
          between alternative source code constructions based on those
          taking  the  minimum  number  of  words of object code or in
          which the information-packing ...  is high."

          5.4.32.   System______  Accessibility._____________.   "Those characteristics of
          software  which provide for control and audit of accesses to
          the software and data."

          5.4.33.  System______ Clarity._______.  "Those characteristics of software
          which  provide for clear description of program structure in
          a non-complex and understandable manner."

          5.4.34.   System______  Compatibility._____________.   "Those characteristics of
          software   which   provide   the   hardware,  software,  and
          communication capability of two systems."

          5.4.35.   Traceability.____________.   "Those characteristics of software
          which  provide a thread of origin from the implementation to
          the  requirements  with respect to the specified development
          envelope and operational environment."

          5.4.36.  Training.________.  "Those characteristics of software which
          provide   transition  from  current  operation  and  provide
          initial  familiarization.   The extent to which training and
          other  user help is available from the vendor of a component
          or   from   the   component   itself,   including   on-line,
          documentation,  listings,  and  printouts,  which  serve the
          purpose  of  providing  operating instructions for using the
          component to obtain desired results."

          5.4.37.   Virtuality.__________.   "Those  characteristics  of software
          which  present a system that does not require user knowledge
          of the physical, logical, or topological characteristics."

          5.4.38.      Visibility,__________,    Test____    Availability.____________.     "Those
          characteristics  of software which provide status monitoring
          of the development and operation.  The availability of tests
          that  verify the correctness or effectiveness of a component
          function  or  feature.   These  tests may also verify proper
          response for an incorrect input or technique."
 
                                      16




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 


                         6. TAXONOMY of APSE FUNCTIONS



               This  taxonomy  is  divided at the top level into three
          main areas:

             - Transformation

             - Management

             - Analysis





          6.1.  Transformation.______________.
          "Transformation   features   describe  how  the  subject  is
          manipulated  to accommodate the user's needs.  They describe
          what  transformations  take  place  as  input to the tool is
          processed."

          6.1.1.  Editing_______ (Text,_____, Data,____, Graphics)._________.  "Selective revision
          of computer-resident data."

          6.1.2.   Formatting__________  (MIL-STD, Table of Contents, Pre-Define
          and  User-Defined  Forms).   "Arranging  data  according  to
          predefined and/or user-defined conventions."

          6.1.3.  On-Line_______ Assistance__________ Processing.__________.  "User interface that
          is part of the input/output process of a programming support
          environment  (e.g.,  command assistance, assistance, on-line
          tutoring, definition assistance, etc.)."

          6.1.4.   Sort/Merge.__________.   "The  process  of arranging data in a
          specific order (e.g., alphabetical order)."

          6.1.5.   Graphics________  Generation.__________.   "The  input,  construction,
          storage,  retrieval,  manipulation, alteration, and analysis
          of pictorial data (e.g., generation of system architectures,
          software designs, financial analysis, maps, graphs, etc.)."

          6.1.6.  Translation___________ (Requirements, Design, Code Compilation,
          Execution  and  Interpretation).   "The  conversion from one
          language form to another."

          6.1.7.  Synthesis_________ (Design, Requirements, Code, Decompilation
          and  Disassembly).  "The generation of programs according to
          predefined   rules   from   a   program   specification   or
          intermediate language."
 
                                      17




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          6.2.  Management.__________.
          "Features   that   aid   the   management   or   control  of
          system/software development."

          6.2.1.   Information___________  Management__________  (Data Base, Documentation,
          Files,    Electronic    Mail,    Electronic    Conferencing,
          Specifications,   Program  Library,  Test  Data,  Evaluation
          Results,   Performance   Monitoring).    "The  organization,
          accessing,  modification,  dissemination,  and processing of
          information  that  is  associated  with the development of a
          software system."

          6.2.2.    Project_______   Management__________   (Cost  Estimation,  Quality
          Specification,   Scheduling,   Work   Breakdown   Structure,
          Resource  Estimation,  Tracking,  Configuration  Management,
          Quality  Assessment).   "The management of a system/software
          development project."

          6.2.3.    Computer________   System______   Management__________  (Command  Language
          Processing,  Input/Output  Support, Kernel, Math/Statistics,
          Runtime  Environment,  Import/Export).   "The  management of
          hardware/software  architectures  to  support the life cycle
          software  engineering  environment.   Such services include:
          creating,  scheduling,  and  removing  tasks;  switching the
          processor  among  tasks;  sending  messages  between  tasks;
          providing   direct   and   import/export   access;  managing
          distributed  systems; sending files from one host machine to
          another on a network, etc."




          6.3.  Analysis.________.
          "The  features  that provide an examination of a substantial
          whole   to   determine  both  qualitative  and  quantitative
          properties."

          6.3.1.  Static______ Analysis________ (Comparison, Spelling Checking, Data
          Flow  Analysis,  Functional  Analysis,  Interface  Analysis,
          Traceability  Analysis, Testability Analysis, Test Condition
          Analysis,    Quality   Analysis,   Complexity   Measurement,
          Correctness  Checking,  Completeness  Checking,  Consistency
          Checking,   Reuseability   Analysis,  Syntax  and  Semantics
          Checking,    Reachability    Analysis,    Cross   Reference,
          Maintainability  Analysis,  Invocation  Analysis,  Scanning,
          Structured    Walkthrough,    Auditing,    Error   Checking,
          Statistical   Analysis,   Statistical  Profiling,  Structure
          Checking,  Type  Analysis, Units Analysis, I/O Specification
          Analysis,   Sizing  Analysis).   "Static  analysis  features
          specify  operations  on  the  subject  without regard to the
          executability  of  the subject.  They describe the manner in
          which the subject is analyzed."

 
                                      18




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 
          6.3.2.     Dynamic_______    Analysis________   (Requirements   Simulation,
          Requirements  Prototyping,  Simulation  and Modeling, Design
          Prototyping,   Debugging,   Executable  Assertion  Checking,
          Constraint Evaluation, Coverage/Frequency Analysis, Mutation
          Analysis, Testing, Regression Testing, Resource Utilization,
          Emulation,  Timing,  Tuning, Reliability Analysis, Real Time
          Analysis).   "Dynamic  analysis  features specify operations
          that  are  determined during or after execution takes place.
          Dynamic  analysis  features  differ from those classified as
          static  by virtue of the fact that they require some form of
          symbolic or machine execution.  They describe the techniques
          used  by  the  tool to derive meaningful information about a
          program's execution behavior."

          6.3.3.    Formal______   Verification.____________.    "The   use  of  rigorous
          mathematical  techniques to prove the consistency between an
          algorithmic  solution and a rigorous, complete specification
          of the intent of the solution."

          6.3.4.   Symbolic________  Execution._________.   "The  reconstruction  of the
          logic and computations along a program path by executing the
          path with symbolic rather than actual values of data."

          6.3.5.   Problem_______  Report______ Analysis.________.  "The analysis of problem
          reports  for  the purpose of determining the validity of the
          reported problem and a corrective action."

          6.3.6.   Change______  Request_______  and___  Change______ Impact______ Analysis.________.  "The
          Change  Request  Analysis is the analysis of change requests
          to determine the necessity of the change, technical/economic
          impacts,  and  approach  to  accomplishing  the change.  The
          Change  Impact  Analysis  is the ability to determine, for a
          proposed   support/enhancement   operation,  the  impact  of
          proposed changes to the software system."



















 
                                      19




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 




                               TABLE of CONTENTS_____ __ ________


          
          1. INTRODUCTION .......................................... 1
          
          2. APSE DEFINITIONS and ALTERNATIVE NAMES ................ 2
             2.1. PSE .............................................. 2
             2.2. APSE  ............................................ 2
          
          3. LIFE CYCLE PHASES  .................................... 3
             3.1. System Concepts .................................. 3
             3.2. System Requirements Analysis  .................... 3
             3.3. Software Requirements Analysis. .................. 4
             3.4. Preliminary Design. .............................. 4
             3.5. Detailed Design.  ................................ 4
             3.6. Coding and Unit Testing.  ........................ 4
             3.7. CSC Integration and Testing.  .................... 4
             3.8. CSCI Testing. .................................... 4
             3.9. System Integration and Testing. .................. 5
             3.10. Operational Testing and Evaluation.  ............ 5
             3.11. Change Requirements. ............................ 5
             3.12. Global.  ........................................ 5
          
          4. APSE TOOL TAXONOMY .................................... 6
             4.1. Computer Management System. ...................... 6
             4.2. Project Management System.  ...................... 6
             4.3. Compilation System. .............................. 7
             4.4. Document System.  ................................ 7
             4.5. Desktop System. .................................. 8
             4.6. Static Analyzer System. .......................... 8
             4.7. Dynamic Analyzer System.  ........................ 9
          
          5. ATTRIBUTES of an APSE  ............................... 11
             5.1. Performance.  ................................... 11
             5.2. Design. ......................................... 12
             5.3. Adaptation. ..................................... 12
             5.4. Software-Oriented Criteria  ..................... 13
          
          6. TAXONOMY of APSE FUNCTIONS ........................... 17
             6.1. Transformation. ................................. 17
             6.2. Management. ..................................... 18
             6.3. Analysis. ....................................... 18






 
                                      ii




                              Selected Taxonomies
          E&V Reference Manual                  Version 1.0, July 1988
 




















                         This page intentionally blank
































 
                                      iii
--::::::::::
--apsetool.ptf
--::::::::::
.lm 11
.rm 70
.nap
.de SEC0
.nr c +1
.nr a 0
.sp 2
.ce
@nc. @1 @2 @3 @4 @5 @6 @7 @8 @9
.sp 2
.cl
.cl 0 @nc. @1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.de SEC1
.sp 4
.ne 10
.nr a +1
.nr b 0
@nc.@na.
.ul
@1 @2 @3 @4 @5 @6 @7 @8 @9
.cl 1 @nc.@na. @1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.de SEC2
.sp 1
.nr b +1
@nc.@na.@nb.
.ul
@1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.nr c 0
.de PP
.sp 1
.ti +5
.en
.sp 15
.ce on
SELECTED TAXONOMIES

from the

E&V REFERENCE MANUAL, VERSION 1.0
July, 1988
Interim Report for Period 6/85 - 3/88
.sp 4
Prepared for:
Ada Software Repository
.sp 2
Prepared by:
Richard Conn
.ce off
.sp 4
The information in this document is, for the most part, extracted literally
from the
.ul
E&V Reference Manual, Version 1.0.
.br
.nlheader 3
.he 1 //Selected Taxonomies//
.he 2 /E&V Reference Manual//Version 1.0, July 1988/
.bp 1
.fo //#//
.SEC0 INTRODUCTION
.PP
From the Executive Summary of the E&V Reference Manual:
.PP
"The Ada community, including government, industry, and academic personnel,
needs the capability to assess APSEs (Ada Programming Support
Environments) and their components and to determine their conformance
to applicable standards (e.g., DOD-STD-1838, the CAIS standard).  The
technology required to fully satisfy this need is extensive and largely
unavailable; it cannot be acquired by a single government-sponsored,
professional society-sponsored, or private effort.  The purpose of the APSE
Evaluation and Validation (E&V) task is to provide a focal point for
addressing the need by:
.li +2
.ri +2
.PP
"(1) Identifying and defining specific technology requirements,
.PP
"(2) Developing selected elements of the required technology,
.PP
"(3) Encouraging others to develop some elements, and
.PP
"(4) Collecting information describing existing elements.
.li -2
.ri -2
.sp 1
"This information will be made available to DoD components, other
government agencies, industry and academia.
.PP
"The purpose of the E&V Reference Manual (this document) is to provide
information that will help users to:
.li +2
.ri +2
.PP
"(1) Gain an overall understanding of APSEs and approaches to their
assessment,
.PP
"(2) Find useful reference information (e.g., definitions) about
specific elements and relationships between elements, and
.PP
"(3) Find criteria and metrics for assessing tools and APSEs, and
techniques for performing such assessment.
.li -2
.ri -2
.sp 1
"The latter are to be found (or referenced) in a companion document called
the E&V Guidebook."
.br
.bp
.SEC0 APSE DEFINITIONS and ALTERNATIVE NAMES
.SEC1 PSE
.PP
PSE stands for "Programming Support Environment," and is defined in the
"IEEE Standard Glossary of Software Engineering Terminology" (dated 1983) as:
.in +5
.rm -5
"An integrated collection of tools accessed via a single command language
to provide programming support capabilities throughout the software
life-cycle.  The environment typically includes tools for design, editing,
compiling, loading, testing, configuration management, and project
management."
.rm +5
.in -5
.SEC1 APSE
.PP
APSE stands for "Ada Programming Support Environment."  It is a programming
support environment for the development of software written in the
Ada computer programming language.
.PP
The "E&V Reference Manual" goes on to describe various ways of viewing an
APSE from various perspectives.  It also describes key attributes of an APSE.
.bp
.SEC0 LIFE CYCLE PHASES
.PP
The life cycle phases recommended in the "E&V Reference Manual" are:
.sp
.in +5
.rm -5
.ti -2
- System Concepts
.sp 1
.ti -2
- System Requirements Analysis
.sp 1
.ti -2
- Software Requirements Analysis
.sp 1
.ti -2
- Preliminary Design
.sp 1
.ti -2
- Detailed Design
.sp 1
.ti -2
- Coding and Unit Testing
.sp 1
.ti -2
- CSC Integration and Testing
.sp 1
.ti -2
- CSCI Testing
.sp 1
.ti -2
- System Integration and Testing
.sp 1
.ti -2
- Operational Testing and Evaluation
.sp 1
.ti -2
- Change Requirements
.sp 1
.ti -2
- Global
.rm +5
.in -5
.SEC1 System Concepts
.SEC1 System Requirements Analysis
.SEC1 Software Requirements Analysis.
"Those activities of the life cycle pertaining to the establishment
of system requirements and a complete set of functional, performance,
and interface requirements for each CSCI."
.SEC1 Preliminary Design.
"Those activities in the life cycle pertaining to the development of
a modular, top-level design of each CSCI from the software requirements."
.SEC1 Detailed Design.
"Those activities in the life cycle pertaining to the development of a
modular, detailed design of each CSCI from the preliminary design."
.SEC1 Coding and Unit Testing.
"Those activities in the life cycle pertaining to the coding and
testing of each unit comprising the detailed design."
.SEC1 CSC Integration and Testing.
"Those activities in the life cycle pertaining to the integration of
units of code and the performance of informal tests on
aggregates of integrated units."
.SEC1 CSCI Testing.
"Those activities in the life cycle pertaining to the conduct of formal
tests on each CSCI and the recording/analysis of test results."
.SEC1 System Integration and Testing.
"Those activities in the life cycle pertaining to the successive
integration and testing of CSCIs and HWCIs to validate that the complete system
is properly integrated and satisfies system requirements."
.SEC1 Operational Testing and Evaluation.
"Those activities in the life cycle where the system is tested and
evaluated in surroundings which are as operationally realistic as possible
to determine that the system will satisfactorily perform the mission
for which it was designed."
.SEC1 Change Requirements.
"Those activities in the life cycle pertaining to the support
(error detection/correction) and enhancement of the operational CSCIs.
Often, this activity will result in a series of software developments
potentially requiring tool features (besides Global features)
different from all preceding life cycle activities."
.SEC1 Global.
"Represents those general support features which include common
(in implementation and use) software elements or functions.  Global
features can be included in each life cycle activity."
.bp
.SEC0 APSE TOOL TAXONOMY
.PP
"APSEs are the highest levels of toolset.  APSEs should contain all the tools
and toolsets needed to support the full spectrum of project activities."
.SEC1 Computer Management System.
"Those tools needed to access, use, and maintain the hardware and
software which consists of the APSE and the system on which it runs."
.SEC2 Command Language Processor
.SEC2 Archive, Backup, and Retrieval System
.SEC2 Security System
.SEC2 Job Scheduler
.SEC2 Resource Controller
.SEC2 File Manager
.SEC2 Import/Export System
.SEC2 On-Line Assistance Processor
.SEC2 Data Base Manager
.SEC1 Project Management System.
"Those tools needed to plan, develop, and maintain an applications system."
.SEC2 Cost Estimator
.SEC2 Quality Analyzer
.SEC2 Scheduler
.SEC2 Work Breakdown Structure
.SEC2 Resource Estimator
.SEC2 Tracking
.SEC2 Configuration Manager
.SEC2 Problem Report Analyzer
.SEC2 Change Request Analyzer
.SEC1 Compilation System.
"Those tools needed to produce and run software systems."
.SEC2 Program Library Manager
.SEC2 Syntax-Directed Editor
.SEC2 Compiler
.SEC2 Assembler
.SEC2 Linker
.SEC2 Loader
.SEC2 Interpreter
.SEC2 Runtime Library
.SEC1 Document System.
"Those tools needed to develop and produce documents."
.SEC2 Document Manager
.SEC2 Word Processor
.SEC2 Spell Checker
.SEC2 Graphics Generator
.SEC2 Formatter
.SEC1 Desktop System.
"Those tools needed to do the every-day, administrative tasks of
business."
.SEC2 Spreadsheet
.SEC2 Calculator
.SEC2 Address Book
.SEC2 Electronic Mail
.SEC2 Phone Book
.SEC2 Electronic Conferencing
.SEC2 Calendar
.SEC2 Dictionary
.SEC1 Static Analyzer System.
"Those tools needed to do analysis of software systems without actually
executing the program(s) being analyzed."
.SEC2 Comparator
.SEC2 Data Flow Analyzer
.SEC2 Functional Analyzer
.SEC2 Interface Analyzer
.SEC2 Traceability Analyzer
.SEC2 Testability Analyzer
.SEC2 Test Condition Analyzer
.SEC2 Quality Analyzer
.SEC2 Complexity Measurer
.SEC2 Correctness Checker
.SEC2 Completeness Checker
.SEC2 Consistency Checker
.SEC2 Reusability Analyzer
.SEC2 Syntax and Semantics Checker
.SEC2 Reachability Analyzer
.SEC2 Cross Referencer
.SEC2 Maintainability Analyzer
.SEC2 Invocation Analyzer
.SEC2 Scanner
.SEC2 Structured Walkthrough Tool
.SEC2 Auditor
.SEC2 Error Checker
.SEC2 Statistical Analyzer
.SEC2 Statistical Profiler
.SEC2 Structure Checker
.SEC2 Type Analyzer
.SEC2 Units Analyzer
.SEC2 I/O Specification Analyzer
.SEC2 Sizing Analyzer
.SEC1 Dynamic Analyzer System.
"Those tools needed to do analysis of software systems while
actually executing the program(s) or some representation of the system
being analyzed."
.SEC2 Requirements Simulator
.SEC2 Requirements Prototype
.SEC2 Simulation and Modelling Tools
.SEC2 Design Prototype
.SEC2 Debugger
.SEC2 Executable Assertion Checker
.SEC2 Constraint Evaluator
.SEC2 Coverage/Frequency Analyzer
.SEC2 Mutation Analyzer
.SEC2 Testing Analyzer
.SEC2 Regression Testing Analyzer
.SEC2 Resource Utilization Analyzer
.SEC2 Emulator
.SEC2 Timing Analyzer
.SEC2 Tuning Analyzer
.SEC2 Reliability Analyzer
.SEC2 Real Time Analyzer
.SEC2 Formal Verification System
.SEC2 Symbolic Execution System
.bp
.SEC0 ATTRIBUTES of an APSE
.PP
"Attributes are the characteristics of tools or "whole APSEs" which the
E&V user evaluates (or validates) to make assessments and
comparisons."  At the top level, three main attributes are of concern:
.sp 1
.in +5
.rm -5
.ti -2
- Performance: how well does it function?
.sp 1
.ti -2
- Design: how well is it designed?
.sp 1
.ti -2
- Adaptation - how adaptable is it?
.sp 1
.ti -2
- Software-Oriented Criteria
.br
.rm +5
.in -5
.sp 1
.SEC1 Performance.
"Performance quality factors deal both with the ability of the
software to function and with error occurrences that affect software
functioning.  Low quality factors predict poor software performance."
.SEC2 Efficiency.
"Efficiency deals with utilization of resources.  The extent to which
a component fulfills its purpose using a minimum of computing resources.
Of course, many of the ways of coding efficiently are not necessarily efficient
in the sense of being cost-effective, since transportability, maintainability,
etc., may be degraded as a result."
.SEC2 Integrity.
"Integrity deals with software failures due to unauthorized access.
The extent to which access to a component or associated data by
unauthorized persons can be controlled."
.SEC2 Reliability.
"Reliability concerns any software failure.  The extent to which a
component can be expected to perform its intended functions in a
satisfactory manner."
.SEC2 Survivability.
"Survivability deals with the continued performance of software
(e.g., in a degraded mode) even when a portion of the system has failed."
.SEC2 Usability.
"Extent to which resources required to acquire, install, learn, operate,
prepare input for, and interpret output of a component are minimized."
.SEC1 Design.
"Design quality factors deal mainly with software failure and correction.
Low quality levels usually result in repeating a portion of the
development process (e.g., redesign, recode, reverify);
hence the term design."
.SEC2 Correctness.
"The extent to which software design and implementation conform to
specifications and standards.  Criteria of correctness deal exclusively
with design and documentation formats.  Agreement between a component's total
response and the stated response in the functional specification (functional
correctness), and/or between the component as coded and the
programming specification (algorithmic correctness)."
.SEC2 Maintainability.
"The ease of effort in locating and fixing software failures.  The
extent to which a component facilitates updating to satisfy new
requirements or to correct deficiencies.  This implies that the component
is understandable, testable, and modifiable."
.SEC2 Verifiability, Testability.
"Software design characteristics affecting the effort to verify software
operation and performance.  The extent to which a component facilitates the
establishment of verification criteria and supports evaluation of
its performance.  This implies that requirements are matched to specific
modules, or diagnostic capabilities are provided, etc."
.SEC1 Adaptation.
"Adaptation quality factors deal mainly with using software beyond its
original requirements, such as extending or expanding capabilities and
adapting for use in another application or environment.  Low quality
levels predict relatively high costs for new software use."
.SEC2 Expandability, Flexibility.
"The effort in increasing software capabilities or performance or to
accommodate changes in requirements.  The extent to which a component
allows new capabilities to be added and existing capabilities to be
easily tailored to user needs."
.SEC2 Interoperability.
"The effort in coupling software of one system to software of one or more
other systems.  The ability of APSEs to exchange data base objects and their
relationships in forms usable by components and user programs without
conversion.  Interoperability is measured by the degree to which this
exchange can be accomplished without conversion."
.SEC2 Reusability.
"The extent to which a component can be adapted for use in another application."
.SEC2 Transportability.
"The extent to which a component can be adapted for use in another
environment (e.g., different host or target hardware, operating system,
APSE).  The ability of a component to be installed on a different APSE
without change in functionality.  Transportability is measured in the
degree to which this installation can be accomplished without reprogramming."
.SEC1 Software-Oriented Criteria
.SEC2 Accuracy.
"Those characteristics of software which provide the required
precision in calculations and outputs."
.SEC2 Anomaly Management, Fault or Error Tolerance, Robustness.
"Those characteristics of software which provide for continuity of
operations under and recovery from non-nominal conditions.  The
protection of a component from itself, user errors, and system errors.
The ability to recover and provide meaningful diagnostics in the event of
unforeseen situations.  A robust routine will avoid failing for input
values where the desired output is well-defined, but the intermediate
results of a straightforward implementation may cause the routine to
fail."
.SEC2 Application Independence.
"Those characteristics of software which determine its non-dependency
on database
system, microcode, computer architecture, and algorithms."
.SEC2 Augmentability.
"Those characteristics of software which provide for expansion of
capability for functions and data."
.SEC2 Autonomy.
"Those characteristics of software which determine its non-dependency on
interfaces and functions."
.SEC2 Capacity.
"The upper and lower limits of the functions implemented by a tool."
.SEC2 Commonality (Data and Communication).
"Those characteristics of software which provide for the use of
interface standards for protocols, routines, and data representations.
The set of assumptions made by the component and made about the
component by the remaining components and the system in which it appears.
Software components have control, data, and service interfaces.
Included in this attribute is conformance to any existing pertinent
interface standards such as the CAIS.
.SEC2 Communication Effectiveness.
"Those characteristics of the software which provide for minimum
utilization of communications resources in performing functions."
.SEC2 Completeness.
"The extent to which a component provides the complete set of operations
necessary to perform a function."
.SEC2 Consistency.
"Those characteristics of software which provide for uniform design and
implementation techniques and notation."
.SEC2 Cost.
"The cost of a complete component or the costs of features of a component.
The cost of a component may vary depending on delivery with source code or
object code only (for example).  Other cost considerations are installation,
user assistance, and maintenance support."
.SEC2 Distributedness.
"Those characteristics of software which determine the degree to which software
functions are geographically or logically separated within the system."
.SEC2 Document Accessibility.
"Those characteristics of software which provide for easy access to software
and selective use of components."
.SEC2 Functional Overlap.
"Those characteristics of software which provide common functions to both
systems."
.SEC2 Functional Scope.
"Those characteristics of software which provide commonality of functions
among applications."
.SEC2 Generality.
"Those characteristics of software which provide breadth to the functions
performed with respect to the application."
.SEC2 Granularity.
"The degree to which a component has separate limited functions that are
composible, user selectable, and communicate through a common data base."
.SEC2 Maturity.
"The extent to which a component has been used in the development of
deliverable software by typical users and to which the feedback from that
use has been reflected in modifications to the component."
.SEC2 Modularity.
"Those characteristics of software which provide a structure of highly
cohesive components with optimum coupling.  The extent to which a
component is implemented in a hierarchical structure in which identifiable
functions are isolated in separate compilation units."
.SEC2 Operability, Communicativeness.
"Those characteristics of software which determine operations and
procedures concerned with operation of software and which provide useful
inputs and outputs which can be assimilated.  The user/component dialog
established to control the execution of the component.  This is driven by
the set of assumptions made by the component and made about the component
by the persons who use it."
.SEC2 Power.
"The extent to which a component has capabilities, such as default options
and wild card operations, that contribute to the effectiveness of the user."
.SEC2 Processing (Execution) Effectiveness.
"Those characteristics of the software which provide for minimum utilization
of processing resources in performing functions.  The choice between
alternative algorithms based on those taking the least amount of time."
.SEC2 Proprietary Rights.
"Restrictions on the release, distribution, or use of a component.
This includes so called "data rights" restrictions."
.SEC2 Reconfigurability.
"Those characteristics of software which provide for continuity of
system operation when one or more processors, storage units, or communication
links fails."
.SEC2 Rehostability.
"The ability of an APSE component to be installed on a different host or
different operating system with needed reprogramming localized to the
KAPSE or machine dependencies."
.SEC2 Required Configuration.
"The amount and types of hardware or software facilities needed for the
operation of a component.  This includes primary and secondary storage and
any other required resources."
.SEC2 Retargetability.
"The ability of an APSE component to accomplish its function with respect
to another target.  The component may require modification."
.SEC2 Self-Descriptiveness.
"Those characteristics of software which provide explanation of the
implementation of functions.  The technical data, including on-line,
documentation, listings, and printouts, which serve the purpose of
elaborating the design or details of a component."
.SEC2 Simplicity.
"Those characteristics of software which provide for definition and
implementation of functions in the most non-complex and understandable
manner.  A simple program style is one which makes the program, as a whole,
easy to understand.  Other things being equal, the style is concise and
straightforward.  It makes use of process, procedural, and data
abstraction, as appropriate, to present a clear exposition of the intent."
.SEC2 Software Production Vehicle(s).
"The methodology(ies), language(s), and technique(s) used to produce the
software related to a component."
.SEC2 Storage Effectiveness.
"Those characteristics of the software which provide for minimum utilization
of storage resources in performing functions.  The choice between
alternative source code constructions based on those taking the
minimum number of words of object code or in which the
information-packing ... is high."
.SEC2 System Accessibility.
"Those characteristics of software which provide for control and audit of
accesses to the software and data."
.SEC2 System Clarity.
"Those characteristics of software which provide for clear description of
program structure in a non-complex and understandable manner."
.SEC2 System Compatibility.
"Those characteristics of software which provide the hardware,
software, and communication capability of two systems."
.SEC2 Traceability.
"Those characteristics of software which provide a thread of origin from the
implementation to the requirements with respect to the specified
development envelope and operational environment."
.SEC2 Training.
"Those characteristics of software which provide transition from current
operation and provide initial familiarization.  The extent to which training
and other user help is available from the vendor of a component or from the
component itself, including on-line, documentation, listings, and
printouts, which serve the purpose of providing operating instructions
for using the component to obtain desired results."
.SEC2 Virtuality.
"Those characteristics of software which present a system that does not
require user knowledge of the physical, logical, or topological
characteristics."
.SEC2 Visibility, Test Availability.
"Those characteristics of software which provide status monitoring of
the development and operation.  The availability of tests that verify
the correctness or effectiveness of a component function or feature.
These tests may also verify proper response for an incorrect input or
technique."
.bp
.SEC0 TAXONOMY of APSE FUNCTIONS
.PP
This taxonomy is divided at the top level into three main areas:
.sp 1
.in +5
.rm -5
.ti -2
- Transformation
.sp 1
.ti -2
- Management
.sp 1
.ti -2
- Analysis
.rm +5
.in -5
.sp 1
.SEC1 Transformation.
"Transformation features describe how the subject is manipulated to accommodate
the user's needs.  They describe what transformations take place as input to
the tool is processed."
.SEC2 Editing (Text, Data, Graphics).
"Selective revision of computer-resident data."
.SEC2 Formatting
(MIL-STD, Table of Contents, Pre-Define and User-Defined Forms).
"Arranging data according to predefined and/or user-defined conventions."
.SEC2 On-Line Assistance Processing.
"User interface that is part of the input/output process of a programming
support environment (e.g., command assistance, assistance, on-line tutoring,
definition assistance, etc.)."
.SEC2 Sort/Merge.
"The process of arranging data in a specific order (e.g., alphabetical order)."
.SEC2 Graphics Generation.
"The input, construction, storage, retrieval, manipulation, alteration,
and analysis of pictorial data (e.g., generation of system architectures,
software designs, financial analysis, maps, graphs, etc.)."
.SEC2 Translation
(Requirements, Design, Code Compilation, Execution and Interpretation).
"The conversion from one language form to another."
.SEC2 Synthesis
(Design, Requirements, Code, Decompilation and Disassembly).
"The generation of programs according to predefined rules from a program
specification or intermediate language."
.SEC1 Management.
"Features that aid the management or control of system/software
development."
.SEC2 Information Management
(Data Base, Documentation, Files, Electronic Mail,
Electronic Conferencing, Specifications, Program Library, Test Data,
Evaluation Results, Performance Monitoring).
"The organization, accessing, modification, dissemination, and processing of
information that is associated with the development of a software system."
.SEC2 Project Management
(Cost Estimation, Quality Specification, Scheduling,
Work Breakdown Structure, Resource Estimation, Tracking, Configuration
Management, Quality Assessment).
"The management of a system/software development project."
.SEC2 Computer System Management
(Command Language Processing, Input/Output
Support, Kernel, Math/Statistics, Runtime Environment, Import/Export).
"The management of hardware/software architectures to support the life cycle
software engineering environment.  Such services include: creating, scheduling,
and removing tasks; switching the processor among tasks;
sending messages between tasks; providing direct and import/export
access; managing distributed systems; sending files from one host
machine to another on a network, etc."
.SEC1 Analysis.
"The features that provide an examination of a substantial whole to determine
both qualitative and quantitative properties."
.SEC2 Static Analysis
(Comparison, Spelling Checking, Data Flow Analysis,
Functional Analysis, Interface Analysis, Traceability Analysis,
Testability Analysis, Test Condition Analysis, Quality Analysis,
Complexity Measurement, Correctness Checking, Completeness Checking,
Consistency Checking, Reuseability Analysis, Syntax and Semantics
Checking, Reachability Analysis, Cross Reference, Maintainability
Analysis, Invocation Analysis, Scanning, Structured Walkthrough,
Auditing, Error Checking, Statistical Analysis, Statistical Profiling,
Structure Checking, Type Analysis, Units Analysis, I/O Specification
Analysis, Sizing Analysis).
"Static analysis features specify operations on the subject without regard
to the executability of the subject.  They describe the manner in which
the subject is analyzed."
.SEC2 Dynamic Analysis
(Requirements Simulation, Requirements Prototyping,
Simulation and Modeling, Design Prototyping, Debugging,
Executable Assertion Checking, Constraint Evaluation,
Coverage/Frequency Analysis, Mutation Analysis, Testing,
Regression Testing, Resource Utilization, Emulation, Timing,
Tuning, Reliability Analysis, Real Time Analysis).
"Dynamic analysis features specify operations that are determined during or
after execution takes place.  Dynamic analysis features differ from those
classified as static by virtue of the fact that they require some form of
symbolic or machine execution.  They describe the techniques used by the
tool to derive meaningful information about a program's execution behavior."
.SEC2 Formal Verification.
"The use of rigorous mathematical techniques to prove the consistency between
an algorithmic solution and a rigorous, complete specification of the intent
of the solution."
.SEC2 Symbolic Execution.
"The reconstruction of the logic and computations along a program path by
executing the path with symbolic rather than actual values of data."
.SEC2 Problem Report Analysis.
"The analysis of problem reports for the purpose of determining the validity
of the reported problem and a corrective action."
.SEC2 Change Request and Change Impact Analysis.
"The Change Request Analysis is
the analysis of change requests to determine the necessity of the change,
technical/economic impacts, and approach to accomplishing the change.
The Change Impact Analysis is the ability to determine, for a proposed
support/enhancement operation, the impact of proposed changes to the
software system."
.bp 2
.pn lower_roman
.sp 4
.ce
.ul
TABLE of CONTENTS
.sp 2
.pc
.bp
.sp 20
.ce
This page intentionally blank
--::::::::::
--hdbk1804.doc
--::::::::::


                                   DRAFT


                          ADA STYLE GUIDE HANDBOOK

                              MIL-HDBK-1804






                          TABLE OF CONTENTS

1.0     SCOPE
1.1     Introduction
1.2     Scope
1.3     Goals

2.0     REFERENCED DOCUMENTS
2.1     Usage
2.2     Referenced Documents

3.0     DEFINITIONS
3.1     Introduction
3.2     Handbook
3.3     Standard

4.0     GENERAL REQUIREMENTS

5.0     SPECIFIC GUIDELINES
5.1     Introduction
5.2     Lexical Elements
5.3     Declarations and Types
5.4     Names and Expressions
5.5     Statements
5.6     Subprograms
5.7     Packages
5.8     Visibility
5.9     Tasks
5.10    Program Structure and Compilation Issues
5.11    Exceptions
5.12    Generic Units
5.13    Representation Clauses and Implementation-Dependent Features
5.14    Input-Output



                                   1.  SCOPE.
 
 
1.1  Introduction.  Ada is a programming language of considerable expressive  
power.  ANSI/MIL-STD-1815A, Ada Programming Language, provides a thorough  
definition of the language.  However, it does not offer sufficient guidance on 
the appropriate use of Ada's powerful features.  This document was developed  
to address "program style" issues and is presented as if the reader does not  
have a mentor to explain all the whys and wherefores.  It is for this reason 
the document goes beyond styling techniques in some sections by showing 
what is "good and proper" Ada constructs, denoting what to avoid, or why  
certain constructs are used in a particular manner (proper software 
engineering techniques are also "good style").  Besides, both facets are  
needed in the code produced for the next person in line - the maintainer  
and/or reuser. 
 
1.2  Scope.  Program source code serves two functions:  to specify an  
algorithm to be performed on a computer, and to communicate this algorithmic  
design to other human readers.  Program style relates to how well a program  
meets the second function.  It is a consistent manner of using the features of 
a programming language to promote the maintainability, readability and 
understandability of a program.  This is a matter of the form of the final,  
delivered, program source code, as opposed to the process of developing the 
code. 
 
1.3  Goals.                                                                    
 
     a.  While some of what constitutes "good style" is subjective and  
somewhat arbitrary, it is important that the style of a program be consistent  
throughout the program.  The primary goal of this guide is to promote such  
consistent use of good style across large numbers of Ada programs.  The whole  
intent of "good style" is to increase the readability of these programs.   
Therefore, these guidelines follow from general principles of program  
readability and understandability. 
 
     b.  The program should reflect the natural levels of abstraction in the  
problem domain, so that the reader can reasonably comprehend each level  
individually.  Just as entites in real world applications have structure and 
organization, so should Ada software systems.  Furthermore, on a gobal level, 
the overall software architecture should exhibit clarity and be readilly 
comprehended.  Ada coding style plays an important role in attainment of  
these goals. 
 
     c.  There are several features in Ada which are unfamiliar to many  
programmers.  There is thus a tendency to either underuse these features or to 
use them inappropriately.  A feature of Ada should generally not be ignored,  
but neither should it be used in excess.  The guidelines highlight the proper  
use of Ada features.  Keep in mind, there are features in the Ada language 
that when used, are considered poor programming and/or software engineering 
practices.  Most of this knowledge has become apparent through the use of the 
language.  This guide's intent is to alert the reader of these practices; and 
although they are functionally correct, should be avoided.  (Words to that 
effect will be used). 
 
     d.  The textual format of a program should be pleasing to the eye and  
promote the readability and understandability of the program.  The format  
should highlight the structure of a program and the role of a program as a  
model of the problem domain.  Just as the careful layout of a book can enhance 
written communication, the careful layout of a program can enhance the  
communication of algorithmic design to another human.  The consistent use of  
formatting style is especially important, because it allows readers to become  
accustomed to the familiar layout of the program constructs.  An automated  
formatting program is particularly helpful, but even in the absence of such a  
tool, much can be gained from a common format style. 

                          2. REFERENCED DOCUMENTS  
 
 
2.1  Usage.   
 
     a.  This is not a static document.  Other references need to be consulted 
to provide a valid mix of ideas and "legal" practices when coding Ada.  Where  
applicable, conformity among the references should be obtained.  Instances, 
for example, where adopting an ISO or ARTEWG practice does not have a negative 
impact, should be encouraged. 
 
     b.  A listing of other references beside the one given in paragraph 2.2 
will not be made.  Other documents were referenced; however, to list them 
could be construed as an endorsement of the document to the exclusion of  
others.  Better none than to miss one. 
 
2.2  Reference documents.  ANSI/MIL-STD-1815A, Ada Programming Language.  
 
                                3.  DEFINITIONS 
 
 
3.1  Introduction.  The definitions and acronyms provided in Ada Reference  
Manual - ANSI/MIL-STD-1815A are applicable for use with this handbook.  Since  
this handbook is intended to be a companion document to the Ada Programming  
Language manual, the definitions and acronyms are not restated here.   
 
3.2  Handbook.  The term "Handbook" (capitalization intended) refers to this  
document, MIL-HDBK-1804, Ada Style Guide Handbook.  This simplification is  
used to improve readability.  
 
3.3  Standard.  The term "Standard" (capitalization intended) refers to  
ANSI/MIL-STD-1815A, Ada Programming Language.  This simplification is to  
improve readability.  
 
                           4. GENERAL REQUIREMENTS  
 
                                NOT APPLICABLE  
 
                           5.  SPECIFIC GUIDELINES  
 
 
5.1  Introduction.  This section contains fourteen major subparagraphs (5.1  
through 5.14) corresponding to the fourteen chapters of ANSI/MIL-STD-1815A,  
Ada Programming Language.  This provides a standard frame of reference for the 
discussion of Ada features.  Where appropriate, the guide includes examples  
and justifications for various guidelines.  Some of the major subparagraphs,  
themselves, have an "Examples" subparagraph giving additional, longer examples 
for the topic.  When more than one example is shown, the order of preference 
will be with the first example, then the second, etc. 
 
5.1.1  Correlation.  Each major subparagraph bears the same title as its 
corresponding chapter in the Standard, e.g.  Lexical elements is chapter 5.2 
in this style guide.  In the Standard, the basic definition starts in chapter  
2. 
 
5.1.2  Handbook Format. 
      
     a.  Some constraints are implicity included in this Handbook.  The reason 
- the explanations are directed towards the Management Information Systems 
environment moreso than the real-time, embedded systems environment.  (Granted,
Ada was initially intended for the latter).  Problems in "style" may occur 
when information presented is slanted towards large memory features instead of 
constrained, limited memory systems.  (Block statements come to mind as an 
example).  Therefore, for real-time programmers/maintainers, comments starting 
with "REAL_TIME" will be included and are directed to their use. 
 
     b.  Non-numbered paragraphs are editorial comments included to provide 
further clarifications.  Also, information in this category and begun with 
the notation of "NOTE:", are of specific interest and special attention should 
be paid to them. 
 
5.1.3   Non-compliance.   It should be noted that some compilers contain 
restrictions that may not allow compliance with all of the guidelines contained
in Section 5.2 and beyond.  An example would be the inability of a system to 
allow the use of the underscore.  The Standard, chapter 2.1, "Charater Set", 
includes the underscore as an allowable special character.  Obviously, a 
physical impasse is apparent, and as such, should be documented up front in  
the program.  This is a basic premise of this guide - if you cannot comply 
with the guidance, information stating such should appear in the program. 
 
5.1.4   Basic Style Format. 
 
      a.  The emphasis in style is to have distinct, recognizable parts.  That 
is, information to be defined should be on one side, information doing the 
defining on the other; or, on one line, with the defining components on the 
following line(s).  The right-left concept comes more into play with the usage 
of the assignment operator (see 5.2.2.7).  The one-line-next-line concept will 
cover the majority of style formating use. 
 
      b.  The reasons for promoting the one-line-next-line style are reada- 
bility and understandability.  From the first character on a line to its 
associated semicolon, some information contained between the two must be 
dominant, some must be subordinate.  Whether all the information is on one 
line or many does not matter syntactically, it does for readability and 
understandability.  Therefore, to promote easier end of line comments,  
maintainability, as well as readability and understandability, the following 
basic style is recommended (exceptions are delineated in other chapter 5 
subchapters): 
 
      1)  Reserved words denoting various elements of an Ada program and 
their associated names should be on one line, their subordinate information 
on the succeeding line(s), e.g. 
 
          procedure  
            []; 
 
          function  
            []; 
 
      2)  Type declarations or other reserve word phrases ending with a verb 
should be on one line, its subordinate information on the succeeding line(s), 
e.g. 
          type (identifier> is 
            ; 
 
          task type  is 
            ; 
          end ; 
 
          task body  is separate; 
 
          : 
          while  loop 
             
          end loop ; 
 
     3)  Objects, strings and similar declarations where the colon 
differentiates the identifier from the definition, should be "muliti-lined" 
by placing the identifier on one line and the colon and the definition on 
the subsequent line(s), e.g. 
 
           
            : ; 
 
     4)  Information being protrayed using the assignment operator should 
use the left-right concept, e.g. 
    
          identifier :=  [ 
                        ]; 
 
The expression(s) are continued by leaving an operator on the previous line 
and continuing the expression directly under the start of the expression on 
the line above (see 5.2.2.7 for an example). 
 
     5)  The basic formats are not used if multiple occurrences of the same 
form are used in a subordinate role (see 5.3.8.4 b), e.g. 
 
          package  is 
            procedure  []; 
            procedure  []; 
            function    []; 
            function    []; 
          private 
          end ; 
 
NOTE:  if any of the procedures or functions in the above example require 
continuation to the next line, all of the subordinate information should be 
continued in the same manner (see 5.2.2.7). 
 
5.2  Lexical elements. 
 
 
5.2.1  The package STANDARD.  Language words with predefined meanings in the  
package STANDARD should not be redefined. 
 
5.2.2  Formatting of lexical elements. 
 
5.2.2.1  Indentation.  The preferred indentation level is two spaces. 
Exceptions are in some cases continuations. 
 
NOTE:  The emphasis is more on the indention being consistent throughout the 
program than the exact number of spaces.  The key word is consistent! 
 
5.2.2.2  Character set.  Full use should be made of the ISO character set  
where available.  Alternate character replacements should only be used when  
the corresponding graphical symbols are not available or are reserved for 
other uses (see chapter 2.10, the Standard). 
 
5.2.2.3  Upper/lower case. 
 
NOTE:  This area is one of just a few that cause the most consternation among 
Ada coders because rationale can be provided for numerous formating methods. 
All things considered, the following was thought best ... 
 
    a.  Reserved words and attributes should appear in lower case, e.g. 
 
          package body Choice is separate; 
 
          type REAL is digits 8; 
 
    b.  All identifiers except type, enumeration value and attribute  
identifiers should be in mixed upper and lower case.  The first letter of each 

word in the identifier should be in upper case with other characters in lower  
case, unless a word is normally written in all upper case, as are acronyms. 
 
    Display_Device  
    Number_Of_User Names  
    Get_FHST_Data  
    Package_Name  
    List'first   -- "first" is an attribute designator (preceeded by an 
                 -- apostrophe), not a reserve word. 
 
    c.  Type names, subtype names and enumeration literals should appear in  
all upper case. 
 
 
    type COLOR        is (WHITE, RED, YELLOW, GREEN, BLUE, BROWN, BLACK); 
      subtype RAINBOW is COLOR range RED .. BLUE;  
 
    type ARMED_FORCE is (ARMY, AIR_FORCE, NAVY, MARINES);  
 
5.2.2.4  Identifiers. 
 
    a.  Identifier names should be meaningful and easily distinguishable from  
each other, including loop parameters, array indices, and common mathematical  
variables.  Names of objects and types should be nouns or noun phrases; names  
of procedures should be verbs or verb phrases; and, names of enumeration  
literals should be adjectives if they are meant to represent properties. 
 
    b.  Distinct words in identifiers should always be separated by  
underscores. 
 
    c.  The use of abbreviations in identifiers should be avoided.  When used, 

an abbreviation should be significantly shorter than the word it abbreviates,  
and its meaning should be clear.  The same abbreviations should be used  
consistently throughout a project, precedence is given to sanctioned 
standard data elements and codes or existing functional data dictionaries 
abbreviations, e.g. MGT for management; RQD for required. 
 
    d.  Acronyms should be avoided if at all possible. 
 
5.2.2.5  Spaces.  Single spaces should be used consistently between lexical  
elements to enhance readability. 
 
5.2.2.6  Blank lines. 
 
    a.  Blank lines should be used to group logically related lines of text. 
 
A careful use of blank lines can greatly enhance readability by making the   
logical structure of a sequence of lines more textually obvious.  However,  
the overuse of blank lines (e.g., "double spacing") defeats the very purpose  
of grouping and can actually reduce readability.  Blank lines should thus  
always be used with grouping in mind and not just to increase white space. 
 
    b.  A blank line should always preceed and follow a construct whose last  
line is not at the same indentation level as its first line. 
 
    -- preceeded by a blank line 
 
    type COMPLEX is  
      record  
        Real      :  REAL := 0.0; 
        Imaginary :  REAL := 0.0; 
      end record;  
 
   --  Followed by a blank line  
 
5.2.2.7  Continuation of statements. 
 
    a. tatements extending over multiple lines should be broken after reserved 
words, operators, delimeters, commas, or if a distinct entity can be 
separated.  The one-line-next-line concept should be utilized as discussed 
in the basic formats section, e.g. 
 
           package Information is 
             procedure Information_Left_Over 
               (Return_File : in RETURN_FILE_TYP); 
             function Check_Last_Element 
               (Return_File : in RETURN_FILE_TYP) 
                 return BOOLEAN; 
           end Information; 
 
For assignments, use the left-right concept, e.g. 
  
    Corrected-Value := ((1 + Sensor_Scale) * Raw_Value) +  
                       (Distortion_Factor * Distortion_Value) -  
                       Sensor_Bias;  
 
NOTE:  Redundant parenthesis are used (see 5.4.2.2). 
 
    b.  Long strings extending over more than one line should be broken up at  
natural boundaries, appropriate to the meaning of the contents of the string,  
if any. 
 
    "This is a rather long string, so it is likely that " 
      & "it will extend over more than one line" 
 
NOTE: Do not confuse continuation with basic format (see 5.1.4). 
 
5.2.2.8  Comments. 
 
    a.  Comments should be used to add information for the reader or to high-  
light sections of code, and should not merely paraphrase the code. 
 
    b.  Comments should begin with the "--" aligned with the indentation level 

of the code that they describe, or to the right of the code, aligned with  
other such comments. 
 
    -- Check if the user has special authorization 
    if Authority = SPECIAL then 
      Display_Special_Menu;    -- All operations are allowed 
    else 
      Display_Normal_Menu;     -- Only normal operations allowed 
    end if; 
 
    c.  Refrain from including any character after the "--", even though 
the Standard gives an example of numerous hyphens in a row.  Several formal 
specification languages (commercial-off-the-shelf tools) use the  
-- in development and production of automated specification  
documents. 
 
5.2.2.9  Length of a Line.  The preferred length of a line is 72 characters. 
Various restrictions begin to occur, window boarders, etc., if the line 
extends further. 
 
5.3  Declarations and types. 
 
NOTE:  Be advised and understand the limitations imposed with predefined 
numeric types (FLOAT, INTEGER, etc.) This is due to their implementation 
dependent precision. 
 
5.3.1  Constants. 
     a.  An object should be declared constant if its value is intended not to 
change. 
 
 Declaring an object to be constant clearly signals both the human reader and  
the compiler the intention that its value will not change.  This not only  
increases readability, it also increases reliability because the compiler will 
detect any attempt to tamper with the object.  Also, it can result in some  
decrease in executable size and better run time efficiency. 
 
     b.  Defining a constant object is preferable to using a numeric literal  
or expression with constant value, as long as the constant object has an  
intrinsic conceptual meaning.  Constants should not be used to avoid 
enumeration type. 
 
There is no use in defining a constant object when a numeric literal is  
obviously more appropriate, for example:  using "One" instead of "1." However, 

the use of constant objects with intrinsic meaning (such as "Buffer_Size" or  
"Field_Of_View") can greatly increase the readability of code.  Further, the  
code is more maintainable since a change in a value will be localized to the  
constant declaration. 
 
     c.  A named number (i.e., a constant object with type universal-integer  
or universal-real) should be used only for values that are truly "universal"  
and "typeless." Other numeric constants should be declared with an explicit  
type. 
 
Constants, such as "Pi", and cardinal integers (e.g., a "number of things")  
should be named numbers.  Note also that declaring a constant in terms of a  
predefined numeric type (INTEGER, FLOAT, etc.) in most cases has no advantage  
over a named number since these predefined types provide only range and  
accuracy constraints and not additional conceptual meaning.  In fact, since 
the range and accuracy of predefined numeric types is implementation-defined,  
portability can be increased by using named numbers, in those cases where a  
constant of a user-defined type is not more appropriate. 
 
     Pi 
       : constant := 3.141_592_65; 
 
     Number_Of Sensors          -- This is a named number  
       : constant := 4;  
 
     Main_Sensor_Number  
      : constant SENSOR_INDEX := 2;  
 
REAL_TIME:  Multiplication or division of a fixed point type by an integer 
results in an object of that fixed point type (as opposed to multiplication 
of an integer by an fixed point type, which results in an integer).  Using 
a constant of universal fixed rather than a specified fixed point type may 
force the introduction of an explicit type conversion, possible reducing the 
efficiency of the multiplication. 
 
5.3.2  Types and Subtypes. 
 
5.3.2.1  Types.  Separate types should be used for values that belong to  
logically independent declarations, and for distinct concepts.  
 
    type X_COORDINATE is  
      range 1 .. 640;  
 
    type Y_COORDINATE is  
      range 1 .. 480;  
 
    type PIXEL_VALUE is  
      range 0 .. 255;  
 
    type IMAGE_GRID is  
      array (X_COORDINATE, Y_COORDINATE) of PIXEL_VALUE;  
 
A data type characterizes a set of values and a set of operations applicable  
to objects of the type.  In the above example, each coordinate has a type  
because coordinates are independent entities.  Explicitly declaring these  
types makes the concepts more obvious to a human reader and also allows the  
detection of mistakes such as: 
 
    X_Coord : X_COORDINATE := 1; 
    Y_Coord : Y_COORDINATE := 1; 
    Pixel   : PIXEL_VALUE  := 0; 
    Image   : IMAGE_GRID; 
 
    Image (Y_Coord, X_Coord) := Pixel;    -- Should be "(X_Coord, Y_Coord)"  
 
The drawback of this kind of typing is that the following construct is  
illegal: 
 
    if X_Coord = Y_Coord then     -- ILLEGAL since X_Coord and Y_Coord  
      ...                         --   have different types  
 
A type conversion must be used:  
 
    if X_Coord = X_COORDINATE (Y_Coord) then  
    ...  
 
Note that, depending on context (and compiler quality), there may or may not  
be some run time penalty associated with type conversion (e.g., testing of  
range constraints). 
 
5.3.2.2  Subtypes.  For understandability and maintainability, all types and 
subtypes should be grouped together.  This ensures the type being subtyped, 
if it is user defined, already exists in the program.  Subtypes should be 
used if the problem consists of subsets of the base type, or subsets of the 
subsets, e.g. 
 
         type NON_NEGATIVE       is              range 0 .. INTEGER'last; 
           subtype ORDER_SIZE    is NON_NEGATIVE range 0 .. 1_000_000; 
             subtype SMALL_ORDER is ORDER_SIZE   range 0 .. 50; 
             subtype BIG_ORDER   is ORDER_SIZE   range 51 .. 1_000_000; 
 
5.3.3  Enumeration types.  An enumeration type should always be used in  
preference to an integer type, unless the logical nature of the concept to be  
modeled demands the other. 
 
For example the type:  
 
    type DEVICE_MODE is  
      (READ_ONLY, WRITE_ONLY, READ_WRITE);  
 
is preferable to encoding DEVICE_MODE as an integer 0, 1 or 2.  
 
5.3.4  "Point" types. 
 
5.3.4.1  Floating point types. 
 
    a.  To enhance portability, always specify the range, constraints and  
accuracy of a floating point type. 
 
    b.  The precision for the predefined floating types (FLOAT, etc.) is  
implementation-dependent, though all implementations should provide at least 6 
decimal digits of accuracy.  Explicitly declaring floating point accuracy 
should yield more reliable, efficient and portable code. 
 
5.3.4.2  Fixed point types.  Fixed point types should be expressed with the 
constraints and boundaries appropriate for the identifier.  Explicitly  
stating these parameters, as noted with floating point types, enhances the 
portability because the type will be code dependent instead of machine 
dependent. 
 
 
5.3.5  Record types. 
         a.  A record type is preferred when each component can be sensibly 
named, the components do not need to be dynamically indexed, and the 
combination of components is needed to provide full meaning to the type, e.g. 
 
             type COMPLEX is  
               record  
                 Real        : REAL := 0.0;  
                 Imaginary   : REAL := 0.0;  
               end record;  
 
"COMPLEX" needs both the Real and the Imaginary part to have meaning.   
Whereas, arrays are useful when one or more component(s) are primary over 
others, or access is needed via indexing, e.g. 
 
             type WORK_DAY is (MON, TUE, WED, THU, FRI, SAT, SUN, HOL); 
             type DOLLARS is array (5 .. 7) of INTEGER; 
             type OVERTIME is array (WORK_DAY) of DOLLARS; 
 
Once the dollars are "loaded" into OVERTIME, computations, etc. will be 
easier than having to scan records for the appropriate OVERTIME. 
 
         b.  Overcomplicated record structures should be avoided by grouping  
related data into subrecord types.  
 
             type COORDINATE is  
               record  
                 Row      : INTEGER range 1 .. 20;  
                 Column   : INTEGER range 1 .. 30;  
               end record;  
 
             type WINDOW is  
               record  
                 Top_Left      :   COORDINATE;  
                 Bottom_Right  :   COORDINATE;  
               end record;  
 
         c.  Discriminants.  Discriminants should be used whenever the object 
has closely related variances which would more easily be understood tied to 
a single data type, e.g. 
 
             type BUFFER (Size : BUFFER_SIZE := 100) is 
               record 
                 Position  : BUFFER_SIZE := 0; 
                 Value     : STRING (1 .. Size); 
               end record; 
 
A record component may or may not depend on the discriminant.  In the above 
example, the component Value depends on the discriminant Size for its upper 
boundary. 
 
         d.  Enumeration types should be used for discriminants of record  
variants  whenever possible.  A discriminant should generally have a default  
initialization only if the discriminant value is intended to change over the  
lifetime of an object. 
 
         e.  Variant parts.  One of the strong features of Ada is the use of 
variants in defining alternate lists of components.  This is good software 
engineering practice because all possible uses of a discriminant are defined 
and in one location, with the constraints being specified in the variable or 
a subtype declaration, e.g. (from the Standard) 
 
           type DEVICE  is (PRINTER, DISK, DRUM); 
           type STATE   is (OPEN, CLOSED); 
 
           type PERIPHERAL (Unit : DEVICE := DISK) is 
             record 
               Status  : STATE; 
               case Unit is 
                 when PRINTER => Line_Count   : LINE_RANGE; 
                 when others  => Cylinder     : CYLINDER_INDEX; 
                                 Track        : TRACK_NUMBER; 
               end case; 
             end record; 
 
In this example, a general record type is made for the three types of 
peripheral units.  From there, subtypes can be created of specific  
peripheral units, e.g. 
 
             subtype DRUM_UNIT is PERIPHERAL (DRUM); 
 
If a constraint was not stated in a subtype or variable declaration, the 
compiler would assume the default of DISK. 
 
5.3.6  Access types.  
 
         a.  Generally, access types should not be used when static types and  
stack allocation would be sufficient. 
 
         b.  Generally access types should be used only when it is necessary  
to have data structures with dynamic pointers or to dynamically create  
objects.  However, access types may be needed for static objects if this leads 

to a more consistent programming style (e.g., so that similar static and  
dynamic objects are treated identically).  For example, if linked lists are  
used in a program, there may be some lists which are constant, but which are  
still implemented as linked lists using access types.  This would allow, for  
example, passing these constant lists to subprograms which also handle dynamic 

lists. 
 
REAL_TIME:  There are certain instances where it is desirable to use access 
types to address static objects in embedded real-time applications.  Certain 
Ada compilers support only limited types of parameters when pragma INTERFACE 
is used (to assembly language, C, or some other language selected for 
efficiency or interface requirements), and access types are usually one of 
those supported when other static types, such as record structures, are not. 
 
5.3.7  Object declarations. 
 
    a.  A single object declaration should be used to gather objects of the 
same type, e.g. 
 
    Table Size, 
    Table Index, 
    Current Entry  
      : TABLE_RANGE;  
 
    b.  An object should not be declared using a unnamed constrained array  
definition. 
 
The unnamed array definition is the only case in Ada where an object can be  
declared to be of a type which does not have a name.  Instead, the array type  
should be named in an array type declaration, and that name used in the object 
declaration, even if there is only one object declared of that type. 
 
    type POOL_TYP is  
      array (POOL_RANGE) of CHARACTER;  
 
    POOL  
      : POOL_TYP;  
 
    c.  Objects should generally be initialized.  Where possible, objects  
should always be initialized by their declaration, rather than in later code. 
 
    Is_Found  
      : BOOLEAN  := FALSE;  
 
5.3.8  Formatting of declarations and types. 
 
 
5.3.8.1  Commenting. 
 
    a.  Type declarations (or groups of declarations) should be commented to  
indicate what is being defined, if that is not obvious from the type  
declaration itself. 
 
    type VELOCITY is            -- Inertial velocity relative to the Earth  
      array (1 .. 3) of FLOAT;  -- Three test samples needed for comparison 
 
    b.  Object declarations should always be commented if the object  
definition is unclear from the object and type identifiers alone.  Note  
that those properties of an object obtained from its type should not be  
repeated in comments on the object declaration. 
 
    Spacecraft_Velocity         -- Spacecraft orbital velocity, assuming a  
      : VELOCITY;               -- circular orbit  
 
5.3.8.2  Indentation.  All declarations in a single declaration part should  
begin with the same indentation level. 
 
5.3.8.3  Type definitions. 
 
    a.  Array type definitions should have one of the following formats: 
 
    type  is  
      array  of ;  
 
    type  is  
      array   
        of ;  
 
    b.  Record type definitions should have one of the following formats: 
 
    type  is  
      record  
          
          
      end record;  
 
    type   
      ( ;  
         ) is  
      record  
          
        case  is  
          when  =>  
              
              
 
        end case;  
 
      end record;  
 
    c.  All  and  should be 

formatted like object declarations (see paragraph 5.3.8.4). 
 
    d.  Other type definitions should be formatted as follows: 
 
    type  is  
      ;  
 
    subtype  is  
      ;  
 
    e.  Long enumeration type definitions should be formatted into easily  
readable columns. 
 
5.3.8.4  Formatting of object declarations. 
 
    a.  Object declarations should have one of the following formats.  The  
preferred formats are: 
 
      
      :  := ;  
 
    b.  When the subtype indication and/or expression is long, or when comments

are needed, it may be necessary to futher continue the declaration as follows: 
 
      
      :     -- narrative explanation of subtype 
        := ;  
 
    c.  Declarations containing short identifiers may also be formatted all on 
one line, and is the perferred method when used as subordinate or supportive 
declarations, e.g. 
 
         :      := ;  
 
In this case, all such declarations textually grouped together or appearing as 
components in a single record definition or in a single parameter list should  
have their ":" and ":=" symbols aligned. 
 
5.3.9  Examples for declarations and types. 
 
 
5.3.9.1  Example 3X1. 
 
    type SENSOR_ARRAY is  
      array (NATURAL range <>) of SENSOR;  
 
    UARS_Sensors                         -- Sensor configuration for the  
      : SENSOR_ARRAY (1 .. Num_Sensors); -- UARS control system  
 
5.3.9.2  Example 3X2. 
 
    type JULIAN_DATE_NUMERIC is  
      record  
        Two_Digit_Year   : INTEGER range 0 .. 99; 
        Numeric_Day      : INTEGER range 1 .. 366;  
      end record;  
 
5.3.9.3  Example 3X3. 
 
    type DEVICE is  
      (PRINTER, DISK, DRUM);  
 
    type STATE is       -- Operational state of a  
      (OPEN, CLOSED);   -- device.  
 
    type PERIPHERAL  
      (Unit : DEVICE := DISK) is  
      record  
        Status : STATE;  
        case Unit is  
          when PRINTER     =>  
            Average_Lines_Per_Page : INTEGER range 1 .. Page_Size;  
          when DISK | DRUM =>  
            Cylinder       : CYLINDER_INDEX;  
            Track          : TRACK__NUMBER;  
        end case;  
      end record;  
 
5.4  Names and expressions 
 
 
5.4.1  Aggregates. 
 
    a.  Aggregates are preferable to individually setting all or most of the  
components of an array or record. 
 
    b.  Named aggregates should be used where possible. 
 
5.4.2  Static expressions.  Being able to differentiate between static and 
universal expressions and their respective uses will assist in understanding 
different characteristics of software engineering practices, i.e. to 
maximize accuracy, static expressions should be used.  The detail can be 
provided to the depth desired, e.g. 
 
       Pi     : constant := 3.141_592; 
       Two_Pi : constant := 6.283_185; 
 
Whereas, understandability and readability are increased using universal 
expressions, e.g. 
 
       Half_Pi     : constant := Pi / 2.0; 
       Deg_To_Rad  : constant := Half_Pi / 90.0; 
       Rad_To_Deg  : constant := 1.0 / Deg_To_Rad; 
 
NOTE:  Two_Pi could have been gained by the expression   Pi * 2.0; however, 
if accuracy is needed to six decimal places, the static expression must be 
used or the original Pi would have to show additional decimal places. (The 
seventh decimal value for Pi is a 6; therefore, doubling Pi, the sixth 
decimal is a 5, not a 4 as would be obtained). 
 
5.4.3  Short-circuit control. 
 
    a.  Short-circuit control forms should generally be used only to avoid  
evaluation of an undefined or illegal expression.  Short circuit operators  
should not be used to optimize execution. 
 
    (N /= 0) and then (Total/N > Limit)  
 
    (Index = 0) or else User(Index).Not_Available  
 
    b.  The short-circuit control forms should be used to signal to a human  
reader that the correctness of the second condition depends on the results of  
the first.  They should not be used for micro-efficiency reasons, concerns  
better handled by an optimizing compiler.  If efficiency considerations are  
substantially important, "if" statements should be used instead of the short-  
circuit forms with functions used to avoid repeated code, if necessary. 
 
REAL_TIME:  Memory considerations are a concern; therefore, the opposite  
should be true, i.e. short-circuits should be used over "if" statements. 
 
5.4.4  Type qualification. 
 
    a.  An explicit type conversion should not be used if a type qualified  
expression is meant. 
 
        Good :  LONG_FLOAT'(3.141_59) 
        Bad  :  LONG_FLOAT (3.141_59) 
 
A qualified expression is used to state explicitly the type, and possibly sub- 
type, of a value.  A type conversion, however, results in the dynamic  
conversion of a value to a target type.  Sometimes a type conversion can be  
used to serve the purpose of a type qualification.  However, if the operand is 
already of the desired base type, a conversion is not really necessary and a  
qualification should be used instead. 
 
    b.  Type qualification should be avoided if possible, especially when 
the type of an enumeration literal or aggregate is not known from context. 
For example: 
 
    type COLOR is  
      (BLACK, RED, GREEN, BLUE, WHITE);  
 
    type LIGHT is  
      (RED, YELLOW, GREEN);  
 
    procedure Set  
      ( Color_Code : in COLOR );  
 
    procedure Set  
      ( Color-_Code : in LIGHT );  
    ...  
 
    Set (COLOR'(RED));   -- Type qualification must be used here to 
    Set (LIGHT'(RED));   -- resolve the overloading of Set and RED 
 
It would be better in this case to rename one of the Set procedures 
or to at least give them different parameter names so the overloading  
could be resolved using name notation. 
 
5.4.5  Formatting of names and expressions. 
 
5.4.5.1  Names. 
 
    a.  The name for a type should be a common noun indicating the class of  
the objects it contains. 
 
    DEVICE  
    AUTHORITY_LEVEL  
    USER_NAME  
    PHONE_LIST  
 
A type name should end with the suffix "_TYP" if convolution will develop  
among other types (enumeration, etc.) with the same name. 
 
    EMPLOYEE_TYP 
    SCHEDULE_TABLE_TYP 
    COLOR_TYP 
 
NOTE:  The POSIX/Ada committee has recommended the suffix "_TYPE" not be used 
because of various problems, and it will not be used in the Ada/POSIX 
interface standard. 
 
    b.  The names of non-BOOLEAN valued objects should be nouns, preferably  
more precise than the names of types. 
 
    Current_User  
      : USER_NAME;  
 
    Output_Device  
      : DEVICE;  
 
    Schedule_Table  
      : SCHEDULE_TABLE_TYP;  
 
    New_Employee  
      : EMPLOYEE_TYP;  
 
BOOLEAN valued objects should have predicate-clause (e.g., "Is Open") or  
adjective names. 
 
    User_Is_Available  
    List_Empty  
    Done  
    Not_Ready  
    Is_Waiting  
 
5.4.5.2  Parentheses.  Syntactically redundant parentheses should generally be 
used to enhance the readability of expressions, especially by indicating the  
order of evaluation.  This is true even for single expressions where operators 
of different precedence levels are present. 
 
For example:  
 
    Variance := (Roll_Error ** 2) + ((Yaw_Error ** 2) / 2);  
 
 
5.4.5.3  Aggregates format. 
 
    a.  When longer than two components, or whenever readability is  
improved, named aggregates should be formatted as indicated below, with one  
association per line and the "=>" arrows aligned. 
 
    Output_Device :=  ( Device         => DISK, 
                        Status         => CLOSED,  
                        Cylinder       => 1,  
                        Track          => Startup_Track_Num );  
 
    b.  Aggregates for multidemensional arrays may be formatted in a  
tabular fashion to enhance readability. 
 
5.5  Statements. 
 
 
5.5.1  Slice Statements.  Array slice assignments should be used rather than  
loops to copy all or part of an array.  This is more readable and less error  
prone, especially in the case of slices with overlapping ranges. 
 
    Client_List (Last_Client .. Number_Of_Clients) := 
      New_Clients (1 .. Num_New_Clients) 
 
NOTE: on format - array elements should stay with the array name, which is 
why a left-right format was not used in this instance (line too long). 
      on syntax - array slice assignments work properly only if both arrays 
are of the same type. 
 
5.5.2  If statements.  An "if" statement should not be used to create the  
effect of a "case" statement controlled by the value of an enumeration type  
other than BOOLEAN. 
 
5.5.3  Case statements. 
 
    a.  A "case" statement should be controlled by an enumeration type, not 
by a BOOLEAN value. 
 
    b.  When possible, the explicit listing of all choices on a "case"  
statement is preferable to the use of an "others" clause. 
 
This makes it easier for a human reader to see that the proper actions are  
being taken in all cases.  Further, if the enumeration type of the control  
expression is modified, the compiler will indicate overlooked alternatives.   
However, there are cases when an "others" clause makes sense.  For example, if 
the control expression is of type character, then it is usually best to use an 
"others" clause to handle the "undesired characters" case. 
 
5.5.4  Block statements. 
 
    a.  Blocks should be used cautiously to introduce local declarations or to 
define a local exception handler.  Resources for data local to the block are 
allocated only when the block is entered (elaborated).  This is a fundamental 
difference between procedures and blocks.  A procedure is callable by any 
number of other program units while a block is limited in scope to its 
immediate lexical level and cannot be called. 
 
To some extent, a block can be thought of as a procedure which is hard coded  
in-line.  However, a procedure call contributes to readability precisely by  
not having its source code in-line (providing a "functional abstraction").   
Therefore, blocks should always be used cautiously and only for specific  
purposes.  Thought should always be given to using a procedure call instead of 
a block to improve readability. 
 
    b.  Declarations of objects used only within a block should be nested  
within the block. 
 
REAL_TIME:  Procedure calls require substanial execution time overhead.  A  
potential run-time efficiency advantage of blocks is memory savings.  If a  
declare statement is used in the block, the resources for data which are local 
to the block will only be allocated when the block is entered.  Additionally, 
some compilers may deallocate these memory resources after the block is exited.

 
5.5.5  Exit statements.  "Exit" statements should be used cautiously, and  
only when they significantly enhance the readability of the code.  If used,  
the exit statement should use the name of the loop it is exiting. 
 
It is often more readable to use exit than to try to add BOOLEAN variables to  
a "while" loop condition to simulate exits form the middle of a loop.   
However, it can be difficult to understand a program where loops can be  
exited from multiple places.  It is best to limit the use of "exit" statements 
to one per loop, if possible, and it is generally more readable to use "exit  
when."  Use "if...then...exit; end if" when "last wishes" processing is needed.

 
REAL_TIME:  "Exit"s should not be used because they can greatly increase run 
time if the code at the exit address has to be paged into working space. 
 
5.5.6  Return statements.  It is preferable to minimize the number of return  
points from a subprogram, as long as this does not distract from the natural  
structure or readability of the subprogram. 
 
5.5.7  Goto statements.  It is deemed as poor programming practice to use  
"goto" statements.   
 
Use of the "goto" makes the textual structure of code less reflective of its  
logical structure.  Possible uses of the "goto" statement can always be  
handled by other constructs in Ada, such as a procedure call or via an exit.  
 
5.5.8  Formatting of statements. 
 
5.5.8.1  Statement sequences.  Blank lines should be used liberally to break  
sequences of statements into short, meaningful groups (see paragraph 5.2.2.6). 
 
    Put_Line ("Welcome to the Electronic Message System");  
 
    Logon_User (Current User);  
    User_Directory.Lookup  
      ( User_Name    => Current_User  
        Authority    => User_Authority );  
 
    if User_Authority = SPECIAL then  
      Put_Line ("** You have SPECIAL authorization **");  
    end if;  
 
5.5.8.2  If statement format. 
    a.  "If" statements should have the following format:  
 
    if  then  
        
        
    elsif  then  
        
        
    else  
        
        
    end if;  
 
    b.  Multiple conditions in an "if" clause should be grouped together,  
placed on appropriate lines, and aligned so as to enhance clarity. 
 
5.5.8.3  Case statement format.  "Case" statements should have the following  
format: 
 
    case  is  
      when  =>   
      when others    =>   
    end case;  
 
    case  is  
      when  =>  
          
          
      when others =>  
          
          
    end case;  
 
5.5.8.4  Loop statement format. 
 
    a.  "Loop" statements should have one of the following formats:  
 
    :  
     loop  
        
        
    end loop ;  
 
    b.  A loop should preferably have a loop identifier.  
 
5.5.8.5  Block statement format. 
 
    a.  Block statements should have the following format:  
 
    :  
    declare  
        
        
    begin  
        
        
    exception  
      when  =>  
          
          
    end ;   
 
    b.  Blocks should always have a block identifier.  
 
5.5.9  Examples for statements. 
 
See also examples 5.9.14.2, 5.9.14.3, 5.9.14.4, 5.14.5.1, and 5.14.5.2.   
 
5.5.9.1  Example 5X1. 
 
    if Security_Level = 0 then                 -- appropriate comments 
      Message_Classification :=UNCLASSIFIED;   -- should be placed here 
 
    elsif Security_Level > User_Clearance then -- stating what's going 
      Message_Classification := PROTECTED;     -- on 
 
    else  
      Message_Classification := Classification (Security_Level);  
 
    end if;  
 
5.5.9.2  Example 5X2. 
 
    case Sensor is  
      when ELEVATION => Record_Elevation (Sensor_Value);    --  
      when AZIMUTH   => Record_Azimuth (Sensor_Value);  
      when DISTANCE  => Record Distance (Sensor_Value);  
    end case;    
 
5.5.9.3  Example 5X3. 
 
     Read_File:  
     while not Text_IO.End_Of_File (File 1) loop  
       Text_IO.Get (File1, Next_Record);    --  
       Store_Record (Next_Record);  
     end loop Read_File;  
 
     Compute_Total_Taxes:  
     while Next /= Head loop  
       Total_Taxes := Total_Taxes + Next.Pay_Period Deductions;  
       Next :=  Next.Successor;  
     end loop Compute_Total_Taxes;  
 
     Merge Files:  
     for N in 1 .. Max_Num_Files loop  
       Get_Items:  
       for J in 1 .. Max_Num_Items loop  
         Get_New_Item (New_Item);  
         Merge_Item (New_Item, Storage_File);  
         exit Merge_Files when New _Item = Terminal Item;  
       end loop Get_Items;  
     end loop Merge_Files;  
 
5.5.9.4  Example 5X4. 
 
    Swap_Integers:  
    declare  
      Temp : constant INTEGER := U;  
    begin  -- Swap_Integers;  
      U := V;  
      V := Temp;  
    end Swap_Integers;  
 
    Check_Entry:  
    begin  
      Int IO.Get (Value);  
      Update (Value);  
    exception  
      when Data Error =>  
        Text_IO.New_Line;  
        Text_IO.Put_Line ("Value entry error.");  
        Entry_Error_Flag := TRUE;  
    end Check_Entry;  
 
5.6  Subprograms. 
 
 
5.6.1  Cohesion.  A subprogram should perform a single, conceptual action  
(i.e., should be "functionally cohesive"). 
 
The use of a subprogram increases readability by hiding the details of how an  
action is performed and giving it a descriptive name.  A subprogram should  
perform only a single conceptual action so that its use can be understood as  
independently as possible from its implementation details and it can be given  
a self-documenting name.  Note that simply shortening a program by placing  
"repeated code" into subprograms must be considered a secondary goal.  Thus it 
is quite acceptable to have subprograms which are only called at one place, so 
long as those programs define cohesive actions. 
 
NOTE:  Explicit parameter passing is the best way to build interfaces to  
subprograms.  This method keeps the affected variables clearly defined and 
visible.  Intensional use of side effects is considered poor programming 
practice and should be used on a limited basis.  If used, side effects should  
be extensively commented ... where they are taking place and where they are  
affected. 
 
5.6.2  Parameters. 
 
    a.  Subprograms with equivalent parameters should generally declare each  
parameter in the same position with the same identifier.  
 
    b.  Parameters with default expressions should be used only when they have 
very well known default values and/or they are defaulted most of the time,  
with the default being over-ridden only in special circumstances.  Great care 
should be taken in using defaults, insuring the "mixing" of default and named  
parameters does not disrupt the understandability and readability of the code. 
 
    c.  Parameters with default expressions should generally be placed at the  
end of the parameter list, so that they may be omitted if desired in calls  
using positional notation. 
 
    d.  As noted in the section for naming (5.2.2.4), parameters should  
follow a similar schema, chosen to promote readability of the subprogram  
calls, and where possible, should reflect the mode of the parameter. 
 
5.6.3  Recursion.  A recursive subprogram should generally be used only if  
it is conceptually simpler for a given problem than a corresponding iterative  
subprogram. 
 
Many people have difficulty in understanding a program which uses recursion  
extensively.  However, there are many cases where a recursive solution is  
considerably simpler and clearer than an iterative one.  This is especially  
true, for example, for traversing complicated data structures such as tree and 
graph structures. 
 
5.6.4  Functions.  A subprogram without side-effects returning a single  
value should generally be written as a function.  Since functions can be called
from within expressions, there is more freedom in how a function can be used. 
For example, if a function is to be called only once within some other
subprogram, it can be used to initialize a constant object. 
 
    procedure Process_Sensor Data is  
      Main_Sensor_Data  
        : constant SENSOR_DATA := Read_Sensor (Main_Sensor_Index);  
 
    begin  
      ...  
 
However, if this sort of freedom is specifically not desired, or if the  
subprogram has side effects, then use of a procedure should be considered  
instead of a function, even if the subprogram returns only a single value. 
 
5.6.5  Overloading. 
 
    a.  Overloading of subprograms should not be done. Use a meaningful  
function name instead.   Possible (a weak possible) exceptions are the  
following cases: 
 
        (1) Widely used utility subprograms which perform identical or very  
similar actions on arguments of different types (e.g., square-root of integer  
and real arguments). 
 
        (2)  Overloading of operator symbols. 
 
Note that this is not meant to cover subprograms with identical names in  
different packages, unless both subprograms are visible through "use" clauses  
for their packages. 
 
    b.  Operator symbols should be overloaded only when the new operator  
definitions comply closely with the traditional meaning of the operator (e.g., 
"+" for vector addition). 
 
5.6.6  Formatting of subprograms. 
 
 
5.6.6.1  Subprogram names. 
 
    a.  Except as indicated below, a subprogram name should be an imperative  
or interrogatory verb phrase describing its action. 
 
    Action_Complete 
    Obtain_Next_Token  
    lncrement_Line_Counter  
    Create_New Group 
  
     b.  Non-BOOLEAN valued function names may also be noun phrases. 
 
     Top_Of_Stack  
     X_Component  
     Successor  
     Sensor_Reading  
 
     c.  BOOLEAN valued functions should have predicate-clause names.  
 
     Stack_Is_Empty  
     Last_Item_Check 
     Device_Not_Ready  
 
5.6.6.2  Subprogram header.  Each subprogram specification, body or stub  
should be preceded by a header comment block containing at least the  
subprogram name and the indication SPEC, BODY, SPEC & BODY, STUB or SUBUNIT. 
 
       --  ............................  
       --  .                          .  
       --  .     Obtain_Next_Token    .     SPEC  
       --  .                          .  
       --  ............................   
 
5.6.6.3  Subprogram declarations. 
 
     a.  Procedure declarations should have the following format:  
 
     --  
 
     procedure   
       ( ;  
          );  
 
     --    
 
 Each  should be formatted like an object declaration 
(see paragraph 5.3.8.4).  The documentary comments should follow guideline d., 
below. 
 
    b.  Function declaration should have the following format:  
 
     --  
 
     function   
       ( ;  
          )  
       return ;  
 
     --   Each  should be  
formatted like an object declaration (see paragraph 5.3.8.4).  The  
 should follow guideline d., below. 
 
    c.  Parameter mode indications should always be used in procedure  
specifications.  In a function specification, mode indications should either  
be used for all of the parameters or none of the parameters. 
 
    d.  Subprogram declarations should be followed by at least the following  
documentation: 
 
  --  PURPOSE   <--headings can be upper or lower case 
  --  A description of all purposes and functions of the subprogram.  
  --   
  --  EXCEPTIONS  
  --  A list of all exceptions which may propagate out of the subprogram,and  
  --  a description of when each would be raised.  
  --   
  --  NOTES                                               
  --  Additional comments on the use of the subprogram, references, etc.  
 
The "Exceptions" and "Notes" headings should be included even if these  
sections are empty.  An empty section may be indicated by placing the  
annotation "(none)" after the appropriate header.  Only in the case that the  
subprogram declaration is a compilation unit, the following section should be  
added to the documentation: 
 
  --  MODIFICATIONS 
  --  A list of modifications made to the subprogram DECLARATION. 
  --  Each entry in the list should include the date of the change, 
  --  the name of the person who made the change and a description 
  --  of the modification.  The first entry in the list should 
  --  always be the initial coding of the subprogram declaration. 
 
5.6.6.4  Subprogram bodies and stubs. 
 
    a.  Subprogram bodies should have the following format if not standalone:  
 
    separate ()  
     is  
 
    --    
 
        
        
 
    begin  --   
 
        
        
    exception  
      when  =>  
          
    end ;  
 
The  should be formatted as in a subprogram  
declaration (see paragraph 5.6.6.3).  The  should follow 
guide- line b., below.  Note that the "end" of a subprogram should always  
include the subprogram name. 
 
    b.  Subprogram bodies should have AT LEAST the following documentation  
placed immediately after the subprogram header:  
 
  --  NOTES  
  --  Comments on the design, implementation and use of the  
  --  subprogram.  
 
The "NOTES" heading should be included even if the section is empty.  An empty 
section may be indicated by the comment "Notes (none)." Only in the case of a  
subprogram body which is a separate compilation unit from its specification,  
the following section should be added to the documentation. 
 
  --  MODIFICATIONS  
  --  A list of modifications made to the subprogram BODY.   
  --  Each entry in the list should include the date of the change,  
  --  the name of the person who made the change and a description  
  --  of the modification.  The description should identify exactly  
  --  where in the compilation unit that the change was made.  The  
  --  first entry in the list should always be the initial coding  
  --  of the subprogram body.  
 
If there is no declaration or stub for a subprogram, then the subprogram body  
should also include all the documentation required for a subprogram  
declaration (see paragraph 5.6.6.3). 
 
    c.  Subprogram stubs should have the following format: 
 
 is separate;  
 
where the  is formatted as in a subprogram  
declaration (see paragraph 5.6.6.3).  If there is no previous declaration for  
a separate subprogram, then the subprogram stub should be followed by the same 
documentary comments required for a subprogram declaration (see paragraph  
5.6.6.3). 
 
5.6.6.5  Named parameter association. 
 
    a.  Named parameter association should generally be used for procedure  
calls of more than a single parameter.  Positional parameters are generally  
preferred for function calls.  
 
    b.  Named and positional parameter associations should generally not be  
mixed in a single subprogram call.  
 
    c.  Named parameter associations should generally appear one to a line  
with formal parameters, "=>" symbols and actual parameters aligned. 
 
    Obtain_Next_Token  
      ( File        => Current Source File,  
        Position    => Current Column',  
        Token       => Next_Token );  
 
5.6.7  Examples for subprograms.  See also examples 5.7.6.3, 5.9.14.3,  
5.12.7.1, 5.12.7.3, 5.14.5.1, and 5.14.5.2. 
 
5.6.7.1  Example 6X1. 
 
       --  .............................  
       --  .                           .  
       --  .     Obtain_Next_Token     .   SPEC  
       --  .                           .  
       --  .............................  
 
         procedure Obtain_Next_Token  
           ( File      : in out Parser_Types.FILE;        -- sequential file  
             Token     : out    Parser_Types_TOKEN_TYP;  
             Position  : in     Parser_Types.COL_NUM_TYP := 0 );  
 
  --  Purpose  
  --  This procedure scans the current input line from the point at  
  --  which it was last called and returns the next token.      
  --  
  --  Exceptions  
  --  
  --  Source_File_Not_Open  --  Raised if the input file is not open      
  --  Notes (None)  
 
5.6.7.2  Example 6X2. 
 
       --  ..........................  
       --  .                        .  
       --  .      Decode_Token      .    SPEC  
       --  .                        .  
       --  ..........................  
 
    function Decode_Token  
      ( File    : Parser_Types.FILE;  
        Token   : Parser_Types.TOKEN_TYP )  
          return Parser_Types.TOKEN_TYP;  
 
  --  Purpose  
  --  This function returns the ordinal value of the decoded token.  
  --   
  --  Exceptions  
  --  Illegal Token  --  raised if the token is not legal  
  --   
  --  Notes  
  --  This function will later be changed to a procedure.  
 
5.6.7.3  Example 6X3. 
 
       --  ...............................  
       --  .                             .  
       --  .     Obtain_Next_Token       .     STUB  
       --  .                             .  
       --  ...............................  
 
    procedure Obtain_Next_Token  
      ( File      : in out Parser_Types.FILE;  
        Token     : out    Parser_Types.TOKEN_TYP;  
        Position  : in     Parser_Types. COL_NUM_TYP :=0 ) is separate;  
 
5.6.7.4  Example 6X4. 
 
       --  .........................   
       --  .                       .        
       --  .    Decode_Token       .    STUB  
       --  .                       .   
       --  .........................   
 
    function Decode_Token  
      ( File   : Parser_Types.FILE;  
        Token  : Parser_Types.TOKEN_TYP )  
          return Parser_Types.TOKEN_TYP is separate;  
 
5.6.7.5  Example 6X5. 
 
       --  ................................  
       --  .                              .  
       --  .     Obtain_Next_Token        .    SUBUNIT  
       --  .                              .  
       --  ................................  
 
    with Parser_Types,  
         File_Handler;  
 
    separate (Lexical_Analyzer)  
 
    procedure Obtain Next Token  
      ( File      : in out Parser_Types.FILE;  
        Token     : out    Parser_Types.TOKEN_TYP;  
        Position  : in     Parser_Types.COL_NUM_TYP :=0 ) is                    
      
 
   --  Notes (None)  
   --   
   --  Modifications                                 
   --  7/4/85   Rebecca DeMornay    Initial version of the subunit  
   --  9/6/85   R. DeMornay         Added the local function  
   --                               "Increment_Line_Counter".  
 
  type LINE_COUNT is                       -- A count of the number  
    range 1 .. File_Handler_Max Size;      -- of lines in a file.  
 
    Line_Counter : LINE_COUNT := 1;  
 
       --  ...............................  
       --  .                             .  
       --  .     Increment_Line_Counter  .    SPEC & BODY  
       --  .                             .  
       --  ...............................  
 
  function Increment_Line_Counter  
    ( File  : Parser_Types.FILE;  
      Line  : LINE_COUNT )                  -- Line number in "File"  
                                            -- at the time of call  
    return LINE_COUNT is  
 
  --  Purpose  
  --  This function increments the line counter from the point at  
  --  which it was after the last call of this routine.  
  --   
  --  Exceptions  
  --  Source_File_Not_Open     -- Raised if "File" is not open.  
  --  End_Of_File              -- Raised if the function is called and  
  --                              the end of the file has already been  
  --                              reached.  
  --   
  --  Notes (None)  
 
  begin    -- Increment_Line_Counter  
    ...  
  end Increment_Line_Counter;  
 
  begin    -- Obtain_Next_Token  
  exception  
    when File_Handler.FILE_ERROR => Token := Parse_Types.NONE;  
      raise Source_File_Not_Open;  
  end Obtain_Next_Token;  
 
5.7  Packages. 
 
 
5.7.1  Use of packages. 
 
    a.  There are numerous roles for packages, the following represent the  
most common:  
 
        (1) Model an abstract entity (or data type) appropriate to the domain  
of a problem. 
 
        (2) Collect related type and object declarations which are used  
together (this kind of package should generally be used only to provide a  
common set of declarations for two or more library units). 
 
        (3) To group together program units for essential configuration  
control (packages fulfilling this role alone should be used sparingly). 
 
The roles above are listed in order of decreasing desirability.  The first  
role, modeling a problem domain entity, is the strongest use of packages for  
structuring a program.  It corresponds to the requirement of functional  
cohesion for subprograms (see paragraph 5.6.1) and contributes to the goal of  
making the structure of a program reflect the structure of its problem domain. 
 
The second kind of package, collection of related declarations, should  
generally be used only to provide a common set of declarations for two or more 
library units.  Further, it is better to minimize the declaration of variables 
in these packages.  Overuse of packages of variables results in a FORTRAN 
COMMON block style program decomposition which defeats the abstraction and  
information hiding properties of packages (see paragraph 5.7.4). 
 
Finally the last type of package, a grouping of units for configuration  
reasons, should be used sparingly since it gives no additional information to  
a human reader on the structure of the program.  This type of package might,  
for example, be used to divide a large program at the top level into  
subsystems to be developed by separate teams.  It would be best, however, if  
these subsystem packages fulfilled, in addition, one of the other two roles. 
 
    b.  Packages should NOT be designed based on the procedural structure of  
the code which calls them. 
 
For example, a group of procedures should not be packaged simply because they  
are all called at system initialization, or because they are always called in  
a certain sequence.  Such a package is closely coupled to the context in which 
it is used and is not very understandable, reusable or maintainable as a unit. 
 
    c.  A logical hierarchy of packages should be used to reflect or model  
levels of abstraction. 
 
5.7.2  Nesting.  The use of nesting is not recommended because of the  
numerous precautions and limitations involved. 
 
 
5.7.3  Initialization.  The initialization process should be self-contained.   
It is poor programming practice to call from the initialization statement of  
a package to subprograms outside the package and should be avoided. 
 
5.7.4  Visible variables. 
 
    a.  Variable declarations in package specifications should be minimized. 
 
One of the aspects of software engineering Ada supports so well is information 
hiding.  The use of variables in a package specification generally reduces the 
abstraction and information hiding properties of the package.  For example, a  
variable cannot provide protection against being changed by units other than  
the package.  Therefore it is generally better to use a function rather than a 
variable to read data from a package.  It is also generally better to use a  
procedure rather than a variable to give data to a package, since a variable  
cannot trigger any package operations and a variable declaration often exposes 
some internal data representation details of the package. 
 
    b.  The private part of a package specification should only be used to  
supply the full definitions of private types and deferred constants; all other 
declarations should be put in the package body. 
 
    c.  Object of private type should be initialized by default, if possible. 
 
5.7.5  Formatting of packages. 
 
5.7.5.1  Package names.  A package name should be a noun phrase describing the 
abstract entity modeled by the package, or simply whatever is being packaged. 
 
    Stack_Handler  
    Vehicle_Controller  
    Terminal_Operations  
    Parser_Types  
    Utilities_Package  
 
5.7.5.2  Package header.  Each package specification, body or stub should be  
preceded by a header comment block containing at least the package name and  
the indication SPEC, BODY, STUB or SUBUNIT.  A suggested format follows: 
 
       --  ***************************  
       --  *                         *  
       --  *    Lexical_Analyzer     *   SPEC  
       --  *                         *  
       --  ***************************  
 
5.7.5.3  Package specifications. 
 
    a.  Package specifications should have the-following format:  package  
 is  
 
    --    
 
        
        
 
    private  --   
 
        
        
 
    end ;  
 
The  should follow guideline b., below.  Note that the  
 should always be repeated at the "end" of the package  
specification. 
 
    b.  A package specification should include AT LEAST the following  
documentation immediately after the package header:  
 
   --  Purpose 
   --  A description of the purpose and function of the package.  
   --   
   --  Initialization Exceptions  
   --  A list of all exceptions which may propagate out of the  
   --  package INITIALIZATION PART and a description of when each  
   --  would be raised.  
   --   
   --  Notes  
   --  Additional comments on the use of the package.  
 
The "Initialization Exceptions" and "Notes" headers should be included even if 
these sections are empty.  An empty section may be indicated by placing the  
annotation "(none)" after the appropriate header.  Only in the case a package  
specification which is a compilation unit, the following section should be  
added to the documentation: 
 
  --  Modifications  
  --  A list of modifications made to the package SPECIFICATION.   
  --  Each entry in the list should include the date of the change,  
  --  the name of the person who made the change and a description  
  --  of the modification.  The description should indicate exactly  
  --  where in the compilation unit that the change was made.  The  
  --  first entry in the list should always be the initial coding of  
  --  the package specification.  
 
    c.  In a declarative part, all package specifications should appear before 
any package or task bodies. 
 
5.7.5.4  Package bodies and stubs. 
 
    a.  Package bodies should have the following format:  
 
    separate ()  
    package body  is  
 
    --    
 
        
        
 
    begin --   
 
        
        
 
    exception  
      when  =>  
          
 
    end ;  
 
The  should follow guideline b below.  Note that the  
 should always be repeated at the "end" of the package  
body. 
 
    b.  A package body should have at least the following documentation placed 
immediately after the package header: 
 
  --  Notes  
  --  Comments on the design, implementation and use of the  
  --  package.  
 
The "Notes" header should be included even if the section is empty.  An empty  
section may be indicated by the comment "Notes (none)." Only in the case of a  
package body which is a compilation unit, should the following section be  
added to the documentation: 
 
  --  Modifications  
  --  A list of modifications made to the package BODY.  Each  
  --  entry in the list should include the date of the change,  
  --  the name of the person who made the change and a  
  --  description of the modification.  The description should  
  --  indicate exactly where in the compilation unit that the  
  --  change was made.  The first entry in the list should always  
  --  be the initial coding of the package body.  
 
    c.  Package stubs should have the following format:  package body  is separate; 
 
5.7.6  Examples for packages.  
 
         See also example 5.12.7.3  
 
5.7.6.1  Example 7X1. 
 
       --  ***************************  
       --  *                         *  
       --  *    Lexical Analyzer     *    SPEC  
       --  *                         *  
       --  ***************************  
 
    with Basic_Types,  
         Parser_Types;   
 
    package Lexical_Analyzer is  
 
   --  Purpose  
   --  The routines in this package read the source program, one  
   --  character at a time, to generate a stream of tokens.  As each  
   --  token is produced it is passed to the package "Parser." The  
   --  legal tokens are defined in the Language Reference Manual.      
   --  
   --  Initialization Exceptions  
   --  
   --  Diana_ File_ Non_Existent -- Raised if the file "DIANA.ADA"  
   --                               does not exist  
   --  Notes  
   --  Tokens are limited to 32 characters in length.  Also, only  
   --  sequential text files can be operated on by the parser.      
   --  Modifications  
   --  
   --  6/14/85  Rebecca DeMornay   Initial version of spec  
   --  8/26/87  C. Royale          Added "Decode_Token" function.  
 
      Diana_File_Non_Existent  
        : exception;  
 
      Source_File_Not_Open  
        : exception;  
 
      Illegal_Token  
        : exception;  
 
       --  .................................  
       --  .                               .  
       --  .    Obtain_Next_Token          .   SPEC  
       --  .                               .  
       --  .................................         
 
      procedure Obtain_Next_Token  
        (  
          ...  
              );  
 
      ...  
 
       --  ....................  
       --  .                  .  
       --  .    Decode_Token  .    SPEC  
       --  .                  .  
       --  ....................  
 
      function Decode_Token  
        (  
          ...  
              )  
        return Parser_Types.TOKEN_VALUE_TYP;  
 
     ...  
    end Lexical_Analyzer;  
 
5.7.6.2  Example 7X2. 
 
       --  ***************************  
       --  *                         *   
       --  *    Lexical Analyzer     *    BODY  
       --  *                         *  
       --  ***************************  
 
    with Text_IO,  
         File_Handler;  
 
    package body Lexical_Analyzer is  
 
  --  Notes 
  --  The package "Lexical_Analyzer" will later be changed to:a task, 
  --  so that the "Parser" task (now a package) can make an entry 
  --  call to "Lexical_Analyzer" when it needs the next token.   
  --  
  --  Modifications 
  --  6/14/85 Charity Royale Initial version of body.  
  --  8/26/85 Charity Royale  Added "Decode_Token" function.                    
         
  --                          Added instantiation of "Enumeration_IO."  
 
         --  ******************  
         --  *                *  
         --  *    Char_IO     *    SPEC  
         --  *                *  
         --  ******************  
 
  package Char_IO is  
    new Text_IO.Enumeration IO (Enum => Character);  
 
  --  Purpose  
  --  Used to read the input text file character by character.  
  --   
  --  Initialization Exceptions (none)  
  --  Notes (none)  
 
       --  ..................................  
       --  .                                .  
       --  .     Obtain_Next_Token          .   STUB  
       --  .                                .  
       --  ..................................                                  

 
  procedure Obtain_Next_Token  
    (  
      ...  
          ) is separate;  
 
       -- ......................  
       -- .                    .  
       -- .    Decode_Token    .   STUB  
       -- .                    .  
       -- ......................  
 
  function Decode_Token  
    (  
      ...  
          )  
    return Parser_Types.TOKEN_VALUE_TYP is separate;  
    ...  
 
    begin  -- Lexical_Analyzer  
 
     ...  
 
    exception  
      when File_Handler.File_Error =>  
        raise Diana_File_Non_Existent  
 
    end Lexical_Analyzer;  
 
5.7.6.3  Example 7X3. 
 
       --  *********************  
       --  *                   *  
       --  *       Disk        *      SPEC  
       --  *                   *  
       --  *********************  
 
    generic  
 
      type SPECIFIC_DATA_TYP is  -- The type of data to be  
        ( <> );                  -- stored on disk  
 
    package Disk is  
 
  --  Purpose  
  --  This package defines an abstract data type to simplify  
  --  the I/O interface to disk files.  
  --   
  --  Initialization Exceptions (none)  
  --  Notes (none)  
  --  Modifications  
  --  9/10/86  Ada Users Group    Initial version  
 
      type FILE_TYP is private;  
 
      End_Of_File  
        :  exception;  
 
      Open_Error  
        :  exception;  
 
      Mode_Error  
        :  exception;  
 
      subtype FILE_MODE is  
        (IN_FILE, OUT_FILE);  
 
       --  .....................  
       --  .                   .  
       --  .    Create         .   SPEC  
       --  .                   .  
       --  .....................  
 
function Create  
  ( Name  :  STRING; 
    Mode  :  FILE_MODE := IN_FILE )  
  return FILE_TYP;  
 
  --  Purpose  
  --  This function creates a FILE_TYP data object to  
  --  represent the disk file with the given name and mode.      
  --  
  --  Exceptions (none) 
  --  Notes  
  --  This function does not actually open the file.  
 
 
       --  .....................  
       --  .                   .  
       --  .       Close       .     SPEC  
       --  .                   .  
       --  .....................  
 
   procedure Close  
     ( Disk_File : in out FILE_TYP );  
 
  --  Purpose  
  --  This procedure closes a disk file if it is open.  If  
  --  the file is already closed it has no effect.      
  --  
  --  Exceptions (none)  
  --  Notes (none)  
 
       --  .................... 
       --  .                  . 
       --  .      Read        .   SPEC  
       --  .                  .  
       --  ....................  
 
   procedure Read 
     ( Disk_File : in out FlLE_TYP;  
       Data      : out    SPECIFIC_DATA_TYP );  
 
  --  Purpose  
  --  This procedure reads the next record from a file,  
  --  opening the file if necessary.  
  --   
  --  Exceptions  
  --  End_Of_File     - raised if no more elements can be  
  --                    read from the file  
  --  Open_Error      - if the file cannot be opened  
  --  Mode_Error      - if the file mode is not IN FILE    
  --   
  --  Notes (none)  
 
       --  ......................  
       --  .                    .  
       --  .      Write         .    SPEC  
       --  .                    .  
       --  ......................  
 
       procedure Write  
         ( Disk_File : in out FILE_TYP;  
           Data      : in     SPECIFIC_DATA_TYP );  
 
  --  Purpose  
  --  This function writes a record to a file,  
  --  opening the file if necessary.  
  --   
  --  Exceptions  
  --  Open_Error         - if the file cannot be opened  
  --  Mode_Error        - if the file mode is not OUT_FILE  
  --  
  --  Notes (none)  
 
  private   -- Disk  
 
       --  *********************  
       --  *                   *  
       --  *     Disk_IO       *     SPEC  
       --  *                   *  
       --  ********************* package Disk_IO is 
 
  new Sequential_IO (SPECIFIC_DATA_TYP);  
 
  --  Purpose --  This package provides the basis for the representation  
  --  of disk files. 
  --   
  --  Initialization Exceptions (none)  
  --  Notes (none)  
 
    File_Name_Length  
      : constant := 40;  
 
    type FILE_TYP is  
      record  
        File_Name : STRING (1..File_Name_Length) := (others => ' ');  
        File      : Disk_IO.FILE_TYP;  
        Mode      : FILE_MODE                    := Disk_IO.IN_FILE;  
      end record;  
  end Disk;  
 
5.8  Visibility. 
 
 
5.8.1  Scope of identifiers.  The scope of identifiers should not extend  
further than necessary.  Where a scope is extended by "with" clauses, these  
clauses should cover as small a region of text as possible. 
 
For example, "with" clauses should be placed only on the subunits that really  
need them, not on their parents.  This promotes information hiding and reduces 
coupling.  It can also result in faster recompilation (due to the dependency  
rules). 
 
5.8.2  The package STANDARD and WITH clauses.  The package STANDARD should  
not be named in a "with" clause. 
 
5.8.3  The use clause.  The "use" clause should be employed only in a limited  
application.  It detracts from the readability of the program by allowing  
the "expanded" name to be shorten (not having to specify the "prefix", not  
having to use the dot notation).  Thus, the understandability of the program  
may be affected.  Another detraction, there is an outside possibility it may  
introduce a name clash. 
 
5.8.4  Renaming declarations.  Usually renaming causes more problems than it  
is worth; so again, use it in a limited fashion, if at all. 
 
    a.  For a name with a large number of package qualifications, a renaming  
declaration may be used to define a new shorter name.  The new identifier  
should still reflect the complete meaning of the full name. 
 
    b.  For a function which can be appropriately represented by an operator  
symbol name, a renaming declaration may be used to give it such a name.   
However, notice that a renaming declaration may have some appropriateness  
for achieving direct visibility, e.g. 
 
A Matrix_ Multiply function could be renamed "*".  
 
5.8.5  Redefinition. 
 
    a.  It is extremely poor programming practice to redefine or rename items  
from the package STANDARD.   
 
    b.  Redefinition of an identifier in different declarations should be  
avoided. 
 
5.9  Tasks. 
 
 
5.9.1  Use of tasks.  A task should fulfill one or more of the following: 
 
    a.  Model a concurrent abstract entity appropriate to the problem domain. 
 
    b.  Serve as an aceess-controlling or synchronizing agent for other tasks, 
or otherwise act as an interface between asynchronous tasks. 
 
    c.  Serve as an interface to asynchronous entities external to the program 
(e.g., asynchronous I/O, devices, interrupts, etc.). 
 
    d.  Define concurrent algorithms for faster execution on multiprocessor  
architectures. 
 
    e.  Perform an activity which must wait a specified time for an event or  
have a specific priority. 
 
Just as for packages (paragraph 5.7.1) it is best to have tasks which model  
problem domain entities.  However, in the case of tasks it is also necessary  
to have some tasks which provide interfaces between other tasks and which  
handle the other issues of concurrency and parallelism mentioned above.  The  
program should generally be structured, however, around the tasks which  
represent problem-domain entities. 
 
5.9.2  Nesting of tasks. 
 
    a.  Tasks should generally not be nested within tasks or subprograms,  
except for the main procedure. 
 
Note that a subprogram containing a task cannot return until the task has  
terminated. 
 
    b.  Nested task bodies should be separate subunits, unless they are quite  
small. 
 
5.9.3  Visibility of tasks. 
 
    a.  When only certain entries of a task are intended to be called by  
program components outside an enclosing package, it is generally preferable to 
hide the task specification in the package body, introducing package  
procedures which in turn call the actual entries. 
 
    b.  This helps to promote information hiding and strengthens the  
abstraction of the enclosing package (see paragraph 5.7.2.d).  It also hides  
the use of tasking within the package.  Note, however, that special care must  
be taken if the task entries are to be called using conditional or timed entry 
calls.  In this case either the outer package must provide special procedures  
or procedure parameters or this guideline should not be followed. 
 
5.9.4  Task types. 
 
    a.  A task type should be used only when multiple instances of that type  
are required.  Otherwise a directly named task should be used. 
 
    b.  Identical tasks should be derived from a common task type.  
 
    c.  Static task structures should be used whenever they are sufficient.   
Access types to task type should be used only when it is essential to create  
and destroy tasks dynamically, or to be able to change the names with which  
they are associated. 
 
5.9.5  Task termination.  Nesting of tasks within other tasks should be  
avoided.  If tasks must be nested, they should be forced to terminate when  
they are suppose to by causing them to reach their end statement.  If a task  
is a "active" task, this is done by having the main loop as a "while" loop.   
If the task is "passive", there should be an entry which causes the main loop  
to be exited. 
 
5.9.6  Entries and accept statements. 
 
    a.  Only those actions should be included in the "accept" statement which  
must be completed before the calling task is released from its waiting state. 
 
    b.  Conditional entry calls should be used sparingly to avoid unnecessary  
busy waiting. 
 
5.9.7  Delay statement. 
 
    a.  A "delay" statement should be used whenever a task must wait for some  
known duration.  A "busy wait" loop should never be used for this purpose.  
 
It is important to remember that "delay t" provides a delay of at least t  
seconds, but possibly more.  A program should not rely on any upper bound for  
this delay, especially when tasks are used (since tasks must compete for CPU  
time).  
 
  The following example is only one of many techniques to alleviate this  
problem in a periodic activity:  
 
    ...  
    Next_Time := Calendar.Clock + Required_ Period;  
 
   Periodic_Activity:  
   while Still_Time.loop  
      -- Perform activity  
      ...  
      -- Correct for delay statement incertitude  
      Period := Next_Time - Calendar.Clock;  
 
      if Period < 0.0 then           -- Processing was too slow  
        Next_Time := Calendar.Clock  -- Avoid cumulative effect  
      end if;  
      Next_Time := Next_Time + Required_Period;  
      delay Period;  
    end loop Periodic_Activity;  
 
    b.  The "delay" statement should normally only be used to manage  
interaction with some external process which works in real time, or to create  
a task which behaves in a well-defined manner in real time. 
 
5.9.8  Task synchronization.  Knowledge of the execution pattern of tasks  
(e.g., fixed, known time pattern, etc.) should not be used to avoid the use of 
explicit task synchronization. 
 
5.9.9  Priorities. 
 
    a.  Only a small number of priority levels should be used.  The priority  
levels used should be spread over the range made available to type PRIORITY in 
the implementation.  Names should be given to the priority levels by declaring 
constants of predefined type PRIORITY and grouping these declarations into a  
single package. 
 
Using only a small number of priority levels makes the interaction of the  
various prioritized tasks easier to understand.  On the other hand, spreading  
the levels across the available range allows easy insertion of a new level  
between existing levels if this later becomes necessary.  As with other  
literal numbers, the use of names is more readable than the use of the  
literals.   
Further, for priorities, the allowable range of levels is implementation  
dependent.  Naming priority levels by constant declarations grouped into a  
single package restricts the implementation dependency to that package.  For  
example:  
 
  with System;  
  package Priority_Levels is  
      Lowest_Priority 
        : constant System.PRIORITY := System.PRIORITY'first;  
      Highest_Priority  
        : constant System.PRIORITY := System.PRIORITY'last;  
      Median 
        : constant                 := Highest_Priority - Lowest_Priority + 1;  
      Average  
        : constant System.PRIORITY := Lowest_Priority + (Median / 2);  
      Idle  
        : constant System.PRIORITY := Lowest_Priority;  
      Background  
        : constant System.PRIORITY := Lowest_Priority + (Median / 5);  
      User  
        : constant System.PRIORITY := Lowest_Priority + (2 * Median / 5);  
      Foreground  
        : constant System.PRIORITY := Lowest_Priority + (4 * Median / 5);  
    end Priority_Levels;  
 
    b.  For any group of related tasks, such as those declared within the same 
program unit, priorities should be specified either for all, or for none of  
them. 
 
This avoids confusion about the scheduling of tasks with undefined priorities. 
 
5.9.10  Abort statements.  Abortion of tasks should generally be avoided. 

Aborting a task can produce unpredictable results.  In particular, do not  
assume anything about the moment at which an aborted task becomes terminated.  
The "abort" statement should generally be used only in case of unrecoverable  
failure. 
 
5.9.11  Shared variables. 
 
    a.  Tasks should not directly share variables unless only one of them can  
possibly be running at any one time. 
 
    b.  Any task which uses shared variables should identify in its  
documentary comments all the shared variables that it uses. 
 
5.9.12  Local exception handling.  To allow the handling of local exceptions  
without task termination, a task should generally have a block statement with  
an exception handler coded within its main loop. 
 
    begin  -- Some Task  
 
      Main_Loop:  
      loop  
 
        Local:  
        begin  
          -- Task code  
          ...  
        exception  -- Local  
          -- handle local exceptions ...  
        end Local;  
 
      end Main_Loop;  
 
    exception  
      -- handle fatal exceptions ...  
 
    end Some_Task;  
 
5.9.13  Formatting of tasks. 
 
5.9.13.1  Task and entry names. 
 
    a.  A task name should be a noun phrase describing the task function or  
abstract entity modeled by the task. 
 
    Sensor_Interface  
    Status_Monitor  
    Event_Handler  
    Message_Buffer  
 
 b.  Entry names should follow the same guidelines as for subprogram names  
(see paragraph 5.6.6.1). 
 
5.9.13.2  Task and entry headers.  Each task or task type specification or  
body and each entry specification should be preceded by a header comment block 
containing at least the unit name and the indication SPEC, BODY or STUB. 
 
       --  **********************  
       --  *                    *  
       --  *       Buffer       *     SPEC  
       --  *                    *  
       --  **********************   
 
     task Buffer is  
 
 
       --  ....................  
       --  .                  .  
       --  .      Read        .   SPEC  
       --  .                  .  
       --  ....................  
 
       entry Read ( Output : out Character ); 
 
 5.9.13.3  Task specifications. 
 
     a.  Task specifications should have the following format:   
 
     task  is  
 
     --     
 
         
         
 
     end ;  
 
Guidelines for  should be AT LEAST as rigorous as those  
for a subprogram declaration (see paragraph 5.6.6.3), except for the  
"Exceptions" section. 
 
NOTE: The  should always be repeated at the "end" of the  
task specification. 
 
    b.  A task type specification should be formatted the same as a task  
specification, with the exception of including "task type" in the header. 
    c.  Entry declarations should have the following format:  
 
    entry  ()  
      (  ;  
           );  
 
    --    
 
Each  should be formatted like an object declaration  
(see paragraph 5.3.8.4).  Guidelines for  should be AT  
LEAST as rigorous as those for a subprogram declaration (see  
paragraph 5.6.6.3). 
 
    d.  Parameter mode indications should always be used in entry  
declarations. 
 
    e.  In a declarative part, all task specifications should appear before  
any task or package bodies. 
 
5.9.13.4  Task bodies and stubs. 
 
    a.  Task bodies should have the following format:  
 
    separate ()  
    task body  is  
 
    --    
 
        
        
 
    begin  --    
 
        
        
 
    exception  
      when  =>  
          
 
    end ;  
 
    b.  Guidelines for  should be AT LEAST as rigorous  
as those for a subprogram declaration (see paragraph 5.6.6.3). 
 
NOTE: The  should always be repeated at the "end" of the  
task body. 
 
    c.  Task stubs should have the following format: 
 
    task body  is separate;  
 
5.9.13.5  Accept statements. 
 
 
    a.  "Accept" statements should have one of the following formats: 
    accept  ();  
 
    accept  ()  
      (  ;  
          )  
    do  
        
        
    end ;  
 
Each  should be formatted like an object declaration  
(see paragraph 5.3.8.4).  Note that the  should always be  
repeated at the "end" of the "accept" (if there is an "end"). 
 
    b.  Parameter mode indications should always be used in accept statements. 

 
5.9.13.6  Select statements. 
 
    a.  Selective wait statements should have the following format: 
 
    select  
        
        
    or  
        
        
    or  
      when  =>  
          
          
    end select;  
 
This format is consistent with the indentation style of other statements.  In  
addition, the added level of indentation especially highlights guarded  
sections of code. 
 
    b.  Conditional and timed entry calls should have the following format: 
 
    select  
        
        
    else  
        
        
    end select;  
 
5.9.13.7  Pragma priority. The priority pragma should appear in task  
specification before any entry declarations, and in the main program before  
any declarations. 
 
5.9.14  Examples for tasks. 
 
 
5.9.14.1  Example 9X1. 
 
       --  **********************  
       --  *                    *  
       --  *       Buffer       *    SPEC  
       --  *                    *  
       --  **********************  
 
    task Buffer is  
 
  --  Purpose  
  --  This task provides a character buffer to smooth variations  
  --  between the speed of output of a producing task and the speed  
  --  of input of a consuming task.  
  --   
  --  Exceptions (none)  
  --  Notes (none)  
 
       --  .....................  
       --  .                   .  
       --  .      Read         .    SPEC  
       --  .                   .  
       --  .....................  
 
      entry Read ( Output     : out Character );  
 
  --  Purpose  
  --  This entry reads a character from the buffer.   
  --  If the buffer is empty, the entry will wait  
  --  until a character is written into the buffer.      
  --  
  --  Exceptions (none)  
  --  Notes (none)  
 
       --  .....................  
       --  .                   .  
       --  .      Write        .    SPEC  
       --  .                   .  
       --  .....................  
 
      entry Write ( Input   : in Character );  
 
  --  Purpose  
  --  This entry writes a character into the buffer.   
  --  If the buffer is full the entry will wait  
  --  until a character is read from the buffer.  
  --   
  --  Exceptions (none)  
  --  Notes (none)  
 
    end Buffer;  
 
5.9.14.2  Example 9X2. 
 
       --  **********************  
       --  *                    *  
       --  *      Buffer        *    BODY  
       --  *                    *  
       --  **********************        
 
    separate (Buffer Package)  
    task body Buffer is  
 
   --  Notes  
   --  This task contains an internal pool of characters processed  
   --  in a round-robin fashion.        
   --   
   --  Modifications  
   --  7/2/86  Fred Blah    Initial version.     
 
      Pool_Size  
        : constant                   := 100;  
      subtype POOL_RANGE is  
        INTEGER range 1..Pool_Size;  
      type POOL_TYP is  
        array (POOL_RANGE) of CHARACTER;  
      Pool  
        : POOL_TYP;  
      Count                                   -- The number of characters in  
        : INTEGER range 0..Pool_Size := 0;    -- the pool.  
      In_Index                                -- The space for the next input 
        : POOL_RANGE                 := 1;    -- character. 
      Out_Index                               -- The space for the next output 
        : POOL_RANGE                 := 1;    -- character. 
 
     begin   -- Buffer 
 
       Pool_Loop: 
       loop 
         select 
           when Count < Pool_Size => 
             accept Write ( Input  : in Character ) do   
               Pool(In_Index) := Input; 
             end write; 
             In_Index := In_Index mod Pool_Size + 1; 
             Count := Count + 1; 
         or 
           when Count > 0 => 
             accept Read ( Output : out Character) do  
               Output := Pool(Out_Index); 
             end Read; 
             Out_Index := Out_Index mod Pool_Size + 1; 
             Count := Count - 1; 
         or  
           terminate; 
         end select; 
 
       end loop Pool_Loop; 
 
     end Buffer; 
 
5.9.14.3  Example 9X3. 
 
       --  ................... 
       --  .                 . 
       --  .   Shellsort     .      BODY 
       --  .                 . 
       --  ................... 
 
    procedure Shellsort 
      ( List            : in out ITEM_LIST;     -- to be sorted in place.  
        Number_Of_Items : in     NATURAL );  
 
  --  Purpose 
  --  This is a basic integer sorting routine. 
 
  --  Notes  
  --  This sorting procedure implements the Shell sort by   
  --  separating the n-sorts into multiple Ada tasks.   
  --  This algorithm is designed for parallel processing  
  --  of the tasks and is not an efficient method on a  
  --  single processor.  The process works on an one  
  --  dimensional array called ITEM_LIST. 
  --   
  --  Modifications  
  --  9/5/86  A. Shell           Initial version  
 
  Increment                   -- Increment of an n-sort  
    : NATURAL;  
 
  Number_of_Sorts             -- Number of parallel sorts  
    : NATURAL;                -- for a single pass  
 
  Number_Of_Tasks  
    : NATURAL;  
 
       --  ********************  
       --  *                  *  
       --  *   SORTER TASK    *      SPEC  
       --  *                  *  
       --  ********************  
 
  task type SORTER_TASK is  
 
  --  Purpose  
  --  Tasks of this type perform the n-sort for the Shell sort.  
  --   
  --  Notes  
  --  A SORTER_TASK terminates itself when it is no longer  
  --  needed for the sort.  
 
       --  ......................  
       --  .                    .  
       --  .     Sort           .   SPEC  
       --  .                    .  
       --  ......................  
 
  entry Sort  
    ( First : in INTEGER;  
      Step  : in NATURAL );  
   --  Purpose  
   --  This entry signals a sorter task to perform a new  
   --  n-sort.  Elements are sorted in place in List,  
   --  starting with the element at index First and  
   --  including subsequent elements at the indicated Step.   
   --   
   --  Exceptions (none)  
   --  Notes (none)  
 
  end SORTER_TASK;  
 
       --  *********************  
       --  *                   *  
       --  *   SORTER_TASK     *      STUB  
       --  *                   *  
       --  *********************  
 
  task body SORTER_TASK is separate;  
 
  type SORTER_ARRAY is  
    array (INTEGER range <>) of SORTER_TASK;  
 
begin   -- Shellsort  
 
  if Number_Of_Items < 2 then  
    return;  
  end if;  
 
  -- Determine the first n-sort increment.   
  Increment := 1;   
 
  while Increment < Number_Of_Items  loop 
    Increment := (3 * Increment) + 1;  
  end loop;  
 
  Increment := Increment / 3;  
  if Increment < 1 then  
    Increment := 1;  
  end if;  
 
  --  Determine the number of tasks required to perform  
  -- the sort.  
 
  if Number_Of_Items / Increment = 1 then  
    Number_of_Sorts := Number Of Items mod Increment;  
    if Increment / 3 > Number Of Sorts then  
      Number_Of_Tasks := Increment / 3;  
    else  
      Number_Of_Tasks := Number_Of_Sorts;  
    end if;  
  else  
    Number_Of_Sorts := Increment;  
    Number_of_Tasks := Number_Of_Sorts;  
  end if;  
 
  -- Perform the sort  
 
  Task_Block:  
  declare  
    Sort_List  
      : SORTER_ARRAY (1 .. Number_Of_Tasks);  
  begin  -- Task_Block 
 
    Incrementation:  
    while Increment > 0 loop 
 
      Sort_Work:  
      for K in 1 .. Number_Of_Sorts loop  
        Sort_List(K).Sort  
          ( First    => List'first + K - 1'  
            Step     => Increment );  
      end loop Sort_Work;  
 
      Increment := Increment / 3;  
      Number_of_Sorts := Increment;  
    end loop Incrementation;  
 
  end Task_Block;  
 
end Shellsort;  
 
5.9.14.4  Example 9X4. 
 
       --  *********************  
       --  *                   *  
       --  *    SORTER_TASK    *    SUBUNIT  
       --  *                   *  
       --  *********************  
 
    separate (Shellsort)  
    task body SORTER_TASK is  
                      
  --  Notes  
  --  This task body implements a task type.  
  --   
  --  Modifications 
  --  9/5/86    A. Shell        Initial version  
 
  -- Global variables  
  -- List                 -- An array of all items to be 
                             sorted by Shellsort. 
  -- Number_Of_Items      -- The number of items in the list.  
 
  Start        : INTEGER;  
  Increment    : NATURAL;  
 
  A            : INTEGER;  
  B            : INTEGER;  
  First_B      : INTEGER;  
 
  Temp         : INTEGER;  
 
   begin   -- SORTER_TASK  
 
  Main_Loop: 
  loop  
 
    accept Sort  
      ( First     : in INTEGER;  
        Step      : in NATURAL )  
    do  
      Start := First;  
      Increment := Step;  
    end Sort;  
 
    First_B := Start + Increment; 
 
    Determine_Criteria: 
    while First_B <= List'first + Number_Of_Items - 1 loop  
      B := First_B;  
      A := B - Increment;  
 
      Find_Position:  
      while A >= Start loop exit when not (List(A) > List(B));  
        Temp := List(A);  
        List(A) := List(B);  
        List(B) := Temp;  
        B := A;  
        A := B - Increment;  
      end loop Find_Position;  
 
      First_B := First_B + Increment;  
 
    end loop Determine_Criteria;  
 
    -- Terminate if task is not needed for n-sort  
    exit when (Increment / 3) < Start - List'first + 1;  
  end loop Main_Loop;  
 
end SORTER_TASK;  
 
5.10  Program structure and compilation issues. 
 
 
5.10.1  Library units.   Library units are divided into two categories,  
subprograms and packages.  Library subprograms define one entity, whereas  
packages provide services which define more than on entity.  Some of the  
primary uses are: 
 
        a. To allow configuration control of the high level functional  
subsystems of a program. 
 
        b. For general purposes, reusable program units.  
 
5.10.2  WITH clauses. 
 
    a.  No unit should have a "with" clause for a unit it does not need to see 

directly. 
 
    b.  If only a small part of a given unit needs access to a library unit,  
then it should generally appear as a subunit and have its own "with" clause  
for that library unit (see paragraph 5.8.1). 
 
NOTE:  Understanding the use of the "with" clause is important.  Where the  
"with" is interpreted, based on the compiler, can cause recompilation  
problems by hiding names. 
  
5.10.3  Program unit dependencies. 
 
    a.  Excessive dependencies between compilation units should be avoided,  
especially the use of complicated networks of "with" clauses. 
 
    b.  It is preferable to limit program unit dependencies to a logical tree  
structure whenever possible.  In this instance, the preferred tree stucture  
would be where a parent can have multiple children; however, every child has  
only one parent.  Any program that creates a dependency of multiple parents  
to multiple children should be evaluated for redesign. 
 
5.11  Exceptions. 
 
 
5.11.1  Exception propagation. 
 
    a. Exceptions propagated by a program unit should be considered part of  
the abstraction or function represented by that unit.  Therefore, it should  
generally only propagate exceptions which are appropriate to that level of  
abstraction.  If necessary, an exception which cannot be handled by a unit at  
one level of abstraction should be converted into an exception which can be  
explicitly recognized by the next higher level. 
 
For example, a Stack package should provide a Stack_Full exception instead of  
propagating a Constraint_Error.  Similarly, a Matrix_lnverse function should  
raise a Matrix_is_Singular exception rather than propagating Numeric_Error. 
 
    b.  Exceptions should not be allowed to propagate outside their own scope.  
An exception may be allowed to propagate to any point where it can be named in 
an exception handler.  Note that this includes the case where an exception is  
defined in a package specification and has its scope "expanded" by a "with"  
clause.  What must be avoided are cases such as the following: 
 
    procedure Raise_Exception is  
      Hidden_Exception  : exception;  
    begin  
      raise Hidden_Exception;  
    end Raise_Exception;  
 
  begin  
    Raise_Exception;  
    -- "Hidden_Exception" CANNOT be named at this point  
 
5.11.2  Use of exceptions. 
 
    a.  An exception should be used sparingly.  If used, extensive and clear  
comments should be included.  Possible reasons for exceptions are: 
 
        (1) It reports an irregular event which is outside the normal  
operation of a program unit or is in some sense an error. 
 
        (2) It is used where it can be argued that it is safer (more  
defensive) than the alternative, in particular to guard against omissions of  
error checking code for especially harmful errors. 
 
        (3) It reports an event for which it is inconvenient or unnatural to  
test at the point of cause/occurrence and thus use of the exception enhances  
readability. Exceptions declared in package specifications are really part of
the abstraction defined by that package.  Therefore their use should be 
integral  to the design of the package (see paragraph 5.10.1). 
 
Also, note that the predefined exceptions should be used with care.  Due to  
allowable implementation differences, they should not be relied upon to  
indicate particular circumstances. 
 
    b.  Exceptions should not be used as means of returning normal state  
information. 
 
For example, a Stack package may have Stack Full and Stack Empty exceptions  
which are raised by its Push and Pop subprograms.  However, these subprograms  
should not be used solely to raise exceptions to test if the appropriate  
conditions are true.  Instead, the package should provide BOOLEAN functions  
such as Full and Empty to test for these state conditions. 
 
5.11.3  Exception handlers. 
 
    a.  The exception handler choice "others" should be used only if it is  
necessary to ensure that no UNANTICIPATED exception can be propagated or if  
some special action must be taken before propagation. 
 
For example, important tasks should generally have an "others" clause in a  
local exception handler (see paragraph 5.9.12) to prevent them from  
terminating due to unanticipated exceptions.  However, in the case when it can 
be expected that a certain exception may sometimes occur, then that exception  
should always be explicitly named in the exception handler. 
 
    b.  Recursion should not be used within an exception handler.   
 
    c.  Exception handlers on block statements should be used sparingly. One  
of the advantages of using exceptions is that it separates the error handling  
code from the more often executed normal processing code.  Excessive use of  
exception handlers in block statements can defeat this advantage.  
 
5.11.4  Raise statements. 
 
    a.  Exceptions declared in the specification of a package which represents 
a problem domain entity should not be raised outside that package. 
 
Exceptions declared in a package specification should be considered part of  
the abstraction defined by the package.  These exceptions provide special  
"signals" from the package operations, and should thus not be raised outside  
of the package. 

    b.  Exceptions raised within a.task should always-be handled within the  
task. 
 
NOTE: In the case of an exception raised during a rendezvous the exception  
will also be propagated back to the point of the entry call. 
 
    c.  The predefined exceptions should generally not be explicitly raised.  
 
5.11.5  Suppressing checks.  Checks should not be suppressed except for  
essential efficiency or timing reasons in thoroughly tested program units. 
 
5.11.6  Exception declarations.  Exception declarations should re formatted  
like object declarations, paragraph 5.3.8.4. 
 
5.11.7  Examples for exceptions.  See examples 5.5.9.4, 5.6.7.5, 5.7.6.2,  
and 5.14.5.2. 
 
5.12  Generic units. 
 
 
5.12.1  Use of generic units. 
 
    a.  Generics should not be used in situations in which normal programming  
constructs are equivalent. 
 
    b.  A generic program unit should fulfill one or more of the following: 
 
        (1) Provide logically equivalent operations on objects of different  
type. 
 
        (2)  Parameterize a program unit by a subprogram value.  
 
        (3) Provide a data abstraction required at many points in a program,  
even if no parameterization is required. 
 
        (4) Provide parameters which are particularly appropriate to be fixed  
at declaration or elaboration time. 
 
        (5) Reduce coupling by controlling visibility. 
 
    c. Functions should be made generic whenever possible to facilitate and  
increase reusability. 
 
5.12.2  Generic library units.  Generic units should generally be library  
units. 
 
5.12.3  Generic instantiation. 
 
    a.  The most commonly used generic instantiations should generally be  
placed in library units. 
 
    b.  Generic instantiations should be used cautiously within generic units. 
 
NOTE:  Information presented in some cases fall into the realm of guidelines  
to compensate for compiler and/or run-time deficiencies.  Sub-subparagraph  
b is an example. 
 
5.12.4  Generic formal subprograms. 
 
    a.  The actual subprograms associated with the formal subprogram  
parameters of a generic unit should be consistent with the conceptual meanings 
of the formal parameters (e.g., only functions which are conceptually "adding  
operations" should be associated with a formal parameter named "plus"). 
 
    b.  Operator symbol function generic parameters should generally be  
provided with a box default body ("is <>"). 
 
    with function "<"  
      ( X : ITEM;  
        Y : ITEM )  
      return BOOLEAN is <>;  
 
5.12.5  Use of attributes. 
 
    In writing generic bodies, attributes should be used as much as possible  
to generalize the code produced. 
 
5.12.6  Formatting of generic units. 
 
5.12.6.1  Generic declarations. 
 
    a.  Generic declarations should have the following format:  
 
    generic  
        
        
    ;  
 
    --  .  
 
Each  should be formatted like its non-formal counterpart (see  
paragraphs 5.3.8.3 and 5.3.8.4), except for formal subprograms which should be 
formatted as in b below.  The  should be formatted 
as for non-generic units (see paragraphs 5.6.6.3 and 5.7.5.3). 
 
    b.  A generic formal parameter subprogram declaration should have one of  
the following formats: 
 
    with ;  
   --     
 
    with  is <>;  
   --     
 
    with  is ;  
   --     
 
The  should be formatted as for a subprogram  
declaration (see paragraph 5.6.3.3).  Note, however, that the only  
documentation generally needed on formal subprograms is the "Purpose." 
 
    c.  A generic declaration should be preceded by the appropriate unit  
header block (see paragraphs 5.6.6.2 and 5.7.5.2). 
 
5.12.6.2  Formatting of generic instantiations. 
 
    a.  Generic instantiations should have one of the following formats:  
 
     is  
      new  (, );  
 
   --    
     is  
      new   
        (  => ,  
           => );  
 
          
 
NOTE:  In the second form the arrows ("=>") should be kept aligned.  Also, the 
 should not duplicate information presented in the  
generic specification.  A referral back to the original comments should be a  
good beginning. 
 
    b.  Generic instantiations should have the same kind of header comment  
block as for a specification of the appropriate kind of unit (paragraphs  
5.6.6.2 and 5.7.5.2). 
 
5.12.7  Examples for generic units.  See also examples 5.7.6.2 and 5.7.6.3. 
 
5.12.7.1  Example 12X1. 
 
       --  ........................  
       --  .                      . 
       --  .  Shellsort_Generic   .     SPEC  
       --  .                      .    
       --  ........................  
 
    generic  
      type ITEM is private;    -- The type of items sorted  
      type LIST_TYP is         -- The type of the item list  
        array (INTEGER range <>) of ITEM;  
 
      with function "<"  
        ( Left  : ITEM;  
          Right : ITEM )  
        return BOOLEAN is <>;  
 
  --  Purpose  
  --  This function defines the ordering used when the 
  --  items are sorted.  
 
    procedure Shellsort_Generic  
      ( List : in out LIST_TYP ;  -- This list will be sorted in place.  
        N    : in     NATURAL );  -- The number of items in the list. 
 
  --  Purpose  
  --  This procedure sorts the items in List using a Shell 
  --  sort algorithm designed for parallel processing.  
  --   
  --  Exceptions (none)  
  --  
  --  Notes  
  --  (This is a generic declaration for the procedure 
  --  body five in example 9X3.)  
  --   
  --  Modifications  
  --  9/5/86    A. Shell        Initial version  
 
5.12.7.2  Example 12X2. 
 
       --  .....................  
       --  .                   .  
       --  .    Name_Sort      .   SPEC  
       --  .                   .  
       --  .....................  
 
    procedure Name_Sort is  
      new Shellsort_Generic 
        ( ITEM       => NAME,  
          LIST_TYP   => NAME_LIST );  
 
5.12.7.3  Example 12X3. 
 
       --  *************************  
       --  *                       *  
       --  *                       *  
       --  *    Unit_Statistics    *    SPEC  
       --  *                       *  
       --  *************************   
 
    with Text_IO;  
    generic  
 
      Unit_Name                 -- Name of the unit for which  
        : STRING;               -- statistics are to be kept.  
 
      type ELEMENT_TYP is       -- Enumeration type of the elements  
        (<>);                   -- to be counted.  
 
    package Unit_Statistics is  
   --  Purpose 
   --  This package provides operations to keep counts for the 
   --  various elements of a program unit.  These counts can be 
   --  incremented or printed out in a report.  
   --   
   --  Initialization Exceptions (none)  
   --    
   -- Notes 
   --  
   --  This package is based on the generic package "Task_Statistics" 
   --  written by Dan Roy.  
   --  
   --  Modifications  
   -- 8/18/86 Ed Seidewitz Initial version    
 
       -- ............................ 
       -- .                          . 
       -- .    Number_Of_Lines       .   SPEC         
       -- .                          .  
       -- ............................  
 
  function Number_Of_Lines  
    return POSITIVE;  
 
  --  Purpose  
  --  This function returns the number of lines printed by 
  --  procedure Report since the last call to Number_Of_Lines.   
  --   
  --  Exceptions (none)  
  --   
  --  Notes (none)  
 
       --  ...........................  
       --  .                         .  
       --  .        Count_of         .    SPEC  
       --  .                         .  
       --  ...........................  
 
  function Count_Of  
    ( Element : ELEMENT_TYP ) return NATURAL;  
 
  --  Purpose  
  --  This function returns the current count for the specified  
  --  element.  
  --   
  --  Exceptions (none)  
  --   
  --  Notes (none)  
 
       --  ...................   
       --  .                 .  
       --  .   Increment     .   SPEC  
       --  .                 .  
       --  ...................  
 
 procedure Increment  
   ( Element     : in ELEMENT_TYP;  
     By_Amount   : in INTEGER       := 1 );  
 
  --  Purpose  
  --  This procedure increments the count for the specified 
  --  element by a certain amount.  By default, this amount 
  --  is one. 
  --  
  --  Exceptions (none) 
  --   
  --  Notes (none)  
 
       --  ....................  
       --  .                  .  
       --  .     Report       .     SPEC  
       --  .                  .  
       --  ....................                    
 
 procedure Report  
   ( Report File  : in  Text_IO.FILE_TYP );  
 
  --  Purpose 
  --  This procedure prints a report of all statistics for 
  --  this unit to the specified text file.  
  --  
  --  Exceptions (none)  
  --  
  --  Notes (none)  
 
end Unit_Statistics  
 
5.12.7.4  Example 12X4. 
 
       --  ***********************************  
       --  *                                 *  
       --  *  Telemetry_Reader_Statistics    *     SPEC  
       --  *                                 *  
       --  ***********************************  
 
    package Telemetry_Reader Statistics is  
      new Unit_Statistics  
        ( Unit_Name       => "Telemetry_Reader",  
          ELEMENT_TYP     => READER_ELEMENTS );  
 
   --  Purpose  
   --  This package collects statistics on elements of the 
   --  Telemetry_Reader.  
   --   
   --  Initialization Exceptions (none) 
   --  Notes (none)  
 
5.13  Representation clauses and implementation-dependent features.  Any  
library units using representation clauses and implementation-dependent  
features should explicitly document their use.  One of the attractions of  
Ada is its code reusability.  If only machine independent interfaces are  
presented, while representation clauses and implementation features are  
hidden, those wishing to make use of the code may find unexplainable errors  
arising.  
 
 
5.13.1  Encapsulation.  Representation clauses and implementation dependent  
features should, if possible, be hidden inside packages which present  
implementation independent interfaces to users. 
 
5.13.2  Use of representation clauses and implementation-dependent features.  
 
    a.  Machine dependent and low-level Ada features should not be used except 
when absolutely necessary. 
 
    b.  Representation clauses and implementation-dependent features should  
only be used for one of the following: 
 
        (1) To increase efficiency (when absolutely necessary).   
        (2) For interrupt handling. 
        (3) For interfacing to hardware, foreign code or foreign data.   
        (4) To specify task storage size. Further, address clauses should be  
        used with entries only to associate them with hardware interrupts.  
 
    c.  Representation clauses should not be used to change the meaning of a  
program. 
 
5.13.3  Interrupts.  Interrupt routines should be kept as short as possible.  
 
5.13.4  Formatting of representation clauses.  Representation clauses should  
be placed near the objects they affect.  An exception may be to separate the  
machine-independent from the machine-dependent representations. 
 
5.14  lnput-output. 
 
 
5.14.1  Encapsulation of I/O. 
 
    a.  Use of the LOW_LEVEL_IO procedures should always be encapsulated in  
packages or tasks. 
 
    b.  Use of the LOW_LEVEL_IO procedures should generally be encapsulated in 
task objects associated with each item of controlled equipment. 
 
    c.  File management and textual input-output software should generally be  
encapsulated in specialized packages with simple interfaces. 
 
This should include file interface code, textual formatting code and user  
inter-face code.  User interface encapsulation can be especially useful when a 
system must accommodate increasing levels of user interface sophistication or  
changing user needs over its lifetime.  In these cases it is crucial that  
details of the implementation of the user interface be hidden so that changes  
can be made to it without affecting the rest of the system. 
 
NOTE:  An argument can be made to encapsulate all I/O, to include the use  
Text_IO and Direct_IO, because most Ada I/O has machine dependencies. 
 
5.14.2  Text formatting.  Line and page formatting should be done using the  
New_Line and New_Page subprograms, rather than explicitly writing end-of-line  
or end-of-page characters. 
 
5.14.3  Low-level input-output.  Use of package Low_Level-IO should be  
avoided unless absolutely necessary. 
 
5.14.4  Form parameter.  Use of the Form parameter of the Open and Create  
procedures should generally be avoided. 
 
The "Form" parameter on the file Open and Create procedures specifies system  
dependent file characteristics.  This can reduce both readability and  
portability, and so should only be used if absolutely necessary. 
 
5.14.5  Examples for input-output.  See also examples 5.5.9.3, 5.5.9.4 and  
5.7.6.3. 
 
5.14.5.1  Example 14X1. 
 
       --  ....................  
       --  .                  .  
       --  .      Report      .   SUBUNIT  
       --  .                  .  
       --  ....................  
 
    separate (Unit_Statistics)  
    procedure Report   
      ( Report_File : in  Text_IO.FILE_TYP ) is  
 
   --  Notes  
   --  This example is based on Task_Statistics.Report 
   --  by Dan Roy.  
   --   
   --  Modifications  
   --  8/18/86    Ed Seidewitz   Initial version.  
 
      Unit_Name_Column  
        : constant := 10;  
 
      Value_Column  
        : constant := 40;  
 
      use Text_IO;         -- For output operations.  
 
    begin    -- Report  
 
      -- Print header  
      New_Line (Report File);  
      Set_Col (Report. File, To => Unit_Name_Column);  
      Put_line (Report_File,  
          "Statistics for " & STRING(Unit_Name)); New Line (Report_File);  
      Number_Lines_Printed := Number_Lines_Printed . 2;  
 
      -- Print "element name element value" for all elements 
      Print_All: 
      for Element in Statistics Array'range loop  
        Put (Report_File, ELEMENT_TYP'image (Element));  
        Set Col (Report_File, To => Value_Column);  
        Put Line (Report_File, INTEGER'image (Statistics_Array(Element)));  
        Number_Lines_Printed := Number_Lines_Printed + 1;  
      end loop Print_All;  
 
    end Report;  
 
5.14.5.2  Example 14X2. 
 
       --  ....................  
       --  .                  .  
       --  .      Read        .   SUBUNIT  
       --  .                  .  
       --  ....................  
 
    separate (Disk)  
    procedure Read  
      ( Disk_File : in out FILE_TYP;  
        Data      : out    SPECIFIC_DATA_TYP ) is  
 
   --  Notes  
   --  (This is the body of procedure Read in example 7X3)  
 
   --  Modifications  
   --  9/10/86     Ada User's Group      Initial version  
 
    begin   -- Read  
 
      if not Disk_IO.Is_Open(Disk_File.File) then  
        Open_File(Disk_File);  
      end if;  
 
      Disk_IO.Read  
        ( File => Disk_File.File,  
          Item => Data );  
 
    exception  
 
      when Disk_IO.End Error =>  
        Disk_IO.Close (Disk_File.File);  
        raise End_Of_File;  
      when Disk_IO.Name Error  Disk_IO.Use_Error =>  
        raise Open_Error;  
      when Disk_IO.Mode_Error =>  
        raise Mode_Error;  
 
    end Read;  
--::::::::::
--mandat90.inf
--::::::::::
                         THE CONGRESSIONAL Ada MANDATE
Form G36-0391
MANDAT90.HLP

Ada Information Clearinghouse, 1-800-AdaIC-11, 1-703-685-1477

      A number of people have asked about the recent Congressional action 
mandating the use of Ada in all Department of Defense software.
      This mandate is contained in the fiscal year 1991 appropriations bill 
(H.R. 5803) for the Department of Defense.
The section number and wording are:
      "Sec. 8092.  Notwithstanding any other provisions of law, after June 1, 
1991, where cost effective, all Department of Defense software shall be 
written in the programming language Ada, in the absence of special exemption 
by an official designated by the Secretary of Defense."
      The bill was signed by the President on November 5, 1990, and is now 
Public Law 101-511.

Implementation Questions
      It should be noted that at this time (mid-January 1991) the Department 
of Defense has not yet established specific procedures for establishing an 
exemption process, nor for establishing a process by which questions of cost 
effectiveness may be evaluated.
      It should further be noted that the House Report accompanying the 
original House-passed version of H.R. 5803 stated that the House 
Appropriations Committee envisioned "that the Office of the Secretary of 
Defense will administer the general provision in a manner that prevents 
disruption to weapon systems that are well into development."  (See below for 
report language.)

Background
      The appropriations bill originated in the House as H.R. 5803.  In the 
version reported out of the House and sent to the Senate, this section 
(originally numbered Sec. 8084) had not contained the proviso "where cost 
effective"; as amended by the Senate, the mandate was deleted entirely; when 
House and Senate conferees met to reconcile differences in the two versions, 
they restored the mandate with the "where cost effective" proviso.  With this 
proviso, the mandate was then a part of the final version 
of the appropriations bill passed by both houses and signed by the President.

House Reasoning
      The following appeared in House Report 101-822, which accompanied the 
original House-passed version of H.R. 5803.

      "Ada Programming Language. -- The Department of Defense developed Ada to 
reduce the cost of development and support of software systems written in the 
hundreds of languages used by the DOD through the early 1980s.  Beside the 
training economies of scale arising from a common language, Ada enables 
software cost reduction in several other ways: (1) its constructs have been 
chosen to be building blocks for disciplined software engineering; (2) its 
internal checking inhibits errors in large systems lying beyond the 
feasibility of manual checking; and (3) its separation of software module 
interfaces from their implementations facilitates and encourages reuse of 
already-built and tested program parts.  While each of these advantages is 
important, Ada's encouragement of software engineering is fundamental.  
Software practitioners increasingly believe the application of engineering 
disciplines is the only currently-feasible avenue toward controlling unbridled 
software cost escalation in ever-larger and more complex systems.  In March, 
1987, the Deputy Secretary of Defense mandated use of Ada in DOD weapons 
systems and strongly recommended it for other DOD applications.  This mandate 
has stimulated the development of commercially-available Ada compilers and 
support tools that are fully responsive to almost all DOD requirements.  
However, there are still too many other languages being used in the DOD, and 
thus the cost benefits of Ada are being substantially delayed.  Therefore, the 
Committee has included a new general provision, Section 8084, that enforces 
the DOD policy to make use of Ada mandatory.  It will remove any doubt of full 
DOD transition to Ada, particularly in other than weapons systems 
applications.  It will stimulate DOD to move forward quickly with Ada-based 
software engineering education and cataloguing/reuse systems.  In addition, 
U.S. and commercial users have already expanded tremendously the use of Ada 
and Ada-related technology.  The DOD, by extending its Ada mandate, can 
leverage off these commercial advances.  Navy Ada is considered to be the same 
as Ada for the purposes of this legislation, and the term Ada is otherwise 
defined by ANSI/MIL-STD-1815.  The Committee envisions that the Office of the 
Secretary of Defense will administer the general provision in a manner that 
prevents disruption to weapon systems that are well into development.  The 
Committee directs that applications using or currently planning to use the 
Enhanced Modular Signal Processor (EMSP) be exempted from mandatory use of Ada 
as a matter of policy."

                                                                              
                                                              Form G36-0291
                                                                mandat90.hlp



--::::::::::
--pmh1804.abs
--::::::::::


                     Proposed MIL-HDBK-1804


                        Military Handbook

                         Ada Style Guide

                          30 April 1988


This  draft,  prepared  by  the  U.S.  Army  Information  Systems
Engineering  Command,  has  not  been  approved and is subject to
modification.   It  should  not  be  used  or  interpreted  as an
approved Military Handbook at this time.  

This  machine-readable  document is provided for the users of the
Ada  Software  Repository.   While  great  care has been taken in
entering  its  text,  typing errors may have been introduced (and
some  typing  errors  have  been corrected), and the users should
review  it.   It  is presented as both raw (for processing by the
PTF [Portable Text Formatter]tool in the Ada Software Repository)
and formatted machine-readable files. If errors are found, please
report  them  to  the Ada Software Repository Support Contractor,
MACA, by phone or email.  

     The Ada   Style   Guide   was   developed  by  the  National
Aeronautics  and Space Administration/Goddard Space Flight Center
Ada  User's  Group.   The principal author is Edwin V. Seidewitz.
The  guide  was  edited and reformatted as a Military Handbook by
the United States Army Information Systems Engineering Command.  

1.  SCOPE 

1.1.    Introduction.    Ada   is   a   programming  language  of
considerable    expressive    power.    ANSI/MIL-STD-1815A,   Ada
Programming  Language,  provides  a  thorough  definition  of the
language.   However, it does not offer sufficient guidance on the
appropriate  use  of  Ada's powerful features.  This document was
developed to address such "program style" issues.  

1.2.   Scope.   Program  source  code  serves  two  functions: to
specify  an  algorithm  to  be  performed  on  a computer, and to
communicate  this  algorithmic  design  to  other  human readers.
Program  style  relates  to  how  well a program meets the second
function.   It  is a consistent manner of using the features of a
programming    language    to   promote   the   readability   and
understandability  of a program.  This is a matter of the form of
the  final,  delivered,  program  source  code, as opposed to the
process of developing the code.  

1.3.  Goals.  

     a. While   some   of   what   constitutes  "good  style"  is
subjective  and  somewhat  arbitrary,  it  is  important that the
style  of  a  program  be consistent throughout the program.  The
primary  goal  of this guide is to promote such consistent use of
good  style  across  large  numbers  of  Ada programs.  The whole
intent  of  "good  style" is to increase the readability of these
programs.    Therefore,  these  guidelines  follow  from  general
principles of program readability and understandability.  

     b. The   program   should  reflect  the  natural  levels  of
abstraction  in  the  problem  domain,  so  that  the  reader can
reasonably comprehend each level individually.  

     c. There  are  several  features in Ada which are unfamiliar
to  many  programmers.   There  is  thus  a  tendency  to  either
underuse  these  features  or  to  use  them  inappropriately.  A
feature  of  Ada  should  generally  not  be ignored, but neither
should  it  be  used  in  excess.   The  guidelines highlight the
proper use of Ada features.  

     d. The  textual  format  of  a program should be pleasing to
the  eye and promote the readability and understandability of the
program.   The format should highlight the structure of a program
and  the  role  of  a  program  as a model of the problem domain.
Just  as  the  careful  layout  of  a  book  can  enhance written
communication,  the  careful  layout of a program can enhance the
communication  of  algorithmic  design  to  another  human.   The
consistent  use  of  formatting  style  is  especially important,
because  it  allows  readers to become accustomed to the familiar
layout  of  the  program  constructs.   An  automated  formatting
program  is particularly helpful, but even in the absence of such
a tool, much can be gained from a common format style.  
--::::::::::
--pmh1804.doc
--::::::::::




 
 














                                        Proposed MIL-HDBK-1804________ _____________




                                  Military Handbook Ada Style Guide
                                                   
                                            30 April 1988
































 
 




 
 
            This draft, prepared by the U.S.  Army Information Systems Engineering Command
            (ISEC),  has  not been approved and is subject to modification.  It should not
            be used or interpreted as an approved Military Handbook at this time.

            This  machine-readable  document is provided for the users of the Ada Software
            Repository  (ASR).   While  great  care  has  been taken in entering its text,
            typing  errors  may  have  been  introduced  (and some typing errors have been
            corrected),  and the users should review it.  It is presented as both raw (for
            processing   by   the  PTF  [Portable  Text  Formatter]  tool)  and  formatted
            machine-readable  files.   The  index is generated by PTF and is slightly more
            extensive  than  the  original  index.   The Appendices were not a part of the
            original  document  and  were  added  by  ASR personnel.  If errors are found,
            please report them to the ASR Support Contractor, MACA, by phone or email.















                                               FOREWORD



                 The  Ada  Style Guide was developed by the National Aeronautics and Space
            Administration/Goddard  Space  Flight  Center Ada User's Group.  The principal
            author  is  Edwin  V.   Seidewitz.   The guide was edited and reformatted as a
            Military  Handbook  by  the United States Army Information Systems Engineering
            Command (ISEC).

















 
 




 
 
                                               1. SCOPE





            1.1.  Introduction____________

                 Ada   is   a  programming  language  of  considerable  expressive  power.
            ANSI/MIL-STD-1815A,  Ada  Programming Language, provides a thorough definition
            of  the  language.   However,  it  does  not  offer sufficient guidance on the
            appropriate  use  of  Ada's powerful features.  This document was developed to
            address such "program style" issues.



            1.2.  Scope_____

                 Program  source  code serves two functions: to specify an algorithm to be
            performed  on  a computer, and to communicate this algorithmic design to other
            human  readers.   Program style relates to how well a program meets the second
            function.   It  is  a consistent manner of using the features of a programming
            language  to promote the readability and understandability of a program.  This
            is  a  matter  of  the  form  of the final, delivered, program source code, as
            opposed to the process of developing the code.



            1.3.  Goals_____

                 a.   While  some  of  what  constitutes  "good  style"  is subjective and
            somewhat  arbitrary, it is important that the style of a program be consistent
            throughout  the  program.   The  primary goal of this guide is to promote such
            consistent  use of good style across large numbers of Ada programs.  The whole
            intent  of  "good  style"  is  to  increase the readability of these programs.
            Therefore,   these  guidelines  follow  from  general  principles  of  program
            readability and understandability.

                 b.   The  program should reflect the natural levels of abstraction in the
            problem  domain,  so  that  the  reader  can  reasonably comprehend each level
            individually.

                 c.   There  are  several  features  in  Ada  which are unfamiliar to many
            programmers.  There is thus a tendency to either underuse these features or to
            use  them  inappropriately.  A feature of Ada should generally not be ignored,
            but  neither should it be used in excess.  The guidelines highlight the proper
            use of Ada features.

                 d.   The  textual  format  of a program should be pleasing to the eye and
            promote  the  readability  and  understandability  of the program.  The format
            should  highlight  the  structure  of a program and the role of a program as a
            model of the problem domain.  Just as the careful layout of a book can enhance
            written  communication,  the  careful  layout  of  a  program  can enhance the
            communication  of  algorithmic design to another human.  The consistent use of
 
            SCOPE                                                                        1




                                            MIL-HDBK-1804
 
            formatting  style is especially important, because it allows readers to become
            accustomed  to  the  familiar  layout of the program constructs.  An automated
            formatting  program is particularly helpful, but even in the absence of such a
            tool, much can be gained from a common format style.


















































 
            2                                                                        SCOPE




                                            MIL-HDBK-1804
 
                                       2. REFERENCED DOCUMENTS





            2.1.  Government__________ Documents_________

                 ANSI/MIL-STD-1815A, Ada Programming Language.













































 
            REFERENCED DOCUMENTS                                                         3




                                            MIL-HDBK-1804
 
                                            3. DEFINITIONS





            3.1.  Introduction____________

                 The  definitions  provided  in  ANSI/MIL-STD-1815A are applicable for use
            with  this  handbook.   Since  this  handbook  is  intended  to be a companion
            document  to  the  Ada  Programming  Language  manual, the definitions are not
            restated here.



            3.2.  Handbook________

                 The  term  "Handbook"  (capitalization intended) refers to this document,
            MIL-HDBK-1804,  Ada  Style  Guide  Handbook.   This  simplification is used to
            improve readability.



            3.3.  Standard________

                 The    term    "Standard"    (capitalization    intended)    refers    to
            ANSI/MIL-STD-1815A,  Ada  Programming  Language.   This  simplification  is to
            improve readability.


























 
            4                                                                  DEFINITIONS




                                            MIL-HDBK-1804
 
                                       4. GENERAL REQUIREMENTS






                                            NOT APPLICABLE














































 
            GENERAL REQUIREMENTS                                                         5




                                            MIL-HDBK-1804
 
                                        5. SPECIFIC GUIDELINES





            5.1.  Introduction____________

                 This  section  contains  fourteen  major subparagraphs (5.1 through 5.14)
            corresponding  to the fourteen chapters of ANSI/MIL-STD-1815A, Ada Programming
            Language.   This  provides a standard frame of reference for the discussion of
            Ada   features.    Where   appropriate,   the   guide  includes  examples  and
            justifications  for  various  guidelines.   Some  of  the major subparagraphs,
            themselves, have an "Examples" subparagraph giving additional, longer examples
            for the topic.



            5.2.  Lexical_______ elements________

            5.2.1.  The___ package_______ STANDARD.________.

                 Language  words  with  predefined meanings in the package STANDARD should
            not be redefined.

            5.2.2.  Formatting__________ of__ lexical_______ elements.________.

            5.2.2.1.  Indentation.___________.  The standard indentation is two spaces.

            5.2.2.2.   Character_________  set.___.   Full  use should be made of the ISO character set
            where  available.   Alternate  character replacements should only be used when
            the corresponding graphical symbols are not available.

            5.2.2.3.  Upper/lower___________ case.____.

                 a.  Reserved words and attributes should appear in lower case.

                 b.    All  identifiers  except  type,  enumeration  value  and  attribute
            identifiers should be in mixed upper and lower case.  The first letter of each
            word  in the identifier should be in upper case with other characters in lower
            case, unless a word is normally written in all upper case (e.g., acronyms).

               Display_Device
               Number_Of_User_Names
               Get_FHST_Data
               Package_Name


                 c.   Type  and  enumeration  value identifiers should appear in all upper
            case.

               LONG_INTEGER
               AUTHORITY_LEVEL
            
 
            6                                                          SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               (RED, GREEN, BLUE)
               (ARMY, AIR_FORCE, NAVY, MARINES)


            5.2.2.4.  Identifiers.___________.

                 a.  Identifier names should be meaningful and easily distinguishable from
            each  other,  except  possibly  for loop parameters, array indices, and common
            mathematical variables, which may be as short as a single character.

                 b.    Distinct  words  in  identifiers  should  always  be  separated  by
            underscores.

                 c.   The  use  of  abbreviations  in identifiers should be avoided.  When
            used,  an  abbreviation  should  be  significantly  shorter  than  the word it
            abbreviates,  and  its meaning should be clear.  The same abbreviations should
            be used consistently throughout a project.

            5.2.2.5.   Spaces.______.   Single spaces should be used consistently between lexical
            elements to enhance readability.

            5.2.2.6.  Blank_____ lines._____.

                 a.  Blank lines should be used to group logically related lines of text.

            A  careful  use  of  blank lines can greatly enhance readability by making the
            logical structure of a sequence of lines more textually obvious.  However, the
            overuse  of  blank  lines (e.g., "double spacing") defeats the very purpose of
            grouping  and can actually reduce readability.  Blank lines should thus always
            be used with grouping in mind and not just to increase white space.

                 b.   A blank line should always follow a construct whose last line is not
            at the same indentation level as its first line.

               type COMPLEX is
                 record
                   Real      : FLOAT;
                   Imaginary : FLOAT;
                 end record;
            
               -- Followed by a blank line


            5.2.2.7.  Continuation____________ of__ statements.__________.

                 a.   Statements  extending  over  multiple  lines should always be broken
            before reserved words, operator symbols, or one of the following symbols:

               :  |  =>  ..  :=


            but  they should be broken after a comma (",").  Unless otherwise specified in
            later  guidelines,  all the continuation lines should be indented at least two
            levels with respect to the original line they continue.
 
            SPECIFIC GUIDELINES                                                          7




                                            MIL-HDBK-1804
 
               Corrected_Value := (1 + Sensor_Scale) * Raw_Value
                   + Distortion_Factor * Distortion_Value + Sensor_Bias;


                 b.  Long strings extending over more than one line should be broken up at
            natural  boundaries, appropriate to the meaning of the contents of the string,
            if any.

               "This is a rather long string, so it is likely that "
                   & "it will extend over more than one line"


            5.2.2.8.  Comments.________.

                 a.   Comments  should  be  used  to  add information for the reader or to
            highlight sections of code, and should not merely paraphrase the code.

                 b.   Comments  should  begin  with  the "--" aligned with the indentation
            level  of  the  code  that they describe, or to the right of the code, aligned
            with other such comments.

               -- Check if the user has special authorization
               if Authority = SPECIAL then
                 Display_Special_Menu;   -- All operations are allowed
               else
                 Display_Normal_Menu;    -- Only normal operations allowed
               end if;




            5.3.  Declarations____________ and___ types_____

            5.3.1.  Constants._________.

                 a.  An object should be declared constant if its value is intended not to
            change.

            Declaring  an  object to be constant clearly signals both the human reader and
            the  compiler  the  intention  that  its value will not change.  This not only
            increases readability, it also increases reliability because the compiler will
            detect  any  attempt  to  tamper with the object.  Also, it can result in some
            decrease in executable size and better run time efficiency.

                 b.   Defining  a constant object is preferable to using a numeric literal
            or  expression  with  constant  value,  as  long as the constant object has an
            intrinsic conceptual meaning.

            There  is  no  use  in  defining  a  constant object when a numeric literal is
            obviously  more appropriate, for example: using "One" instead of "1." However,
            the  use  of constant objects with intrinsic meaning (such as "Buffer_Size" or
            "Field_Of_View")  can  greatly increase the readability of code.  Further, the
            code  is  more maintainable since a change in a value will be localized to the
            constant declaration.
 
            8                                                          SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 c.   A  named number (i.e., a constant object with type universal-integer
            or  universal-real)  should be used only for values that are truly "universal"
            and  "typeless."  Other  numeric constants should be declared with an explicit
            type.

            Such  constants  as  "Pi"  and  cardinal integers (e.g., a "number of things")
            should  be  named  numbers.  Note also that declaring a constant in terms of a
            predefined  numeric  type (INTEGER, FLOAT, etc.) has no advantage over a named
            number   since   these  predefined  types  provide  only  range  and  accuracy
            constraints  and  not additional conceptual meaning.  In fact, since the range
            and   accuracy   of   predefined   numeric  types  is  implementation-defined,
            portability  can  be  increased by using named numbers, in those cases where a
            constant of a user-defined type is not more appropriate.

               Number_Of_Sensors       -- This is a named number
                 : constant := 4;
            
               Main_Sensor_Number
                 : constant SENSOR_INDEX := 2;


            5.3.2.  Types._____.

                 Separate  types  should  be  used  for  values  that  belong to logically
            independent sets, and for distinct concepts.

               type X_COORDINATE is
                 range 1 .. 640;
            
               type Y_COORDINATE is
                 range 1 .. 480;
            
               type PIXEL_VALUE is
                 range 0 .. 255;
            
               type IMAGE_GRID is
                 array (X_COORDINATE, Y_COORDINATE) of PIXEL_VALUE;


            A  data  type characterizes a set of values and a set of operations applicable
            to  objects  of  the  type.   In the above example, each coordinate has a type
            because  coordinates  are  independent  entities.   Explicitly declaring these
            types  makes  the  concepts more obvious to a human reader and also allows the
            compiler to detect mistakes such as:

               Image (Y, X) := Pixel;   -- Should be "(X, Y)"


            The  drawback  of  this  kind  of  typing  is  that the following construct is
            illegal:

               if X = Y then     -- ILLEGAL since X and Y have different types
                 ...

 
            SPECIFIC GUIDELINES                                                          9




                                            MIL-HDBK-1804
 

            A type conversion must be used:

               if X = X_COORDINATE(Y) then
                 ...


            Note  that,  depending on context (and compiler quality), there may or may not
            be  some  run  time  penalty associated with type conversion (e.g., testing of
            range constraints).

            5.3.3.  Enumeration___________ types._____.

                 An  enumeration  type  should  always be used in preference to an integer
            type,  unless  the  logical  nature  of  the concept to be modeled demands the
            other.

            For example, the type:

               type DEVICE_MODE is
                 (READ_ONLY, WRITE_ONLY, READ_WRITE);


            is preferable to encoding DEVICE_MODE as an integer 0, 1 or 2.

            5.3.4.  Floating________ types._____.

                 a.   To  enhance  portability, the range and accuracy of a floating point
            type should generally be specified.

                 b.   The  precision  for  the  predefined floating types (FLOAT, etc.) is
            implementation-dependent, though all implementations should provide at least 6
            decimal  digits  of  accuracy.  Explicitly declaring floating point ranges can
            yield more reliable and more efficient results as well as more portable code.

            5.3.5.  Record______ types._____.

                 a.   A  record type should be used instead of an array type even when all
            the  record  components  have  the same type, as long as each component can be
            sensibly named and the components do not need to be dynamically indexed.

            For example, the definition:

               type COMPLEX is
                 record
                   Real      : FLOAT;
                   Imaginary : FLOAT;
                 end record;


            is preferable to defining COMPLEX as an array of two FLOATs.

                 b.   Overcomplicated  record  structures  should  be  avoided by grouping
            related data into subrecord types.
 
            10                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               type COORDINATE is
                 record
                   Row    : FLOAT;
                   Column : FLOAT;
                 end record;
            
               type WINDOW is
                 record
                   Top_Left     : COORDINATE;
                   Bottom_Right : COORDINATE;
                 end record;


                 c.  Enumeration types should be used for discriminants of record variants
            whenever   possible.    A   discriminant   should  generally  have  a  default
            initialization  only  if the discriminant value is intended to change over the
            lifetime of an object.

            5.3.6.  Access______ types._____.

                 a.   Generally,  access  types  should  not be used when static types and
            stack allocation would be sufficient.

                 b.   Generally,  access types should be used only when it is necessary to
            have  data  structures with dynamic pointers or to dynamically create objects.
            However, access types may be needed for static objects if this leads to a more
            consistent programming style (e.g., so that similar static and dynamic objects
            are treated identically).  For example, if linked lists are used in a program,
            there may be some lists which are constant, but which are still implemented as
            linked lists using access types.  This would allow, for example, passing these
            constant lists to subprograms which also handle dynamic lists.

            5.3.7.  Object______ declarations.____________.

                 a.  Each object declaration should declare only one object.

            For example, the following objects should be declared in separate declarations
            even though they are all of the same type:

               Table_Size
                 : TABLE_RANGE;
            
               Table_Index
                 : TABLE_RANGE;
            
               Current_Entry
                 : TABLE_RANGE;


                 b.   An  object should not be declared using an unnamed constrained array
            definition.

            The  unnamed  array  definition is the only case in Ada where an object can be
            declared  to be of a type which does not have a name.  Instead, the array type
 
            SPECIFIC GUIDELINES                                                         11




                                            MIL-HDBK-1804
 
            should  be  named  in  an  array  definition, and that name used in the object
            declaration, even if there is only one object declared of that type.

               type POOL_TYPE is
                 array (POOL_RANGE) of CHARACTER;
            
               POOL
                 : POOL_TYPE;


                 c.   Objects  should  generally  be initialized.  Where possible, objects
            should always be initialized by their declaration, rather than in later code.

               Is_Found
                 : BOOLEAN := FALSE;


            5.3.8.  Formatting__________ of__ declarations____________ and___ types._____.

            5.3.8.1.  Commenting.__________.

                 a.   Type declarations (or groups of declarations) should be commented to
            indicate  what  is  being  defined,  if  that  is  not  obvious  from the type
            declaration itself.

               type VELOCITY is     -- Inertial velocity relative to the Earth
                 array (1 .. 3) of FLOAT;


                 b.   Object  declarations should be commented if the object definition is
            unclear  from  the  object  and  type  identifiers  alone.   Note  that  those
            properties  of  an  object  obtained  from  its type should not be repeated in
            comments on the object declaration.

               Spacecraft_Velocity    -- Spacecraft orbital velocity, assuming
                 : VELOCITY;          -- a circular orbit


            5.3.8.2.   Indentation.___________.   All declarations in a single declaration part should
            begin at the same indentation level.

            5.3.8.3.  Type____ definitions.___________.

                 a.  Array type definitions should have one of the following formats:

               type  is
                 array  of ;
            
               type  is
                 array 
                   of ;


                 b.  Record type definitions should have one of the following formats:
 
            12                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               type  is
                 record
                   
                   
                 end record;
            
               type 
                 ( ;
                    ) is
                 record
                   
                   case  is
                     when  =>
                       
                       
            
                   end case;
            
                 end record;


                 c.   All   and  should
            be formatted like object declarations (see paragraph 5.3.8.4).

                 d.  Other type definitions should be formatted as follows:

               type  is
                 ;
            
               subtype  is
                 ;


                 e.   Long  enumeration  type  definitions should be formatted into easily
            readable columns.

            5.3.8.4.  Formatting__________ of__ object______ declarations.____________.

                 a.   Object  declarations  should have one of the following formats.  The
            preferred formats are:

               
                 :  := ;
            
               
                 : 
                   := ;


                 b.   Declarations  containing short identifiers may also be formatted all
            on one line:

                :  := ;

 
            SPECIFIC GUIDELINES                                                         13




                                            MIL-HDBK-1804
 

            In this case, all such declarations textually grouped together or appearing as
            components  in a single record definition or in a single parameter list should
            have their ":" and ":=" symbols aligned.

            5.3.9.  Examples________ for___ declarations____________ and___ types._____.

            5.3.9.1.  Example_______ 3X1.___.

               type SENSOR_ARRAY is
                 array (NATURAL range <>) of SENSOR;
            
               UARS_Sensors                        -- Sensor configuration for
                 : SENSOR_ARRAY(1 .. Num_Sensors); -- the UARS control system


            5.3.9.2.  Example_______ 3X2.___.

               type COMPLEX is
                 record
                   Real      : FLOAT;
                   Imaginary : FLOAT;
                 end record;


            5.3.9.3.  Example_______ 3X3.___.

               type DEVICE is
                 (PRINTER, DISK, DRUM);
            
               type STATE is     -- Operational state
                 (OPEN, CLOSED); -- of a device.
            
               type PERIPHERAL
                 ( Unit : DEVICE := DISK) is
                 record
                   Status
                     : STATE;
                   case Unit is
                     when PRINTER =>
                       Lines_Per_Page
                         : INTEGER range 1 .. Page_Size;
            
                     when DISK | DRUM =>
                       Cylinder
                         : CYLINDER_INDEX;
                       Track
                         : TRACK_NUMBER;
            
                   end case;
            
                 end record;


 
            14                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.4.  Names_____ and___ expressions___________

            5.4.1.  Aggregates.__________.

                 a.   Aggregates are preferable to individually setting all or most of the
            components of an array or record.

                 b.  Named aggregates should be used where possible.

                 c.  The "others" choice should not be used within aggregates without good
            reason.

            5.4.1.1.  Static______ expressions.___________.

                 a.   Where  possible,  universal  expressions  are  preferable  to static
            expressions, which are in turn preferable to dynamic expressions.

            Since  they  do not depend on run time dynamics, static expressions are easier
            for  a  human  reader  to  understand.   Also,  universal expressions maximize
            accuracy and portability, and static expressions eliminate run time overhead.

            5.4.1.2.  Short-circuit_____________ control._______.

                 a.   Short-circuit  control  forms should generally be used only to avoid
            evaluation  of  an  undefined  or illegal expression.  Short circuit operators
            should not be used to optimize execution.

               (N /= 0) and then (Total/N > Limit)
            
               (Index = 0) or else User(Index).Not_Available


                 b.   The  short-circuit control forms should be used to signal to a human
            reader  that the correctness of the second condition depends on the results of
            the  first.   They  should  not be used for micro-efficiency reasons, concerns
            better  handled  by  an optimizing compiler.  If efficiency considerations are
            substantially  important,  "if"  statements  should  be  used  instead  of the
            short-circuit forms with functions used to avoid repeated code, if necessary.

            5.4.1.3.  Type____ qualification._____________.

                 a.   An  explicit  type conversion should not be used if a type qualified
            expression is meant.

               Good : LONG_FLOAT'(3.14159);
               Bad  : LONG_FLOAT (3.14159);


            A  qualified  expression  is  used  to state explicitly the type, and possibly
            subtype,  of  a  value.   A  type  conversion, however, results in the dynamic
            conversion  of  a  value to a target type.  Sometimes a type conversion can be
            used to serve the purpose of a type qualification.  However, if the operand is
            already  of  the desired base type, a conversion is not really necessary and a
            qualification should be used instead.
 
            SPECIFIC GUIDELINES                                                         15




                                            MIL-HDBK-1804
 
                 b.  Situations where type qualification is necessary should be avoided if
            possible.   Other  than  where absolutely necessary, type qualification may be
            justified only if it makes the program clearer to the reader.

            The main case to avoid is when the type of an enumeration literal or aggregate
            is not known from context.  For example:

               type COLOR is
                 (BLACK, RED, GREEN, BLUE, WHITE);
            
               type LIGHT is
                 (RED, YELLOW, GREEN);
            
               procedure Set
                 ( Color_Code : in COLOR );
            
               procedure Set
                 ( Color_Code : in LIGHT );
            
               ...
            
               Set(COLOR'(RED));  -- Type qualification must be used here to
               Set(LIGHT'(RED));  -- resolve the overloading of Set and RED


            It  would be better in this case to rename one of the Set procedures, or to at
            least give them different parameter names so the overloading could be resolved
            using name notation.

            5.4.2.  Formatting__________ of__ names_____ and___ expressions.___________.

            5.4.2.1.  Names._____.

                 a.   The  name for a type should be a common noun indicating the class of
            the objects it contains.

               DEVICE
               AUTHORITY_LEVEL
               USER_NAME
               PHONE_LIST


            A type name may also end with the suffix "TYPE."

               EMPLOYEE_TYPE
               SCHEDULE_TABLE_TYPE
               COLOR_TYPE


                 b.   The  names of non-BOOLEAN valued objects should be nouns, preferably
            more precise than the names of types.

               Current_User
                 : USER_NAME;
 
            16                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            
               Output_Device
                 : DEVICE;
            
               Schedule_Table
                 : SCHEDULE_TABLE_TYPE;
            
               New_Employee
                 : EMPLOYEE_TYPE;


            BOOLEAN  valued  objects  should  have  predicate-clause  (e.g., "Is_Open") or
            adjective names.

               User_Is_Available
               List_Empty
               Done
               Not_Ready
               Is_Waiting


            5.4.2.2.   Parentheses.___________.   Syntactically redundant parentheses should generally
            be  used  to  enhance the readability of expressions, especially by indicating
            the order of evaluation.

            For example:

               Variance := (Roll_Error ** 2) + ((Yaw_Error ** 2) / 2);


            5.4.2.3.  Aggregates__________ format.______.

                 a.   When longer than two or three components, or whenever readability is
            improved,  named  aggregates  should be formatted as indicated below, with one
            association per line and the "=>" arrows aligned.

               Output_Device :=
                 ( Device   => DISK,
                   Status   => CLOSED,
                   Cylinder => 1,
                   Track    => Startup_Track_Number );


                 b.   Aggregates for tabular data structures may instead be formatted in a
            tabular fashion, so as to enhance readability.

            5.4.2.4.   Continuation.____________.   When a long expression is broken over more than one
            line,  it  should be broken near the end of the line before an operator symbol
            with the lowest reasonable precedence.

               Corrected_Value := (1 + Sensor_Scale) * Raw_Value
                 + Distortion_Factor * Distortion_Value + Sensor_Bias;


 
            SPECIFIC GUIDELINES                                                         17




                                            MIL-HDBK-1804
 
            5.5.  Statements__________

            5.5.1.  Slice_____ statements.__________.

                 Array  slice  assignments should be used rather than loops to copy all or
            part  of  an array.  This is more readable and less error prone, especially in
            the case of slices with overlapping ranges.

               Client_List (Last_Client .. Number_Of_Clients)
                 := New_Clients (1 .. Num_New_Clients);


            5.5.1.1.   If__  statements.__________.  An "if" statement should not be used to create the
            effect  of  a  "case" statement controlled by the value of an enumeration type
            other than BOOLEAN.

            5.5.1.2.  Case____ statements.__________.

                 a.  A "case" statement should not be controlled by a BOOLEAN value.

                 b.   When  possible,  the  explicit  listing  of  all choices on a "case"
            statement is preferable to the use of an "others" clause.

            This  makes  it  easier  for a human reader to see that the proper actions are
            being  taken  in  all  cases.  Further, if the enumeration type of the control
            expression  is  modified,  the compiler will indicate overlooked alternatives.
            However, there are cases when an "others" clause makes sense.  For example, if
            the control expression is of type CHARACTER, then is is usually best to use an
            "others" clause to handle the "undesired characters" case.

            5.5.1.3.  Block_____ statements.__________.

                 a.   Blocks  should be used cautiously to introduce local declarations or
            to define a local exception handler.

            To  some  extent, a block can be thought of as a procedure which is hard coded
            in-line.   However,  a  procedure call contributes to readability precisely by
            not  having  its  source  code in-line (providing a "functional abstraction").
            Therefore,  blocks  should  always  be  used  cautiously and only for specific
            purposes.  Thought should always be given to using a procedure call instead of
            a block to improve readability.

                 b.   Declarations  of  objects  used only within a block should be nested
            within the block.

            5.5.1.4.   Exit____  statements.__________.  "Exit" statements should be used cautiously, and
            only when they significantly enhance the readability of the code.

            It  is often more readable to use exit than to try to add BOOLEAN variables to
            a  "while"  loop  condition  to  simulate  exits  from the middle of the loop.
            However, it can be difficult to understand a program where loops can be exited
            from multiple places.  It is best to limit the use of "exit" statements to one
            per  loop,  if possible, and it is generally more readable to use "exit when."
            Use "if ...  then ...  exit; end if;" when "last wishes" processing is needed.
 
            18                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.5.1.5.   Return______  statements.__________.   It  is  preferable  to minimize the number of
            return  points  from  a subprogram, as long as this does not distract from the
            natural structure or readability of the subprogram.

            5.5.1.6.   Goto____  statements.__________.  Neither "goto" statements nor labels should ever
            be used.

            Use  of  the "goto" makes the textual structure of code less reflective of its
            logical  structure.   Possible  uses  of  the  "goto"  statement can always be
            handled  by other constructs in Ada.  Cases in Ada when the "goto" still seems
            appropriate  almost  always  indicate  poorly  designed code.  It is better to
            redesign the code than to use the "goto" statement.

            5.5.2.  Formatting__________ of__ statements.__________.

            5.5.2.1.   Statement_________ sequences._________.  Blank lines should be used liberally to break
            sequences of statements into short, meaningful groups (see paragraph 5.2.2.6).

               Put_Line ("Welcome to the Electronic Message System");
            
               Logon_User(Current_User);
               User_Directory.Lookup
                 ( User_Name => Current_User,
                   Authority => User_Authority );
            
               if User_Authority = SPECIAL then
                 Put_Line ("** You have SPECIAL authorization **");
               end if;


            5.5.2.2.  If__ statement_________ format.______.

                 a.  "If" statements should have the following format:

               if  then
                 
                 
               elsif  then
                 
                 
               else
                 
                 
               end if;


                 b.   Multiple  conditions  in  an "if" clause should be grouped together,
            placed on appropriate lines, and aligned so as to enhance clarity.






 
            SPECIFIC GUIDELINES                                                         19




                                            MIL-HDBK-1804
 
            5.5.2.3.   Case____ statement_________ format.______.  "Case" statements should have the following
            format:

               case  is
                 when  =>
                   
                   
                 when others =>
                   
                   
               end case;


            5.5.2.4.  Loop____ statement_________ format.______.

                 a.  "Loop" statements should have one of the following formats:

               :
                loop
                 
                 
               end loop ;
            
                loop
                 
                 
               end loop;


                 b.  A loop should preferably have a loop identifier.

            5.5.2.5.  Block_____ statement_________ format.______.

                 a.  Block statements should have the following format:

               :
               declare
                 
                 
               begin
                 
                 
               exception
                 when  =>
                   
                   
               end ;


                 b.  Blocks should always have a block identifier.




 
            20                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.5.3.  Examples________ for___ statements.__________.

            See also examples 5.9.4.2, 5.9.4.3, 5.9.4.4, 5.14.3.1, and 5.14.3.2.

            5.5.3.1.  Example_______ 5X1.___.

               if Security_Level = 0 then
                 Message_Classification := UNCLASSIFIED;
            
               elsif Security_Level > User_Clearance then
                 Message_Classification := PROTECTED;
            
               else
                 Message_Classification := Classification (Security_Level);
            
               end if;


            5.5.3.2.  Example_______ 5X2.___.

               case Sensor is
                 when ELEVATION =>
                   Record_Elevation (Sensor_Value);
                 when AZIMUTH =>
                   Record_Azimuth (Sensor_Value);
                 when DISTANCE =>
                   Record_Distance (Sensor_Value);
               end case;


            5.5.3.3.  Example_______ 5X3.___.

               Read_File:
               loop
            
                 Text_IO.Get(File1, Next_Record);
                 Store_Record(Next_Record);
            
                 exit when Text_IO.End_Of_File(File1);
            
               end loop Read_File;


               Compute_Total_Taxes:
               while Next /= Head loop
            
                 Total_Taxes := Total_Taxes + Next.Pay_Period_Deductions;
                 Next := Next.Successor;
            
               end loop Compute_Total_Taxes;


               Merge_Files:
               for N in 1 .. Max_Num_Files loop
 
            SPECIFIC GUIDELINES                                                         21




                                            MIL-HDBK-1804
 
            
                 Get_Items:
                 for J in 1 .. Max_Num_Items loop
            
                   Get_New_Item(New_Item);
                   Merge_Item(New_Item, Storage_File);
            
                   exit Merge_Files when New_Item = Terminal_Item;
            
                 end loop Get_Items;
            
               end loop Merge_Files;


            5.5.3.4.  Example_______ 5X4.___.

               Swap_Integers:
               declare
            
                 Temp
                   : constant INTEGER := 0;
            
               begin -- Swap_Integers
            
                 U := V;
                 V := Temp;
            
               end Swap_Integers;


               Check_Entry:
               begin
            
                 Int_IO.Get(Value);
                 Update(Value);
            
               exception
            
                 when Data_Error =>
                   Text_IO.New_Line;
                   Text_IO.Put_Line("Value entry error.");
                   Entry_Error_Flag := TRUE;
            
               end Check_Entry;










 
            22                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.6.  Subprograms___________

            5.6.1.  Cohesion.________.

                 A  subprogram should perform a single, conceptual action (i.e., should be
            "functionally cohesive").

            The  use of a subprogram increases readability by hiding the details of how an
            action  is  performed  and  giving it a descriptive name.  A subprogram should
            perform  only  a single conceptual action so that its use can be understood as
            independently  as possible from its implementation details and it can be given
            a  self-documenting  name.   Note  that simply shortening a program by placing
            "repeated  code"  into subprograms must be considered a secondary goal.  Thus,
            it is quite acceptable to have subprograms which are only called at one place,
            so long as those programs define cohesive actions.

            5.6.2.  Parameters.__________.

                 a.   Subprograms with equivalent parameters should generally declare each
            parameter in the same position with the same identifier.

                 b.   Parameters with default expressions should usually be used only when
            they have very well known default values and/or they are defaulted most of the
            time and the default is only over-ridden in special circumstances.

                 c.  Parameters with default expressions should generally be placed at the
            end  of  the  parameter  list, so that they may be omitted if desired in calls
            using positional notation.

            5.6.2.1.   Recursion._________.  A recursive subprogram should generally be used only if
            it  is conceptually simpler for a given problem than a corresponding iterative
            subprogram.

            Many  people  have  difficulty in understanding a program which uses recursion
            extensively.   However,  there  are  many  cases where a recursive solution is
            considerably  simpler  and  clearer than an iterative one.  This is especially
            true, for example, for traversing complicated data structures such as tree and
            graph structures.

            5.6.2.2.   Functions._________.   A  subprogram  without side-effects returning a single
            value should generally be written as a function.

            Since  functions  can be called from within expressions, there is more freedom
            in  how  a  function  can be used.  For example, if a function is to be called
            only  once  within  some  other  subprogram,  it  can  be used to initialize a
            constant object.

               procedure Process_Sensor_Data is
            
                 Main_Sensor_Data
                   : constant SENSOR_DATA
                     := Read_Sensor (Main_Sensor_Index);
            
               begin
 
            SPECIFIC GUIDELINES                                                         23




                                            MIL-HDBK-1804
 
                 ...


            However,  if  this  sort  of  freedom  is  specifically not desired, or if the
            subprogram  has  side  effects,  then  use of a procedure should be considered
            instead of a function, even if the subprogram returns only a single value.

            5.6.2.3.  Overloading.___________.

                 a.  Overloading of subprograms should not be used except in the following
            cases:

                  (1)  Widely  used  utility  subprograms  which perform identical or very
            similar  actions on arguments of different types (e.g., square-root of integer
            and real arguments).

                  (2) Overloading of operator symbols.

            Note  that  this  is  not  meant  to cover subprograms with identical names in
            different  packages, unless both subprograms are visible through "use" clauses
            for their packages.

                 b.   Operator  symbols  should  be  overloaded only when the new operator
            definitions comply closely with the traditional meaning of the operator (e.g.,
            "+" for vector addition).

            5.6.3.  Formatting__________ of__ subprograms.___________.

            5.6.3.1.  Subprogram__________ names._____.

                 a.   Except as indicated below, a subprogram name should be an imperative
            verb phrase describing its action.

               Obtain_Next_Token
               Increment_Line_Counter
               Create_New_Group


                 b.  Non-BOOLEAN valued function names may also be noun phrases.

               Top_Of_Stack
               X_Component
               Successor
               Sensor_Reading


                 c.  BOOLEAN valued functions should have predicate-clause names.

               Stack_Is_Empty
               Last_Item
               Device_Not_Ready



 
            24                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.6.3.2.   Subprogram__________  header.______.   Each  subprogram  specification, body or stub
            should  be  preceded  by  a  header  comment  block  containing  at  least the
            subprogram name and the indication SPEC, BODY, SPEC & BODY, STUB or SUBUNIT.

               -- .......................
               -- .                     .
               -- .  Obtain_Next_Token  .  SPEC
               -- .                     .
               -- .......................


            5.6.3.3.  Subprogram__________ declarations.____________.

                 a.  Procedure declarations should have the following format:

               procedure 
                 ( ;
                    );
            
               --| 


            Each   should be formatted like an object declaration
            (see paragraph 5.3.8.4).  The documentary comments should follow guideline d.,
            below.

                 b.  Function declarations should have the following format:

               function 
                 ( ;
                    )
                 return ;
            
               --| 


            Each   should be formatted like an object declaration
            (see  paragraph  5.3.8.4).  The  should follow guideline
            d., below.

                 c.   Parameter  mode  indications  should  always  be  used  in procedure
            specifications.   In  a function specification, mode indications should either
            be used for all of the parameters or none of the parameters.

                 d.   Subprogram declarations should be followed by at least the following
            documentation:

               --| Purpose
               --| A description of all purposes and functions of the subprogram.
               --|
               --| Exceptions
               --| A list of all exceptions which may propagate out of the
               --| subprogram, and a description of when each would be raised.
               --|
 
            SPECIFIC GUIDELINES                                                         25




                                            MIL-HDBK-1804
 
               --| Notes
               --| Additional comments on the use of the subprogram.


            The  "Exceptions"  and  "Notes"  headings  should  be  included  even if these
            sections  are  empty.   An  empty  section  may  be  indicated  by placing the
            annotation  "(none)"  after the appropriate header.  Only in the case that the
            subprogram  declaration is a compilation unit, the following section should be
            added to the documentation:

               --|
               --| Modifications
               --| A list of modifications made to the subprogram DECLARATION.
               --| Each entry in the list should include the date of the change,
               --| the name of the person who made the change and a description
               --| of the modification.  The first entry in the list should
               --| always be the initial coding of the subprogram declaration.


            5.6.3.4.  Subprogram__________ bodies______ and___ stubs._____.

                 a.  Subprogram bodies should have the following format:

               separate ()
                is
            
               --| 
            
                 
                 
            
               begin -- 
            
                 
                 
            
               exception
                 when  =>
                   
            
               end ;


            The    should  be  formatted  as  in  a  subprogram
            declaration (see paragraph 5.6.3.3).  The  should follow
            guideline  b.,  below.   Note  that  the  "end"  of a subprogram should always
            include the subprogram name.

                 b.   Subprogram  bodies  should have AT LEAST the following documentation
            placed immediately after the subprogram header:

               --| Notes
               --| Comments on the design, implementation and use of the
               --| subprogram.
 
            26                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 

            The "Notes" heading should be included even if the section is empty.  An empty
            section  may be indicated by the comment "Notes (none)." Only in the case of a
            subprogram  body  which is a compilation unit, the following section should be
            added to the documentation.

               --|
               --| Modifications
               --| A list of modifications made to the subprogram BODY.
               --| Each entry in the list should include the date of the change,
               --| the name of the person who made the change and a description
               --| of the modification.  The description should identify exactly
               --| where in the compilation unit the change was made.  The
               --| first entry in the list should always be the initial coding
               --| of the subprogram body.


            If  there is no declaration or stub for a subprogram, then the subprogram body
            should   also   include  all  the  documentation  required  for  a  subprogram
            declaration (see paragraph 5.6.3.3).

                 c.  Subprogram stubs should have the following format:

                is separate;


            where   the    is  formatted  as  in  a  subprogram
            declaration  (see paragraph 5.6.3.3).  If there is no previous declaration for
            a separate subprogram, then the subprogram stub should be followed by the same
            documentary  comments  required  for  a  subprogram declaration (see paragraph
            5.6.3.3).

            5.6.3.5.  Named_____ parameter_________ association.___________.

                 a.   Named  parameter  association should generally be used for procedure
            calls  of  more  than a single parameter.  Positional parameters are generally
            preferred for function calls.

                 b.   Named  and positional parameter associations should generally not be
            mixed in a single subprogram call.

                 c.   Named  parameter  associations should generally appear one to a line
            with formal parameters, "=>" symbols and actual parameters aligned.

               Obtain_Next_Token
                 ( File     => Current_Source_File,
                   Position => Current_Column,
                   Token    => Next_Token );






 
            SPECIFIC GUIDELINES                                                         27




                                            MIL-HDBK-1804
 
            5.6.4.  Examples________ for___ subprograms.___________.

                 See  also  examples  5.7.4.3,  5.9.4.3, 5.12.4.1, 5.12.4.3, 5.14.3.1, and
            5.14.3.2.

            5.6.4.1.  Example_______ 6X1.___.

               -- .......................
               -- .                     .
               -- .  Obtain_Next_Token  .  SPEC
               -- .                     .
               -- .......................
            
               procedure Obtain_Next_Token
            
                 ( File                               -- Sequential text file.
                    : in out Parser_Types.FILE;
            
                  Token
                    : out Parser_Types.TOKEN_TYPE;
            
                  Position                            -- Column position of the
                    : in Parser_Types.COL_NUM_TYPE    -- beginning of the next
                      := 0 );                         -- token.
            
               --| Purpose
               --| This procedure scans the current input line from the point at
               --| which it was last called and returns the next token.
               --|
               --| Exceptions
               --| Source_File_Not_Open -- Raised if the input file is not open
               --|
               --| Notes (None)


            5.6.4.2.  Example_______ 6X2.___.

               -- ..................
               -- .                .
               -- .  Decode_Token  .  SPEC
               -- .                .
               -- ..................
            
               function Decode_Token
            
                 ( File                              -- Sequential text file
                     : Parser_Types.FILE;
            
                   Token
                     : Parser_Types.TOKEN_TYPE )
            
                 return Parser_Types.TOKEN_TYPE;
            
               --| Purpose
 
            28                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               --| This function returns the ordinal value of the decoded token.
               --|
               --| Exceptions
               --| Illegal_Token -- raised if the token is not legal
               --|
               --| Notes
               --| This function will later be changed to a procedure.


            5.6.4.3.  Example_______ 6X3.___.

               -- .......................
               -- .                     .
               -- .  Obtain_Next_Token  .  STUB
               -- .                     .
               -- .......................
            
            
               procedure Obtain_Next_Token
            
                 ( File                               -- Sequential text file.
                    : in out Parser_Types.FILE;
            
                  Token
                    : out Parser_Types.TOKEN_TYPE;
            
                  Position                            -- Column position of the
                    : in Parser_Types.COL_NUM_TYPE    -- beginning of the next
                      := 0 ) is separate;             -- token.


            5.6.4.4.  Example_______ 6X4.___.

               -- ..................
               -- .                .
               -- .  Decode_Token  .  STUB
               -- .                .
               -- ..................
            
               function Decode_Token
            
                 ( File
                     : Parser_Types.FILE;
            
                   Token
                     : Parser_Types.TOKEN_TYPE )
            
                 return Parser_Types.TOKEN_TYPE is separate;






 
            SPECIFIC GUIDELINES                                                         29




                                            MIL-HDBK-1804
 
            5.6.4.5.  Example_______ 6X5.___.

               -- .......................
               -- .                     .
               -- .  Obtain_Next_Token  .  SUBUNIT
               -- .                     .
               -- .......................
            
               with Parser_Types,
                    File_Handler;
            
               separate (Lexical_Analyzer)
               procedure Obtain_Next_Token
            
                 ( File                               -- Sequential text file.
                    : in out Parser_Types.FILE;
            
                  Token
                    : out Parser_Types.TOKEN_TYPE;
            
                  Position                            -- Column position of the
                    : in Parser_Types.COL_NUM_TYPE    -- beginning of the next
                      := 0 ) is                       -- token.
            
               --| Notes (None)
               --|
               --| Modifications
               --| 7/4/85   Rebecca DeMornay  Initial version of the subunit
               --| 9/6/85   R. DeMornay       Added the local function
               --|                            "Increment_Line_Counter".
            
                 type LINE_COUNT is                   -- A count of the number
                   range 1 .. File_Handler.Max_Size;  -- of lines in a file.
            
                 Line_Counter
                   : LINE_COUNT := 1;
            
                 -- ............................
                 -- .                          .
                 -- .  Increment_Line_Counter  .  SPEC & BODY
                 -- .                          .
                 -- ............................
            
                 function Increment_Line_Counter
            
                   ( File                              -- Sequential text file
                       : Parser_Types.FILE;
            
                     Line                              -- Line number in "File"
                       : LINE_COUNT )                  -- at the time of call
            
                   return LINE_COUNT is
            
                 --| Purpose
 
            30                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 --| This function increments the line counter from the point at
                 --| which it was after the last call of this routine.
                 --|
                 --| Exceptions
                 --| Source_File_Not_Open  -- Raised if "File" is not open.
                 --| End_Of_File           -- Raised if the function is called and
                 --|                          the end of the file has already been
                 --|                          reached.
                 --|
                 --| Notes (None)
            
                 begin  -- Increment_Line_Counter
            
                   ...
            
                 end Increment_Line_Counter;
            
               begin  -- Obtain_Next_Token
            
                 ...
            
               exception
            
                 when File_Handler.FILE_ERROR =>
                   Token := Parser_Types.NONE;
                   raise Source_File_Not_Open;
            
               end Obtain_Next_Token;




            5.7.  Packages________

            5.7.1.  Use___ of__ packages.________.

                 a.  A package should fulfill one or more of the following:

                  (1) Model an abstract entity (or data type) appropriate to the domain of
            a problem.

                  (2) Collect related type and object declarations which are used together
            (this kind of package should generally be used only to provide a common set of
            declarations for two or more library units).

                  (3)  To group together program units for essential configuration control
            or  visibility  reasons  (packages  fulfilling  this role alone should be used
            sparingly).

            The  roles  above  are  listed in order of decreasing desirability.  The first
            role,  modeling  a problem domain entity, is the strongest use of packages for
            structuring  a  program.   It  corresponds  to  the  requirement of functional
            cohesion  for subprograms (see paragraph 5.6.1) and contributes to the goal of
            making the structure of a program reflect the structure of its problem domain.
 
            SPECIFIC GUIDELINES                                                         31




                                            MIL-HDBK-1804
 
            The  second  kind  of  package,  collection  of  related  declarations, should
            generally be used only to provide a common set of declarations for two or more
            library units.  Further, it is better to minimize the declaration of variables
            in  these  packages.   Overuse  of  packages of variables results in a FORTRAN
            COMMON  block  style  program  decomposition which defeats the abstraction and
            information hiding properties of packages (see paragraph 5.7.2.1).

            Finally,  the  last  type  of  package,  a grouping of units for configuration
            reasons,  should be used sparingly since it gives no additional information to
            a  human  reader on the structure of the program.  This type of package might,
            for  example,  be  used  to  divide  a  large  program  at  the top level into
            subsystems  to  be developed by separate teams.  It would be best, however, if
            these subsystem packages fulfilled, in addition, one of the other two roles.

                 b.   Packages should NOT be designed based on the procedural structure of
            the code which calls them.

            For  example, a group of procedures should not be packaged simply because they
            are  all called at system initialization, or because they are always called in
            a certain sequence.  Such a package is closely coupled to the context in which
            it is used and is not very understandable, reusable or maintainable as a unit.

                 c.   A  logical  hierarchy of packages should be used to reflect or model
            levels of abstraction.

            5.7.1.1.  Nesting._______.

                 a.  Nested package bodies should be separate subunits.

                 b.   Subprogram  bodies  within  a  package  should generally be separate
            subunits (when this is possible).

                 c.   Packages  should  generally not be nested within subprograms, except
            within the main procedure.

            A  possible  exception to this recommendation is when a package has objects of
            variable size which can be allocated when a procedure is called.  For example,
            suppose  some  data processing uses a Buffer package which implements a buffer
            area of a user-specified size:

               procedure Process_Data
                 ( Buffer_Size : POSITIVE ) is
            
                 package body Buffer is
            
                   type BUFFER_TYPE is
                     array (INTEGER range <>) of DATUM;
            
                   Buffer_Area : BUFFER_TYPE (1 .. Buffer_Size);
            
                   ...
            
                 end Buffer;
            
 
            32                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               ...


            Note, however, that the nested package cannot be reused outside the context of
            the procedure.  An alternative would be to allocate the buffer using an access
            type.  This would require careful handling of allocation and deallocation, but
            would result in a more self-contained package.

                 d.    Nesting   of   a   package  specification  inside  another  package
            specification should generally be avoided.

            When  a  package  provides  a  good  abstraction,  it hides the details of its
            implementation.   Generally,  nesting one package specification inside another
            either  exposes  too  much  of  the  internal details of the outer package, or
            indicates  that  the  outer package does not provide a good abstraction in the
            first  place.   It  is usually better to nest the package specification within
            the  body  of the outer package.  Certain inner package operations can then be
            called  on  by  outer package operations which are at the appropriate level of
            abstraction for the outer package.

            5.7.2.  Initialization.______________.

                 Calls from the initialization section of a package to subprograms outside
            the package should be avoided.

            5.7.2.1.  Visible_______ variables._________.

                 a.  Variable declarations in package specifications should be minimized.

            The  use  of  variables  in  a  package  specification  generally  reduces the
            abstraction  and information hiding properties of the package.  For example, a
            variable  cannot  provide protection against being changed by units other than
            the package.  Therefore it is generally better to use a function rather than a
            variable  to  read  data from a package.  It is also generally better to use a
            procedure  rather  than a variable to give data to a package, since a variable
            cannot trigger any package operations and a variable declaration often exposes
            some internal data representation details of the package.

                 b.   The  private  part of a package specification should only be used to
            supply the full definitions of private types and deferred constants; all other
            declarations should be put in the package body.

                 c.   Objects  of  a  private  type  should  be initialized by default, if
            possible.

            5.7.3.  Formatting__________ of__ packages.________.

            5.7.3.1.   Package_______  names._____.   A package name should be a noun phrase describing
            the  abstract  entity  modeled  by  the  package,  or simply whatever is being
            packaged.

               Stack_Handler
               Vehicle_Controller
               Terminal_Operations
 
            SPECIFIC GUIDELINES                                                         33




                                            MIL-HDBK-1804
 
               Parser_Types
               Utilities_Package


            5.7.3.2.   Package_______ header.______.  Each package specification, body or stub should be
            preceded  by  a  header comment block containing at least the package name and
            the indication SPEC, BODY, STUB or SUBUNIT.

               -- **********************
               -- *                    *
               -- *  Lexical_Analyzer  *  SPEC
               -- *                    *
               -- **********************


            5.7.3.3.  Package_______ specifications.______________.

                 a.  Package specifications should have the following format:

               package  is
            
               --| 
            
                 
                 
            
               private  -- 
            
                 
                 
            
               end ;


            The   should follow guideline b., below.  Note that the
              should  always  be repeated at the "end" of the package
            specification.

                 b.   A  package  specification  should  include  AT  LEAST  the following
            documentation immediately after the package header:

               --| Purpose
               --| A description of the purpose and function of the package.
               --|
               --| Initialization Exceptions
               --| A list of all exceptions which may propagate out of the
               --| package INITIALIZATION PART and a description of when each
               --| would be raised.
               --|
               --| Notes
               --| Additional comments on the use of the package.


            The "Initialization Exceptions" and "Notes" headers should be included even if
 
            34                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            these  sections  are  empty.  An empty section may be indicated by placing the
            annotation  "(none)"  after  the  appropriate  header.   Only in the case of a
            package  specification  which  is  a  compilation  unit, the following section
            should be added to the documentation:

               --|
               --| Modifications
               --| A list of modifications made to the package SPECIFICATION.
               --| Each entry in the list should include the date of the change,
               --| the name of the person who made the change and a description
               --| of the modification.  The description should indicate exactly
               --| where in the compilation unit that the change was made.  The
               --| first entry in the list should always be the initial coding of
               --| the package specification.


                 c.   In  a  declarative  part,  all  package specifications should appear
            before any package or task bodies.

            5.7.3.4.  Package_______ bodies______ and___ stubs._____.

                 a.  Package bodies should have the following format:

               separate ()
               package body  is
            
               --| 
            
                 
                 
            
               begin  -- 
            
                 
                 
            
               exception
                 when  =>
                   
            
               end ;


            The   should follow guideline b., below.  Note that the
              should  always  be repeated at the "end" of the package
            body.

                 b.   A  package  body  should  have  at least the following documentation
            placed immediately after the package header:

               --| Notes
               --| Comments on the design, implementation and use of the
               --| package.

 
            SPECIFIC GUIDELINES                                                         35




                                            MIL-HDBK-1804
 

            The  "Notes" header should be included even if the section is empty.  An empty
            section  may be indicated by the comment "Notes (none)." Only in the case of a
            package  specification  which  is  a  compilation  unit, the following section
            should be added to the documentation:

               --|
               --| Modifications
               --| A list of modifications made to the package BODY.  Each
               --| entry in the list should include the date of the change,
               --| the name of the person who made the change and a
               --| description of the modification.  The description should
               --| indicate exactly where in the compilation unit that the
               --| change was made.  The first entry in the list should always
               --| be the initial coding of the package body.


                 c.  Package stubs should have the following format:

               package body  is separate;


            5.7.4.  Examples________ for___ packages.________.

                 See also example 5.12.4.3.

            5.7.4.1.  Example_______ 7X1.___.

               -- **********************
               -- *                    *
               -- *  Lexical_Analyzer  *  SPEC
               -- *                    *
               -- **********************
            
               with Basic_Types,
                    Parser_Types;
            
               package Lexical_Analyzer is
            
               --| Purpose
               --| The routines in this package read the source program, one
               --| character at a time, to generate a stream of tokens.  As each
               --| token is produced it is passed to the package "Parser."  The
               --| legal tokens are defined in the Language Reference Manual.
               --|
               --| Initialization Exceptions
               --| Diana_File_Non_Existent  -- Raised if the file "DIANA.ADA"
               --|                             does not exist
               --|
               --| Notes
               --| Tokens are limited to 32 characters in length.  Also, only
               --| sequential text files can be operated on by the parser.
               --|
               --| Modifications
 
            36                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               --| 6/14/85  Rebecca DeMornay  Initial version of spec
               --| 8/26/87  C. Royale         Added "Decode_Token" function.
            
                 Diana_File_Non_Existent
                   : exception;
            
                 Source_File_Not_Open
                   : exception;
            
                 Illegal_Token
                   : exception;
            
                 -- .......................
                 -- .                     .
                 -- .  Obtain_Next_Token  .  SPEC
                 -- .                     .
                 -- .......................
            
                 procedure Obtain_Next_Token
            
                   (
                     ...
                          );
            
                 ...
            
                 -- ..................
                 -- .                .
                 -- .  Decode_Token  .  SPEC
                 -- .                .
                 -- ..................
            
                 function Decode_Token
            
                   (
                     ...
                          )
            
                   return Parser_Types.TOKEN_VALUE_TYPE;
            
                 ...
            
               end Lexical_Analyzer;


            5.7.4.2.  Example_______ 7X2.___.

               -- **********************
               -- *                    *
               -- *  Lexical_Analyzer  *  BODY
               -- *                    *
               -- **********************
            
               with Text_IO,
 
            SPECIFIC GUIDELINES                                                         37




                                            MIL-HDBK-1804
 
                    File_Handler;
            
               package body Lexical_Analyzer is
            
               --| Notes
               --| The package "Lexical_Analyzer" will later be changed to a task,
               --| so that the "Parser" task (now a package) can make an entry
               --| call to "Lexical_Analyzer" when it needs the next token.
               --|
               --| Modifications
               --| 6/14/85  Charity Royale    Initial version of body.
               --| 8/26/85  Charity Royale    Added "Decode_Token" function.
               --|                            Added instantiation of "Enumeration_IO."
            
                 -- *************
                 -- *           *
                 -- *  Char_IO  *  SPEC
                 -- *           *
                 -- *************
            
                 package Char_IO is
                   next Text_IO.Enumeration_IO (Enum => Character);
            
                 --| Purpose
                 --| Used to read the input text file character by character.
                 --|
                 --| Initialization Exceptions (none)
                 --| Notes (none)
            
                 -- .......................
                 -- .                     .
                 -- .  Obtain_Next_Token  .  STUB
                 -- .                     .
                 -- .......................
            
                 procedure Obtain_Next_Token
            
                   (
                     ...
                          ) is separate;
            
                 -- ..................
                 -- .                .
                 -- .  Decode_Token  .  STUB
                 -- .                .
                 -- ..................
            
                 function Decode_Token
            
                   (
                     ...
                          )
            
                   return Parser_Types.TOKEN_VALUE_TYPE is separate;
 
            38                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            
                 ...
            
               begin  -- Lexical_Analyzer
            
                 ...
            
               exception
            
                 when File_Handler.File_Error =>
                   raise Diana_File_Non_Existent;
            
               end Lexical_Analyzer;


            5.7.4.3.  Example_______ 7X3.___.

               -- **********
               -- *        *
               -- *  Disk  *  SPEC
               -- *        *
               -- **********
            
               generic
            
                 type SPECIFIC_DATA_TYPE is  -- The type of data to be
                   ( <> );                   -- stored on disk
            
               package Disk is
            
               --| Purpose
               --| This package defines an abstract data type to simplify
               --| the I/O interface to disk files.
               --|
               --| Initialization Exceptions (none)
               --| Notes (none)
               --| Modifications
               --| 9/10/86  Ada Users Group   Initial version
            
                 type FILE_TYPE is
                   private;
            
                 End_Of_File
                   : exception;
            
                 Open_Error
                   : exception;
            
                 Mode_Error
                   : exception;
            
                 subtype FILE_MODE is
                   (IN_FILE, OUT_FILE);
            
 
            SPECIFIC GUIDELINES                                                         39




                                            MIL-HDBK-1804
 
                 -- ............
                 -- .          .
                 -- .  Create  . SPEC
                 -- .          .
                 -- ............
            
                 function Create
            
                   ( Name
                       : STRING;
            
                     Mode
                       : FILE_MODE := IN_FILE )
            
                   return FILE_TYPE;
            
                 --| Purpose
                 --| This function creates a FILE_TYPE data object to
                 --| represent the disk file with the given name and mode.
                 --|
                 --| Exceptions (none)
                 --| Notes
                 --| This function does not actually open the file.
            
                 -- ............
                 -- .          .
                 -- .  Close   . SPEC
                 -- .          .
                 -- ............
            
                 procedure Close
            
                   ( Disk_File
                       : in out FILE_TYPE );
            
                 --| Purpose
                 --| This procedure closes a disk file if it is open.  If
                 --| the file is already closed it has no effect.
                 --|
                 --| Exceptions (none)
                 --| Notes (none)
            
                 -- ............
                 -- .          .
                 -- .  Read    . SPEC
                 -- .          .
                 -- ............
            
                 procedure Read
            
                   ( Disk_File
                       : in out FILE_TYPE;
            
                     Data
 
            40                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                       : out SPECIFIC_DATA_TYPE );
            
                 --| Purpose
                 --| This procedure reads the next record from a file,
                 --| opening the file if necessary.
                 --|
                 --| Exceptions
                 --| End_Of_File - raised if no more elements can be
                 --|               read from the file
                 --| Open_Error  - if the file cannot be opened
                 --| Mode_Error  - if the file mode if not IN_FILE
                 --|
                 --| Notes (none)
            
                 -- ............
                 -- .          .
                 -- .  Write   . SPEC
                 -- .          .
                 -- ............
            
                 procedure Write
            
                   ( Disk_File
                       : in out FILE_TYPE;
            
                     Data
                       : in SPECIFIC_DATA_TYPE );
            
                 --| Purpose
                 --| This function writes a record to a file,
                 --| opening the file if necessary.
                 --|
                 --| Exceptions
                 --| Open_Error  - if the file cannot be opened
                 --| Mode_Error  - if the file mode if not OUT_FILE
                 --|
                 --| Notes (none)
            
                 private  -- Disk
            
                   -- *************
                   -- *           *
                   -- *  Disk_IO  *  SPEC
                   -- *           *
                   -- *************
            
                   package DiskIO is
                     new Sequential_IO (SPECIFIC_DATA_TYPE);
            
                   --| Purpose
                   --| This package provides the basis for the representation
                   --| of disk files.
                   --|
                   --| Initialization Exceptions (none)
 
            SPECIFIC GUIDELINES                                                         41




                                            MIL-HDBK-1804
 
                   --| Notes (none)
            
                     File_Name_Length
                       : constant := 40;
            
                     type FILE_TYPE is
                       record
                         File_Name
                           : STRING(1..File_Name_Length) := (others => ' ');
                         File
                           : Disk_IO.FILE_TYPE;
                         Mode
                           : FILE_MODE := Disk_IO.IN_FILE;
                       end record;
            
                 end Disk;




            5.8.  Visibility__________

            5.8.1.  Scope_____ of__ identifiers.___________.

                 The scope of identifiers should not extend further than necessary.  Where
            a  scope  is extended by "with" clauses, these clauses should cover as small a
            region of text as possible.

            For  example, "with" clauses should be placed only on the subunits that really
            need them, not on their parents.  This promotes information hiding and reduces
            coupling.   It  can also result in faster recompilation (due to the dependency
            rules).

            5.8.1.1.   The___ package_______ STANDARD________ and___ WITH____ clauses._______.  The package STANDARD should
            not be named in a "with" clause.

            5.8.2.  The___ use___ clause.______.

                 The "use" clause should be used only in the following cases:

                 a.   For  packages of commonly known utility operations used throughout a
            program (e.g., MATHLIB).

                 b.   To  make  overloaded  operators visible, so that they may be used in
            infix notation.

                 c.   For  predefined input/output packages (e.g., Text_IO, instantiations
            of Integer_IO, etc.).

                 d.   To  make  enumeration  constants  visible  so that they can be named
            without using the dot notation.

            Note  that  even when a "use" clause is used, the dot notation should still be
            used in cases other than those listed above.
 
            42                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.8.2.1.  Renaming________ declarations.____________.

                 a.   For a name with a large number of package qualifications, a renaming
            declaration  may  be  used  to  define a new shorter name.  The new identifier
            should still reflect the complete meaning of the full name.

                 b.   For a function which can be appropriately represented by an operator
            symbol name, a renaming declaration may be used to give it such a name.

            For example, a Matrix_Multiply function could be renamed "*".

            5.8.2.2.  Redefinition.____________.

                 a.  Items from the package STANDARD should not be redefined or renamed.

                 b.   Redefinition  of  an  identifier in different declarations should be
            avoided.



            5.9.  Tasks_____

            5.9.1.  Use___ of__ tasks._____.

                 A task should fulfill one or more of the following:

                 a.  Model a concurrent abstract entity appropriate to the problem domain.

                 b.   Serve  as an access-controlling or synchronizing agent for the other
            tasks, or otherwise act as an interface between asynchronous tasks.

                 c.   Serve  as  an  interface  to  asynchronous  entities external to the
            program (e.g., asynchronous I/O, devices, interrupts, etc.).

                 d.   Define  concurrent algorithms for faster execution on multiprocessor
            architectures.

                 e.   Perform an activity which must wait a specified time for an event or
            have a specific priority.

            Just  as  for packages (paragraph 5.7.1), it is best to have tasks which model
            problem  domain entities.  However, in the case of tasks, it is also necessary
            to  have  some  tasks  which solely provide interfaces between other tasks and
            which  handle the other issues of concurrency and parallelism mentioned above.
            The  program  should  generally be structured, however, around the tasks which
            represent problem-domain entities.

            5.9.1.1.  Nesting_______ of__ tasks._____.

                 a.   Tasks  should  generally  not be nested within tasks or subprograms,
            except for the main procedure.

            Note  that  a  subprogram  containing  a task cannot return until the task has
            terminated.
 
            SPECIFIC GUIDELINES                                                         43




                                            MIL-HDBK-1804
 
                 b.  Nested task bodies should be separate subunits, unless they are quite
            small.

            5.9.1.2.  Visibility__________ of__ tasks._____.

                 a.   When  only  certain  entries  of a task are intended to be called by
            program components outside an enclosing package, it is generally preferable to
            hide   the  task  specification  in  the  package  body,  introducing  package
            procedures which in turn call the actual entries.

                 b.   This  helps  to  promote  information  hiding  and  strengthens  the
            abstraction of the enclosing package (see paragraph 5.7.1.1.d).  It also hides
            the  use of tasking within the package.  Note, however, that special care must
            be taken if the task entries are to be called using conditional or timed entry
            calls.  In this case, either the outer package must provide special procedures
            or procedure parameters or this guideline should not be followed.

            5.9.2.  Task____ types._____.

                 a.   A task type should be used only when multiple instances of that type
            are required.  Otherwise, a directly named task should be used.

                 b.  Identical tasks should be derived from a common task type.

                 c.   Static  task structures should be used whenever they are sufficient.
            Access  types  to task type should be used only when it is essential to create
            and  destroy  tasks  dynamically, or to be able to change the names with which
            they are associated.

            5.9.2.1.  Task____ termination.___________.

                 a.   A task nested within the main program must terminate by reaching its
            "end," or must have a selective wait with a terminate alternative.

            All  tasks  nested  within  a  program  must  terminate before the program can
            terminate.   Therefore,  if  this  guideline  is  not  followed,  it  will  be
            impossible  for  the main program to ever terminate other than by aborting all
            nested  tasks.   However,  "abort" statements are to be avoided (see paragraph
            5.9.2.6).

                 b.   Tasks  dependent  on  library  units  should not use the "terminate"
            alternative of a select statement.  Therefore, other provisions should be made
            for the graceful termination of such tasks at system close down.

            Tasks  which  are  dependent  on  library  units  will  not terminate due to a
            "terminate"  alternative.  Therefore, a library unit task should have an entry
            which  forces  termination.   If it does not, an "abort" statement in the main
            program may be used to terminate the task.  However, "abort" statements are to
            be avoided (see paragraph 5.9.2.6).





 
            44                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.9.2.2.  Entries_______ and___ accept______ statements.__________.

                 a.  Only those actions should be included in the "accept" statement which
            must be completed before the calling task is released from its waiting state.

                 b.   A task should never call its own entries, even by indirection.  This
            would result in a deadlock.

                 c.  Conditional entry calls should be used sparingly to avoid unnecessary
            busy waiting.

            5.9.2.3.  Delay_____ statement._________.

                 a.  A "delay" statement should be used whenever a task must wait for some
            known duration.  A "busy wait" loop should never be used for this purpose.

            It  is  important  to  remember  that "delay t" provides a delay of at least t
            seconds,  but possibly more.  A program should not rely on any upper bound for
            this  delay,  especially when tasks are used (since tasks must compete for CPU
            time).   The  following  example  shows  how  to  alleviate  this problem in a
            periodic activity:

               ...
               Next_Time := Calendar.Clock + Required_Period;
            
               Periodic_Activity:
               while Still_Time loop
            
                 -- Perform activity
                 ...
            
                 -- Correct for delay statement incertitude
            
                 Period := Next_Time - Calendar.Clock;
            
                 if Period < 0.0 then           -- Processing was too slow
                   Next_Time := Calendar.Clock; -- Avoid cumulative effect
                 end if;
                 Next_Time := Next_Time + Required_Period;
            
                 delay Period;
            
               end loop Periodic_Activity;


                 b.   The  "delay"  statement  should  normally  only  be  used  to manage
            interaction  with some external process which works in real time, or to create
            a task which behaves in a well-defined manner in real time.






 
            SPECIFIC GUIDELINES                                                         45




                                            MIL-HDBK-1804
 
            5.9.2.4.   Task____  synchronization._______________.  Knowledge of the execution pattern of tasks
            (e.g., fixed, known time pattern, etc.) should not be used to avoid the use of
            explicit task synchronization.

            5.9.2.5.  Priorities.__________.

                 a.   Only a small number of priority levels should be used.  The priority
            levels used should be spread over the range made available to type PRIORITY in
            the implementation.  Names should be given to the priority levels by declaring
            constants  of  predefined type PRIORITY and grouping these declarations into a
            single package.

            Using  only  a  small  number  of priority levels makes the interaction of the
            various  prioritized tasks easier to understand.  On the other hand, spreading
            the  levels  across  the  available range allows easy insertion of a new level
            between  existing  levels  if  this  later  becomes  necessary.  As with other
            literal  numbers,  the  use  of  names  is  more  readable than the use of the
            literals.    Further,  for  priorities,  the  allowable  range  of  levels  is
            implementation  dependent.   Naming  priority  levels by constant declarations
            grouped  into a single package restricts the implementation dependency to that
            package.  For example:

               with System;
               package Priority_Levels is
            
                 Lowest
                   : constant System.PRIORITY := System.PRIORITY'first;
                 Highest
                   : constant System.PRIORITY := System.PRIORITY'last;
                 Number
                   : constant := Highest - Lowest + 1;
                 Average
                   : constant System.PRIORITY := Number / 2;
            
                 Idle
                   : constant System.PRIORITY := Lowest;
                 Background
                   : constant System.PRIORITY := Average - 20;
                 User
                   : constant System.PRIORITY := Average - 10;
                 Foreground
                   : constant System.PRIORITY := Average + 10;
            
               end Priority_Levels;


                 b.   For  any  group  of related tasks, such as those declared within the
            same  program unit, priorities should be specified either for all, or for none
            of them.

            This avoids confusion about the scheduling of tasks with undefined priorities.



 
            46                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.9.2.6.  Abort_____ statements.__________.  Abortion of tasks should generally be avoided.

            Aborting  a  task  can  produce  unpredictable results.  In particular, do not
            assume  anything about the moment at which an aborted task becomes terminated.
            The  "abort"  statement should generally be used only in case of unrecoverable
            failure.

            5.9.2.7.  Shared______ variables._________.

                 a.  Tasks should not directly share variables unless only one of them can
            possibly be running at any one time.

                 b.   Any  task  which  uses  shared  variables  should  identify  in  its
            documentary comments all the shared variables that it uses.

            5.9.2.8.  Local_____ exception_________ handling.________.  To allow the handling of local exceptions
            without  task termination, a task should generally have a block statement with
            an exception handler coded within its main loop.

               begin -- Some_Task
            
                 Main_Loop:
                 loop
            
                   Local:
                   begin
            
                     -- Task code
                     ...
            
                   exception -- Local
                     ... handle local exceptions ...
            
                   end Local;
            
                 end Main_Loop;
            
               exception
                 ... handle fatal exceptions ...
            
               end Some_Task;


            5.9.3.  Formatting__________ of__ tasks._____.

            5.9.3.1.  Task____ and___ entry_____ names._____.

                 a.   A  task name should be a noun phrase describing the task function or
            abstract entity modeled by the task.

               Sensor_Interface
               Status_Monitor
               Event_Handler
               Message_Buffer
 
            SPECIFIC GUIDELINES                                                         47




                                            MIL-HDBK-1804
 

                 b.   Entry names should follow the same guidelines as for procedure names
            (see paragraph 5.6.3.1).

            5.9.3.2.   Task____  and___  entry_____  headers._______.  Each task or task type specification or
            body and each entry specification should be preceded by a header comment block
            containing at least the unit name and the indication SPEC, BODY or STUB.

               -- ************
               -- *          *
               -- *  Buffer  *  SPEC
               -- *          *
               -- ************
               task Buffer is
            
                 -- ..........
                 -- .        .
                 -- .  Read  .  SPEC
                 -- .        .
                 -- ..........
                 entry Read;
            
               end Buffer;


            5.9.3.3.  Task____ specifications.______________.

                 a.  Task specifications should have the following format:

               task  is
            
               --| 
            
                 
                 
            
               end ;


            The    should  be  AT LEAST as required for a procedure
            declaration  (see  paragraph  5.6.3.3),  except  for the "Exceptions" section.
            Note  that the  should always be repeated at the "end" of the
            task specification.

                 b.   A  task  type  specification  should be formatted the same as a task
            specification, with the exception of including "task type" in the header.

                 c.  Entry declarations should have the following format:

               entry  ()
                 ( ;
                    );
            
               --| 
 
            48                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 

            Each   should be formatted like an object declaration
            (see  paragraph  5.3.8.4).   The   should be AT LEAST as
            required for a procedure declaration (see paragraph 5.6.3.3).

                 d.    Parameter   mode   indications  should  always  be  used  in  entry
            declarations.

                 e.   In  a declarative part, all task specifications should appear before
            any task or package bodies.

            5.9.3.4.  Task____ bodies______ and___ stubs._____.

                 a.  Task bodies should have the following format:

               separate ()
               task body  is
            
               --| 
            
                 
                 
            
               begin -- 
            
                 
                 
            
               exception
                 when  =>
                   
            
               end ;


                 b.   The    should  be  AT LEAST as required for a
            procedure  body  (see  paragraph  5.6.3.4).   Note  that the 
            should always be repeated at the "end" of the task body.

                 c.  Task stubs should have the following format:

               task body  is separate;


            5.9.3.5.  Accept______ statements.__________.

                 a.  "Accept" statements should have one of the following formats:

               accept  ();
            
               accept  ()
                 ( ;
                    )
               do
 
            SPECIFIC GUIDELINES                                                         49




                                            MIL-HDBK-1804
 
                 
                 
               end ;


            Each   should be formatted like an object declaration
            (see  paragraph  5.3.8.4).   Note that the  should always be
            repeated at the "end" of the "accept" (if there is an "end").

                 b.    Parameter   mode  indications  should  always  be  used  in  accept
            statements.

            5.9.3.6.  Select______ statements.__________.

                 a.  Selective wait statements should have the following format:

               select
                 
                 
               or
                 
                 
               or
                 when  =>
                   
                   
               end select;


            This  format is consistent with the indentation style of other statements.  In
            addition,  the  added  level  of  indentation  especially  highlights  guarded
            sections of code.

                 b.  Conditional and timed entry calls should have the following formats:

               select
                 
                 
               else
                 
                 
               end select;


            5.9.3.7.   Pragma______  priority.________.   The  priority  pragma  should  appear  in  task
            specifications  before  any entry declarations, and in the main program before
            any declarations.

            5.9.4.  Examples________ for___ tasks._____.





 
            50                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.9.4.1.  Example_______ 9X1.___.

               -- ************
               -- *          *
               -- *  Buffer  *  SPEC
               -- *          *
               -- ************
               task Buffer is
            
               --| Purpose
               --| This task provides a character buffer to smooth variations
               --| between the speed of output of a producing task and the speed
               --| of input of a consuming task.
               --|
               --| Exceptions (none)
               --| Notes (none)
            
                 -- ..........
                 -- .        .
                 -- .  Read  .  SPEC
                 -- .        .
                 -- ..........
            
                 entry Read
                   ( Output : out Character );
            
                 --| Purpose
                 --| This entry reads a character from the buffer.
                 --| If the buffer is empty, the entry will wait
                 --| until a character is written into the buffer.
                 --|
                 --| Exceptions (none)
                 --| Notes (none)
            
                 -- ...........
                 -- .         .
                 -- .  Write  .  SPEC
                 -- .         .
                 -- ...........
            
                 entry Write
                   ( Input : in Character );
            
                 --| Purpose
                 --| This entry writes a character into the buffer.
                 --| If the buffer is full the entry will wait
                 --| until a character is read from the buffer.
                 --|
                 --| Exceptions (none)
                 --| Notes (none)
            
               end Buffer;


 
            SPECIFIC GUIDELINES                                                         51




                                            MIL-HDBK-1804
 
            5.9.4.2.  Example_______ 9X2.___.

               -- ************
               -- *          *
               -- *  Buffer  *  BODY
               -- *          *
               -- ************
            
               separate (Buffer_Package)
               task body Buffer is
            
               --| Notes
               --| This task contains an internal pool of characters processed
               --| in a round-robin fashion.
               --|
               --| Modifications
               --| 7/2/86  Fred Blah    Initial version.
            
                 Pool_Size
                   : constant := 100;
            
                 subtype POOL_RANGE is
                   INTEGER range 1..Pool_Size;
            
                 type POOL_TYPE is
                   array (POOL_RANGE) of CHARACTER;
            
                 Pool
                   : POOL_TYPE;
            
                 Count                          -- The number of characters in
                   : INTEGER range 0..Pool_Size -- the pool.
                     := 0;
            
                 In_Index                       -- The space for the next input
                   : POOL_RANGE := 1;           -- character.
            
                 Out_Index                      -- The space for the next output
                   : POOL_RANGE := 1;           -- character.
            
               begin -- Buffer
            
                 loop
                   select
                     when Count < Pool_Size =>
                       accept Write
                         ( Input : in Character )
                       do
                         Pool(In_Index) := Input;
                       end Write;
            
                       In_Index := In_Index mod Pool_Size + 1;
                       Count := Count + 1;
                   or
 
            52                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                     when Count > 0 =>
                       accept Read
                         ( Output : out Character )
                       do
                         Output := Pool(Out_Index);
                       end Read;
            
                       Out_Index := Out_Index mod Pool_Size + 1;
                       Count := Count - 1;
                   or
                     terminate;
            
                   end select;
            
                 end loop;
            
               end Buffer;


            5.9.4.3.  Example_______ 9X3.___.

               -- ...............
               -- .             .
               -- .  Shellsort  .  BODY
               -- .             .
               -- ...............
            
               procedure Shellsort
                 ( List                  -- This list will be sorted
                     : in out ITEM_LIST; -- in place.
                   Number_Of_Items
                     : in NATURAL );
            
               --| Notes
               --| This sorting procedure implements the Shell sort by
               --| separating the n-sorts into multiple Ada tasks.
               --| This algorithm is designed for parallel processing
               --| of the tasks and is not necessarily an efficient
               --| method on a single processor.
               --|
               --| Modifications
               --| 9/5/86  A. Shell    Initial version
               --|
            
                 Increment                -- Increment of an n-sort
                   : NATURAL;
            
                 Number_Of_Sorts          -- Number of paralleled sorts
                   : NATURAL;             -- for a single pass
            
                 Number_Of_Tasks
                   : NATURAL;
            
                 -- *****************
 
            SPECIFIC GUIDELINES                                                         53




                                            MIL-HDBK-1804
 
                 -- *               *
                 -- *  SORTER_TASK  *  SPEC
                 -- *               *
                 -- *****************
            
                 task type SORTER_TASK is
            
                 --| Purpose
                 --| Tasks of this type perform the n-sort for the Shell sort.
                 --|
                 --| Notes
                 --| A SORTER_TASK terminates itself when it is no longer
                 --| needed for the sort.
            
                   -- ..........
                   -- .        .
                   -- .  Sort  .  SPEC
                   -- .        .
                   -- ..........
            
                   entry Sort
                     ( First : in INTEGER;
                       Step  : in NATURAL );
            
                   --| Purpose
                   --| This entry signals a sorter task to perform a new
                   --| n-sort.  Elements are sorted in place in List,
                   --| starting with the element at index First and
                   --| including subsequent elements at the indicated Step.
                   --|
                   --| Exceptions (none)
                   --| Notes (none)
            
                 end SORTER_TASK;
            
                 -- *****************
                 -- *               *
                 -- *  SORTER_TASK  *  STUB
                 -- *               *
                 -- *****************
            
                 task body SORTER_TASK is separate;
            
                 type SORTER_ARRAY is
                   array (INTEGER range <>) of SORTER_TASK;
            
               begin -- Shellsort
            
                 if Number_Of_Items < 2 then
                   return;
                 end if;
            
                 -- Determine the first n-sort increment
            
 
            54                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 Increment := 1;
            
                 while Increment < Number_Of_Items
                   Increment := 3*Increment + 1;
                 end loop;
            
                 Increment := Increment / 3;
                 if Increment < 1 then
                   Increment := 1;
                 end if;
            
                 -- Determine the number of tasks required to perform
                 -- the sort.
            
                 if Number_Of_Items / Increment = 1 then
                   Number_Of_Sorts := Number_Of_Items mode Increment;
                   if Increment/3 > Number_Of_Sorts then
                     Number_Of_Tasks := Increment / 3;
                   else
                     Number_Of_Tasks := Number_Of_Sorts;
                   end if;
            
                 else
                   Number_Of_Sorts := Increment;
                   Number_Of_Tasks := Number_Of_Sorts;
            
                 end if;
            
                 -- Perform the sort
            
                 Task_Block:
                 declare
            
                   Sort_List
                     : SORTER_ARRAY (1 .. Number_Of_Tasks);
            
                 begin
            
                   while Increment > 0 loop
            
                     for K in 1 .. Number_Of_Sorts loop
            
                       Sort_List(K).Sort
                         ( First => List'first + K - 1,
                           Step  => Increment );
            
                     end loop;
            
                     Increment := Increment / 3;
                     Number_Of_Sorts := Increment;
            
                   end loop;
            
                 end Task_Block;
 
            SPECIFIC GUIDELINES                                                         55




                                            MIL-HDBK-1804
 
            
               end Shellsort;


            5.9.4.4.  Example_______ 9X4.___.

               -- *****************
               -- *               *
               -- *  SORTER_TASK  *  SUBUNIT
               -- *               *
               -- *****************
            
               separate (Shellsort)
               task body SORTER_TASK is
            
               --| Notes
               --| This task body implements a task type.
               --|
               --| Modifications
               --| 9/5/86  A. Shell    Initial version
            
               -- Global variables
               -- List                -- An array of all items to be
               --                        sorted by Shellsort.
               -- Number_Of_Items     -- The number of items in the list.
            
                 Start     : INTEGER;
                 Increment : NATURAL;
            
                 A         : INTEGER;
                 B         : INTEGER;
                 First_B   : INTEGER;
            
                 Temp      : INTEGER;
            
               begin -- SORTER_TASK
            
                 loop
            
                   accept Sort
                     ( First : in INTEGER;
                       Step  : in NATURAL )
                   do
                     Start := First;
                     Increment := Step;
                   end Sort;
            
                   First_B := Start + Increment;
                   while First_B <= List'first + Number_Of_Items - 1 loop
            
                     B := First_B;
                     A := B - Increment;
            
                     Find_Position:
 
            56                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                     while A >= Start loop
                       exit when not (List(A) > List(B));
            
                       Temp := List(A);
                       List(A) := List(B);
                       List(B) := Temp;
            
                       B := A;
                       A := B - Increment;
            
                     end loop Find_Position;
            
                     First_B := First_B + Increment;
            
                   end loop;
            
                   -- Terminate if task is not needed for n-sort
                   exit when Increment/3 < Start - List'first + 1;
            
                 end loop;
            
               end SORTER_TASK;




            5.10.  Program_______ structure_________ and___ compilation___________ issues______

            5.10.1.  Program_______ units._____.

                 a.  Library units should be used in the following cases:

                  (1)  To  allow  configuration  control  of  the  high  level  functional
            subsystems of a program.

                  (2) For general purposes, reusable program units.

                 b.  Nested program units should be used in the following cases:

                  (1) To allow direct access to objects declared in an enclosing scope.

                  (2)  To  increase  the  structural hiding of the internal implementation
            details of an enclosing program unit.

                 c.   Bodies  of  nested program units should be made separate unless they
            are small enough to effect the readability of the enclosing unit.

                 d.   Library  units  which  are  packages  are  generally preferable over
            library  units which are subprograms.  Library units providing services to the
            main program should be packages.




 
            SPECIFIC GUIDELINES                                                         57




                                            MIL-HDBK-1804
 
            5.10.1.1.  WITH____ clauses._______.

                 a.   No  unit  should have a "with" clause for a unit it does not need to
            see directly.

                 b.   If only a small part of a given unit needs access to a library unit,
            then  it  should  generally appear as a subunit and have its own "with" clause
            for that library unit (see paragraph 5.8.1).

            5.10.1.2.  Program_______ unit____ dependencies.____________.

                 a.   Excessive  dependencies between compilation units should be avoided,
            especially the use of complicated networks of "with" clauses.

                 b.   It  is  preferable  to  limit  program  unit  dependencies to a tree
            structure whenever possible.

            5.10.2.  Compilation___________ units._____.

                 Each  compilation  unit  should be in a separate file, except possibly in
            the case of a generic procedure specification and its body.



            5.11.  Exceptions__________

            5.11.1.  Exception_________ propagation.___________.

                 a.   Exceptions propagated by a program unit should be considered part of
            the  abstraction  or  function represented by that unit.  Therefore, it should
            generally  only  propagate  exceptions  which are appropriate to that level of
            abstraction.   If necessary, an exception which cannot be handled by a unit at
            one  level  of  abstraction should be converted into an exception which can be
            explicitly recognized by the next higher level.

            For  example, a Stack package should provide a Stack_Full exception instead of
            propagating  a  Constraint_Error.  Similarly, a Matrix_Inverse function should
            raise a Matrix_Is_Singular exception rather than propagating Numeric_Error.

                 b.   Exceptions  should  not  be  allowed  to propagate outside their own
            scope.   An exception may be allowed to propagate to any point where it can be
            named  in  an  exception  handler.   Note that this includes the case where an
            exception  is  defined in a package specification and has its scope "expanded"
            by a "with" clause.  What must be avoided are cases such as the following:

               ...
                 procedure Raise_Exception is
                   Hidden_Exception : exception;
                 begin -- Raise_Exception
                   raise Hidden_Exception;
                 end Raise_Exception;
            
               begin
                 Raise_Exception;
 
            58                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 -- "Hidden_Exception" CANNOT be seen at this point
                 ...


            5.11.2.  Use___ of__ exceptions.__________.

                 a.   An  exception  should  be used only for one or more of the following
            reasons:

                  (1)  It reports an irregular event which is outside the normal operation
            of a program unit or is in some sense an error.

                  (2)  It is used where it can be argued that it is safer (more defensive)
            than  the  alternative,  in  particular  to  guard  against omissions of error
            checking code for especially harmful errors.

                  (3)  It  reports  an  event for which it is inconvenient or unnatural to
            test  at  the point of cause/occurrence and thus use of the exception enhances
            readability.

            Exceptions   declared  in  package  specifications  are  really  part  of  the
            abstraction  defined by that package.  Therefore, their use should be integral
            to the design of the package (see paragraph 5.10.1).

            Also,  note  that  the predefined exceptions should be used with care.  Due to
            allowable  implementation  differences,  they  should  not  be  relied upon to
            indicate particular circumstances.

                 b.   Exceptions  should  not be used as a means of returning normal state
            information.

            For  example,  a  Stack package may have Stack_Full and Stack_Empty exceptions
            which  are raised by its Push and Pop subprograms.  However, these subprograms
            should  not  be  used  solely  to  raise exceptions to test if the appropriate
            conditions  are  true.   Instead, the package should provide BOOLEAN functions
            such as Full and Empty to test for these state conditions.

            5.11.2.1.  Exception_________ handlers.________.

                 a.   The  exception  handler choice "others" should be used only if it is
            necessary  to  ensure  that no UNANTICIPATED exception can be propagated or if
            some special action must be taken before propagation.

            For  example,  important  tasks  should generally have an "others" clause in a
            local   exception  handler  (see  paragraph  5.9.2.8)  to  prevent  them  from
            terminating due to unanticipated exceptions.  However, in the case when it can
            be  expected that a certain exception may sometimes occur, then that exception
            should always be explicitly named in the exception handler.

                 b.  Recursion should not be used within an exception handler.

                 c.  Exception handlers on block statements should be used sparingly.

            One  of  the  advantages  of  using  exceptions is that it separates the error
 
            SPECIFIC GUIDELINES                                                         59




                                            MIL-HDBK-1804
 
            handling  code from the more often executed normal processing code.  Excessive
            use of exception handlers in block statements can defeat this advantage.

            5.11.2.2.  Raise_____ statements.__________.

                 a.    Exceptions  declared  in  the  specification  of  a  package  which
            represents a problem domain entity should not be raised outside that package.

            Exceptions  declared  in  a package specification should be considered part of
            the  abstraction  defined  by  the  package.  These exceptions provide special
            "signals"  from  the package operations, and should thus not be raised outside
            of the package.

                 b.   Exceptions  raised within a task should always be handled within the
            task.

            Note  that  in  the  case  of  an  exception  raised  during a rendezvous, the
            exception will also be propagated back to the point of the entry call.

                 c.  The predefined exceptions should generally not be explicitly raised.

            5.11.2.3.   Suppressing___________  checks.______.   Checks  should not be suppressed except for
            essential efficiency or timing reasons in thoroughly tested program units.

            5.11.3.  Exception_________ declarations.____________.

                 Exception  declarations  should  be  formatted  like object declarations,
            paragraph 5.3.8.4.

            5.11.4.  Examples________ for___ exceptions.__________.

                 See examples 5.5.3.4, 5.6.4.5, 5.7.4.2, and 5.14.3.2.



            5.12.  Generic_______ units_____

            5.12.1.  Use___ of__ generic_______ units._____.

                 a.  Generics should not be used in situations in which normal programming
            constructs are equivalent.

                 b.  A generic program unit should fulfill one or more of the following:

                  (1)  Provide  logically  equivalent  operations  on objects of different
            type.

                  (2) Parameterize a program unit by a subprogram value.

                  (3)  Provide  a  data  abstraction required at many points in a program,
            even if no parameterization is required.

                  (4) Provide parameters which are particularly appropriate to be fixed at
            declaration or elaboration time.
 
            60                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.12.1.1.   Generic_______  library_______ units._____.  Generic units should generally be library
            units.

            5.12.1.2.  Generic_______ instantiation._____________.

                 a.   The  most  commonly  used generic instantiations should generally be
            placed in library units.

                 b.   Generic  instantiations  should  be  used  cautiously within generic
            units.

            5.12.2.  Generic_______ formal______ subprograms.___________.

                 a.    The  actual  subprograms  associated  with  the  formal  subprogram
            parameters of a generic unit should be consistent with the conceptual meanings
            of  the formal parameters (e.g., only functions which are conceptually "adding
            operations" should be associated with a formal parameter named "plus").

                 b.   Operator  symbol  function  generic  parameters  should generally be
            provided with a box default body ("is <>").

               with function "<"
                 ( X : ITEM;
                   Y : ITEM )
                 return BOOLEAN is <>;


            5.12.2.1.  Use___ of__ attributes.__________.

                 In  writing generic bodies, attributes should be used as much as possible
            to generalize the code produced.

            5.12.3.  Formatting__________ of__ generic_______ units._____.

            5.12.3.1.  Generic_______ declarations.____________.

                 a.  Generic declarations should have the following format:

               generic
                 
                 
               ;
            
               --| 


            Each    should  be formatted like its non-formal counterpart (see
            paragraphs 5.3.8.3 and 5.3.8.4), except for formal subprograms which should be
            formatted  as in paragraph b., below.  The  should
            be formatted as for non-generic units (see paragraphs 5.6.3.3 and 5.7.3.3).

                 b.   A generic formal parameter subprogram declaration should have one of
            the following formats:

 
            SPECIFIC GUIDELINES                                                         61




                                            MIL-HDBK-1804
 
               with ;
               --| 
            
               with  is <>;
               --| 
            
               with  is ;
               --| 


            The    should  be  formatted  as  for  a subprogram
            declaration   (see   paragraph   5.6.3.3).    Note,  however,  that  the  only
            documentation generally needed on formal subprograms is the "Purpose."

                 c.   A  generic  declaration  should  be preceded by the appropriate unit
            header block (see paragraphs 5.6.3.2 and 5.7.3.2).

            5.12.3.2.  Formatting__________ of__ generic_______ instantiations.______________.

                 a.  Generic instantiations should have one of the following formats:

                is
                 new  (, );
            
               --| 
            
            
                is
                 new 
                   (  => ,
                      =>  );
            
               --| 


            Note  that  in  the second form the arrows ("=>") should be kept aligned.  The
               should   be  the  same  as  those  required  for  a
            specification  of  the  appropriate  kind  of  unit  (paragraphs  5.6.3.3  and
            5.7.3.3).

                 b.   Generic  instantiations  should have the same kind of header comment
            block  as  for a specification of the appropriate kind of unit (see paragraphs
            5.6.3.2 and 5.7.3.2).

            5.12.4.  Examples________ of__ generic_______ units._____.

                 See also example 5.7.4.2 and 5.7.4.3.

            5.12.4.1.  Example_______ 12X1.____.

               -- ...............
               -- .             .
               -- .  Shellsort  .  SPEC
               -- .             .
 
            62                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
               -- ...............
            
               generic
            
                 type ITEM is
                   private;                 -- The type of items sorted
            
                 type ITEM_LIST is          -- The type of the item list
                   array (INTEGER range <>) of ITEM;
            
                 with function "<"
                   ( Left  : ITEM;
                     Right : ITEM )
                   return BOOLEAN is <>;
            
                 --| Purpose
                 --| This function defines the ordering used when the
                 --| items are sorted.
            
               procedure Shellsort
            
                 ( List                    -- This list will be sorted
                     : in out LIST_TYPE;   -- in place.
            
                   N                       -- The number of items in
                     : in NATURAL );       -- the list.
            
                 --| Purpose
                 --| This procedure sorts the items in List using a Shell
                 --| sort algorithm designed for parallel processing.
                 --|
                 --| Exceptions (none)
                 --| Notes
                 --| (This is a generic declaration for the procedure
                 --| body given in example 9X3.)
                 --|
                 --| Modifications
                 --| 9/5/86  A. Shell    Initial version


            5.12.4.2.  Example_______ 12X2.____.

               -- ...............
               -- .             .
               -- .  Name_Sort  .  SPEC
               -- .             .
               -- ...............
            
               procedure Name_Sort is
                 new Shellsort
                   ( ITEM      => NAME,
                     LIST_TYPE => NAME_LIST );


 
            SPECIFIC GUIDELINES                                                         63




                                            MIL-HDBK-1804
 
            5.12.4.3.  Example_______ 12X3.____.

               -- *********************
               -- *                   *
               -- *  Unit_Statistics  *  SPEC
               -- *                   *
               -- *********************
            
               with Text_IO;
               generic
            
                 Unit_Name             -- Name of the unit for which
                   : STRING;           -- statistics are to be kept.
            
                 type ELEMENT_TYPE is  -- Enumeration type of the elements
                   (<>);               -- to be counted.
            
               package Unit_Statistics is
            
               --| Purpose
               --| This package provides operations to keep counts for the
               --| various elements of a program unit.  These counts can be
               --| incremented or printed out in a report.
               --|
               --| Initialization Exceptions (none)
               --|
               --| Notes
               --| This package is based on the generic package "Task_Statistics"
               --| written by Dan Roy.
               --|
               --| Modifications
               --| 8/18/86  Ed Seidewitz    Initial version
            
                 -- .....................
                 -- .                   .
                 -- .  Number_Of_Lines  .  SPEC
                 -- .                   .
                 -- .....................
            
                 function Number_Of_Lines
                   return POSITIVE;
            
                 --| Purpose
                 --| This function returns the number of lines printed by
                 --| procedure Report since the last call to Number_Of_Lines.
                 --|
                 --| Exceptions (none)
                 --|
                 --| Notes (none)
            
                 -- ..............
                 -- .            .
                 -- .  Count_Of  .  SPEC
                 -- .            .
 
            64                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 -- ..............
            
                 function Count_Of
                   ( Element
                       : ELEMENT_TYPE )
                   return NATURAL;
            
                 --| Purpose
                 --| This function returns the current count for the specified
                 --| element.
                 --|
                 --| Exceptions (none)
                 --|
                 --| Notes (none)
            
                 -- ...............
                 -- .             .
                 -- .  Increment  .  SPEC
                 -- .             .
                 -- ...............
            
                 procedure Increment
                   ( Element
                       : in ELEMENT_TYPE;
                     By_Amount
                       : in INTEGER := 1 );
            
                 --| Purpose
                 --| This procedure increments the count for the specified
                 --| element by a certain amount.  By default, this amount
                 --| is one.
                 --|
                 --| Exceptions (none)
                 --|
                 --| Notes (none)
            
                 -- ............
                 -- .          .
                 -- .  Report  .  SPEC
                 -- .          .
                 -- ............
            
                 procedure Report
                   ( Report_File
                       : Text_IO.FILE_TYPE );
            
                 --| Purpose
                 --| This procedure prints a report of all statistics for
                 --| this unit to the specified text file.
                 --|
                 --| Exceptions (none)
                 --|
                 --| Notes (none)
            
 
            SPECIFIC GUIDELINES                                                         65




                                            MIL-HDBK-1804
 
               end Unit_Statistics;


            5.12.4.4.  Example_______ 12X4.____.

               -- *********************************
               -- *                               *
               -- *  Telemetry_Reader_Statistics  *  SPEC
               -- *                               *
               -- *********************************
            
               package Telemetry_Reader_Statistics is
                 new Unit_Statistics
                   ( Unit_Name    => "Telemetry_Reader",
                     ELEMENT_TYPE => READER_ELEMENTS );
            
               --| Purpose
               --| This package collects statistics on elements of the
               --| Telemetry_Reader.
               --|
               --| Initialization Exceptions (none)
               --|
               --| Notes (none)




            5.13.  Representation______________ clauses_______ and___ implementation-dependent________________________ features________

            5.13.1.  Encapsulation._____________.

                 Representation  clauses  and implementation dependent features should, if
            possible,  be  hidden inside packages which present implementation independent
            interfaces to users.

            5.13.2.  Use___ of__ representation______________ clauses_______ and___ implementation-dependent________________________ features.________.

                 a.   Machine  dependent  and  low-level  Ada  features should not be used
            except when absolutely necessary.

                 b.   Representation  clauses and implementation-dependent features should
            only be used for one of the following:

                  (1) To increase efficiency (when absolutely necessary).

                  (2) For interrupt handling.

                  (3) For interfacing to hardware, foreign code or foreign data.

                  (4) To specify task storage size.

            Further,  address  clauses  should be used with entries only to associate them
            with hardware interrupts.

 
            66                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                 c.   Representation clauses should not be used to change the meaning of a
            program.

            5.13.2.1.   Interrupts.__________.   Interrupt  routines  should  be  kept  as  short  as
            possible.

            5.13.3.  Formatting__________ of__ representation______________ clauses._______.

                 Representation clauses should be placed near to the objects they affect.



            5.14.  Input-Output____________

            5.14.1.  Encapsulation_____________ of__ I/O.___.

                 a.   Use  of the LOW_LEVEL_IO procedures should always be encapsulated in
            packages or tasks.

                 b.   Use  of the LOW_LEVEL_IO procedures should generally be encapsulated
            in task objects associated with each item of controlled equipment.

                 c.  File management and textual input-output software should generally be
            encapsulated in specialized packages with simple interfaces.

            This  should  include  file  interface  code, textual formatting code and user
            interface  code.  User interface encapsulation can be especially useful when a
            system  must accommodate increasing levels of user interface sophistication or
            changing  user  needs  over  its lifetime.  In these cases, it is crucial that
            details  of the implementation of the user interface be hidden so that changes
            can be made to it without affecting the rest of the system.

            5.14.2.  Text____ formatting.__________.

                 Line  and  page formatting should be done using the New_Line and New_Page
            subprograms,   rather  than  explicitly  writing  end-of-line  or  end-of-page
            characters.

            5.14.2.1.   Low-level_________  input-output.____________.   Use  of  package Low_Level_IO should be
            avoided unless absolutely necessary.

            5.14.2.2.   Form____  parameter._________.  Use of the Form parameter of the Open and Create
            procedures should generally be avoided.

            The  "Form"  parameter  on  the  file  Open  and  Create  procedures specifies
            system-dependent  file  characteristics.  This can reduce both readability and
            portability, and so should only be used if absolutely necessary.

            5.14.3.  Examples________ for___ input-output.____________.

                 See also examples 5.5.3.3., 5.5.3.4, and 5.7.4.3.



 
            SPECIFIC GUIDELINES                                                         67




                                            MIL-HDBK-1804
 
            5.14.3.1.  Example_______ 14X1.____.

               -- ............
               -- .          .
               -- .  Report  .  SUBUNIT
               -- .          .
               -- ............
            
               separate (Unit_Statistics)
               procedure Report is
                 ( Report_File
                     : in Text_IO.FILE_TYPE ) is
            
               --| Notes
               --| This example is based on Task_Statistics.Report
               --| by Dan Roy.
               --|
               --| Modifications
               --| 8/18/86  Ed Seidewitz    Initial version
            
                 Unit_Name_Column
                   : constant := 10;
            
                 Value_Column
                   : constant := 40;
            
                 use Text_IO;          -- For output operations
            
               begin -- Report
            
                 -- Print header
                 New_Line (Report_File);
                 Set_Col (Report_File, To => Unit_Name_Column);
                 Put_Line (Report_File,
                     "Statistics for " & STRING(Unit_Name));
                 New_Line (Report_File);
                 Number_Lines_Printed := Number_Lines_Printed + 2;
            
                 -- Print "element name    element value" for all elements
                 for Element in Statistics_Array'range loop
                   Put (Report_File, ELEMENT_TYPE'image (Element));
                   Set_Col (Report_File, To => Value_Column);
                   Put_Line (Report_File,
                       INTEGER'image (Statistics_Array(Element)));
                   Number_Lines_Printed := Number_Lines_Printed + 1;
                 end loop;
            
               end Report;






 
            68                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
            5.14.3.2.  Example_______ 14X2.____.

               -- ..........
               -- .        .
               -- .  Read  .  SUBUNIT
               -- .        .
               -- ..........
            
               separate (Disk)
               procedure Read
            
                 ( Disk_File
                     : in out FILE_TYPE;
            
                   Data
                     : out SPECIFIC_DATA_TYPE ) is
            
               --| Notes
               --| (This is the body of procedure Read in example 7X3)
               --|
               --| Modifications
               --| 9/10/86  Ada User's Group    Initial version
            
               begin -- Read
            
                 if not Disk_IO.Is_Open(Disk_File.File) then
                   Open_File(Disk_File);
                 end if;
            
                 Disk_IO.Read
                   ( File => Disk_File.File,
                     Item => Data );
            
               exception
            
                 when Disk_IO.End_Error =>
                   Disk_IO.Close (Disk_File.File);
                   raise End_Of_File;
            
                 when Disk_IO.Name_Error | Disk_IO.Use_Error =>
                   raise Open_Error;
            
                 when Disk_IO.Mode_Error =>
                   raise Mode_Error;
            
               end Read;








 
            SPECIFIC GUIDELINES                                                         69




                                            MIL-HDBK-1804
 




















                                    This page intentionally blank

































 
            70                                                         SPECIFIC GUIDELINES




                                            MIL-HDBK-1804
 
                                     A. TEMPLATES OF ANNOTATIONS




                                     A.1. Function Specification



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a function subprogram specification.


            -- ..................................
            -- .                                .
            -- .  Subprogram_name               .  SPEC
            -- .                                .
            -- ..................................
            function 
              ( ;
                 )
              return ;
            
            --| Purpose
            --| [This section is a description of all purposes and functions
            --| of the subprogram.]
            --|
            --| Exceptions (none)
            --| [A list of all exceptions which may propagate out of the
            --| subprogram, and a description of when each would be raised.]
            --|
            --| Notes (none)
            --| [Additional comments on the use of the subprogram.]
            --|
            --| Modifications
            --| [A list of modifications made to the subprogram DECLARATION.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the subprogram declaration.
            --| The "Modifications" section is required only when the
            --| subprogram declaration is a stand-alone compilation unit
            --| in a file of its own.]











 
            Templates of Annotations                                                   A-1




                                            MIL-HDBK-1804
 
                                          A.2. Function Body



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a function subprogram body.


            -- ..................................
            -- .                                .
            -- .  Subprogram_name               .  BODY
            -- .                                .
            -- ..................................
            function 
              ( ;
                 )
              return  is
            
            --| Notes (none)
            --| [Additional comments on the use of the subprogram.]
            --|
            --| Modifications
            --| [A list of modifications made to the subprogram BODY.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the subprogram body.
            --| The "Modifications" section is required only when the
            --| subprogram body is a stand-alone compilation unit
            --| in a file of its own.]
























 
            A-2                                                   Templates of Annotations




                                            MIL-HDBK-1804
 
                                     A.3. Procedure Specification



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a procedure subprogram specification.


            -- ..................................
            -- .                                .
            -- .  Subprogram_name               .  SPEC
            -- .                                .
            -- ..................................
            procedure 
              ( ;
                 );
            
            --| Purpose
            --| [This section is a description of all purposes and functions
            --| of the subprogram.]
            --|
            --| Exceptions (none)
            --| [A list of all exceptions which may propagate out of the
            --| subprogram, and a description of when each would be raised.]
            --|
            --| Notes (none)
            --| [Additional comments on the use of the subprogram.]
            --|
            --| Modifications
            --| [A list of modifications made to the subprogram DECLARATION.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the subprogram declaration.
            --| The "Modifications" section is required only when the
            --| subprogram declaration is a stand-alone compilation unit
            --| in a file of its own.]

















 
            Templates of Annotations                                                   A-3




                                            MIL-HDBK-1804
 
                                         A.4. Procedure Body



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a procedure subprogram body.


            -- ..................................
            -- .                                .
            -- .  Subprogram_name               .  BODY
            -- .                                .
            -- ..................................
            procedure 
              ( ;
                 ) is
            
            --| Notes (none)
            --| [Additional comments on the use of the subprogram.]
            --|
            --| Modifications
            --| [A list of modifications made to the subprogram BODY.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the subprogram body.
            --| The "Modifications" section is required only when the
            --| subprogram body is a stand-alone compilation unit
            --| in a file of its own.]

























 
            A-4                                                   Templates of Annotations




                                            MIL-HDBK-1804
 
                                      A.5. Package Specification



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a package specification.


            -- **********************************
            -- *                                *
            -- *  Package_name                  *  SPEC
            -- *                                *
            -- **********************************
            package  is
            
            --| Purpose
            --| [This section is a description of the purpose and function
            --| of the package.]
            --|
            --| Initialization Exceptions (none)
            --| [A list of all exceptions which may propagate out of the
            --| package INITIALIZATION PART and a description of when each
            --| would be raised.]
            --|
            --| Notes (none)
            --| [Additional comments on the use of the package.]
            --|
            --| Modifications
            --| [A list of modifications made to the package SPECIFICATION.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the package specification.
            --| The "Modifications" section is required only when the
            --| package specification is a stand-alone compilation unit
            --| in a file of its own.]


















 
            Templates of Annotations                                                   A-5




                                            MIL-HDBK-1804
 
                                          A.6. Package Body



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a package body.


            -- **********************************
            -- *                                *
            -- *  Package_name                  *  BODY
            -- *                                *
            -- **********************************
            package body  is
            
            --| Notes (none)
            --| [Additional comments on the design, implementation, and
            --| use of the package.]
            --|
            --| Modifications
            --| [A list of modifications made to the package BODY.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the package BODY.
            --| The "Modifications" section is required only when the
            --| package BODY is a stand-alone compilation unit
            --| in a file of its own.]


























 
            A-6                                                   Templates of Annotations




                                            MIL-HDBK-1804
 
                                       A.7. Task Specification



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a task specification.


            -- **********************************
            -- *                                *
            -- *  Task_name                     *  SPEC
            -- *                                *
            -- **********************************
            task  is
            
            --| Purpose
            --| [This section is a description of all purposes and functions
            --| of the task.]
            --|
            --| Notes (none)
            --| [Additional comments on the use of the task.]
            --|
            --| Modifications
            --| [A list of modifications made to the task DECLARATION.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the task declaration.
            --| The "Modifications" section is required only when the
            --| task declaration is a stand-alone compilation unit
            --| in a file of its own.]























 
            Templates of Annotations                                                   A-7




                                            MIL-HDBK-1804
 
                                            A.8. Task Body



                 This  appendix contains a template of the annotations recommended in this
            guide.  This template is for a task body.


            -- **********************************
            -- *                                *
            -- *  Task_name                     *  BODY
            -- *                                *
            -- **********************************
            task body  is
            
            --| Notes (none)
            --| [Additional comments on the use of the task.]
            --|
            --| Modifications
            --| [A list of modifications made to the task BODY.
            --| Each entry in the list should include the date of the change,
            --| the name of the person who made the change, and a description
            --| of the modification.  The first entry in the list should
            --| always be the initial coding of the task BODY.
            --| The "Modifications" section is required only when the
            --| task BODY is a stand-alone compilation unit
            --| in a file of its own.]



























 
            A-8                                                   Templates of Annotations




                                            MIL-HDBK-1804
 




















                                    This page intentionally blank

































 
            Templates of Annotations                                                   A-9




                                            MIL-HDBK-1804
 




                                          TABLE OF CONTENTS


            
            1. SCOPE  .................................................................. 1
               1.1. Introduction  ...................................................... 1
               1.2. Scope .............................................................. 1
               1.3. Goals .............................................................. 1
            
            2. REFERENCED DOCUMENTS .................................................... 3
               2.1. Government Documents  .............................................. 3
            
            3. DEFINITIONS  ............................................................ 4
               3.1. Introduction  ...................................................... 4
               3.2. Handbook  .......................................................... 4
               3.3. Standard  .......................................................... 4
            
            4. GENERAL REQUIREMENTS .................................................... 5
            
            5. SPECIFIC GUIDELINES  .................................................... 6
               5.1. Introduction  ...................................................... 6
               5.2. Lexical elements  .................................................. 6
                  5.2.1. The package STANDARD.  ........................................ 6
                  5.2.2. Formatting of lexical elements.  .............................. 6
               5.3. Declarations and types  ............................................ 8
                  5.3.1. Constants. .................................................... 8
                  5.3.2. Types. ........................................................ 9
                  5.3.3. Enumeration types. ........................................... 10
                  5.3.4. Floating types.  ............................................. 10
                  5.3.5. Record types.  ............................................... 10
                  5.3.6. Access types.  ............................................... 11
                  5.3.7. Object declarations. ......................................... 11
                  5.3.8. Formatting of declarations and types.  ....................... 12
                  5.3.9. Examples for declarations and types. ......................... 14
               5.4. Names and expressions ............................................. 15
                  5.4.1. Aggregates.  ................................................. 15
                  5.4.2. Formatting of names and expressions. ......................... 16
               5.5. Statements  ....................................................... 18
                  5.5.1. Slice statements.  ........................................... 18
                  5.5.2. Formatting of statements.  ................................... 19
                  5.5.3. Examples for statements. ..................................... 21
               5.6. Subprograms ....................................................... 23
                  5.6.1. Cohesion.  ................................................... 23
                  5.6.2. Parameters.  ................................................. 23
                  5.6.3. Formatting of subprograms. ................................... 24
                  5.6.4. Examples for subprograms.  ................................... 28
               5.7. Packages  ......................................................... 31
                  5.7.1. Use of packages. ............................................. 31
                  5.7.2. Initialization.  ............................................. 33
                  5.7.3. Formatting of packages.  ..................................... 33
 
                                                - i -




                                            MIL-HDBK-1804
 
                  5.7.4. Examples for packages. ....................................... 36
               5.8. Visibility  ....................................................... 42
                  5.8.1. Scope of identifiers.  ....................................... 42
                  5.8.2. The use clause.  ............................................. 42
               5.9. Tasks ............................................................. 43
                  5.9.1. Use of tasks.  ............................................... 43
                  5.9.2. Task types.  ................................................. 44
                  5.9.3. Formatting of tasks. ......................................... 47
                  5.9.4. Examples for tasks.  ......................................... 50
               5.10. Program structure and compilation issues ......................... 57
                  5.10.1. Program units.  ............................................. 57
                  5.10.2. Compilation units.  ......................................... 58
               5.11. Exceptions ....................................................... 58
                  5.11.1. Exception propagation.  ..................................... 58
                  5.11.2. Use of exceptions.  ......................................... 59
                  5.11.3. Exception declarations. ..................................... 60
                  5.11.4. Examples for exceptions.  ................................... 60
               5.12. Generic units  ................................................... 60
                  5.12.1. Use of generic units. ....................................... 60
                  5.12.2. Generic formal subprograms. ................................. 61
                  5.12.3. Formatting of generic units.  ............................... 61
                  5.12.4. Examples of generic units.  ................................. 62
               5.13. Representation clauses and implementation-dependent features ..... 66
                  5.13.1. Encapsulation.  ............................................. 66
                  5.13.2. Use of representation clauses and implementation-dependent fe 66
                  5.13.3. Formatting of representation clauses. ....................... 67
               5.14. Input-Output ..................................................... 67
                  5.14.1. Encapsulation of I/O. ....................................... 67
                  5.14.2. Text formatting.  ........................................... 67
                  5.14.3. Examples for input-output.  ................................. 67
            
            A. TEMPLATES OF ANNOTATIONS .............................................. A-1
               A.1. Function Specification  .......................................... A-1
               A.2. Function Body .................................................... A-2
               A.3. Procedure Specification .......................................... A-3
               A.4. Procedure Body  .................................................. A-4
               A.5. Package Specification ............................................ A-5
               A.6. Package Body  .................................................... A-6
               A.7. Task Specification  .............................................. A-7
               A.8. Task Body ........................................................ A-8














 
                                               - ii -
--::::::::::
--pmh1804.idx
--::::::::::




                                            MIL-HDBK-1804
 
                                                       continuation of statements        7
            A                                          control, short-circuit           15
            abbreviations in identifiers      7        conversion, explicit type        15
            abort statements                 44        conversion, type                 10
            abort statements                 47
            abstraction, levels of            1        D
            accept statements                49        declarations, exception          60
            access types                     11        declarations, generic            61
            Ada Programming Language          1        declarations, object             11
            Ada Programming Language          4        declarations, renaming           43
            Ada Programming Language          6        declarations, subprogram         25
            Ada Software Repository           2        delay statement                  45
            Ada Style Guide Handbook          4        dependencies, program unit       58
            aggregates                       15        documentary comments             25
            ANSI/MIL-STD-1815A                1        documentary comments             25
            ANSI/MIL-STD-1815A                4        documentary comments             26
            ANSI/MIL-STD-1815A                6        documentary comments             27
            array types                      12        documentary comments             34
            ASR                               2        documentary comments             35
            association, named parameter     27        documentary comments             48
            attributes                        6        documentary comments             49
            attributes, use of               61        documentary comments             49
                                                       documentary comments             61
            B                                          documentary comments             62
            blank lines                       7
            block statement format           20        E
            block statements                 18        encapsulation                    66
            bodies and stubs, package        35        entries and accept statements    45
                                                       enumeration types                10
            C                                          examples, declarations           14
            case statement format            20        examples, exceptions             60
            case statements                  18        examples, generic units          62
            character set                     6        examples, input-output           67
            clauses, with                    58        examples, packages               36
            cohesion                         23        examples, statements             21
            cohesive, functionally           23        examples, subprograms            28
            comments                          8        examples, tasks                  50
            comments, documentary            25        examples, types                  14
            comments, documentary            25        exception declarations           60
            comments, documentary            26        exception handlers               59
            comments, documentary            27        exception propagation            58
            comments, documentary            34        Exceptions                       26
            comments, documentary            35        exceptions                       58
            comments, documentary            48        exceptions, examples for         60
            comments, documentary            49        exceptions, use of               59
            comments, documentary            49        exit statements                  18
            comments, documentary            61        expressions, qualified           15
            comments, documentary            62        expressions, static              15
            compilation issues               57
            compilation units                58        F
            constant object                   8        floating types                   10
            constants                         8        form parameter                   67
            constants                         9        format, aggregates               17
            continuation lines               17        format, array types              12
 
                                               Index-1




                                            MIL-HDBK-1804
 
            format, block statement          20        header, subprogram               25
            format, case statement           20
            format, comments                 12        I
            format, continuation lines       17        identifiers                       6
            format, declarations             12        identifiers                       7
            format, entry names              47        identifiers, abbreviations in     7
            format, function body           A-2        identifiers, scope of            42
            format, function spec           A-1        identifiers, underscores in       7
            format, generic instant.s        62        if statement format              19
            format, generic units            61        if statements                    18
            format, if statement             19        implementation-dependent features66
            format, indentation              12        Initialization Exceptions        34
            format, loop statement           20        initialization, object           12
            format, names and expressions    16        initialization, package          33
            format, objects                  13        input-output, low-level          67
            format, package body            A-6        instantiations, generic          61
            format, package spec            A-5        interrupts                       67
            format, packages                 33        ISEC, U.S. Army                   2
            format, parentheses              17        ISEC, U.S. Army                   2
            format, procedure body          A-4        issues, compilation              57
            format, procedure spec          A-3        issues, program structure        57
            format, record types             12
            format, rep clauses              67        L
            format, select statements        50        levels of abstraction             1
            format, statements               19        library units                    57
            format, subprograms              24        library units, generic           61
            format, task bodies              49        lines, blank                      7
            format, task body               A-8        lines, continuation              17
            format, task names               47        long strings                      8
            format, task spec               A-7        loop statement format            20
            format, task specs               48        low-level input-output           67
            format, task stubs               49
            format, tasks                    47        M
            format, text                     67        MIL-HDBK-1804                     4
            format, types                    12        Modifications                    26
            function body, formatting of    A-2        Modifications                    27
            function spec, formatting of    A-1        Modifications                    35
            functionally cohesive            23        Modifications                    36
            functions                        23
                                                       N
            G                                          named number                      9
            generic declarations             61        named param. association         27
            generic formal subprogs          61        names                            16
            generic instant.s, format        62        names and expressions            15
            generic instantiations           61        NASA/GSFC                         2
            generic library units            61        nesting of tasks                 43
            generic units                    60        nesting, package                 32
            generic units, use of            60        Notes                            26
            good style                        1        Notes                            27
            goto statements                  19        Notes                            34
                                                       Notes                            36
            H                                          number, named                     9
            handlers, exception              59
            header, package                  34        O
 
                                               Index-2




                                            MIL-HDBK-1804
 
            object                            8        scope of identifiers             42
            object declarations              11        select statements                50
            object initialization            12        sequences, statement             19
            object, constant                  8        set, character                    6
            operators, overloading of        24        shared variables                 47
            overloading of operators         24        short-circuit control            15
            overloading of subprograms       24        slice statements                 18
                                                       source code, functions of         1
            P                                          specifications, package          34
            package                          31        STANDARD, package                 6
            package bodies and stubs         35        STANDARD, package                42
            package body, formatting of     A-6        statements                       18
            package header                   34        statements, abort                44
            package initialization           33        statements, abort                47
            package nesting                  32        statements, accept               49
            package spec, formatting of     A-5        statements, block                18
            package specifications           34        statements, case                 18
            package STANDARD                  6        statements, continuation of       7
            package STANDARD                 42        statements, delay                45
            package, use of                  31        statements, entries and accept   45
            packages, formatting of          33        statements, examples for         21
            packages, variables in           33        statements, exit                 18
            parameters, subprogram           23        statements, goto                 19
            Portable Text Formatter           2        statements, if                   18
            pragma priority                  50        statements, raise                60
            priority                         46        statements, return               19
            priority, pragma                 50        statements, select               50
            problem domain                    1        statements, sequences            19
            procedure body, formatting of   A-4        statements, slice                18
            procedure spec, formatting of   A-3        statements, terminate            44
            program structure issues         57        static expressions               15
            program unit dependencies        58        strings, long                     8
            program units                    57        subprogram bodies and stubs      26
            propagation, exception           58        subprogram declaration           25
            PTF                               2        subprogram header                25
            Purpose                          26        subprogram names                 24
            Purpose                          34        subprogram parameters            23
                                                       subprograms                      23
            Q                                          subprograms, formatting of       24
            qualification, type              15        subprograms, functions           23
            qualified expression             15        subprograms, generic formal      61
                                                       subprograms, overloading         24
            R                                          synchronization, task            46
            raise statements                 60
            record types                     10        T
            recursion                        23        task and entry names             47
            redefinition                     43        task bodies and stubs            49
            renaming declarations            43        task body, formatting of        A-8
            rep clauses, format              67        task spec, formatting of        A-7
            representation clauses           66        task specifications              48
            reserved words                    6        task synchronization             46
            return statements                19        task termination                 44
                                                       task type                        48
            S                                          task types                       44
 
                                               Index-3




                                            MIL-HDBK-1804
 
            tasks                            43
            tasks, format                    47
            tasks, nesting of                43
            tasks, priorities                46
            tasks, shared variables          47
            tasks, use of                    43
            tasks, visibility of             44
            terminate statements             44
            termination, task                44
            text format                      67
            type conversion                  10
            type conversion, explicit        15
            type qualification               15
            types, access                    11
            types, array                     12
            types, enumeration               10
            types, floating                  10
            types, record                    10
            types, task                      44
            types, task                      48
            
            U
            U.S. Army ISEC                    2
            U.S. Army ISEC                    2
            underscores in identifiers        7
            units, compilation               58
            use clause                       42
            use of attributes                61
            use of exceptions                59
            use of generic units             60
            use of package                   31
            use of tasks                     43
            
            V
            variables in package             33
            variables, shared                47
            visibility                       42
            visibility of tasks              44
            
            W
            with clauses                     42
            with clauses                     58












 
                                               Index-4




                                            MIL-HDBK-1804
 




















                                    This page intentionally blank

































 
                                               Index-5
--::::::::::
--pmh1804.inc
--::::::::::
-- Include file for PMH1804
pmh1804.ptf
pmh1804i.ptf

pmh1804.mac

fctspec.ada
fctbody.ada
prospec.ada
probody.ada
pacspec.ada
pacbody.ada
tskspec.ada
tskbody.ada
--::::::::::
--pmh1804.pra
--::::::::::
-- Ada Pretty Printer Directives (must be 14 lines long)
pragma form_set (pretty_printer_format => special);
pragma form_set (indentation => 2);
pragma form_set (using_half_indentation => false);
pragma form_set (types_case => upper_case);
pragma form_set (enumeration_case => upper_case);
pragma form_set (identifier_case => capitalize_first);
pragma form_set (using_echeloned_declarations => true);
pragma form_set (using_echeloned_assigns => true);
pragma form_set (using_colon_alinement => true);
pragma form_set (using_value_alinement => true);
pragma form_set (using_assign_alinement => true);
pragma form_set (using_pointer_alinement => true);
--::::::::::
--pmh1804.ptf
--::::::::::
.lm 12
.rm 90
.ulmode nopunctuation
.de LIST
.nr z 0
.en
.de LE
.sp 1
.nr z +1
.ti +6
(@nz)
.en
.de ASIS
.sp
.nf
.en
.de ENDASIS
.fi
.sp
.en
.de EXP
.sp 1
.en
.de PP
.sp 1
.ti +5
.en
.nr a 0
.de S1
.nr a +1
.nr b 0
.ce
@na. @1 @2 @3 @4 @5 @6 @7 @8 @9
.cl
.cl 0 @na. @1 @2 @3 @4 @5 @6 @7 @8 @9
.sp 2
.en
.de S2
.sp 3
.ne 10
.nr b +1
.nr c 0
@na.@nb.
.ul
@1 @2 @3 @4 @5 @6 @7 @8 @9
.cl 1 @na.@nb. @1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.de S3
.sp 1
.ne 5
.nr c +1
.nr d 0
@na.@nb.@nc.
.ul
@1 @2 @3 @4 @5 @6 @7 @8 @9
.cl 2 @na.@nb.@nc. @1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.de S4
.sp 1
.ne 5
.nr d +1
@na.@nb.@nc.@nd.
.ul
@1 @2 @3 @4 @5 @6 @7 @8 @9
.en
.ce on
.ul
Proposed MIL-HDBK-1804
.sp 4
Military Handbook

Ada Style Guide

30 April 1988
.ce off
.sp 15
.in +10
.rm -10
This draft, prepared by the U.S. Army Information
Systems Engineering Command, has not been approved and is subject to
modification.  It should not be used or interpreted as an approved
Military Handbook at this time.
.sp 1
This machine-readable document is provided for the users of the
Ada Software Repository.  While great care has been taken in entering
its text, typing errors may have been introduced (and some typing
errors have been corrected), and the users should
review it.  It is presented as both raw (for processing by the
PTF [Portable Text Formatter]
tool) and formatted machine-readable files.  If errors are found, please
report them to the Ada Software Repository Support Contractor, MACA, by
phone or email.
.rm +10
.in -10
.bp
.ce
FOREWORD
.sp 2
.PP
The Ada Style Guide was developed by the National Aeronautics and Space
Administration/Goddard Space Flight Center Ada User's Group.  The principal
author is Edwin V. Seidewitz.  The guide was edited and reformatted as a
Military Handbook by the United States Army Information Systems Engineering
Command.
.bp 1
.S1 SCOPE
.he //MIL-HDBK-1804//
.of /SCOPE//#/
.ef /#//SCOPE/
.S2 Introduction
.PP
Ada is a programming language of considerable expressive power.
ANSI/MIL-STD-1815A, Ada Programming Language, provides a thorough
definition of the language.  However, it does not offer sufficient
guidance on the appropriate use of Ada's powerful features.  This document
was developed to address such "program style" issues.
.S2 Scope
.PP
Program source code serves two functions: to specify an algorithm to be
performed on a computer, and to communicate this algorithmic design to
other human readers.  Program style relates to how well a program meets the
second function.  It is a consistent manner of using the features of a
programming language to promote the readability and understandability of a
program.  This is a matter of the form of the final, delivered, program
source code, as opposed to the process of developing the code.
.S2 Goals
.PP
a. While some of what constitutes "good style" is subjective and somewhat
arbitrary, it is important that the style of a program be consistent
throughout the program.  The primary goal of this guide is to promote such
consistent use of good style across large numbers of Ada programs.  The whole
intent of "good style" is to increase the readability of these programs.
Therefore, these guidelines follow from general principles of program
readability and understandability.
.PP
b. The program should reflect the natural levels of abstraction in the
problem domain, so that the reader can reasonably comprehend each level
individually.
.PP
c. There are several features in Ada which are unfamiliar to many programmers.
There is thus a tendency to either underuse these features or to use them
inappropriately.  A feature of Ada should generally not be ignored, but
neither should it be used in excess.  The guidelines highlight the proper
use of Ada features.
.PP
d. The textual format of a program should be pleasing to the eye and
promote the readability and understandability of the program.  The format
should highlight the structure of a program and the role of a program as
a model of the problem domain.  Just as the careful layout of a book
can enhance written communication, the careful layout of a program can enhance
the communication of algorithmic design to another human.  The consistent use of
formatting style is especially important, because it allows readers to become
accustomed to the familiar layout of the program constructs.  An automated
formatting program is particularly helpful, but even in the absence of such
a tool, much can be gained from a common format style.
.bp
.S1 REFERENCED DOCUMENTS
.of /REFERENCED DOCUMENTS//#/
.ef /#//REFERENCED DOCUMENTS/
.S2 Government Documents
.PP
ANSI/MIL-STD-1815A, Ada Programming Language.
.bp
.S1 DEFINITIONS
.of /DEFINITIONS//#/
.ef /#//DEFINITIONS/
.S2 Introduction
.PP
The definitions provided in ANSI/MIL-STD-1815A are applicable for use
with this handbook.  Since this handbook is intended to be a companion
document to the Ada Programming Language manual, the definitions are not
restated here.
.S2 Handbook
.PP
The term "Handbook" (capitalization intended) refers to this document,
MIL-HDBK-1804, Ada Style Guide Handbook.  This simplification is used
to improve readability.
.S2 Standard
.PP
The term "Standard" (capitalization intended) refers to ANSI/MIL-STD-1815A,
Ada Programming Language.  This simplification is to improve readability.
.bp
.S1 GENERAL REQUIREMENTS
.of /GENERAL REQUIREMENTS//#/
.ef /#//GENERAL REQUIREMENTS/
.sp 4
.ce
NOT APPLICABLE
.bp
.S1 SPECIFIC GUIDELINES
.of /SPECIFIC GUIDELINES//#/
.ef /#//SPECIFIC GUIDELINES/
.S2 Introduction
.PP
This section contains fourteen major subparagraphs (5.1 through 5.14)
corresponding to the fourteen chapters of ANSI/MIL-STD-1815A,
Ada Programming Language.  This provides a standard frame of
reference for the discussion of Ada features.  Where appropriate, the
guide includes examples and justifications for various guidelines.
Some of the major subparagraphs, themselves, have an "Examples"
subparagraph giving additional, longer examples for the topic.
.S2 Lexical elements
.S3 The package STANDARD.
.PP
Language words with predefined meanings in the package STANDARD should
not be redefined.
.S3 Formatting of lexical elements.
.S4 Indentation.
The standard indentation is two spaces.
.S4 Character set.
Full use should be made of the ISO character set where available.
Alternate character replacements should only be used when the corresponding
graphical symbols are not available.
.S4 Upper/lower case.
.PP
a. Reserved words and attributes should appear in lower case.
.PP
b. All identifiers except type, enumeration value and attribute identifiers
should be in mixed upper and lower case.  The first letter of each word in the
identifier should be in upper case with other characters in lower case, unless
a word is normally written in all upper case (e.g., acronyms).
.ASIS
   Display__Device
   Number__Of__User__Names
   Get__FHST__Data
   Package__Name
.ENDASIS
.PP
c. Type and enumeration value identifiers should appear in all upper case.
.ASIS
   LONG__INTEGER
   AUTHORITY__LEVEL

   (RED, GREEN, BLUE)
   (ARMY, AIR__FORCE, NAVY, MARINES)
.ENDASIS
.S4 Identifiers.
.PP
a. Identifier names should be meaningful and easily distinguishable from
each other, except possibly for loop parameters, array indices, and common
mathematical variables, which may be as short as a single character.
.PP
b. Distinct words in identifiers should always be separated by
underscores.
.PP
c. The use of abbreviations in identifiers should be avoided.  When used,
an abbreviation should be significantly shorter than the word it
abbreviates, and its meaning should be clear.  The same abbreviations
should be used consistently throughout a project.
.S4 Spaces.
Single spaces should be used consistently between lexical elements to
enhance readability.
.S4 Blank lines.
.PP
a. Blank lines should be used to group logically related lines of text.
.EXP
A careful use of blank lines can greatly enhance readability by making
the logical structure of a sequence of lines more textually obvious.
However, the overuse of blank lines (e.g., "double spacing") defeats the
very purpose of grouping and can actually reduce readability.  Blank lines
should thus always be used with grouping in mind and not just to increase
white space.
.PP
b. A blank line should always follow a construct whose last line is not at
the same indentation level as its first line.
.ASIS
   type COMPLEX is
     record
       Real      : FLOAT;
       Imaginary : FLOAT;
     end record;

   -- Followed by a blank line
.ENDASIS
.S4 Continuation of statements.
.PP
a. Statements extending over multiple lines should always be broken before
reserved words, operator symbols, or one of the following symbols:
.ASIS
   :  |  =>  ..  :=
.ENDASIS
.sp 1
but they should be broken after a comma (",").  Unless otherwise specified in
later guidelines, all the continuation lines should be indented at least
two levels with respect to the original line they continue.
.ASIS
   Corrected__Value := (1 + Sensor__Scale) * Raw__Value
       + Distortion__Factor * Distortion__Value + Sensor__Bias;
.ENDASIS
.PP
b. Long strings extending over more than one line should be broken up at
natural boundaries, appropriate to the meaning of the contents of the string, if
any.
.ASIS
   "This is a rather long string, so it is likely that "
       & "it will extend over more than one line"
.ENDASIS
.S4 Comments.
.PP
a. Comments should be used to add information for the reader or to highlight
sections of code, and should not merely paraphrase the code.
.PP
b. Comments should begin with the "--" aligned with the indentation level
of the code that they describe, or to the right of the code, aligned with
other such comments.
.ASIS
   -- Check if the user has special authorization
   if Authority = SPECIAL then
     Display__Special__Menu;   -- All operations are allowed
   else
     Display__Normal__Menu;    -- Only normal operations allowed
   end if;
.ENDASIS
.S2 Declarations and types
.S3 Constants.
.PP
a. An object should be declared constant if its value is intended not to change.
.EXP
Declaring an object to be constant clearly signals both the human reader
and the compiler the intention that its value will not change.  This not
only increases readability, it also increases reliability because the
compiler will detect any attempt to tamper with the object.  Also, it can
result in some decrease in executable size and better run time efficiency.
.PP
b. Defining a constant object is preferable to using a numeric literal or
expression with constant value, as long as the constant object has an
intrinsic conceptual meaning.
.EXP
There is no use in defining a constant object when a numeric literal is
obviously more appropriate, for example: using "One" instead of "1."
However, the use of constant objects with intrinsic meaning (such as
"Buffer__Size" or "Field__Of__View") can greatly increase the readability of
code.  Further, the code is more maintainable since a change in a value
will be localized to the constant declaration.
.PP
c. A named number (i.e., a constant object with type universal-integer
or universal-real) should be used only for values that are truly "universal"
and "typeless."  Other numeric constants should be declared with an explicit
type.
.EXP
Such constants as "Pi" and cardinal integers (e.g., a "number of things")
should be named numbers.  Note also that declaring a constant in terms of a
predefined numeric type (INTEGER, FLOAT, etc.) has no advantage over a named
number since these predefined types provide only range and accuracy constraints
and not additional conceptual meaning.  In fact, since the range and
accuracy of predefined numeric types is implementation-defined, portability
can be increased by using named numbers, in those cases where a constant
of a user-defined type is not more appropriate.
.ASIS
   Number__Of__Sensors       -- This is a named number
     : constant := 4;

   Main__Sensor__Number
     : constant SENSOR__INDEX := 2;
.ENDASIS
.S3 Types.
.PP
Separate types should be used for values that belong to logically independent
sets, and for distinct concepts.
.ASIS
   type X__COORDINATE is
     range 1 .. 640;

   type Y__COORDINATE is
     range 1 .. 480;

   type PIXEL__VALUE is
     range 0 .. 255;

   type IMAGE__GRID is
     array (X__COORDINATE, Y__COORDINATE) of PIXEL__VALUE;
.ENDASIS
.EXP
A data type characterizes a set of values and a set of operations
applicable to objects of the type.  In the above example, each coordinate
has a type because coordinates are independent entities.  Explicitly
declaring these types makes the concepts more obvious to a human reader
and also allows the compiler to detect mistakes such as:
.ASIS
   Image (Y, X) := Pixel;   -- Should be "(X, Y)"
.ENDASIS
.EXP
The drawback of this kind of typing is that the following construct is
illegal:
.ASIS
   if X = Y then     -- ILLEGAL since X and Y have different types
     ...
.ENDASIS
.EXP
A type conversion must be used:
.ASIS
   if X = X__COORDINATE(Y) then
     ...
.ENDASIS
.EXP
Note that, depending on context (and compiler quality), there may or may
not be some run time penalty associated with type conversion (e.g.,
testing of range constraints).
.S3 Enumeration types.
.PP
An enumeration type should always be used in preference to an integer type,
unless the logical nature of the concept to be modeled demands the other.
.EXP
For example, the type:
.ASIS
   type DEVICE__MODE is
     (READ__ONLY, WRITE__ONLY, READ__WRITE);
.ENDASIS
.EXP
is preferable to encoding DEVICE__MODE as an integer 0, 1 or 2.
.S3 Floating types.
.PP
a. To enhance portability, the range and accuracy of a floating point type
should generally be specified.
.PP
b. The precision for the predefined floating types (FLOAT, etc.) is
implementation-dependent, though all implementations should provide
at least 6 decimal digits of accuracy.  Explicitly declaring floating
point ranges can yield more reliable and more efficient results as well
as more portable code.
.S3 Record types.
.PP
a. A record type should be used instead of an array type even when all the
record components have the same type, as long as each component can be
sensibly named and the components do not need to be dynamically indexed.
.EXP
For example, the definition:
.ASIS
   type COMPLEX is
     record
       Real      : FLOAT;
       Imaginary : FLOAT;
     end record;
.ENDASIS
.EXP
is preferable to defining COMPLEX as an array of two FLOATs.
.PP
b. Overcomplicated record structures should be avoided by grouping related
data into subrecord types.
.ASIS
   type COORDINATE is
     record
       Row    : FLOAT;
       Column : FLOAT;
     end record;

   type WINDOW is
     record
       Top__Left     : COORDINATE;
       Bottom__Right : COORDINATE;
     end record;
.ENDASIS
.PP
c. Enumeration types should be used for discriminants of record variants
whenever possible.  A discriminant should generally have a default
initialization only if the discriminant value is intended to change over
the lifetime of an object.
.S3 Access types.
.PP
a. Generally, access types should not be used when static types and
stack allocation would be sufficient.
.PP
b. Generally, access types should be used only when it is necessary to have
data structures with dynamic pointers or to dynamically create objects.
However, access types may be needed for static objects if this leads to a
more consistent programming style (e.g., so that similar static and dynamic
objects are treated identically).  For example, if linked lists are used in a
program, there may be some lists which are constant, but which are still
implemented as linked lists using access types.  This would allow, for
example, passing these constant lists to subprograms which also handle dynamic
lists.
.S3 Object declarations.
.PP
a. Each object declaration should declare only one object.
.EXP
For example, the following objects should be declared in separate
declarations even though they are all of the same type:
.ASIS
   Table__Size
     : TABLE__RANGE;

   Table__Index
     : TABLE__RANGE;

   Current__Entry
     : TABLE__RANGE;
.ENDASIS
.PP
b. An object should not be declared using an unnamed constrained array
definition.
.EXP
The unnamed array definition is the only case in Ada where an object
can be declared to be of a type which does not have a name.  Instead,
the array type should be named in an array definition, and that name
used in the object declaration, even if there is only one object
declared of that type.
.ASIS
   type POOL__TYPE is
     array (POOL__RANGE) of CHARACTER;

   POOL
     : POOL__TYPE;
.ENDASIS
.PP
c. Objects should generally be initialized.  Where possible, objects
should always be initialized by their declaration, rather than in
later code.
.ASIS
   Is__Found
     : BOOLEAN := FALSE;
.ENDASIS
.S3 Formatting of declarations and types.
.S4 Commenting.
.PP
a. Type declarations (or groups of declarations) should be commented to
indicate what is being defined, if that is not obvious from the type
declaration itself.
.ASIS
   type VELOCITY is     -- Inertial velocity relative to the Earth
     array (1 .. 3) of FLOAT;
.ENDASIS
.PP
b. Object declarations should be commented if the object definition is
unclear from the object and type identifiers alone.  Note that those
properties of an object obtained from its type should not be repeated in
comments on the object declaration.
.ASIS
   Spacecraft__Velocity    -- Spacecraft orbital velocity, assuming
     : VELOCITY;          -- a circular orbit
.ENDASIS
.S4 Indentation.
All declarations in a single declaration part should begin at the same
indentation level.
.S4 Type definitions.
.PP
a. Array type definitions should have one of the following formats:
.ASIS
   type  is
     array  of ;

   type  is
     array 
       of ;
.ENDASIS
.PP
b. Record type definitions should have one of the following formats:
.ASIS
   type  is
     record
       
       
     end record;

   type 
     ( ;
        ) is
     record
       
       case  is
         when  =>
           
           

       end case;

     end record;
.ENDASIS
.PP
c. All  and  should be
formatted like object declarations (see paragraph 5.3.8.4).
.PP
d. Other type definitions should be formatted as follows:
.ASIS
   type  is
     ;

   subtype  is
     ;
.ENDASIS
.PP
e. Long enumeration type definitions should be formatted into easily
readable columns.
.S4 Formatting of object declarations.
.PP
a. Object declarations should have one of the following formats.  The
preferred formats are:
.ASIS
   
     :  := ;

   
     : 
       := ;
.ENDASIS
.PP
b. Declarations containing short identifiers may also be formatted all
on one line:
.ASIS
    :  := ;
.ENDASIS
.EXP
In this case, all such declarations textually grouped together or
appearing as components in a single record definition or in a single
parameter list should have their ":" and ":=" symbols aligned.
.S3 Examples for declarations and types.
.S4 Example 3X1.
.ASIS
   type SENSOR__ARRAY is
     array (NATURAL range <>) of SENSOR;

   UARS__Sensors                        -- Sensor configuration for
     : SENSOR__ARRAY(1 .. Num__Sensors); -- the UARS control system
.ENDASIS
.S4 Example 3X2.
.ASIS
   type COMPLEX is
     record
       Real      : FLOAT;
       Imaginary : FLOAT;
     end record;
.ENDASIS
.S4 Example 3X3.
.ASIS
   type DEVICE is
     (PRINTER, DISK, DRUM);

   type STATE is     -- Operational state
     (OPEN, CLOSED); -- of a device.

   type PERIPHERAL
     ( Unit : DEVICE := DISK) is
     record
       Status
         : STATE;
       case Unit is
         when PRINTER =>
           Lines__Per__Page
             : INTEGER range 1 .. Page__Size;

         when DISK | DRUM =>
           Cylinder
             : CYLINDER__INDEX;
           Track
             : TRACK__NUMBER;

       end case;

     end record;
.ENDASIS
.S2 Names and expressions
.S3 Aggregates.
.PP
a. Aggregates are preferable to individually setting all or most of the
components of an array or record.
.PP
b. Named aggregates should be used where possible.
.PP
c. The "others" choice should not be used within aggregates without good
reason.
.S4 Static expressions.
.PP
a. Where possible, universal expressions are preferable to static
expressions, which are in turn preferable to dynamic expressions.
.EXP
Since they do not depend on run time dynamics, static expressions
are easier for a human reader to understand.  Also, universal expressions
maximize accuracy and portability, and static expressions eliminate
run time overhead.
.S4 Short-circuit control.
.PP
a. Short-circuit control forms should generally be used only to avoid
evaluation of an undefined or illegal expression.  Short circuit operators
should not be used to optimize execution.
.ASIS
   (N /= 0) and then (Total/N > Limit)

   (Index = 0) or else User(Index).Not__Available
.ENDASIS
.PP
b. The short-circuit control forms should be used to signal to a human
reader that the correctness of the second condition depends on the results of
the first.  They should not be used for micro-efficiency reasons, concerns
better handled by an optimizing compiler.  If efficiency considerations are
substantially important, "if" statements should be used instead of the
short-circuit forms with functions used to avoid repeated code, if necessary.
.S4 Type qualification.
.PP
a. An explicit type conversion should not be used if a type qualified
expression is meant.
.ASIS
   Good : LONG__FLOAT'(3.14159);
   Bad  : LONG__FLOAT (3.14159);
.ENDASIS
.EXP
A qualified expression is used to state explicitly the type, and possibly
subtype, of a value.  A type conversion, however, results in the dynamic
conversion of a value to a target type.  Sometimes a type conversion can be
used to serve the purpose of a type qualification.  However, if the operand
is already of the desired base type, a conversion is not really necessary
and a qualification should be used instead.
.PP
b. Situations where type qualification is necessary should be avoided if
possible.  Other than where absolutely necessary, type qualification may be
justified only if it makes the program clearer to the reader.
.EXP
The main case to avoid is when the type of an enumeration literal or
aggregate is not known from context.  For example:
.ASIS
   type COLOR is
     (BLACK, RED, GREEN, BLUE, WHITE);

   type LIGHT is
     (RED, YELLOW, GREEN);

   procedure Set
     ( Color__Code : in COLOR );

   procedure Set
     ( Color__Code : in LIGHT );

   ...

   Set(COLOR'(RED));  -- Type qualification must be used here to
   Set(LIGHT'(RED));  -- resolve the overloading of Set and RED
.ENDASIS
.EXP
It would be better in this case to rename one of the Set procedures, or to at
least give them different parameter names so the overloading could be
resolved using name notation.
.S3 Formatting of names and expressions.
.S4 Names.
.PP
a. The name for a type should be a common noun indicating the class of the
objects it contains.
.ASIS
   DEVICE
   AUTHORITY__LEVEL
   USER__NAME
   PHONE__LIST
.ENDASIS
.EXP
A type name may also end with the suffix "TYPE."
.ASIS
   EMPLOYEE__TYPE
   SCHEDULE__TABLE__TYPE
   COLOR__TYPE
.ENDASIS
.PP
b. The names of non-BOOLEAN valued objects should be nouns, preferably
more precise than the names of types.
.ASIS
   Current__User
     : USER__NAME;

   Output__Device
     : DEVICE;

   Schedule__Table
     : SCHEDULE__TABLE__TYPE;

   New__Employee
     : EMPLOYEE__TYPE;
.ENDASIS
.EXP
BOOLEAN valued objects should have predicate-clause (e.g., "Is__Open") or
adjective names.
.ASIS
   User__Is__Available
   List__Empty
   Done
   Not__Ready
   Is__Waiting
.ENDASIS
.S4 Parentheses.
Syntactically redundant parentheses should generally be used to enhance
the readability of expressions, especially by indicating the order of
evaluation.
.EXP
For example:
.ASIS
   Variance := (Roll__Error ** 2) + ((Yaw__Error ** 2) / 2);
.ENDASIS
.S4 Aggregates format.
.PP
a. When longer than two or three components, or whenever readability is
improved, named aggregates should be formatted as indicated below, with one
association per line and the "=>" arrows aligned.
.ASIS
   Output__Device :=
     ( Device   => DISK,
       Status   => CLOSED,
       Cylinder => 1,
       Track    => Startup__Track__Number );
.ENDASIS
.PP
b. Aggregates for tabular data structures may instead be formatted in a
tabular fashion, so as to enhance readability.
.S4 Continuation.
When a long expression is broken over more than one
line, it should be broken near the end of the line before an operator
symbol with the lowest reasonable precedence.
.ASIS
   Corrected__Value := (1 + Sensor__Scale) * Raw__Value
     + Distortion__Factor * Distortion__Value + Sensor__Bias;
.ENDASIS
.S2 Statements
.S3 Slice statements.
.PP
Array slice assignments should be used rather than loops to copy all
or part of an array.  This is more readable and less error
prone, especially in the case of slices with overlapping ranges.
.ASIS
   Client__List (Last__Client .. Number__Of__Clients)
     := New__Clients (1 .. Num__New__Clients);
.ENDASIS
.S4 If statements.
An "if" statement should not be used to create the effect
of a "case" statement controlled by the value of an enumeration type
other than BOOLEAN.
.S4 Case statements.
.PP
a. A "case" statement should not be controlled by a BOOLEAN value.
.PP
b. When possible, the explicit listing of all choices on a "case"
statement is preferable to the use of an "others" clause.
.EXP
This makes it easier for a human reader to see that the proper actions
are being taken in all cases.  Further, if the enumeration type of the control
expression is modified, the compiler will indicate overlooked
alternatives.  However, there are cases when an "others" clause
makes sense.  For example, if the control expression is of type
CHARACTER, then is is usually best to use an "others" clause to handle
the "undesired characters" case.
.S4 Block statements.
.PP
a. Blocks should be used cautiously to introduce local declarations or to
define a local exception handler.
.EXP
To some extent, a block can be thought of as a procedure which is hard
coded in-line.  However, a procedure call contributes to readability precisely
by not having its source code in-line (providing a "functional
abstraction").
Therefore, blocks should always be used cautiously and only for specific
purposes.  Thought should always be given to using a procedure call instead
of a block to improve readability.
.PP
b. Declarations of objects used only within a block should be nested
within the block.
.S4 Exit statements.
"Exit" statements should be used cautiously, and only when they
significantly enhance the readability of the code.
.EXP
It is often more readable to use exit than to try to add BOOLEAN
variables to a "while" loop condition to simulate exits from the middle
of the loop.  However, it can be difficult to understand a program
where loops can be exited from multiple places.  It is best to limit the
use of "exit" statements to one per loop, if possible, and it is
generally more readable to use "exit when."  Use
"if ... then ... exit; end if;"
when "last wishes" processing is needed.
.S4 Return statements.
It is preferable to minimize the number of return points from a subprogram,
as long as this does not distract from the natural structure or
readability of the subprogram.
.S4 Goto statements.
Neither "goto" statements nor labels should ever be used.
.EXP
Use of the "goto" makes the textual structure of code less reflective of its
logical structure.  Possible uses of the "goto" statement can always be handled
by other constructs in Ada.  Cases in Ada when the "goto" still seems
appropriate almost always indicate poorly designed code.  It is better
to redesign the code than to use the "goto" statement.
.S3 Formatting of statements.
.S4 Statement sequences.
Blank lines should be used liberally to break
sequences of statements into short, meaningful groups (see paragraph 5.2.2.6).
.ASIS
   Put__Line ("Welcome to the Electronic Message System");

   Logon__User(Current__User);
   User__Directory.Lookup
     ( User__Name => Current__User,
       Authority => User__Authority );

   if User__Authority = SPECIAL then
     Put__Line ("** You have SPECIAL authorization **");
   end if;
.ENDASIS
.S4 If statement format.
.PP
a. "If" statements should have the following format:
.ASIS
   if  then
     
     
   elsif  then
     
     
   else
     
     
   end if;
.ENDASIS
.PP
b. Multiple conditions in an "if" clause should be grouped together,
placed on appropriate lines, and aligned so as to enhance clarity.
.S4 Case statement format.
"Case" statements should have the following format:
.ASIS
   case  is
     when  =>
       
       
     when others =>
       
       
   end case;
.ENDASIS
.S4 Loop statement format.
.PP
a. "Loop" statements should have one of the following formats:
.ASIS
   :
    loop
     
     
   end loop ;

    loop
     
     
   end loop;
.ENDASIS
.PP
b. A loop should preferably have a loop identifier.
.S4 Block statement format.
.PP
a. Block statements should have the following format:
.ASIS
   :
   declare
     
     
   begin
     
     
   exception
     when  =>
       
       
   end ;
.ENDASIS
.PP
b. Blocks should always have a block identifier.
.S3 Examples for statements.
.EXP
See also examples 5.9.4.2, 5.9.4.3, 5.9.4.4, 5.14.3.1, and 5.14.3.2.
.S4 Example 5X1.
.ASIS
   if Security__Level = 0 then
     Message__Classification := UNCLASSIFIED;

   elsif Security__Level > User__Clearance then
     Message__Classification := PROTECTED;

   else
     Message__Classification := Classification (Security__Level);

   end if;
.ENDASIS
.S4 Example 5X2.
.ASIS
   case Sensor is
     when ELEVATION =>
       Record__Elevation (Sensor__Value);
     when AZIMUTH =>
       Record__Azimuth (Sensor__Value);
     when DISTANCE =>
       Record__Distance (Sensor__Value);
   end case;
.ENDASIS
.S4 Example 5X3.
.ASIS
   Read__File:
   loop

     Text__IO.Get(File1, Next__Record);
     Store__Record(Next__Record);

     exit when Text__IO.End__Of__File(File1);

   end loop Read__File;
.ENDASIS
.ASIS
   Compute__Total__Taxes:
   while Next /= Head loop

     Total__Taxes := Total__Taxes + Next.Pay__Period__Deductions;
     Next := Next.Successor;

   end loop Compute__Total__Taxes;
.ENDASIS
.ASIS
   Merge__Files:
   for N in 1 .. Max__Num__Files loop

     Get__Items:
     for J in 1 .. Max__Num__Items loop

       Get__New__Item(New__Item);
       Merge__Item(New__Item, Storage__File);

       exit Merge__Files when New__Item = Terminal__Item;

     end loop Get__Items;

   end loop Merge__Files;
.ENDASIS
.S4 Example 5X4.
.ASIS
   Swap__Integers:
   declare

     Temp
       : constant INTEGER := 0;

   begin -- Swap__Integers

     U := V;
     V := Temp;

   end Swap__Integers;
.ENDASIS
.ASIS
   Check__Entry:
   begin

     Int__IO.Get(Value);
     Update(Value);

   exception

     when Data__Error =>
       Text__IO.New__Line;
       Text__IO.Put__Line("Value entry error.");
       Entry__Error__Flag := TRUE;

   end Check__Entry;
.ENDASIS
.S2 Subprograms
.S3 Cohesion.
.PP
A subprogram should perform a single, conceptual action (i.e.,
should be "functionally cohesive").
.EXP
The use of a subprogram increases readability by hiding the details of how an
action is performed and giving it a descriptive name.  A subprogram should
perform only a single conceptual action so that its use can be
understood as independently as possible from its implementation details
and it can be given a self-documenting name.  Note that simply
shortening a program by placing "repeated code" into subprograms must be
considered a secondary goal.  Thus, it is quite acceptable to have
subprograms which are only called at one place, so long as those
programs define cohesive actions.
.S3 Parameters.
.PP
a. Subprograms with equivalent parameters should generally declare each
parameter in the same position with the same identifier.
.PP
b. Parameters with default expressions should usually be used only when
they have very well known default values and/or they are defaulted most of the
time and the default is only over-ridden in special circumstances.
.PP
c. Parameters with default expressions should generally be placed at the
end of the parameter list, so that they may be omitted if desired in calls
using positional notation.
.S4 Recursion.
A recursive subprogram should generally be used only if it
is conceptually simpler for a given problem than a corresponding
iterative subprogram.
.EXP
Many people have difficulty in understanding a program which uses
recursion extensively.  However, there are many cases where a recursive
solution is considerably simpler and clearer than an iterative one.
This is especially true, for example, for traversing
complicated data structures such as tree and graph structures.
.S4 Functions.
A subprogram without side-effects returning a single value should
generally be written as a function.
.EXP
Since functions can be called from within expressions, there is more
freedom in how a function can be used.  For example, if a function is to be
called only once within some other subprogram, it can be used to initialize a
constant object.
.ASIS
   procedure Process__Sensor__Data is

     Main__Sensor__Data
       : constant SENSOR__DATA
         := Read__Sensor (Main__Sensor__Index);

   begin
     ...
.ENDASIS
.EXP
However, if this sort of freedom is specifically not desired, or if the
subprogram has side effects, then use of a procedure should be considered
instead of a function, even if the subprogram returns only a single value.
.S4 Overloading.
.PP
a. Overloading of subprograms should not be used except in the following
cases:
.LIST
.LE
Widely used utility subprograms which perform identical or very
similar actions on arguments of different types (e.g., square-root of
integer and real arguments).
.LE
Overloading of operator symbols.
.EXP
Note that this is not meant to cover subprograms with identical names in
different packages, unless both subprograms are visible through "use"
clauses for their packages.
.PP
b. Operator symbols should be overloaded only when the new operator
definitions comply closely with the traditional meaning of the operator
(e.g., "+" for vector addition).
.S3 Formatting of subprograms.
.S4 Subprogram names.
.PP
a. Except as indicated below, a subprogram name should be an imperative
verb phrase describing its action.
.ASIS
   Obtain__Next__Token
   Increment__Line__Counter
   Create__New__Group
.ENDASIS
.PP
b. Non-BOOLEAN valued function names may also be noun phrases.
.ASIS
   Top__Of__Stack
   X__Component
   Successor
   Sensor__Reading
.ENDASIS
.PP
c. BOOLEAN valued functions should have predicate-clause names.
.ASIS
   Stack__Is__Empty
   Last__Item
   Device__Not__Ready
.ENDASIS
.S4 Subprogram header.
Each subprogram specification, body or stub should be preceded by a header
comment block containing at least the subprogram name and the indication
SPEC, BODY, SPEC _& BODY, STUB or SUBUNIT.
.ASIS
   -- .......................
   -- .                     .
   -- .  Obtain__Next__Token  .  SPEC
   -- .                     .
   -- .......................
.ENDASIS
.S4 Subprogram declarations.
.PP
a. Procedure declarations should have the following format:
.ASIS
   procedure 
     ( ;
        );

   --| 
.ENDASIS
.EXP
Each  should be formatted like an object declaration
(see paragraph 5.3.8.4).  The documentary comments should follow guideline d.,
below.
.PP
b. Function declarations should have the following format:
.ASIS
   function 
     ( ;
        )
     return ;

   --| 
.ENDASIS
.EXP
Each  should be formatted like an object
declaration (see paragraph 5.3.8.4).  The  should
follow guideline d., below.
.PP
c. Parameter mode indications should always be used in procedure
specifications.  In a function specification, mode indications should either
be used for all of the parameters or none of the parameters.
.PP
d. Subprogram declarations should be followed by at least the following
documentation:
.ASIS
   --| Purpose
   --| A description of all purposes and functions of the subprogram.
   --|
   --| Exceptions
   --| A list of all exceptions which may propagate out of the
   --| subprogram, and a description of when each would be raised.
   --|
   --| Notes
   --| Additional comments on the use of the subprogram.
.ENDASIS
.EXP
The "Exceptions" and "Notes" headings should be included even if these
sections are empty.  An empty section may be indicated by placing the
annotation "(none)" after the appropriate header.  Only in the case
that the subprogram declaration is a compilation unit, the following
section should be added to the documentation:
.ASIS
   --|
   --| Modifications
   --| A list of modifications made to the subprogram DECLARATION.
   --| Each entry in the list should include the date of the change,
   --| the name of the person who made the change and a description
   --| of the modification.  The first entry in the list should
   --| always be the initial coding of the subprogram declaration.
.ENDASIS
.S4 Subprogram bodies and stubs.
.PP
a. Subprogram bodies should have the following format:
.ASIS
   separate ()
    is

   --| 

     
     

   begin -- 

     
     

   exception
     when  =>
       

   end ;
.ENDASIS
.EXP
The  should be formatted as in a subprogram
declaration (see paragraph 5.6.3.3).  The 
should follow guideline b., below.  Note that the "end" of a subprogram should
always include the subprogram name.
.PP
b.  Subprogram bodies should have AT LEAST the following documentation
placed immediately after the subprogram header:
.ASIS
   --| Notes
   --| Comments on the design, implementation and use of the
   --| subprogram.
.ENDASIS
.EXP
The "Notes" heading should be included even if the section is empty.
An empty section may be indicated by the comment "Notes (none)."
Only in the case of a subprogram body which is a compilation unit, the following
section should be added to the documentation.
.ASIS
   --|
   --| Modifications
   --| A list of modifications made to the subprogram BODY.
   --| Each entry in the list should include the date of the change,
   --| the name of the person who made the change and a description
   --| of the modification.  The description should identify exactly
   --| where in the compilation unit the change was made.  The
   --| first entry in the list should always be the initial coding
   --| of the subprogram body.
.ENDASIS
.EXP
If there is no declaration or stub for a subprogram, then the subprogram body
should also include all the documentation required for a subprogram
declaration (see paragraph 5.6.3.3).
.PP
c. Subprogram stubs should have the following format:
.ASIS
    is separate;
.ENDASIS
.EXP
where the  is formatted as in a subprogram
declaration (see paragraph 5.6.3.3).  If there is no previous
declaration for a separate subprogram, then the subprogram stub should be
followed by the same documentary comments required for a subprogram
declaration (see paragraph 5.6.3.3).
.S4 Named parameter association.
.PP
a. Named parameter association should generally be used for procedure
calls of more than a single parameter.  Positional parameters are
generally preferred for function calls.
.PP
b. Named and positional parameter associations should generally not be
mixed in a single subprogram call.
.PP
c. Named parameter associations should generally appear one to a line with
formal parameters, "=>" symbols and actual parameters aligned.
.ASIS
   Obtain__Next__Token
     ( File     => Current__Source__File,
       Position => Current__Column,
       Token    => Next__Token );
.ENDASIS
.S3 Examples for subprograms.
.PP
See also examples 5.7.4.3, 5.9.4.3, 5.12.4.1, 5.12.4.3, 5.14.3.1, and 5.14.3.2.
.S4 Example 6X1.
.ASIS
   -- .......................
   -- .                     .
   -- .  Obtain__Next__Token  .  SPEC
   -- .                     .
   -- .......................

   procedure Obtain__Next__Token

     ( File                               -- Sequential text file.
        : in out Parser__Types.FILE;

      Token
        : out Parser__Types.TOKEN__TYPE;

      Position                            -- Column position of the
        : in Parser__Types.COL__NUM__TYPE    -- beginning of the next
          := 0 );                         -- token.

   --| Purpose
   --| This procedure scans the current input line from the point at
   --| which it was last called and returns the next token.
   --|
   --| Exceptions
   --| Source__File__Not__Open -- Raised if the input file is not open
   --|
   --| Notes (None)
.ENDASIS
.S4 Example 6X2.
.ASIS
   -- ..................
   -- .                .
   -- .  Decode__Token  .  SPEC
   -- .                .
   -- ..................

   function Decode__Token

     ( File                              -- Sequential text file
         : Parser__Types.FILE;

       Token
         : Parser__Types.TOKEN__TYPE )

     return Parser__Types.TOKEN__TYPE;

   --| Purpose
   --| This function returns the ordinal value of the decoded token.
   --|
   --| Exceptions
   --| Illegal__Token -- raised if the token is not legal
   --|
   --| Notes
   --| This function will later be changed to a procedure.
.ENDASIS
.S4 Example 6X3.
.ASIS
   -- .......................
   -- .                     .
   -- .  Obtain__Next__Token  .  STUB
   -- .                     .
   -- .......................


   procedure Obtain__Next__Token

     ( File                               -- Sequential text file.
        : in out Parser__Types.FILE;

      Token
        : out Parser__Types.TOKEN__TYPE;

      Position                            -- Column position of the
        : in Parser__Types.COL__NUM__TYPE    -- beginning of the next
          := 0 ) is separate;             -- token.
.ENDASIS
.S4 Example 6X4.
.ASIS
   -- ..................
   -- .                .
   -- .  Decode__Token  .  STUB
   -- .                .
   -- ..................

   function Decode__Token

     ( File
         : Parser__Types.FILE;

       Token
         : Parser__Types.TOKEN__TYPE )

     return Parser__Types.TOKEN__TYPE is separate;
.ENDASIS
.S4 Example 6X5.
.ASIS
   -- .......................
   -- .                     .
   -- .  Obtain__Next__Token  .  SUBUNIT
   -- .                     .
   -- .......................

   with Parser__Types,
        File__Handler;

   separate (Lexical__Analyzer)
   procedure Obtain__Next__Token

     ( File                               -- Sequential text file.
        : in out Parser__Types.FILE;

      Token
        : out Parser__Types.TOKEN__TYPE;

      Position                            -- Column position of the
        : in Parser__Types.COL__NUM__TYPE    -- beginning of the next
          := 0 ) is                       -- token.

   --| Notes (None)
   --|
   --| Modifications
   --| 7/4/85   Rebecca DeMornay  Initial version of the subunit
   --| 9/6/85   R. DeMornay       Added the local function
   --|                            "Increment__Line__Counter".

     type LINE__COUNT is                   -- A count of the number
       range 1 .. File__Handler.Max__Size;  -- of lines in a file.

     Line__Counter
       : LINE__COUNT := 1;

     -- ............................
     -- .                          .
     -- .  Increment__Line__Counter  .  SPEC _& BODY
     -- .                          .
     -- ............................

     function Increment__Line__Counter

       ( File                              -- Sequential text file
           : Parser__Types.FILE;

         Line                              -- Line number in "File"
           : LINE__COUNT )                  -- at the time of call

       return LINE__COUNT is

     --| Purpose
     --| This function increments the line counter from the point at
     --| which it was after the last call of this routine.
     --|
     --| Exceptions
     --| Source__File__Not__Open  -- Raised if "File" is not open.
     --| End__Of__File           -- Raised if the function is called and
     --|                          the end of the file has already been
     --|                          reached.
     --|
     --| Notes (None)

     begin  -- Increment__Line__Counter

       ...

     end Increment__Line__Counter;

   begin  -- Obtain__Next__Token

     ...

   exception

     when File__Handler.FILE__ERROR =>
       Token := Parser__Types.NONE;
       raise Source__File__Not__Open;

   end Obtain__Next__Token;
.ENDASIS
.S2 Packages
.S3 Use of packages.
.PP
a. A package should fulfill one or more of the following:
.LIST
.LE
Model an abstract entity (or data type) appropriate to the domain
of a problem.
.LE
Collect related type and object declarations which are used
together (this kind of package should generally be used only to provide
a common set of declarations for two or more library units).
.LE
To group together program units for essential configuration control
or visibility reasons (packages fulfilling this role alone should be used
sparingly).
.EXP
The roles above are listed in order of decreasing desirability.  The first
role, modeling a problem domain entity, is the strongest use of packages
for structuring a program.  It corresponds to the requirement of functional
cohesion for subprograms (see paragraph 5.6.1) and contributes to the goal
of making the structure of a program reflect the structure of its problem
domain.
.EXP
The second kind of package, collection of related declarations, should
generally be used only to provide a common set of declarations for two
or more library units.  Further, it is better to minimize the declaration of
variables in these packages.  Overuse of packages of variables results in a
FORTRAN COMMON block style program decomposition which defeats the
abstraction and information hiding properties of packages
(see paragraph 5.7.2.1).
.EXP
Finally, the last type of package, a grouping of units for configuration
reasons, should be used sparingly since it gives no additional information
to a human reader on the structure of the program.  This type of package
might, for example, be used to divide a large program at the top level
into subsystems to be developed by separate teams.  It would be best, however,
if these subsystem packages fulfilled, in addition, one of the other two
roles.
.PP
b. Packages should NOT be designed based on the procedural structure of
the code which calls them.
.EXP
For example, a group of procedures should not be packaged simply because
they are all called at system initialization, or because they are always
called in a certain sequence.  Such a package is closely coupled to the
context in which it is used and is not very understandable, reusable or
maintainable as a unit.
.PP
c. A logical hierarchy of packages should be used to reflect or model
levels of abstraction.
.S4 Nesting.
.PP
a. Nested package bodies should be separate subunits.
.PP
b. Subprogram bodies within a package should generally be separate subunits
(when this is possible).
.PP
c. Packages should generally not be nested within subprograms, except
within the main procedure.
.EXP
A possible exception to this recommendation is when a package has objects of
variable size which can be allocated when a procedure is called.  For example,
suppose some data processing uses a Buffer package which implements a buffer
area of a user-specified size:
.ASIS
   procedure Process__Data
     ( Buffer__Size : POSITIVE ) is

     package body Buffer is

       type BUFFER__TYPE is
         array (INTEGER range <>) of DATUM;

       Buffer__Area : BUFFER__TYPE (1 .. Buffer__Size);

       ...

     end Buffer;

   ...
.ENDASIS
.EXP
Note, however, that the nested package cannot be reused outside the context of
the procedure.  An alternative would be to allocate the buffer using an access
type.  This would require careful handling of allocation and deallocation, but
would result in a more self-contained package.
.PP
d. Nesting of a package specification inside another package
specification should generally be avoided.
.EXP
When a package provides a good abstraction, it hides the details of its
implementation.  Generally, nesting one package specification inside another
either exposes too much of the internal details of the outer package, or
indicates that the outer package does not provide a good abstraction in the
first place.  It is usually better to nest the package specification within
the body of the outer package.  Certain inner package operations can then be
called on by outer package operations which are at the appropriate level of
abstraction for the outer package.
.S3 Initialization.
.PP
Calls from the initialization section of a package to subprograms outside
the package should be avoided.
.S4 Visible variables.
.PP
a. Variable declarations in package specifications should be minimized.
.EXP
The use of variables in a package specification generally reduces the
abstraction and information hiding properties of the package.
For example, a variable cannot provide protection against being changed
by units other than the package.  Therefore it is generally better
to use a function rather than a variable to read data from a package.
It is also generally better to use a procedure rather
than a variable to give data to a package, since a variable cannot trigger
any package operations and a variable declaration often exposes some
internal data representation details of the package.
.PP
b. The private part of a package specification should only be used to
supply the full definitions of private types and deferred constants; all
other declarations should be put in the package body.
.PP
c. Objects of a private type should be initialized by default, if possible.
.S3 Formatting of packages.
.S4 Package names.
A package name should be a noun phrase describing the abstract
entity modeled by the package, or simply whatever is being packaged.
.ASIS
   Stack__Handler
   Vehicle__Controller
   Terminal__Operations
   Parser__Types
   Utilities__Package
.ENDASIS
.S4 Package header.
Each package specification, body or stub should be preceded by a
header comment block containing at least the package name and the
indication SPEC, BODY, STUB or SUBUNIT.
.ASIS
   -- **********************
   -- *                    *
   -- *  Lexical__Analyzer  *  SPEC
   -- *                    *
   -- **********************
.ENDASIS
.S4 Package specifications.
.PP
a. Package specifications should have the following format:
.ASIS
   package  is

   --| 

     
     

   private  -- 

     
     

   end ;
.ENDASIS
.EXP
The  should follow guideline b., below.  Note that the
 should always be repeated at the "end" of the package
specification.
.PP
b. A package specification should include AT LEAST the following
documentation immediately after the package header:
.ASIS
   --| Purpose
   --| A description of the purpose and function of the package.
   --|
   --| Initialization Exceptions
   --| A list of all exceptions which may propagate out of the
   --| package INITIALIZATION PART and a description of when each
   --| would be raised.
   --|
   --| Notes
   --| Additional comments on the use of the package.
.ENDASIS
.EXP
The "Initialization Exceptions" and "Notes" headers should be included even if
these sections are empty.  An empty section may be indicated by placing the
annotation "(none)" after the appropriate header.  Only in the case of a
package specification which is a compilation unit, the following section should
be added to the documentation:
.ASIS
   --|
   --| Modifications
   --| A list of modifications made to the package SPECIFICATION.
   --| Each entry in the list should include the date of the change,
   --| the name of the person who made the change and a description
   --| of the modification.  The description should indicate exactly
   --| where in the compilation unit that the change was made.  The
   --| first entry in the list should always be the initial coding of
   --| the package specification.
.ENDASIS
.PP
c. In a declarative part, all package specifications should appear before
any package or task bodies.
.S4 Package bodies and stubs.
.PP
a. Package bodies should have the following format:
.ASIS
   separate ()
   package body  is

   --| 

     
     

   begin  -- 

     
     

   exception
     when  =>
       

   end ;
.ENDASIS
.EXP
The  should follow guideline b., below.  Note that the
 should always be repeated at the "end" of the package
body.
.PP
b. A package body should have at least the following documentation placed
immediately after the package header:
.ASIS
   --| Notes
   --| Comments on the design, implementation and use of the
   --| package.
.ENDASIS
.EXP
The "Notes" header should be included even if the section is empty.  An empty
section may be indicated by the comment "Notes (none)."  Only in the case of a
package specification which is a compilation unit, the following section should
be added to the documentation:
.ASIS
   --|
   --| Modifications
   --| A list of modifications made to the package BODY.  Each
   --| entry in the list should include the date of the change,
   --| the name of the person who made the change and a
   --| description of the modification.  The description should
   --| indicate exactly where in the compilation unit that the
   --| change was made.  The first entry in the list should always
   --| be the initial coding of the package body.
.ENDASIS
.PP
c. Package stubs should have the following format:
.ASIS
   package body  is separate;
.ENDASIS
.S3 Examples for packages.
.PP
See also example 5.12.4.3.
.S4 Example 7X1.
.ASIS
   -- **********************
   -- *                    *
   -- *  Lexical__Analyzer  *  SPEC
   -- *                    *
   -- **********************

   with Basic__Types,
        Parser__Types;

   package Lexical__Analyzer is

   --| Purpose
   --| The routines in this package read the source program, one
   --| character at a time, to generate a stream of tokens.  As each
   --| token is produced it is passed to the package "Parser."  The
   --| legal tokens are defined in the Language Reference Manual.
   --|
   --| Initialization Exceptions
   --| Diana__File__Non__Existent  -- Raised if the file "DIANA.ADA"
   --|                             does not exist
   --|
   --| Notes
   --| Tokens are limited to 32 characters in length.  Also, only
   --| sequential text files can be operated on by the parser.
   --|
   --| Modifications
   --| 6/14/85  Rebecca DeMornay  Initial version of spec
   --| 8/26/87  C. Royale         Added "Decode__Token" function.

     Diana__File__Non__Existent
       : exception;

     Source__File__Not__Open
       : exception;

     Illegal__Token
       : exception;

     -- .......................
     -- .                     .
     -- .  Obtain__Next__Token  .  SPEC
     -- .                     .
     -- .......................

     procedure Obtain__Next__Token

       (
         ...
              );

     ...

     -- ..................
     -- .                .
     -- .  Decode__Token  .  SPEC
     -- .                .
     -- ..................

     function Decode__Token

       (
         ...
              )

       return Parser__Types.TOKEN__VALUE__TYPE;

     ...

   end Lexical__Analyzer;
.ENDASIS
.S4 Example 7X2.
.ASIS
   -- **********************
   -- *                    *
   -- *  Lexical__Analyzer  *  BODY
   -- *                    *
   -- **********************

   with Text__IO,
        File__Handler;

   package body Lexical__Analyzer is

   --| Notes
   --| The package "Lexical__Analyzer" will later be changed to a task,
   --| so that the "Parser" task (now a package) can make an entry
   --| call to "Lexical__Analyzer" when it needs the next token.
   --|
   --| Modifications
   --| 6/14/85  Charity Royale    Initial version of body.
   --| 8/26/85  Charity Royale    Added "Decode__Token" function.
   --|                            Added instantiation of "Enumeration__IO."

     -- *************
     -- *           *
     -- *  Char__IO  *  SPEC
     -- *           *
     -- *************

     package Char__IO is
       next Text__IO.Enumeration__IO (Enum => Character);

     --| Purpose
     --| Used to read the input text file character by character.
     --|
     --| Initialization Exceptions (none)
     --| Notes (none)

     -- .......................
     -- .                     .
     -- .  Obtain__Next__Token  .  STUB
     -- .                     .
     -- .......................

     procedure Obtain__Next__Token

       (
         ...
              ) is separate;

     -- ..................
     -- .                .
     -- .  Decode__Token  .  STUB
     -- .                .
     -- ..................

     function Decode__Token

       (
         ...
              )

       return Parser__Types.TOKEN__VALUE__TYPE is separate;

     ...

   begin  -- Lexical__Analyzer

     ...

   exception

     when File__Handler.File__Error =>
       raise Diana__File__Non__Existent;

   end Lexical__Analyzer;
.ENDASIS
.S4 Example 7X3.
.ASIS
   -- **********
   -- *        *
   -- *  Disk  *  SPEC
   -- *        *
   -- **********

   generic

     type SPECIFIC__DATA__TYPE is  -- The type of data to be
       ( <> );                   -- stored on disk

   package Disk is

   --| Purpose
   --| This package defines an abstract data type to simplify
   --| the I/O interface to disk files.
   --|
   --| Initialization Exceptions (none)
   --| Notes (none)
   --| Modifications
   --| 9/10/86  Ada Users Group   Initial version

     type FILE__TYPE is
       private;

     End__Of__File
       : exception;

     Open__Error
       : exception;

     Mode__Error
       : exception;

     subtype FILE__MODE is
       (IN__FILE, OUT__FILE);

     -- ............
     -- .          .
     -- .  Create  . SPEC
     -- .          .
     -- ............

     function Create

       ( Name
           : STRING;

         Mode
           : FILE__MODE := IN__FILE )

       return FILE__TYPE;

     --| Purpose
     --| This function creates a FILE__TYPE data object to
     --| represent the disk file with the given name and mode.
     --|
     --| Exceptions (none)
     --| Notes
     --| This function does not actually open the file.

     -- ............
     -- .          .
     -- .  Close   . SPEC
     -- .          .
     -- ............

     procedure Close

       ( Disk__File
           : in out FILE__TYPE );

     --| Purpose
     --| This procedure closes a disk file if it is open.  If
     --| the file is already closed it has no effect.
     --|
     --| Exceptions (none)
     --| Notes (none)

     -- ............
     -- .          .
     -- .  Read    . SPEC
     -- .          .
     -- ............

     procedure Read

       ( Disk__File
           : in out FILE__TYPE;

         Data
           : out SPECIFIC__DATA__TYPE );

     --| Purpose
     --| This procedure reads the next record from a file,
     --| opening the file if necessary.
     --|
     --| Exceptions
     --| End__Of__File - raised if no more elements can be
     --|               read from the file
     --| Open__Error  - if the file cannot be opened
     --| Mode__Error  - if the file mode if not IN__FILE
     --|
     --| Notes (none)

     -- ............
     -- .          .
     -- .  Write   . SPEC
     -- .          .
     -- ............

     procedure Write

       ( Disk__File
           : in out FILE__TYPE;

         Data
           : in SPECIFIC__DATA__TYPE );

     --| Purpose
     --| This function writes a record to a file,
     --| opening the file if necessary.
     --|
     --| Exceptions
     --| Open__Error  - if the file cannot be opened
     --| Mode__Error  - if the file mode if not OUT__FILE
     --|
     --| Notes (none)

     private  -- Disk

       -- *************
       -- *           *
       -- *  Disk__IO  *  SPEC
       -- *           *
       -- *************

       package Disk_IO is
         new Sequential__IO (SPECIFIC__DATA__TYPE);

       --| Purpose
       --| This package provides the basis for the representation
       --| of disk files.
       --|
       --| Initialization Exceptions (none)
       --| Notes (none)

         File__Name__Length
           : constant := 40;

         type FILE__TYPE is
           record
             File__Name
               : STRING(1..File__Name__Length) := (others => ' ');
             File
               : Disk__IO.FILE__TYPE;
             Mode
               : FILE__MODE := Disk__IO.IN__FILE;
           end record;

     end Disk;
.ENDASIS
.S2 Visibility
.S3 Scope of identifiers.
.PP
The scope of identifiers should not extend further
than necessary.  Where a scope is extended by "with" clauses, these clauses
should cover as small a region of text as possible.
.EXP
For example, "with" clauses should be placed only on the subunits that really
need them, not on their parents.  This promotes information hiding and reduces
coupling.  It can also result in faster recompilation (due to the dependency
rules).
.S4 The package STANDARD and WITH clauses.
The package STANDARD should not be named in a "with" clause.
.S3 The use clause.
.PP
The "use" clause should be used only in the following cases:
.PP
a. For packages of commonly known utility operations used throughout a
program (e.g., MATHLIB).
.PP
b. To make overloaded operators visible, so that they may be used in infix
notation.
.PP
c. For predefined input/output packages (e.g., Text__IO, instantiations of
Integer__IO, etc.).
.PP
d. To make enumeration constants visible so that they can be named without
using the dot notation.
.EXP
Note that even when a "use" clause is used, the dot notation should still be
used in cases other than those listed above.
.S4 Renaming declarations.
.PP
a. For a name with a large number of package qualifications, a renaming
declaration may be used to define a new shorter name.  The new identifier
should still reflect the complete meaning of the full name.
.PP
b. For a function which can be appropriately represented by an operator
symbol name, a renaming declaration may be used to give it such a name.
.EXP
For example, a Matrix__Multiply function could be renamed "*".
.S4 Redefinition.
.PP
a. Items from the package STANDARD should not be redefined or renamed.
.PP
b. Redefinition of an identifier in different declarations should be
avoided.
.S2 Tasks
.S3 Use of tasks.
.PP
A task should fulfill one or more of the following:
.PP
a. Model a concurrent abstract entity appropriate to the problem domain.
.PP
b. Serve as an access-controlling or synchronizing agent for the other
tasks, or otherwise act as an interface between asynchronous tasks.
.PP
c. Serve as an interface to asynchronous entities external to the program
(e.g., asynchronous I/O, devices, interrupts, etc.).
.PP
d. Define concurrent algorithms for faster execution on multiprocessor
architectures.
.PP
e. Perform an activity which must wait a specified time for an event or
have a specific priority.
.EXP
Just as for packages (paragraph 5.7.1), it is best to have tasks which model
problem domain entities.  However, in the case of tasks, it is also necessary
to have some tasks which solely provide interfaces between other tasks and which
handle the other issues of concurrency and parallelism mentioned above.
The program should generally be structured, however, around the tasks
which represent problem-domain entities.
.S4 Nesting of tasks.
.PP
a. Tasks should generally not be nested within tasks or subprograms, except for
the main procedure.
.EXP
Note that a subprogram containing a task cannot return until the task has
terminated.
.PP
b. Nested task bodies should be separate subunits, unless they are quite
small.
.S4 Visibility of tasks.
.PP
a. When only certain entries of a task are intended to be called by program
components outside an enclosing package, it is generally preferable to hide
the task specification in the package body, introducing package procedures
which in turn call the actual entries.
.PP
b. This helps to promote information hiding and strengthens the abstraction
of the enclosing package (see paragraph 5.7.1.1.d).  It also hides the use of
tasking within the package.  Note, however, that special care must be taken if
the task entries are to be called using conditional or timed entry calls.
In this case, either the outer package must provide special procedures or
procedure parameters or this guideline should not be followed.
.S3 Task types.
.PP
a. A task type should be used only when multiple instances of that type are
required.  Otherwise, a directly named task should be used.
.PP
b. Identical tasks should be derived from a common task type.
.PP
c. Static task structures should be used whenever they are sufficient.
Access types to task type should be used only when it is essential to create
and destroy tasks dynamically, or to be able to change the names with which they
are associated.
.S4 Task termination.
.PP
a. A task nested within the main program must terminate by reaching its
"end," or must have a selective wait with a terminate alternative.
.EXP
All tasks nested within a program must terminate before the program can
terminate.  Therefore, if this guideline is not followed, it will be
impossible for the main program to ever terminate other than by aborting
all nested tasks.  However, "abort" statements are to be avoided
(see paragraph 5.9.2.6).
.PP
b. Tasks dependent on library units should not use the "terminate" alternative
of a select statement.  Therefore, other provisions should be made for the
graceful termination of such tasks at system close down.
.EXP
Tasks which are dependent on library units will not terminate due to a
"terminate" alternative.  Therefore, a library unit task should have an
entry which forces termination.  If it does not, an "abort" statement in the
main program may be used to terminate the task.  However, "abort" statements
are to be avoided (see paragraph 5.9.2.6).
.S4 Entries and accept statements.
.PP
a. Only those actions should be included in the "accept" statement which
must be completed before the calling task is released from its waiting state.
.PP
b. A task should never call its own entries, even by indirection.  This
would result in a deadlock.
.PP
c. Conditional entry calls should be used sparingly to avoid unnecessary
busy waiting.
.S4 Delay statement.
.PP
a. A "delay" statement should be used whenever a task must wait for some
known duration.  A "busy wait" loop should never be used for this purpose.
.EXP
It is important to remember that "delay t" provides a delay of at least t
seconds, but possibly more.  A program should not rely on any upper bound
for this delay, especially when tasks are used (since tasks must compete
for CPU time).  The following example shows how to alleviate this problem
in a periodic activity:
.ASIS
   ...
   Next__Time := Calendar.Clock + Required__Period;

   Periodic__Activity:
   while Still__Time loop

     -- Perform activity
     ...

     -- Correct for delay statement incertitude

     Period := Next__Time - Calendar.Clock;

     if Period < 0.0 then           -- Processing was too slow
       Next__Time := Calendar.Clock; -- Avoid cumulative effect
     end if;
     Next__Time := Next__Time + Required__Period;

     delay Period;

   end loop Periodic__Activity;
.ENDASIS
.PP
b. The "delay" statement should normally only be used to manage interaction
with some external process which works in real time, or to create a task
which behaves in a well-defined manner in real time.
.S4 Task synchronization.
Knowledge of the execution pattern of tasks (e.g., fixed, known time pattern,
etc.) should not be used to avoid the use of explicit task synchronization.
.S4 Priorities.
.PP
a. Only a small number of priority levels should be used.  The priority
levels used should be spread over the range made available to type
PRIORITY in the implementation.  Names should be given to the priority
levels by declaring constants of predefined type PRIORITY and grouping these
declarations into a single package.
.EXP
Using only a small number of priority levels makes the interaction of the
various prioritized tasks easier to understand.  On the other hand,
spreading the levels across the available range allows easy insertion
of a new level between existing levels if this later becomes necessary.
As with other literal numbers, the use of names is more readable than the use
of the literals.  Further, for priorities, the allowable range of levels is
implementation dependent.  Naming priority levels by constant declarations
grouped into a single package restricts the implementation dependency to that
package.  For example:
.ASIS
   with System;
   package Priority__Levels is

     Lowest
       : constant System.PRIORITY := System.PRIORITY'first;
     Highest
       : constant System.PRIORITY := System.PRIORITY'last;
     Number
       : constant := Highest - Lowest + 1;
     Average
       : constant System.PRIORITY := Number / 2;

     Idle
       : constant System.PRIORITY := Lowest;
     Background
       : constant System.PRIORITY := Average - 20;
     User
       : constant System.PRIORITY := Average - 10;
     Foreground
       : constant System.PRIORITY := Average + 10;

   end Priority__Levels;
.ENDASIS
.PP
b. For any group of related tasks, such as those declared within the same
program unit, priorities should be specified either for all, or for none of
them.
.EXP
This avoids confusion about the scheduling of tasks with undefined
priorities.
.S4 Abort statements.
Abortion of tasks should generally be avoided.
.EXP
Aborting a task can produce unpredictable results.  In particular, do not
assume anything about the moment at which an aborted task becomes terminated.
The "abort" statement should generally be used only in case of unrecoverable
failure.
.S4 Shared variables.
.PP
a. Tasks should not directly share variables unless only one of them can
possibly be running at any one time.
.PP
b. Any task which uses shared variables should identify in its documentary
comments all the shared variables that it uses.
.S4 Local exception handling.
To allow the handling of local exceptions without task termination,
a task should generally have a block statement with an exception
handler coded within its main loop.
.ASIS
   begin -- Some__Task

     Main__Loop:
     loop

       Local:
       begin

         -- Task code
         ...

       exception -- Local
         ... handle local exceptions ...

       end Local;

     end Main__Loop;

   exception
     ... handle fatal exceptions ...

   end Some__Task;
.ENDASIS
.S3 Formatting of tasks.
.S4 Task and entry names.
.PP
a. A task name should be a noun phrase describing the task function or
abstract entity modeled by the task.
.ASIS
   Sensor__Interface
   Status__Monitor
   Event__Handler
   Message__Buffer
.ENDASIS
.PP
b. Entry names should follow the same guidelines as for procedure names
(see paragraph 5.6.3.1).
.S4 Task and entry headers.
Each task or task type specification or body and each entry specification
should be preceded by a header comment block containing at least the unit
name and the indication SPEC, BODY or STUB.
.ASIS
   -- ************
   -- *          *
   -- *  Buffer  *  SPEC
   -- *          *
   -- ************
   task Buffer is

     -- ..........
     -- .        .
     -- .  Read  .  SPEC
     -- .        .
     -- ..........
     entry Read;

   end Buffer;
.ENDASIS
.S4 Task specifications.
.PP
a. Task specifications should have the following format:
.ASIS
   task  is

   --| 

     
     

   end ;
.ENDASIS
.EXP
The  should be AT LEAST as required for a procedure
declaration (see paragraph 5.6.3.3), except for the "Exceptions" section.
Note that the  should always be repeated at the "end"
of the task specification.
.PP
b. A task type specification should be formatted the same as a task
specification, with the exception of including "task type" in the header.
.PP
c. Entry declarations should have the following format:
.ASIS
   entry  ()
     ( ;
        );

   --| 
.ENDASIS
.EXP
Each  should be formatted like an object
declaration (see paragraph 5.3.8.4).  The 
should be AT LEAST as required for a procedure declaration (see paragraph
5.6.3.3).
.PP
d. Parameter mode indications should always be used in entry declarations.
.PP
e. In a declarative part, all task specifications should appear before any
task or package bodies.
.S4 Task bodies and stubs.
.PP
a. Task bodies should have the following format:
.ASIS
   separate ()
   task body  is

   --| 

     
     

   begin -- 

     
     

   exception
     when  =>
       

   end ;
.ENDASIS
.PP
b. The  should be AT LEAST as required for a procedure
body (see paragraph 5.6.3.4).  Note that the  should
always be repeated at the "end" of the task body.
.PP
c. Task stubs should have the following format:
.ASIS
   task body  is separate;
.ENDASIS
.S4 Accept statements.
.PP
a. "Accept" statements should have one of the following formats:
.ASIS
   accept  ();

   accept  ()
     ( ;
        )
   do
     
     
   end ;
.ENDASIS
.EXP
Each  should be formatted like an object
declaration (see paragraph 5.3.8.4).  Note that the 
should always be repeated at the "end" of the "accept" (if there is an
"end").
.PP
b. Parameter mode indications should always be used in accept statements.
.S4 Select statements.
.PP
a. Selective wait statements should have the following format:
.ASIS
   select
     
     
   or
     
     
   or
     when  =>
       
       
   end select;
.ENDASIS
.EXP
This format is consistent with the indentation style of other statements.
In addition, the added level of indentation especially highlights guarded
sections of code.
.PP
b. Conditional and timed entry calls should have the following formats:
.ASIS
   select
     
     
   else
     
     
   end select;
.ENDASIS
.S4 Pragma priority.
The priority pragma should appear in task specifications before any entry
declarations, and in the main program before any declarations.
.S3 Examples for tasks.
.S4 Example 9X1.
.ASIS
   -- ************
   -- *          *
   -- *  Buffer  *  SPEC
   -- *          *
   -- ************
   task Buffer is

   --| Purpose
   --| This task provides a character buffer to smooth variations
   --| between the speed of output of a producing task and the speed
   --| of input of a consuming task.
   --|
   --| Exceptions (none)
   --| Notes (none)

     -- ..........
     -- .        .
     -- .  Read  .  SPEC
     -- .        .
     -- ..........

     entry Read
       ( Output : out Character );

     --| Purpose
     --| This entry reads a character from the buffer.
     --| If the buffer is empty, the entry will wait
     --| until a character is written into the buffer.
     --|
     --| Exceptions (none)
     --| Notes (none)

     -- ...........
     -- .         .
     -- .  Write  .  SPEC
     -- .         .
     -- ...........

     entry Write
       ( Input : in Character );

     --| Purpose
     --| This entry writes a character into the buffer.
     --| If the buffer is full the entry will wait
     --| until a character is read from the buffer.
     --|
     --| Exceptions (none)
     --| Notes (none)

   end Buffer;
.ENDASIS
.S4 Example 9X2.
.ASIS
   -- ************
   -- *          *
   -- *  Buffer  *  BODY
   -- *          *
   -- ************

   separate (Buffer__Package)
   task body Buffer is

   --| Notes
   --| This task contains an internal pool of characters processed
   --| in a round-robin fashion.
   --|
   --| Modifications
   --| 7/2/86  Fred Blah    Initial version.

     Pool__Size
       : constant := 100;

     subtype POOL__RANGE is
       INTEGER range 1..Pool__Size;

     type POOL__TYPE is
       array (POOL__RANGE) of CHARACTER;

     Pool
       : POOL__TYPE;

     Count                          -- The number of characters in
       : INTEGER range 0..Pool__Size -- the pool.
         := 0;

     In__Index                       -- The space for the next input
       : POOL__RANGE := 1;           -- character.

     Out__Index                      -- The space for the next output
       : POOL__RANGE := 1;           -- character.

   begin -- Buffer

     loop
       select
         when Count < Pool__Size =>
           accept Write
             ( Input : in Character )
           do
             Pool(In__Index) := Input;
           end Write;

           In__Index := In__Index mod Pool__Size + 1;
           Count := Count + 1;
       or
         when Count > 0 =>
           accept Read
             ( Output : out Character )
           do
             Output := Pool(Out__Index);
           end Read;

           Out__Index := Out__Index mod Pool__Size + 1;
           Count := Count - 1;
       or
         terminate;

       end select;

     end loop;

   end Buffer;
.ENDASIS
.S4 Example 9X3.
.ASIS
   -- ...............
   -- .             .
   -- .  Shellsort  .  BODY
   -- .             .
   -- ...............

   procedure Shellsort
     ( List                  -- This list will be sorted
         : in out ITEM__LIST; -- in place.
       Number__Of__Items
         : in NATURAL );

   --| Notes
   --| This sorting procedure implements the Shell sort by
   --| separating the n-sorts into multiple Ada tasks.
   --| This algorithm is designed for parallel processing
   --| of the tasks and is not necessarily an efficient
   --| method on a single processor.
   --|
   --| Modifications
   --| 9/5/86  A. Shell    Initial version
   --|

     Increment                -- Increment of an n-sort
       : NATURAL;

     Number__Of__Sorts          -- Number of paralleled sorts
       : NATURAL;             -- for a single pass

     Number__Of__Tasks
       : NATURAL;

     -- *****************
     -- *               *
     -- *  SORTER__TASK  *  SPEC
     -- *               *
     -- *****************

     task type SORTER__TASK is

     --| Purpose
     --| Tasks of this type perform the n-sort for the Shell sort.
     --|
     --| Notes
     --| A SORTER__TASK terminates itself when it is no longer
     --| needed for the sort.

       -- ..........
       -- .        .
       -- .  Sort  .  SPEC
       -- .        .
       -- ..........

       entry Sort
         ( First : in INTEGER;
           Step  : in NATURAL );

       --| Purpose
       --| This entry signals a sorter task to perform a new
       --| n-sort.  Elements are sorted in place in List,
       --| starting with the element at index First and
       --| including subsequent elements at the indicated Step.
       --|
       --| Exceptions (none)
       --| Notes (none)

     end SORTER__TASK;

     -- *****************
     -- *               *
     -- *  SORTER__TASK  *  STUB
     -- *               *
     -- *****************

     task body SORTER__TASK is separate;

     type SORTER__ARRAY is
       array (INTEGER range <>) of SORTER__TASK;

   begin -- Shellsort

     if Number__Of__Items < 2 then
       return;
     end if;

     -- Determine the first n-sort increment

     Increment := 1;

     while Increment < Number__Of__Items
       Increment := 3*Increment + 1;
     end loop;

     Increment := Increment / 3;
     if Increment < 1 then
       Increment := 1;
     end if;

     -- Determine the number of tasks required to perform
     -- the sort.

     if Number__Of__Items / Increment = 1 then
       Number__Of__Sorts := Number__Of__Items mode Increment;
       if Increment/3 > Number__Of__Sorts then
         Number__Of__Tasks := Increment / 3;
       else
         Number__Of__Tasks := Number__Of__Sorts;
       end if;

     else
       Number__Of__Sorts := Increment;
       Number__Of__Tasks := Number__Of__Sorts;

     end if;

     -- Perform the sort

     Task__Block:
     declare

       Sort__List
         : SORTER__ARRAY (1 .. Number__Of__Tasks);

     begin

       while Increment > 0 loop

         for K in 1 .. Number__Of__Sorts loop

           Sort__List(K).Sort
             ( First => List'first + K - 1,
               Step  => Increment );

         end loop;

         Increment := Increment / 3;
         Number__Of__Sorts := Increment;

       end loop;

     end Task__Block;

   end Shellsort;
.ENDASIS
.S4 Example 9X4.
.ASIS
   -- *****************
   -- *               *
   -- *  SORTER__TASK  *  SUBUNIT
   -- *               *
   -- *****************

   separate (Shellsort)
   task body SORTER__TASK is

   --| Notes
   --| This task body implements a task type.
   --|
   --| Modifications
   --| 9/5/86  A. Shell    Initial version

   -- Global variables
   -- List                -- An array of all items to be
   --                        sorted by Shellsort.
   -- Number__Of__Items     -- The number of items in the list.

     Start     : INTEGER;
     Increment : NATURAL;

     A         : INTEGER;
     B         : INTEGER;
     First__B   : INTEGER;

     Temp      : INTEGER;

   begin -- SORTER__TASK

     loop

       accept Sort
         ( First : in INTEGER;
           Step  : in NATURAL )
       do
         Start := First;
         Increment := Step;
       end Sort;

       First__B := Start + Increment;
       while First__B <= List'first + Number__Of__Items - 1 loop

         B := First__B;
         A := B - Increment;

         Find__Position:
         while A >= Start loop
           exit when not (List(A) > List(B));

           Temp := List(A);
           List(A) := List(B);
           List(B) := Temp;

           B := A;
           A := B - Increment;

         end loop Find__Position;

         First__B := First__B + Increment;

       end loop;

       -- Terminate if task is not needed for n-sort
       exit when Increment/3 < Start - List'first + 1;

     end loop;

   end SORTER__TASK;
.ENDASIS
.S2 Program structure and compilation issues
.S3 Program units.
.PP
a. Library units should be used in the following cases:
.LIST
.LE
To allow configuration control of the high level functional
subsystems of a program.
.LE
For general purposes, reusable program units.
.PP
b. Nested program units should be used in the following cases:
.LIST
.LE
To allow direct access to objects declared in an enclosing scope.
.LE
To increase the structural hiding of the internal implementation
details of an enclosing program unit.
.PP
c. Bodies of nested program units should be made separate unless they are
small enough to effect the readability of the enclosing unit.
.PP
d. Library units which are packages are generally preferable over library
units which are subprograms.  Library units providing services to the main
program should be packages.
.S4 WITH clauses.
.PP
a. No unit should have a "with" clause for a unit it does not need to see
directly.
.PP
b. If only a small part of a given unit needs access to a library unit,
then it should generally appear as a subunit and have its own
"with" clause for that library unit (see paragraph 5.8.1).
.S4 Program unit dependencies.
.PP
a. Excessive dependencies between compilation units should be avoided,
especially the use of complicated networks of "with" clauses.
.PP
b. It is preferable to limit program unit dependencies to a tree structure
whenever possible.
.S3 Compilation units.
.PP
Each compilation unit should be in a separate file,
except possibly in the case of a generic procedure specification and its body.
.S2 Exceptions
.S3 Exception propagation.
.PP
a. Exceptions propagated by a program unit should be considered part of the
abstraction or function represented by that unit.  Therefore, it should
generally only propagate exceptions which are appropriate to that level of
abstraction.  If necessary, an exception which cannot be handled by a unit
at one level of abstraction should be converted into an exception which can
be explicitly recognized by the next higher level.
.EXP
For example, a Stack package should provide a Stack__Full exception instead of
propagating a Constraint__Error.  Similarly, a Matrix__Inverse function should
raise a Matrix__Is__Singular exception rather than propagating Numeric__Error.
.PP
b. Exceptions should not be allowed to propagate outside their own scope.
An exception may be allowed to propagate to any point where it can be named in
an exception handler.  Note that this includes the case where an exception is
defined in a package specification and has its scope "expanded" by a "with"
clause.  What must be avoided are cases such as the following:
.ASIS
   ...
     procedure Raise__Exception is
       Hidden__Exception : exception;
     begin -- Raise__Exception
       raise Hidden__Exception;
     end Raise__Exception;

   begin
     Raise__Exception;
     -- "Hidden__Exception" CANNOT be seen at this point
     ...
.ENDASIS
.S3 Use of exceptions.
.PP
a. An exception should be used only for one or more of the following
reasons:
.LIST
.LE
It reports an irregular event which is outside the normal operation
of a program unit or is in some sense an error.
.LE
It is used where it can be argued that it is safer (more defensive)
than the alternative, in particular to guard against omissions of error
checking code for especially harmful errors.
.LE
It reports an event for which it is inconvenient or unnatural to
test at the point of cause/occurrence and thus use of the exception enhances
readability.
.EXP
Exceptions declared in package specifications are really part of the abstraction
defined by that package.  Therefore, their use should be integral to the design
of the package (see paragraph 5.10.1).
.EXP
Also, note that the predefined exceptions should be used with care.
Due to allowable implementation differences, they should not be relied upon
to indicate particular circumstances.
.PP
b. Exceptions should not be used as a means of returning normal state
information.
.EXP
For example, a Stack package may have Stack__Full and Stack__Empty exceptions
which are raised by its Push and Pop subprograms.  However, these subprograms
should not be used solely to raise exceptions to test if the appropriate
conditions are true.  Instead, the package should provide BOOLEAN functions
such as Full and Empty to test for these state conditions.
.S4 Exception handlers.
.PP
a. The exception handler choice "others" should be used only if it is
necessary to ensure that no UNANTICIPATED exception can be propagated
or if some special action must be taken before propagation.
.EXP
For example, important tasks should generally have an "others" clause in a
local exception handler (see paragraph 5.9.2.8) to prevent them from
terminating due to unanticipated exceptions.  However, in the case when it
can be expected that a certain exception may sometimes occur, then that
exception should always be explicitly named in the exception handler.
.PP
b. Recursion should not be used within an exception handler.
.PP
c. Exception handlers on block statements should be used sparingly.
.EXP
One of the advantages of using exceptions is that it separates the error
handling code from the more often executed normal processing code.  Excessive
use of exception handlers in block statements can defeat this advantage.
.S4 Raise statements.
.PP
a. Exceptions declared in the specification of a package which represents
a problem domain entity should not be raised outside that package.
.EXP
Exceptions declared in a package specification should be considered part
of the abstraction defined by the package.  These exceptions provide special
"signals" from the package operations, and should thus not be raised outside
of the package.
.PP
b. Exceptions raised within a task should always be handled within the task.
.EXP
Note that in the case of an exception raised during a rendezvous, the
exception will also be propagated back to the point of the entry call.
.PP
c. The predefined exceptions should generally not be explicitly raised.
.S4 Suppressing checks.
Checks should not be suppressed except for essential efficiency or
timing reasons in thoroughly tested program units.
.S3 Exception declarations.
.PP
Exception declarations should be formatted like object declarations,
paragraph 5.3.8.4.
.S3 Examples for exceptions.
.PP
See examples 5.5.3.4, 5.6.4.5, 5.7.4.2, and 5.14.3.2.
.S2 Generic units
.S3 Use of generic units.
.PP
a. Generics should not be used in situations in which normal programming
constructs are equivalent.
.PP
b. A generic program unit should fulfill one or more of the following:
.LIST
.LE
Provide logically equivalent operations on objects of different type.
.LE
Parameterize a program unit by a subprogram value.
.LE
Provide a data abstraction required at many points in a program, even
if no parameterization is required.
.LE
Provide parameters which are particularly appropriate to be fixed at
declaration or elaboration time.
.S4 Generic library units.
Generic units should generally be library units.
.S4 Generic instantiation.
.PP
a. The most commonly used generic instantiations should generally be
placed in library units.
.PP
b. Generic instantiations should be used cautiously within generic units.
.S3 Generic formal subprograms.
.PP
a. The actual subprograms associated with the formal subprogram parameters
of a generic unit should be consistent with the conceptual meanings of the
formal parameters (e.g., only functions which are conceptually
"adding operations" should be associated with a formal parameter named "plus").
.PP
b. Operator symbol function generic parameters should generally be provided
with a box default body ("is <>").
.ASIS
   with function "<"
     ( X : ITEM;
       Y : ITEM )
     return BOOLEAN is <>;
.ENDASIS
.S4 Use of attributes.
.PP
In writing generic bodies, attributes should be used as much as possible
to generalize the code produced.
.S3 Formatting of generic units.
.S4 Generic declarations.
.PP
a. Generic declarations should have the following format:
.ASIS
   generic
     
     
   ;

   --| 
.ENDASIS
.EXP
Each  should be formatted like its non-formal counterpart
(see paragraphs 5.3.8.3 and 5.3.8.4), except for formal subprograms which
should be formatted as in paragraph b., below.  The  should be formatted as for non-generic units (see
paragraphs 5.6.3.3 and 5.7.3.3).
.PP
b. A generic formal parameter subprogram declaration should have one of
the following formats:
.ASIS
   with ;
   --| 

   with  is <>;
   --| 

   with  is ;
   --| 
.ENDASIS
.EXP
The  should be formatted as for a subprogram
declaration (see paragraph 5.6.3.3).  Note, however, that the only
documentation generally needed on formal subprograms is the "Purpose."
.PP
c. A generic declaration should be preceded by the appropriate unit
header block (see paragraphs 5.6.3.2 and 5.7.3.2).
.S4 Formatting of generic instantiations.
.PP
a. Generic instantiations should have one of the following formats:
.ASIS
    is
     new  (, );

   --| 


    is
     new 
       (  => ,
          =>  );

   --| 
.ENDASIS
.EXP
Note that in the second form the arrows ("=>") should be kept aligned.  The
 should be the same as those required for a specification
of the appropriate kind of unit (paragraphs 5.6.3.3 and 5.7.3.3).
.PP
b. Generic instantiations should have the same kind of header comment
block as for a specification of the appropriate kind of unit
(see paragraphs 5.6.3.2 and 5.7.3.2).
.S3 Examples of generic units.
.PP
See also example 5.7.4.2 and 5.7.4.3.
.S4 Example 12X1.
.ASIS
   -- ...............
   -- .             .
   -- .  Shellsort  .  SPEC
   -- .             .
   -- ...............

   generic

     type ITEM is
       private;                 -- The type of items sorted

     type ITEM__LIST is          -- The type of the item list
       array (INTEGER range <>) of ITEM;

     with function "<"
       ( Left  : ITEM;
         Right : ITEM )
       return BOOLEAN is <>;

     --| Purpose
     --| This function defines the ordering used when the
     --| items are sorted.

   procedure Shellsort

     ( List                    -- This list will be sorted
         : in out LIST__TYPE;   -- in place.

       N                       -- The number of items in
         : in NATURAL );       -- the list.

     --| Purpose
     --| This procedure sorts the items in List using a Shell
     --| sort algorithm designed for parallel processing.
     --|
     --| Exceptions (none)
     --| Notes
     --| (This is a generic declaration for the procedure
     --| body given in example 9X3.)
     --|
     --| Modifications
     --| 9/5/86  A. Shell    Initial version
.ENDASIS
.S4 Example 12X2.
.ASIS
   -- ...............
   -- .             .
   -- .  Name__Sort  .  SPEC
   -- .             .
   -- ...............

   procedure Name__Sort is
     new Shellsort
       ( ITEM      => NAME,
         LIST__TYPE => NAME__LIST );
.ENDASIS
.S4 Example 12X3.
.ASIS
   -- *********************
   -- *                   *
   -- *  Unit__Statistics  *  SPEC
   -- *                   *
   -- *********************

   with Text__IO;
   generic

     Unit__Name             -- Name of the unit for which
       : STRING;           -- statistics are to be kept.

     type ELEMENT__TYPE is  -- Enumeration type of the elements
       (<>);               -- to be counted.

   package Unit__Statistics is

   --| Purpose
   --| This package provides operations to keep counts for the
   --| various elements of a program unit.  These counts can be
   --| incremented or printed out in a report.
   --|
   --| Initialization Exceptions (none)
   --|
   --| Notes
   --| This package is based on the generic package "Task__Statistics"
   --| written by Dan Roy.
   --|
   --| Modifications
   --| 8/18/86  Ed Seidewitz    Initial version

     -- .....................
     -- .                   .
     -- .  Number__Of__Lines  .  SPEC
     -- .                   .
     -- .....................

     function Number__Of__Lines
       return POSITIVE;

     --| Purpose
     --| This function returns the number of lines printed by
     --| procedure Report since the last call to Number__Of__Lines.
     --|
     --| Exceptions (none)
     --|
     --| Notes (none)

     -- ..............
     -- .            .
     -- .  Count__Of  .  SPEC
     -- .            .
     -- ..............

     function Count__Of
       ( Element
           : ELEMENT__TYPE )
       return NATURAL;

     --| Purpose
     --| This function returns the current count for the specified
     --| element.
     --|
     --| Exceptions (none)
     --|
     --| Notes (none)

     -- ...............
     -- .             .
     -- .  Increment  .  SPEC
     -- .             .
     -- ...............

     procedure Increment
       ( Element
           : in ELEMENT__TYPE;
         By__Amount
           : in INTEGER := 1 );

     --| Purpose
     --| This procedure increments the count for the specified
     --| element by a certain amount.  By default, this amount
     --| is one.
     --|
     --| Exceptions (none)
     --|
     --| Notes (none)

     -- ............
     -- .          .
     -- .  Report  .  SPEC
     -- .          .
     -- ............

     procedure Report
       ( Report__File
           : Text__IO.FILE__TYPE );

     --| Purpose
     --| This procedure prints a report of all statistics for
     --| this unit to the specified text file.
     --|
     --| Exceptions (none)
     --|
     --| Notes (none)

   end Unit__Statistics;
.ENDASIS
.S4 Example 12X4.
.ASIS
   -- *********************************
   -- *                               *
   -- *  Telemetry__Reader__Statistics  *  SPEC
   -- *                               *
   -- *********************************

   package Telemetry__Reader__Statistics is
     new Unit__Statistics
       ( Unit__Name    => "Telemetry__Reader",
         ELEMENT__TYPE => READER__ELEMENTS );

   --| Purpose
   --| This package collects statistics on elements of the
   --| Telemetry__Reader.
   --|
   --| Initialization Exceptions (none)
   --|
   --| Notes (none)
.ENDASIS
.S2 Representation clauses and implementation-dependent features
.S3 Encapsulation.
.PP
Representation clauses and implementation dependent features should,
if possible, be hidden inside packages which present implementation
independent interfaces to users.
.S3 Use of representation clauses and implementation-dependent features.
.PP
a. Machine dependent and low-level Ada features should not be used except
when absolutely necessary.
.PP
b. Representation clauses and implementation-dependent features should
only be used for one of the following:
.LIST
.LE
To increase efficiency (when absolutely necessary).
.LE
For interrupt handling.
.LE
For interfacing to hardware, foreign code or foreign data.
.LE
To specify task storage size.
.EXP
Further, address clauses should be used with entries only to associate
them with hardware interrupts.
.PP
c. Representation clauses should not be used to change the meaning of a
program.
.S4 Interrupts.
Interrupt routines should be kept as short as possible.
.S3 Formatting of representation clauses.
.PP
Representation clauses should be placed near to the objects they affect.
.S2 Input-Output
.S3 Encapsulation of I/O.
.PP
a. Use of the LOW__LEVEL__IO procedures should always be encapsulated in
packages or tasks.
.PP
b. Use of the LOW__LEVEL__IO procedures should generally be encapsulated in
task objects associated with each item of controlled equipment.
.PP
c. File management and textual input-output software should generally be
encapsulated in specialized packages with simple interfaces.
.EXP
This should include file interface code, textual formatting code and user
interface code.  User interface encapsulation can be especially useful
when a system must accommodate increasing levels of user interface
sophistication or changing user needs over its lifetime.  In these cases,
it is crucial that details of the implementation of the user interface be
hidden so that changes can be made to it without affecting the rest of the
system.
.S3 Text formatting.
.PP
Line and page formatting should be done using the
New__Line and New__Page subprograms, rather than explicitly writing
end-of-line or end-of-page characters.
.S4 Low-level input-output.
Use of package Low__Level__IO should be avoided unless absolutely necessary.
.S4 Form parameter.
Use of the Form parameter of the Open and Create procedures should generally
be avoided.
.EXP
The "Form" parameter on the file Open and Create procedures specifies
system-dependent file characteristics.  This can reduce both readability and
portability, and so should only be used if absolutely necessary.
.S3 Examples for input-output.
.PP
See also examples 5.5.3.3., 5.5.3.4, and 5.7.4.3.
.S4 Example 14X1.
.ASIS
   -- ............
   -- .          .
   -- .  Report  .  SUBUNIT
   -- .          .
   -- ............

   separate (Unit__Statistics)
   procedure Report is
     ( Report__File
         : in Text__IO.FILE__TYPE ) is

   --| Notes
   --| This example is based on Task__Statistics.Report
   --| by Dan Roy.
   --|
   --| Modifications
   --| 8/18/86  Ed Seidewitz    Initial version

     Unit__Name__Column
       : constant := 10;

     Value__Column
       : constant := 40;

     use Text__IO;          -- For output operations

   begin -- Report

     -- Print header
     New__Line (Report__File);
     Set__Col (Report__File, To => Unit__Name__Column);
     Put__Line (Report__File,
         "Statistics for " & STRING(Unit__Name));
     New__Line (Report__File);
     Number__Lines__Printed := Number__Lines__Printed + 2;

     -- Print "element name    element value" for all elements
     for Element in Statistics__Array'range loop
       Put (Report__File, ELEMENT__TYPE'image (Element));
       Set__Col (Report__File, To => Value__Column);
       Put__Line (Report__File,
           INTEGER'image (Statistics__Array(Element)));
       Number__Lines__Printed := Number__Lines__Printed + 1;
     end loop;

   end Report;
.ENDASIS
.S4 Example 14X2.
.ASIS
   -- ..........
   -- .        .
   -- .  Read  .  SUBUNIT
   -- .        .
   -- ..........

   separate (Disk)
   procedure Read

     ( Disk__File
         : in out FILE__TYPE;

       Data
         : out SPECIFIC__DATA__TYPE ) is

   --| Notes
   --| (This is the body of procedure Read in example 7X3)
   --|
   --| Modifications
   --| 9/10/86  Ada User's Group    Initial version

   begin -- Read

     if not Disk__IO.Is__Open(Disk__File.File) then
       Open__File(Disk__File);
     end if;

     Disk__IO.Read
       ( File => Disk__File.File,
         Item => Data );

   exception

     when Disk__IO.End__Error =>
       Disk__IO.Close (Disk__File.File);
       raise End__Of__File;

     when Disk__IO.Name__Error | Disk__IO.Use__Error =>
       raise Open__Error;

     when Disk__IO.Mode__Error =>
       raise Mode__Error;

   end Read;
.ENDASIS
.bp 1
.pn lower_roman
.fo //- # -//
.sp 4
.ce
TABLE OF CONTENTS
.sp 2
.pc
--::::::::::
--pmh1804.src
--::::::::::
--::::::::::
--pmh1804.ptf
--::::::::::
.comment
.! PMH1804.PTF and PMH1804I.PTF
.! Created in PTF form from the original PMH1804 document by Richard Conn
.!
.! This is a version of MIL-HDBK-1804 which is machine-readable and
.! can be processed by PTF in the Ada Software Repository to produce
.! a printable document.
.!
.! To process this file, issue the following commands:
.!     ptf pmh1804.ptf pmh1804.doc
.!     ptfidx
.!     ptf pmh1804i.ptf pmh1804.idx
.!     rm ptfidx.ptf
.!
.! If you issued the above commands, the output documents are:
.!     pmh1804.doc -- main document
.!     pmh1804.idx -- index pages
.comment

.comment
.! The following include file sets the left and right margins and
.! defines some useful macros.  It is used by both pmh1804.ptf and
.! pmh1804i.ptf.
.comment
.include pmh1804.mac

.spaceto 15
.ce on
.ul
Proposed MIL-HDBK-1804
.sp 4
Military Handbook Ada Style Guide

30 April 1988
.ce off
.bp
This draft, prepared by the U.S. Army Information
Systems Engineering Command (ISEC), has not been approved and is subject to
.index ISEC, U.S. Army
.index U.S. Army ISEC
modification.  It should not be used or interpreted as an approved
Military Handbook at this time.
.sp 1
This machine-readable document is provided for the users of the
Ada Software Repository (ASR).  While great care has been taken in entering
.index Ada Software Repository
.index ASR
its text, typing errors may have been introduced (and some typing
errors have been corrected), and the users should
review it.  It is presented as both raw (for processing by the
PTF [Portable Text Formatter]
.index Portable Text Formatter
.index PTF
tool) and formatted machine-readable files.  The index is generated by
PTF and is slightly more extensive than the original index.
The Appendices were not a part of the original document and were
added by ASR personnel.  If errors are found, please
report them to the ASR Support Contractor, MACA, by
phone or email.
.sp 15
.ce
FOREWORD
.sp 2
.PP
The Ada Style Guide was developed by the National Aeronautics and Space
Administration/Goddard Space Flight Center Ada User's Group.  The principal
author is Edwin V. Seidewitz.  The guide was edited and reformatted as a
Military Handbook by the United States Army Information Systems Engineering
Command (ISEC).
.index U.S. Army ISEC
.index ISEC, U.S. Army
.index NASA/GSFC
.bp 1
.S1 SCOPE
.he //MIL-HDBK-1804//
.of /SCOPE//#/
.ef /#//SCOPE/
.S2 Introduction
.PP
Ada is a programming language of considerable expressive power.
ANSI/MIL-STD-1815A, Ada Programming Language, provides a thorough
.index ANSI/MIL-STD-1815A
.index Ada Programming Language
definition of the language.  However, it does not offer sufficient
guidance on the appropriate use of Ada's powerful features.  This document
was developed to address such "program style" issues.
.S2 Scope
.PP
Program source code serves two functions: to specify an algorithm to be
.index source code, functions of
performed on a computer, and to communicate this algorithmic design to
other human readers.  Program style relates to how well a program meets the
second function.  It is a consistent manner of using the features of a
programming language to promote the readability and understandability of a
program.  This is a matter of the form of the final, delivered, program
source code, as opposed to the process of developing the code.
.S2 Goals
.PP
a. While some of what constitutes "good style" is subjective and somewhat
.index good style
arbitrary, it is important that the style of a program be consistent
throughout the program.  The primary goal of this guide is to promote such
consistent use of good style across large numbers of Ada programs.  The whole
intent of "good style" is to increase the readability of these programs.
Therefore, these guidelines follow from general principles of program
readability and understandability.
.PP
b. The program should reflect the natural levels of abstraction in the
problem domain, so that the reader can reasonably comprehend each level
individually.
.index abstraction, levels of
.index levels of abstraction
.index problem domain
.PP
c. There are several features in Ada which are unfamiliar to many programmers.
There is thus a tendency to either underuse these features or to use them
inappropriately.  A feature of Ada should generally not be ignored, but
neither should it be used in excess.  The guidelines highlight the proper
use of Ada features.
.PP
d. The textual format of a program should be pleasing to the eye and
promote the readability and understandability of the program.  The format
should highlight the structure of a program and the role of a program as
a model of the problem domain.  Just as the careful layout of a book
can enhance written communication, the careful layout of a program can enhance
the communication of algorithmic design to another human.  The consistent use of
formatting style is especially important, because it allows readers to become
accustomed to the familiar layout of the program constructs.  An automated
formatting program is particularly helpful, but even in the absence of such
a tool, much can be gained from a common format style.
.bp
.S1 REFERENCED DOCUMENTS
.of /REFERENCED DOCUMENTS//#/
.ef /#//REFERENCED DOCUMENTS/
.S2 Government Documents
.PP
ANSI/MIL-STD-1815A, Ada Programming Language.
.bp
.S1 DEFINITIONS
.of /DEFINITIONS//#/
.ef /#//DEFINITIONS/
.S2 Introduction
.PP
The definitions provided in ANSI/MIL-STD-1815A are applicable for use
with this handbook.  Since this handbook is intended to be a companion
document to the Ada Programming Language manual, the definitions are not
restated here.
.index ANSI/MIL-STD-1815A
.index Ada Programming Language
.S2 Handbook
.PP
The term "Handbook" (capitalization intended) refers to this document,
MIL-HDBK-1804, Ada Style Guide Handbook.  This simplification is used
.index MIL-HDBK-1804
.index Ada Style Guide Handbook
to improve readability.
.S2 Standard
.PP
The term "Standard" (capitalization intended) refers to ANSI/MIL-STD-1815A,
Ada Programming Language.  This simplification is to improve readability.
.bp
.S1 GENERAL REQUIREMENTS
.of /GENERAL REQUIREMENTS//#/
.ef /#//GENERAL REQUIREMENTS/
.sp 4
.ce
NOT APPLICABLE
.bp
.S1 SPECIFIC GUIDELINES
.of /SPECIFIC GUIDELINES//#/
.ef /#//SPECIFIC GUIDELINES/
.S2 Introduction
.PP
This section contains fourteen major subparagraphs (5.1 through 5.14)
corresponding to the fourteen chapters of ANSI/MIL-STD-1815A,
.index ANSI/MIL-STD-1815A
Ada Programming Language.  This provides a standard frame of
.index Ada Programming Language
reference for the discussion of Ada features.  Where appropriate, the
guide includes examples and justifications for various guidelines.
Some of the major subparagraphs, themselves, have an "Examples"
subparagraph giving additional, longer examples for the topic.
.S2 Lexical elements
.S3 The package STANDARD.
.PP
Language words with predefined meanings in the package STANDARD should
not be redefined.
.index package STANDARD
.index STANDARD, package
.S3 Formatting of lexical elements.
.S4 Indentation.
The standard indentation is two spaces.
.S4 Character set.
Full use should be made of the ISO character set where available.
Alternate character replacements should only be used when the corresponding
graphical symbols are not available.
.index character set
.index set, character
.S4 Upper/lower case.
.PP
a. Reserved words and attributes should appear in lower case.
.index reserved words
.index attributes
.PP
b. All identifiers except type, enumeration value and attribute identifiers
should be in mixed upper and lower case.  The first letter of each word in the
identifier should be in upper case with other characters in lower case, unless
a word is normally written in all upper case (e.g., acronyms).
.index identifiers
.ASIS
   Display__Device
   Number__Of__User__Names
   Get__FHST__Data
   Package__Name
.ENDASIS
.PP
c. Type and enumeration value identifiers should appear in all upper case.
.ASIS
   LONG__INTEGER
   AUTHORITY__LEVEL

   (RED, GREEN, BLUE)
   (ARMY, AIR__FORCE, NAVY, MARINES)
.ENDASIS
.S4 Identifiers.
.PP
a. Identifier names should be meaningful and easily distinguishable from
each other, except possibly for loop parameters, array indices, and common
mathematical variables, which may be as short as a single character.
.PP
b. Distinct words in identifiers should always be separated by
underscores.
.index identifiers
.index identifiers, underscores in
.index underscores in identifiers
.PP
c. The use of abbreviations in identifiers should be avoided.  When used,
an abbreviation should be significantly shorter than the word it
abbreviates, and its meaning should be clear.  The same abbreviations
should be used consistently throughout a project.
.index abbreviations in identifiers
.index identifiers, abbreviations in
.S4 Spaces.
Single spaces should be used consistently between lexical elements to
enhance readability.
.S4 Blank lines.
.PP
a. Blank lines should be used to group logically related lines of text.
.index blank lines
.index lines, blank
.EXP
A careful use of blank lines can greatly enhance readability by making
the logical structure of a sequence of lines more textually obvious.
However, the overuse of blank lines (e.g., "double spacing") defeats the
very purpose of grouping and can actually reduce readability.  Blank lines
should thus always be used with grouping in mind and not just to increase
white space.
.PP
b. A blank line should always follow a construct whose last line is not at
the same indentation level as its first line.
.ASIS
   type COMPLEX is
     record
       Real      : FLOAT;
       Imaginary : FLOAT;
     end record;

   -- Followed by a blank line
.ENDASIS
.S4 Continuation of statements.
.PP
a. Statements extending over multiple lines should always be broken before
reserved words, operator symbols, or one of the following symbols:
.index continuation of statements
.index statements, continuation of
.ASIS
   :  |  =>  ..  :=
.ENDASIS
.sp 1
but they should be broken after a comma (",").  Unless otherwise specified in
later guidelines, all the continuation lines should be indented at least
two levels with respect to the original line they continue.
.ASIS
   Corrected__Value := (1 + Sensor__Scale) * Raw__Value
       + Distortion__Factor * Distortion__Value + Sensor__Bias;
.ENDASIS
.PP
b. Long strings extending over more than one line should be broken up at
natural boundaries, appropriate to the meaning of the contents of the string, if
any.
.index long strings
.index strings, long
.ASIS
   "This is a rather long string, so it is likely that "
       & "it will extend over more than one line"
.ENDASIS
.S4 Comments.
.PP
a. Comments should be used to add information for the reader or to highlight
sections of code, and should not merely paraphrase the code.
.index comments
.PP
b. Comments should begin with the "--" aligned with the indentation level
of the code that they describe, or to the right of the code, aligned with
other such comments.
.ASIS
   -- Check if the user has special authorization
   if Authority = SPECIAL then
     Display__Special__Menu;   -- All operations are allowed
   else
     Display__Normal__Menu;    -- Only normal operations allowed
   end if;
.ENDASIS
.S2 Declarations and types
.S3 Constants.
.index constants
.PP
a. An object should be declared constant if its value is intended not
to change.
.index object
.EXP
Declaring an object to be constant clearly signals both the human reader
and the compiler the intention that its value will not change.  This not
only increases readability, it also increases reliability because the
compiler will detect any attempt to tamper with the object.  Also, it can
result in some decrease in executable size and better run time efficiency.
.PP
b. Defining a constant object is preferable to using a numeric literal or
expression with constant value, as long as the constant object has an
intrinsic conceptual meaning.
.index constant object
.index object, constant
.EXP
There is no use in defining a constant object when a numeric literal is
obviously more appropriate, for example: using "One" instead of "1."
However, the use of constant objects with intrinsic meaning (such as
"Buffer__Size" or "Field__Of__View") can greatly increase the readability of
code.  Further, the code is more maintainable since a change in a value
will be localized to the constant declaration.
.PP
c. A named number (i.e., a constant object with type universal-integer
or universal-real) should be used only for values that are truly "universal"
and "typeless."  Other numeric constants should be declared with an explicit
type.
.index named number
.index number, named
.EXP
Such constants as "Pi" and cardinal integers (e.g., a "number of things")
.index constants
should be named numbers.  Note also that declaring a constant in terms of a
predefined numeric type (INTEGER, FLOAT, etc.) has no advantage over a named
number since these predefined types provide only range and accuracy
constraints
and not additional conceptual meaning.  In fact, since the range and
accuracy of predefined numeric types is implementation-defined, portability
can be increased by using named numbers, in those cases where a constant
of a user-defined type is not more appropriate.
.ASIS
   Number__Of__Sensors       -- This is a named number
     : constant := 4;

   Main__Sensor__Number
     : constant SENSOR__INDEX := 2;
.ENDASIS
.S3 Types.
.PP
Separate types should be used for values that belong to logically independent
sets, and for distinct concepts.
.ASIS
   type X__COORDINATE is
     range 1 .. 640;

   type Y__COORDINATE is
     range 1 .. 480;

   type PIXEL__VALUE is
     range 0 .. 255;

   type IMAGE__GRID is
     array (X__COORDINATE, Y__COORDINATE) of PIXEL__VALUE;
.ENDASIS
.EXP
A data type characterizes a set of values and a set of operations
applicable to objects of the type.  In the above example, each coordinate
has a type because coordinates are independent entities.  Explicitly
declaring these types makes the concepts more obvious to a human reader
and also allows the compiler to detect mistakes such as:
.ASIS
   Image (Y, X) := Pixel;   -- Should be "(X, Y)"
.ENDASIS
.EXP
The drawback of this kind of typing is that the following construct is
illegal:
.ASIS
   if X = Y then     -- ILLEGAL since X and Y have different types
     ...
.ENDASIS
.EXP
A type conversion must be used:
.index type conversion
.index conversion, type
.ASIS
   if X = X__COORDINATE(Y) then
     ...
.ENDASIS
.EXP
Note that, depending on context (and compiler quality), there may or may
not be some run time penalty associated with type conversion (e.g.,
testing of range constraints).
.S3 Enumeration types.
.index enumeration types
.index types, enumeration
.PP
An enumeration type should always be used in preference to an integer type,
unless the logical nature of the concept to be modeled demands the other.
.EXP
For example, the type:
.ASIS
   type DEVICE__MODE is
     (READ__ONLY, WRITE__ONLY, READ__WRITE);
.ENDASIS
.EXP
is preferable to encoding DEVICE__MODE as an integer 0, 1 or 2.
.S3 Floating types.
.index floating types
.index types, floating
.PP
a. To enhance portability, the range and accuracy of a floating point type
should generally be specified.
.PP
b. The precision for the predefined floating types (FLOAT, etc.) is
implementation-dependent, though all implementations should provide
at least 6 decimal digits of accuracy.  Explicitly declaring floating
point ranges can yield more reliable and more efficient results as well
as more portable code.
.S3 Record types.
.index record types
.index types, record
.PP
a. A record type should be used instead of an array type even when all the
record components have the same type, as long as each component can be
sensibly named and the components do not need to be dynamically indexed.
.EXP
For example, the definition:
.ASIS
   type COMPLEX is
     record
       Real      : FLOAT;
       Imaginary : FLOAT;
     end record;
.ENDASIS
.EXP
is preferable to defining COMPLEX as an array of two FLOATs.
.PP
b. Overcomplicated record structures should be avoided by grouping related
data into subrecord types.
.ASIS
   type COORDINATE is
     record
       Row    : FLOAT;
       Column : FLOAT;
     end record;

   type WINDOW is
     record
       Top__Left     : COORDINATE;
       Bottom__Righ