Chapter 5 Flashcards

1
Q

What are some design issues when it comes to names?

A

Are there any special words/ key words. How long can it be?
is it case sensitive

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

Disadvantage of case sensitivity?

A

Readability - Names that look alike arent alike.
Writeability - IndexOutOfBoundException = difficult to remember exact case

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

Does special words increase or decrease readability?

A

Increase since we name actions

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

What is the problem with too many reserved words?

A

Too many collisions with users

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

Attributes of a variable?

A

Name
Address ( memory )
Value ( content)
Type ( how its stored
Lifetime
Scope

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

What is l-value and r-value?

A

l = address (logical value)
r = value ( real value )

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

What are the possible binding times? ( type binding )

A

Language design time
Language implementation time
Compile time
Load time
Run time

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

What are the different types of type binding?

A

Static + dynamic

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

Explicit vs implicit declaration

A

Explicit: int val
implicit: var val = “aaaaa” ( this is implicit type inferencing

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

What is the adv + disadv of implicit declaration?

A

adv: writability
Disadv: reliability

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

What is the adv + cons of dynamic type binding?

A

Adv: flexibility
Con: Cost + error detection

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

What is the lifetime of a variable?

A

when a variable is bound to a memory location

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

What are the different categories of variables by lifetimes?

A

Static
Stack-dynamic
heap-dynamic

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

Adv + cons of static variables?

A

Adv: efficiency
Cons: flexibility

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

Adv + cons of stack-dynamic?

A

Adv: allows recursion
Cons: overhead of allocations

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

Example of a stack-dynamic variable

17
Q

Example of static variable

A

static myVar

18
Q

Adv + cons of heap dynamic variables

A

( pointers )
Adv: dynamic storage management
Cons: unreliable + divficult to implement

19
Q

Example of a explicit heap dynamic variable:

A

int* p = new int(12)

new indicates that it is heap
int* p = int indicates it is explicit

20
Q

ADV + cons of Implicit heap-dynamic variables?

A

Adv: flexibility
Cons: inefficient

21
Q

What is the scope of a variable?

A

The range of statements over which it is visible

22
Q

2 scoping rules:

A

static scope
dynamic scope

23
Q

How does static scoping work?

A

Start where variable is used. Go outwards until you find where the variable has been declared

24
Q

How do you create static scopes inside of program units?

A

Blocks
void sub() {
int count;
while (…) {
int count;
count++;
}
}

25
In scheme what are the 2 parts of the let construct?
1st = bind names to values 2nd = use the name
26
Adv + cons of Static scoping?
Adv: usually works well Cons: too much access is possible + subprograms gravitate toward global
27
Adv + Con of dynamic scoping?
Adv: convenience ( no need for parameters ) Cons: Variables are visible to all subprograms it calls. no static type checking
28
TODO: dynamic scoping example
29
What is the referencing environment of a statement?
Collection of all names that are visible in the statement
30
What variables can you see when using dynamic scoping?
Local vars + vars in all active subprograms
31
What variables can you see when using static scope?
Local vars + variables of the enclosing scopes ( my own + those that i am a part of aka normal c++? )
32
What is good about constants?
It increases readability + reliability