Week 8- Subprogram Flashcards
What is abstraction in programming languages?
Abstraction in programming languages refers to the concept of hiding low-level details and replacing them with subprogram calls, which enhances readability and manages complexity.
What are the two main types of abstraction in programming?
The two main types of abstraction are data abstraction and process abstraction.
What are the benefits of using subprograms in programming?
Subprograms promote reuse, leading to savings in memory space and coding time, and increase readability by hiding low-level details.
How are subprograms related to methods in object-oriented programming (OOP)?
Subprograms are closely related to methods in OOP, but they differ in how they are called and their associations with classes.
What are the fundamental characteristics of subprograms?
Subprograms typically have a single entry point, only one subprogram is in execution at a time, and control returns to the caller after termination.
What is the difference between procedures and functions in subprograms?
Procedures perform actions without returning a value, whereas functions return a value as a result of their execution.
What are some design issues related to subprograms?
Design issues include local referencing environments, parameter-passing methods, handling parameters that are subprograms, and the use of overloaded and generic subprograms.
What is a closure in the context of subprograms?
A closure is a subprogram that captures the environment in which it was created, allowing it to access those captured variables even when called outside their scope.
What are coroutines and how do they differ from subprograms?
Coroutines allow multiple entry points and can suspend and resume execution, unlike traditional subprograms that have a single entry point and run to completion.
How does parameter passing improve subprogram flexibility?
Parameter passing allows subprograms to be more flexible by not relying extensively on nonlocal variables, which enhances reliability and reduces side effects.
What are the common parameter-passing methods in subprograms?
Common parameter-passing methods include pass-by-value, pass-by-reference, pass-by-value-result, and pass-by-name.
What is the significance of a subprogram header?
A subprogram header specifies the name, parameter list (if any), and indicates the start of a subprogram definition.
What are user-defined overloaded operators in subprograms?
User-defined overloaded operators are custom definitions for existing operators (like +, -, etc.) that allow them to be used with user-defined data types.
How do generic subprograms function?
Generic subprograms are designed to work with any data type, allowing the same subprogram to handle different types without rewriting the code for each type.
How does local referencing environment affect subprograms?
The local referencing environment defines the scope of variables and how they are accessed, impacting the subprogram’s behavior and interaction with nonlocal variables.
Describe the difference between direct access to nonlocal variables and parameter passing.
Direct access to nonlocal variables can reduce reliability due to potential side effects, while parameter passing provides a more controlled and flexible way to access data.
What is a protocol of a subprogram, and why is it important?
Parameter profile + return type, defining how the subprogram can be called and what it returns, crucial for interface consistency and type checking.
What are the challenges of extensive access to nonlocal variables?
Extensive access to nonlocal variables can lead to reduced reliability and increased risk of unintended side effects in subprograms.
Why is it important to declare subprogram protocols in advance?
Declaring subprogram protocols in advance allows for static type checking, ensuring that the subprograms are used correctly according to their defined interfaces.
What are parameters in subprograms?
Parameters are values or references passed to subprograms to transmit computations.
Can the name of a subprogram be used as a parameter?
Yes
What are formal and actual parameters in Python?
Formal parameters are placeholders in the subprogram definition, while actual parameters are the values passed during the call.
How are positional parameters bound in Python?
Positional parameters are bound by their position in the subprogram call.
How are keyword parameters bound in Python?
Keyword parameters are bound by name.
What is a default parameter in Python?
A default parameter is a parameter with a predefined value used if no actual parameter is provided.