Chapter 5 Flashcards

(28 cards)

1
Q

What are the design issues for names?

A

The primary design issues are whether names are case sensitive and whether the special words of the language are reserved words or keywords .

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

What is the potential danger of case-sensitive names?

A

They hurt readability because similar-looking names (like Rose and rose) mean different things.

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

In what way are reserved words better than keywords?

A

Reserved words cannot be redefined, preventing confusion; keywords can be redefined.

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

What is an alias?

A

When two or more variable names access the same memory location.

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

Which category of C++ reference variables is always aliases?

A

Reference variables and dereferenced pointers that point to the same location are always aliases

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

What is the l-value?

A

The address of a variable used on the left side of an assignment.

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

What is the r-value?

A

The value of a variable used on the right side of an assignment.

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

Define binding.

A

Connecting an attribute to an entity.

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

Define binding time.

A

The moment when a binding occurs.

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

When can bindings take place?

A

Compile time, link time, load time, run time.

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

Define static binding and dynamic binding.

A

Static Binding: Occurs before run time and stays unchanged throughout execution.

Dynamic Binding: Occurs during run time or can change during execution

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

What are the advantages and disadvantages of implicit declarations?

A

Advantage: It is a minor convenience for programmers.

Disadvantage: It hurts reliability because the compiler cannot detect typo errors (e.g., misspelling a variable name creates a new variable instead of an error)

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

What are the advantages and disadvantages of dynamic type binding?

A

Advantage: Provides great programming flexibility (e.g., writing generic code).

Disadvantages: It makes programs less reliable (error detection is lost) and increases the cost of execution time.

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

Define Static variables, and their advantages/disadvantages

A

The variable is bound to storage before execution; efficient but no recursion.

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

Define Stack-dynamic variables, and their advantages/disadvantages

A

The variable is bound to storage when their declaration statement is reached; supports recursion with overhead.

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

Define Explicit heap-dynamic variables, and their advantages/disadvantages

A

Explicit heap-dynamic variables are nameless (abstract) memory cells that are
allocated and deallocated by explicit run-time instructions; good for dynamic structures.

17
Q

Define Implicit heap-dynamic variables, and their advantages/disadvantages

A

The variable is bound to heap storage only when they are assigned a value; flexible but slow and error-prone.

18
Q

Define lifetime, scope, static scope, and dynamic scope.

A

Lifetime: How long a variable is bound to memory

Scope: The range of statements where the variable is visible.

Static Scope: Determined by the text layout before running.

Dynamic Scope: Determined by the call chain while running.

19
Q

How is a reference to a nonlocal variable in a static-scoped program connected to its definition?

A

The compiler first searches the local declarations. If not found, it searches the “static parent” (the enclosing program unit), then that parent’s parent, and so on, until the definition is found

20
Q

General problem with static scoping.

A

It often allows more access to variables than is necessary; structure decays as programs change.

21
Q

What is the referencing environment?

A

It is the collection of all variables that are visible in that statement.

22
Q

What is a static ancestor of a subprogram? What is a dynamic ancestor?

A

Static Ancestor: The enclosing subprogram

Dynamic Ancestor: The calling function

23
Q

What is a block?

A

A code section with its own local scope.

24
Q

What is the purpose of let constructs.

A

To bind names to values in a small scope.

25
ML let vs C block variables.
ML lets bind immutable values; C variables are mutable.
26
Describe the encapsulation of an F# let inside a function and outside all functions.
Inside a function: The scope extends from the definition to the end of the function (or indentation block). Outside all functions: The name is global, and its scope extends to the end of the file.
27
What are the advantages and disadvantages of dynamic scoping?
Advantages: It is convenient because parameters don't need to be passed explicitly; they are implicitly visible from the caller. Disadvantages: It makes programs hard to read less reliable, and slower
28
Advantages of named constants.
Improves readability and simplifies later modification.