|Ada 95 Quality and Style Guide||Chapter 5|
5.1.2 Block Names
Associate names with blocks when they are nested.
exampleTrip: declare ... begin -- Trip Arrive_At_Airport: declare ... begin -- Arrive_At_Airport Rent_Car; Claim_Baggage; Reserve_Hotel; ... end Arrive_At_Airport; Visit_Customer: declare ... begin -- Visit_Customer -- again a set of activities... ... end Visit_Customer; Departure_Preparation: declare ... begin -- Departure_Preparation Return_Car; Check_Baggage; Wait_For_Flight; ... end Departure_Preparation; Board_Return_Flight; end Trip;
When there is a nested block structure, it can be difficult to determine which end corresponds to which block. Naming blocks alleviates this confusion. The choice of a good name for the block documents its purpose, reducing the need for explanatory comments. If a name for the block is very difficult to choose, this could indicate a need for more thought about the algorithm.
This guideline is also useful if nested blocks are broken over a screen or page boundary.
It can be difficult to think up a name for each block; therefore, the guideline specifies nested blocks. The benefits in readability and second thought outweigh the inconvenience of naming the blocks.
|< Previous Page||Search||Contents||Index||Next Page >|