Ada 95 Quality and Style Guide Chapter 3

Chapter 3: Readability - TOC - 3.1 SPELLING

3.1.3 Capitalization

guideline

  • Make reserved words and other elements of the program visually distinct from each other.

  • instantiation

    Use lowercase for all reserved words (when used as reserved words).
    - Use mixed case for all other identifiers, a capital letter beginning every word separated by underscores.
    - Use uppercase for abbreviations and acronyms (see
    automation notes).

    example

    ...
    type Second_Of_Day      is range 0 .. 86_400;
    type Noon_Relative_Time is (Before_Noon, After_Noon, High_Noon);
    subtype Morning   is Second_Of_Day range 0 .. 86_400 / 2 - 1;
    subtype Afternoon is Second_Of_Day range Morning'Last + 2 .. 86_400;
    ...
    Current_Time := Second_Of_Day(Calendar.Seconds(Calendar.Clock));
    if Current_Time in Morning then
       Time_Of_Day := Before_Noon;
    elsif Current_Time in Afternoon then
       Time_Of_Day := After_Noon;
    else
       Time_Of_Day := High_Noon;
    end if;
    case Time_Of_Day is
       when Before_Noon =>   Get_Ready_For_Lunch;
       when High_Noon   =>   Eat_Lunch;
       when After_Noon  =>   Get_To_Work;
    end case;
    ...
    

    rationale

    Visually distinguishing reserved words allows you to focus on program structure alone, if desired, and also aids scanning for particular identifiers.

    The instantiation chosen here is meant to be more readable for the experienced Ada programmer, who does not need reserved words to leap off the page. Beginners to any language often find that reserved words should be emphasized to help them find the control structures more easily. Because of this, instructors in the classroom and books introducing the Ada language may want to consider an alternative instantiation. The Ada Reference Manual (1995) chose bold lowercase for all reserved words.

    automation notes

    Ada names are not case sensitive. Therefore, the names max_limit, MAX_LIMIT, and Max_Limit denote the same object or entity. A good code formatter should be able to automatically convert from one style to another as long as the words are delimited by underscores.

    As recommended in Guideline 3.1.4, abbreviations should be project-wide. An automated tool should allow a project to specify those abbreviations and format them accordingly.


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