Chapter 5 Flashcards
What are some design issues when it comes to names?
Are there any special words/ key words. How long can it be?
is it case sensitive
Disadvantage of case sensitivity?
Readability - Names that look alike arent alike.
Writeability - IndexOutOfBoundException = difficult to remember exact case
Does special words increase or decrease readability?
Increase since we name actions
What is the problem with too many reserved words?
Too many collisions with users
Attributes of a variable?
Name
Address ( memory )
Value ( content)
Type ( how its stored
Lifetime
Scope
What is l-value and r-value?
l = address (logical value)
r = value ( real value )
What are the possible binding times? ( type binding )
Language design time
Language implementation time
Compile time
Load time
Run time
What are the different types of type binding?
Static + dynamic
Explicit vs implicit declaration
Explicit: int val
implicit: var val = “aaaaa” ( this is implicit type inferencing
What is the adv + disadv of implicit declaration?
adv: writability
Disadv: reliability
What is the adv + cons of dynamic type binding?
Adv: flexibility
Con: Cost + error detection
What is the lifetime of a variable?
when a variable is bound to a memory location
What are the different categories of variables by lifetimes?
Static
Stack-dynamic
heap-dynamic
Adv + cons of static variables?
Adv: efficiency
Cons: flexibility
Adv + cons of stack-dynamic?
Adv: allows recursion
Cons: overhead of allocations
Example of a stack-dynamic variable
int myVar
Example of static variable
static myVar
Adv + cons of heap dynamic variables
( pointers )
Adv: dynamic storage management
Cons: unreliable + divficult to implement
Example of a explicit heap dynamic variable:
int* p = new int(12)
new indicates that it is heap
int* p = int indicates it is explicit
ADV + cons of Implicit heap-dynamic variables?
Adv: flexibility
Cons: inefficient
What is the scope of a variable?
The range of statements over which it is visible
2 scoping rules:
static scope
dynamic scope
How does static scoping work?
Start where variable is used. Go outwards until you find where the variable has been declared
How do you create static scopes inside of program units?
Blocks
void sub() {
int count;
while (…) {
int count;
count++;
}
}