|
In this section... 5.2.1 Formal Parameters 5.2.2 Named Association 5.2.3 Default Parameters 5.2.4 Mode Indication |
| Summary of Guidelines from this section |
List_Manager.Insert (Element => New_Employee,
Into_List => Probationary_Employees,
At_Position => 1); |
Language Ref Manual references: 2.3 Identifiers, 2.7 Comments, 6.1 Subprogram Declarations, 9.5 Entries, Entry Calls, and Accept Statements
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); |
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.
Language Ref Manual references: 6.4 Subprogram Calls, 6.4.1 Parameter Associations, 6.4.2 Default Parameters, 12.3 Generic Instantiation
Placing default parameters at the end of the formal parameter list allows the caller to use positional association on the call, otherwise defaults are available only when named association is used.
Often during maintenance activities, you increase the functionality of a subprogram or entry. This requires more parameters than the original form for some calls. New parameters may be required to control this new functionality. Give the new parameters default values which specify the old functionality. Calls needing the old functionality need not be changed; they take the defaults. This is true if the new parameters are added to the end of the parameter list, or if named association is used on all calls. New calls needing the new functionality can specify that by providing other values for the new parameters.
This enhances maintainability in that the places which use the modified routines do not themselves have to be modified, while the previous functionality levels of the routines are allowed to be "reused."
Language Ref Manual references: 6.4.2 Default Parameters
in out only when the parameter is both read from and updated.
procedure Open_File (File_Name : in String;
Open_Status : out Status_Codes);
entry Acquire (Key : in Capability;
Resource : out Tape_Drive); |
Use the mode that reflects the actual use of the parameter. Only use
in out mode when reading and writing to a parameter.
in out to allow changes to the implementation and to document
more accurately what the operation is doing. If you later change the
implementation to a simple array, the mode will have to be in out, potentially
causing changes to all places that the routine is called.Language Ref Manual references: 6.2 Formal Parameter Modes, 9.5 Entries, Entry Calls, and Accept Statements