Chapter 9 Flashcards

1
Q

What are the 2 fundamental abstraction facilities?

A

Process abstraction
Data abstraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Fundamentals of the subprograms

A

Single entry point.
Calling program is suspended during subprogram execution
Control returns to caller after execution of sub program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a subprogram definition?

A

(the entire function) Defines interface(how to use) + actions(What is does) of a subprogram

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a subprogram header?

A

1st part of the subprogram definition ( name, type, parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Example of a subprogram header:

A

int doSomething(int first){…}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Formal vs actual parameters:

A

Formal = “dummy” (int first)
Actual = (12)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a parameter profile/signature?

A

Parameters + types of the function
(length: int, width : int, height : int)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a protocol?

A

Parameter profile + return type
int calc(x: int, y: int);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a subprogram declaration?

A

The entire function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Prototype function example:

A

void foo(int,float);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a positional parameter?

A

Bind actual to formal parameters by position

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the advantage of positional parameters?

A

Safe and effective

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Disadvantage of positional parameters?

A

Hard to read + if you switch 2 numbers, the function will still run perfectly

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is keyword parameters?

A

Bind to the names of formal parameters

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Example of keyword parameters:

A

add(first = 10, second = 12, third = 3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Advantage of keyword parameters?

A

Any order
Avoid parameter correspondence errors

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

DisAdvantage of keyword parameters?

A

Writeability

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What are default parameters?

A

When you assign a value to the parameter in the declaration. If no value is passed in for that parameter then it get assigned the default value

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Why must default parameters be last?

A

How else would you know which parameter is which/

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How many parameters are there in variable number parameter?

A

1+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

How are variable number of parameters processed?

A

Like a list

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Difference between functions and procedures?

A

Procedures give results by modifying.
Functions give results by returning

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Do procedures have return values?

A

No

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

Advantage of stack-dynamic local variables:

A

recursion + flexibility

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Disadvantage of stack-dynamic variables
cost of Time for allocation, initialization and de allocation
26
In most languages local variables are ....?
stack-dynamic
27
What are the 3 modes for parameters?
In mode (receive data from actual parameter) out mode (send data to parameter) inout(send + receive data from actual parameter)
28
What are the 2 ways data transfer can take place?
Physical copy Transmit access path
29
5 models for parameter passing:
Pass-by-value Pass-by-result Pass-by-value-result Pass-by-reference Pass-by-name
30
How does pass-by-value work?
Copy Or transmit access path(not recommended cause of protection)
31
Disadvantage of Pass-by-value?
(copying) additional storage (access path) accesses cost more
32
What mode is pass by value?
In Mode
33
How does pass-by-result work?
Value of formal parameter is used to change actual parameter
34
What mode is pass by result?
Out mode
35
What is a disadvantage of pass by result?
Extra storage + copy operation
36
What is pass-by-value-result?
Combines pass by value and pass by result
37
What is pass-by-value-result drawbacks?
Both the drawbacks of pass by value and result
38
What mode is pass-by-value-result?
inout
39
What is pass by reference?
Pass a access path
40
How do you pass by reference?
With a reference or pointer
41
What is the advantage of pass by reference?
Efficiency ( no copying + duplicate storage)
42
What mode is pass by reference?
inout
43
What is the disadvantage of Pass by reference
Slower access to formal parameters Side effects
44
What mode is pass by name
inout
45
How does pass by name work?
It uses textual substitution All formal parameters are are replaced by appropriate actual parameter
46
How does pass by assignment work?
Assign actual parameter to formal parameter
47
What are the benefits of parameter type checking?
Increased reliability
48
Can multidimensional arrays be passed in as parameters?
Yes, but mapping function must know size of all dimensions in the multidimensional array except the first
49
How is a multidimensional array used as a parameter in C++?
void fun(int matrix[][10]){...} (Dont need to know 1st dimension)
50
What is a disadvantage of multidimensional arrays as parameters?
No writing flexible subprograms Must have exact dimensions
51
How can we by pass no flexibility and rigid structure?
Pass array as a pointer, and dimensions as parameters
52
What is the disadvantage of passing an array as a pointer, and the dimensions as separate parameters
Error-prone Less readable
53
What is the most important for designing parameter passing
Efficiency 1-way or 2-way
54
What parameter passing is best for structures of significant size?
Pass by reference
55
What is a method pointer in C++?
A pointer to a function but you dont know which function. float myFunc(float a, int b){..} float(*ptr)(float,int) = myFunc;
56
What is a delegate in C#?
Similar to a method pointer in C++
57
what is shallow binding when passing subprograms as parameters?
Bind subprogram's referencing environment to the one of the caller ( use callers referencing environment)
58
For what type of languages is shallow binding normally used for?
Dynamic scoped languages
59
what is deep binding when passing subprograms as parameters?
Use referencing environment of when it is passed in (if a variable is overwritten when it is passed as a parameter use that new parameter)
60
what is ad-hoc binding when passing subprograms as parameters?
fun sub3(){ var x = 3; call sub4(sub2) } Since sub2 was passed to sub4 in sub 3... It will have sub3's referencing environment
61
What is a overloaded subprogram?
Same name as another subprogram in the same referencing environment
62
How do you distinguish overloaded subprograms?
It has a unique protocol
63
What is a generic/polymorphic subprogram?
Different parameter types in different calls template T add(T a, T b){} (this is generic)
64
What is ad hoc polymorphism?
Function overloading
65
What is parametric polymorphism?
A subprogram that takes a generic parameter template in c++
66
When are subprogram versions created for C++?
At compile time
67
When are Java generic methods instantiated?
At run time
68
How many times are Java generic methods instantiated?
Once
69
What happens when casts are not automatically in Java?
Any type errors will only be detected at runtime
70
How does a wildcard look like for type declaration in java?
Usually used in the sense List l
71
What does the wildcard in java type declaration mean?
Any type of object
72
How do you reduce side effects?
Make parameters in-mode only
73
What is a closure in JS?
An anonymous function return function(y){return x + y} if x = makeAdder(5) and adder returns this then x becomes a function
74
What is a coroutine?
A subprogram with multiple entry points Controls the entry points itself
75
What is symmetric control in the context of coroutines?
Caller + callee coroutine exist on a more equal basis
76
What is a coroutine call called?
A resume
77
What is quasi-concurrent execution in coroutines?
They appear to run at the same type but actually they are interleaved on a single thread