|Ada 95 Quality and Style Guide||Chapter 5|
Use an aggregate instead of a sequence of assignments to assign values to all components of a record.
Use an aggregate instead of a temporary variable when building a record to pass as an actual parameter.
Use positional association only when there is a conventional ordering of the arguments.
It is better to use aggregates:Set_Position((X, Y)); Employee_Record := (Number => 42, Age => 51, Department => Software_Engineering);
than to use consecutive assignments or temporary variables:Temporary_Position.X := 100; Temporary_Position.Y := 200; Set_Position(Temporary_Position); Employee_Record.Number := 42; Employee_Record.Age := 51; Employee_Record.Department := Software_Engineering;
Using aggregates during maintenance is beneficial. If a record structure is altered, but the corresponding aggregate is not, the compiler flags the missing field in the aggregate assignment. It would not be able to detect the fact that a new assignment statement should have been added to a list of assignment statements.
Aggregates can also be a real convenience in combining data items into a record or array structure required for passing the information as a parameter. Named component association makes aggregates more readable.
See Guideline 10.4.5 for the performance impact of aggregates.
|< Previous Page||Search||Contents||Index||Next Page >|