Ada 95 Quality and Style Guide Chapter 5

Chapter 5: Programming Practices - TOC - 5.2 PARAMETER LISTS

5.2.2 Named Association


  • Use named parameter association in calls of infrequently used subprograms or entries with many formal parameters.
  • Use named association when instantiating generics.
  • Use named association for clarification when the actual parameter is any literal or expression.
  • Use named association when supplying a nondefault value to an optional parameter.

  • instantiation

    - Use named parameter association in calls of subprograms or entries called from less than five places in a single source file or with more than two formal parameters.


    Encode_Telemetry_Packet (Source         => Power_Electronics,
                             Content        => Temperature,
                             Value          => Read_Temperature_Sensor(Power_Electronics),
                             Time           => Current_Time,
                             Sequence       => Next_Packet_ID,
                             Vehicle        => This_Spacecraft,
                             Primary_Module => True);


    Calls of infrequently used subprograms or entries with many formal parameters can be difficult to understand without referring to the subprogram or entry code. Named parameter association can make these calls more readable.

    When the formal parameters have been named appropriately, it is easier to determine exactly what purpose the subprogram serves without looking at its code. This reduces the need for named constants that exist solely to make calls more readable. It also allows variables used as actual parameters to be given names indicating what they are without regard to why they are being passed in a call. An actual parameter, which is an expression rather than a variable, cannot be named otherwise.

    Named association allows subprograms to have new parameters inserted with minimal ramifications to existing calls.


    The judgment of when named parameter association improves readability is subjective. Certainly, simple or familiar subprograms, such as a swap routine or a sine function, do not require the extra clarification of named association in the procedure call.


    A consequence of named parameter association is that the formal parameter names may not be changed without modifying the text of each call.

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