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
Q

What is the Advantage and Disadvantage of Static type binding?

A

Adv: Writability

DisAdv : typographic errors cant be picked up by compiler

26
Q

What is type inferencing?

A

Determining the types of variables form context (C#, Visual B 9.0+, Haskell, ML, F#)

27
Q

What is the advantage + disAdv of dynamic type binding?

A

Adv: Flexibility

DisAdv: Cost + type error detection by compiler/interpreter is difficult

(JS,Python,ruby,PHP,C# (limited))

28
Q

What are the 3 stages of Storage bindings and lifetime?

A

Allocation, Deallocation, and lifetime of a variable

29
Q

What are the different categories of Variables by Lifetime?

A

Static
Stack-dynamic
Explicit heap-dynamic
Implicit heap-Dynamic

30
Q

What is Stack-dynamic variables?

A

Storage bindings created for variables when their declaration statements are elaborated

31
Q

Adv + DisAdv of Stack-dynamic variables

A

Adv: Allows recursion + conserves storage

DISAsv: Overhead of allocation + deallocation
Subprograms cannot be history sensitive
inefficient references

32
Q

How is Explicit heap-dynamic variables allocated?

A

By explicit directives, specified by the programmer, which takes effect during execution (The variables are nameless)
(int * p = new int(12))

33
Q

If Explicit heap-dynamic variables are nameless how are they referenced?

A

Through separate pointers or references

34
Q

Adv + DisAdv of explicit heap-dynamic variables?

A

Adv: Custom dynamic storage management

DisAdv: unreliable (difficult to use correctly)
inefficient
Difficult to implement

35
Q

How is Implicit heap-dynamic variables allocated?

A

Assignment (all strings and arrays in JS, PHP and Perl)

36
Q

Adv + DisAdv of Implicit heal-dynamic variables?

A

Adv: Flexible

DisAdv: Inefficient (most attribute binding is dynamic)
Loss of error detection

37
Q

What is the scope of a variable?

A

The range of statements over which it is visible

38
Q

What are the scope rules of a language?

A

The definition of how name references are associated with variables

39
Q

What are the approaches to scoping rules?

A

Static scope
Dynamic scope

40
Q

How does static scope work?

A

It is based on program text to connect name reference to a variable (compiler + reader must find the declaration)

41
Q

How do you find the declaration in a static scope?

A

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
Q

What are enclosing static scopes called?

A

Static ancestors(nearest static ancestor is called a static parent)

43
Q

In what languages are variable hiding in blocks?

A

C and C++

44
Q

What are the 2 parts of a let construct?

A

Part that binds names to values
2nd part uses the names defined in the first part

45
Q

What is the Declaration Order of C99,C++ and Java and C#?

A

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
Q

what is the variable scope in C#

A

The whole block that the variable appears in

47
Q

in which languages is this allowed?
{{int x} int x}

A

C99, C++, and Java but not C#

48
Q

What is the scope of variables in PHP?

A

The scope is from the declaration to end of program.

49
Q

How can global variables be accessed in PHP?

A

Through the $GLOBALS array and declaring it “global” in the function

50
Q

When can a global variable be assigned to in a function

A

When the variable is declared as global in the function

51
Q

What is the advantages and DisAdv of static scoping?

A

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
Q

What is Dynamic Scope based on?

A

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
Q

Advantage and DisAdv of Dynamic scoping:

A

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
Q

What is the referencing environment of a statement

A

The collection of all names that are visible in the statement

55
Q

When a language uses a static scope what variables are visible?

A

Local variables + all the visible variables in all of the active subprograms

56
Q

When a language uses a dynamic scope what variables are visible?

A

static scope + active subprograms have started execution and have not yet terminated

57
Q

How many times is a name bound to a value for names constants?

A

Only once

58
Q

What is the Adv of Named constants

A

Readability and reliability

59
Q

How is named constant bound statically vs dynamically?

A

Static : const int SIZE = 10 + 5

Dynamic: const int SIZE
Size = a + 1

60
Q

What are the 2 kind of named constant in C#

A

const <- static
readonly <- dynamic