Subprograms Flashcards
Subroutines are the
Fundamental building blocks of programs
Where can subroutines be defined?
Within programs or separately in libraries
What are some other names for a subroutine are (4)
Procedure, routine, method or subprogram
During the execution of a subroutine the caller is
Suspended
Where is the control returned to when a subroutine execution terminates
To the caller
Parameters/formal params are the
Expected values
Actual pamareter/arguments are the
Actual values provided by the calling program
What are the two types of actual/formal parameters
Positional and keyword parameters
Position parameters the binding is done
By the position
Keywords parameters, what are stored together
Formal parameters and corresponding actual parameters
What are the advantages of network parameters
Order is irrelevant
Don’t worry about wrongly ordered parameters
Disadvantages keyword parameters
Users must know and specify the names of formal parameters
What are the two parameters passing methods
Semantic models and implementation models
What are the three distinct semantic models that formal parameters are characterized by?
In mode, out mode, and inout mode
What is inmode?
They can receive data from the corresponding actual parameters
What is out mode?
They can transmit data to the actual parameters
Inout mode
Inmode and out mode
What are the five implementation models?
Pass by value, pass by result, pass by value result, pass by reference and pass by name
What is pass by value
The value of the actual parameter is used to initialize the corresponding formal parameters which then acts as a local variable in the subprogram.
What do pass by value used to implement
In-mode semantics
What are Pass by value implemented by
Copy
What is Pass by result
No value is transmites to a subroutine
The corresponding formal parameter acts as a local variables whose value is transmitted back to the callers actual parameter
What as pass by result used to implement
Out-mode params
What are the pros for pas any result and pass by value?
Fast for scalars (linkage costs and access time)
No side affects to the params
What are the cons for pass by value, pass by result and pass by value-result
Parameter collision for the result ones
Extra storage
Copy and storage can be costly if large
What is pass by value result and what are the two steps
Combo of pass by value and pass by result (pass by copy)
(1) value of the actual parameter is used to initialize the corresponding formal param
(2) the formal parameters acts as a local variables and at sub termination value is transmitted back to the actual parameter
Pass by reference is an implementation model for
Inout mode params
Most languages use what type of stack to pass parameters
runtime
When are inmode parameters used
Whenever no data is returned to the caller
When is outmode parameters used
When no data is transferred to the callee but the sub routine but transmit data back to the caller
When is inout mode params used
Used only when data must move in both directions between caller and caller
What are two complications with subroutine params
Are params type checked
What ref envi should be used for executing the passed subroutine
Shallow binding is the environment of the call statement that
Enacts the passed subroutine
Deep binding is the environment of the
Definition of the subroutine
Ad hoc binding is the environment of the call statement that
Passed it as an actual parameter
When can deep binding and ad hoc brining be the same
When a subroutine is declared and passed by the same subroutine
Static scoped languages usually use what type of being gay
Deep
Dynamic scoped languages usually used what type of binding
Shallow
What is an overloaded subroutine
Has same name as another subroutine but different referencing environment but different signature
What is an generic/polymorphic subroutine
Takes parameters of different types on different activations
Ad hoc polymorphism is what type of subroutines
Overloaded subroutines that need not behave similarly
What type of polymorphism is provided by a subroutine that takes generic params to describe the types of params
Parametric
Often called generic subroutines
What is a subroutine that has multiple entry points which are controlled by these particular types of subroutines themselves
Coroutine
What is the invocation of a coroutine named
Resume