|Ada 95 Quality and Style Guide||Chapter 2|
2.1.8 Number of Statements Per Line
Start each statement on a new line.
Write no more than one simple statement per line.
Break compound statements over multiple lines.
Use:if End_Of_File then Close_File; else Get_Next_Record; end if;
rather than:if End_Of_File then Close_File; else Get_Next_Record; end if;
exceptional case:Put("A="); Natural_IO.Put(A); New_Line; Put("B="); Natural_IO.Put(B); New_Line; Put("C="); Natural_IO.Put(C); New_Line;
A single statement on each line enhances the reader's ability to find statements and helps prevent statements being missed. Similarly, the structure of a compound statement is clearer when its parts are on separate lines.
If a statement is longer than the remaining space on the line, continue it on the next line. This guideline includes declarations, context clauses, and subprogram parameters.
According to the Ada Reference Manual (1995, §1.1.4), "The preferred places for other line breaks are after semicolons."
The guidelines in this section are easily enforced with an automatic code formatter, with the single exception of the last example, which shows a semantic grouping of multiple statements onto a single line.
The example of Put and New_Line statements shows a legitimate exception. This grouping of closely related statements on the same line makes the structural relationship between the groups clear.
|< Previous Page||Search||Contents||Index||Next Page >|