Chapter 5 Flashcards

1
Q

What are variables an abstraction of?

A

Memory cells that are characterized by attributes

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

What are some common problems with Names/identifiers?

A

What form can names take and are there special words reserved (keywords)

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

What are the aspects of a name?

A

Length
use of special characters
Case sensitivity

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

What is the problem when names are too short?

A

They cannot be connotative

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

How does Fortran, C99, C++, C#, Ada and Java handle name length?

A

Fortran = 6 in F1, 31 in F95 and 63 in F 2003
C99 = No limit but only 1st 63 are significant, external names are limited to a max of 31
C++ = No limit but implementers often impose one
C# + ADA + Java = No limit and all are significant

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

Special Characters in PHP, Perl and Ruby

A

PHP = All variable names need to start with $
Perl = Scalars use $ arrays use @ and hashes use a %
Ruby = Instance variable names begin with @, Class variables names begin with @@

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

What is the disadvantages Of case sensitivity?

A

Decreased readability and write-ability

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

Why are there special words?

A

To aid in readability by naming actions

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

Can reserved words be user-defined?

A

Nope

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

What is the problem with an excess in special words?

A

Name collisions are more likely to occur (COBOL has 300 reserved words)

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

What are the 6 attributes of a variable?

A

Name
Address
Value
Type
Lifetime
Scope

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

All variables have names? T/F

A

F

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

Can there be different addresses at different execution times for variables?

A

Yes

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

What is a alias?

A

When 2 variables can be used to access the same memory locations (pointers, references, and unions)

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

Are aliases good for readibility or bad?

A

Bad (readers must remember all of them)

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

What is the Value of a variable

A

Stores the content of a memory location is associated with

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

What is the l-value of a variable?

A

The address (l-value = location value)

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

What is the r-value?

A

Value of a variable (real value)

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

What does the type define for variables?

A

How a value is stored in memory

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

What are the possible binding times?

A

Language design time(binding operators symbols to operations)
Language implementation time (binding floating point type to a representation)
Compile time(Binding variable to type in C or Java)
Load time (Binding C++ local static to memory cell)
Runtime (binding nonstatic local variable to a memory cell)

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

Whats the difference between static binding and Dynamic binding?

A

Static = occurs before run time
Dynamic = during execution

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

What is type binding and what are the issues?

A

Binding of a variable to a type

How is a type specified and when does the binding take place

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

What is explicit declaration?

A

statement used to declare types of variables. (int var )

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

What is implicit declaration?

A

A default mechanism for specifying variable types.
Used in BASIC, Perl,Ruby, JS, PHP

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the Advantage and Disadvantage of Static type binding?
Adv: Writability DisAdv : typographic errors cant be picked up by compiler
26
What is type inferencing?
Determining the types of variables form context (C#, Visual B 9.0+, Haskell, ML, F#)
27
What is the advantage + disAdv of dynamic type binding?
Adv: Flexibility DisAdv: Cost + type error detection by compiler/interpreter is difficult (JS,Python,ruby,PHP,C# (limited))
28
What are the 3 stages of Storage bindings and lifetime?
Allocation, Deallocation, and lifetime of a variable
29
What are the different categories of Variables by Lifetime?
Static Stack-dynamic Explicit heap-dynamic Implicit heap-Dynamic
30
What is Stack-dynamic variables?
Storage bindings created for variables when their declaration statements are elaborated
31
Adv + DisAdv of Stack-dynamic variables
Adv: Allows recursion + conserves storage DISAsv: Overhead of allocation + deallocation Subprograms cannot be history sensitive inefficient references
32
How is Explicit heap-dynamic variables allocated?
By explicit directives, specified by the programmer, which takes effect during execution (The variables are nameless) (int * p = new int(12))
33
If Explicit heap-dynamic variables are nameless how are they referenced?
Through separate pointers or references
34
Adv + DisAdv of explicit heap-dynamic variables?
Adv: Custom dynamic storage management DisAdv: unreliable (difficult to use correctly) inefficient Difficult to implement
35
How is Implicit heap-dynamic variables allocated?
Assignment (all strings and arrays in JS, PHP and Perl)
36
Adv + DisAdv of Implicit heal-dynamic variables?
Adv: Flexible DisAdv: Inefficient (most attribute binding is dynamic) Loss of error detection
37
What is the scope of a variable?
The range of statements over which it is visible
38
What are the scope rules of a language?
The definition of how name references are associated with variables
39
What are the approaches to scoping rules?
Static scope Dynamic scope
40
How does static scope work?
It is based on program text to connect name reference to a variable (compiler + reader must find the declaration)
41
How do you find the declaration in a static scope?
Start at program local unit and continue search in increasingly larger enclosing scopes . Stop when found void f(){ int i = 10; // declaration for(...){ if(){i++; // local program unit} } }
42
What are enclosing static scopes called?
Static ancestors(nearest static ancestor is called a static parent)
43
In what languages are variable hiding in blocks?
C and C++
44
What are the 2 parts of a let construct?
Part that binds names to values 2nd part uses the names defined in the first part
45
What is the Declaration Order of C99,C++ and Java and C#?
C99,C++,Java C# = variable declarations can appear anywhere a statement can C99 C++ and Java = Scope of local variables is from declaration to end of block C++ Java and C# = Loop control variables can be declared in for loop header and scope restricted
46
what is the variable scope in C#
The whole block that the variable appears in
47
in which languages is this allowed? {{int x} int x}
C99, C++, and Java but not C#
48
What is the scope of variables in PHP?
The scope is from the declaration to end of program.
49
How can global variables be accessed in PHP?
Through the $GLOBALS array and declaring it "global" in the function
50
When can a global variable be assigned to in a function
When the variable is declared as global in the function
51
What is the advantages and DisAdv of static scoping?
Adv: Works well in many situations DisAdv: too much access is possible. local variables tend to gravitate towards becoming global. Subprograms also gravitate toward becoming global rather than nested
52
What is Dynamic Scope based on?
The calling sequence of program units (not text layout like global scope) To connect a variable reference to a declaration: Search through chain of subprogram calls that brought execution to the variable reference
53
Advantage and DisAdv of Dynamic scoping:
Adv: Convenience DisAdv: When a subprogram is executing, its variables are visible to all subprograms it calls. impossible to statically type check. Access to non-local variables is slower
54
What is the referencing environment of a statement
The collection of all names that are visible in the statement
55
When a language uses a static scope what variables are visible?
Local variables + all the visible variables in all of the active subprograms
56
When a language uses a dynamic scope what variables are visible?
static scope + active subprograms have started execution and have not yet terminated
57
How many times is a name bound to a value for names constants?
Only once
58
What is the Adv of Named constants
Readability and reliability
59
How is named constant bound statically vs dynamically?
Static : const int SIZE = 10 + 5 Dynamic: const int SIZE Size = a + 1
60
What are the 2 kind of named constant in C#
const <- static readonly <- dynamic