Ada Style Guide

A. Reserved words

  1. Reserved words should appear in all lower case letters.

B. Identifiers

  1. All user-defined identifiers should start with a capital letter.
  2. Identifiers formed by more than one word should be connected by underscores, e.g., Default_Initial_Size, and not DefaultInitialSize.
  3. Letters other than the beginning of a word should be in lower case, unless the word is normally written completely in uppercase, e.g., acronyms or abbreviations such as IO in Text_IO.
  4. Whenever possible, avoid abbreviations and yet avoid identifiers greater than 20 characters or so.
  5. Although Ada ignores case, always capitialize variables consistently. Distinct identifiers cannot differ only by capitalization in Ada, but it distracts the human reader to be inconsistent.
  6. All identifiers should have meaningful names. Occasionally single letter loop indices like I are accepable. But do not overlook other possibilities like Row or Column.
  7. Choose names for different identifiers that are "psychologically distant" in order to avoid confusion. Compare:
          Disk_1     Disk_2      Disk_3
          Small_Disk Medium_Disk Large_Disk
          
  8. Nouns should be used for types, constants, variables; verb phrases for procedures and functions. For example,
          procedure Free
          procedure Assign
          function  Multiply
          procedure Rescale
          procedure Print_Titles
          function  Roll_Two
          procedure Correct_Table
          
    Functions that return a boolean value often begin with Is
          function Is_Empty return Boolean
          function Is_All_Zero return Boolean
          
  9. Identifiers bound to constants may appear in all uppercase, though I discourage it. In any case, be consistent.
  10. Predefined identifiers like Natural, String may appear in all uppercase, though I discourage it. In any case, be consistent.
  11. Do not choose predfined identifiers for you own use.

C. Comments

  1. Comments should be helpful, clear, and grammatically correct.
  2. Do not restate the obvious. For example,
          I := I + 1;   --  Add one to I
          
    Answer the question why you are doing it.
          I := I + 1;   --  Prepare for next record in list
          

D. Indentation

  1. Indentation should be 2, 3 or 4 columns. Whatever the number of columns is chosen, that number should be used consistently whenever indentation is called for.
  2. Do not use tabs.
  3. In a procedure, the declarations and body should be indented.
          procedure Main is
             -- declarations
          begin
             -- statements
          end Main;
          
  4. In an if statement, the if, elsif, else, and end if should all be aligned in the same column. The statements should be indented.
          if ... then
             -- statements
          elsif ... then
             -- statements
          else
             -- otherwise
          end if;
          
  5. In a while loop, the body should be indented.
          while ... loop
             --  The body
             --  of the loop.
          end loop;
          

E. Visibility

  1. Restrict the visibility of variables and other identifiers as much as possible; use the block statement.
  2. Avoid non-local variables.
  3. The use clause should be avoided.

F. General

  1. Use blank lines to separate logically related parts of the program. Do not use too many blank lines.
  2. Use constants instead of variables as much as possible.
  3. Use functions instead of subprocedures as much as possible.
  4. Use the parameter passing mode in instead of out as much as possible.
  5. Do not use the goto statement.
  6. Avoid comparing boolean constants or assigning boolean constant values to variables.

G. Design

  1. Do not write essentially the same code twice; use functions and procedures.
  2. Avoid multiple exits from loops.
  3. Try to have exactly one return at the end of functions.
  4. Use exception handling to handle uncommon cases.
  5. Try to keep procedures to limited to 50-90 lines.
  6. Use subunits to keep the size of files to a few pages.
  7. Use packages to modularlize complex programs.

Ryan Stansifer <ryan@cs.fit.edu>
Document location: http://www.cs.fit.edu/~ryan/ada/style.html
Last modified: Thu Oct 22 11:37:00 EDT 1998