Final Exam Flashcards

1
Q

System langages vs scripting languages?

A

System programming languages has an emphasis on computing a result, high performance compilers. Scripting languages emphasis on automating a process, highly-portable interpreters.

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

What is a scripting language?

A

One that coordinates other programs.

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

Traditional programming vs scripting langues stress different priorities…

A

traditional programming stress efficiency, maintainability, portability, and the static detection of errors.

Scripting languages stress flexibility, rapid development, local customization, and dynamic runtime checking

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

General thumb of rule on speed of traditional “system languages” and scripting languages:

A

Code can be developed 5 to 10 times faster in a scripting language, but will run 10 to 20 times slower.

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

What are some common characteristics of a scripting language?

A
  1. Both batch and interactive use
  2. Economy of expression.
  3. Lack of declarations; simple scoping rules
  4. Flexible dynamic typing.
  5. Easy access to other programs.
  6. Sophisticated pattern matching and string manipulation.
  7. High level data types.

Tend to find their principal use in well-defined problem domains

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

General purpose languages widely used for scripting?

A

Scheme, visual basic

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

Scripting languages intended to be general purpose:

A

Perl, python, ruby.

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

Ancestors of modern scripting languages:

A
  1. Command interpreters or “shells” of traditional batch and “termina” computing.

Varios tools for text processing and repot generation: Unix sed and awk

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

Problem domains of scripting languages

A

Mathematics and Statistics (Matlab), Extension Languages, General-Purpose scripting Languages

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

Lua is Portuguese for?

A

Moon

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

Advantages of Lua?

A

Extensibility, simplicity, efficiency, and portability. Easy to write modules that add functionality. Easy to embed Lua as a scripting language in other program such a game or use it on hardware device.

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

What are the basic types in Lua?

A

nil, number, string, boolean, table, function, thread, userdata

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

How to define default values in functions?

A

the or operator:
function Hello(str)
str = str or “World”
end

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

How to create own blocks in lua?

A

Use do end

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

How to do variable number of parameters in lua?

A
... 
function printLines(...)
    for i = 1, select("#", ...) do
        print((select(i, ...)))
    end
end
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are closures?

A

Function bound by scope preserving local variables accessed by the function.

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

What are types good for?

A
  1. Implicit context: programmer does not need to know the exact size of a block of memory to set aside for a variable.
  2. Checking to make sure that certain meaningless operations do not occur. Does not catch all but enough of them to be useful.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is strong typing and what is static typing?

A

Strong typing is a buzzword that informally means that the language prevents you from applying an operation to data on which it is not appropriate.
STATIC typing means that the complier can do all the checking at compile time.

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

What is orthogonality?

A

No restrictions on the ways in which features can be combined. For example, Pascal is more orthogonal than Fortran because it allows arrays of any type.

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

Why is orthogonality considered good?

A

Makes a language easy to understand, easy to use, and easy to reason about.

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

What are primitive data types?

A

Those not defined in terms of other data types.

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

What is the integer type?

A

Almost always exact reflection of hardware.

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

Floating-Point Types?

A

Model real numbers, but only as approximations. Usually exactly like the hardware, but not always.

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

Decimal Types?

A

Essential for business applications to represent money. Essential to COBOL, c# offers a decimal data type. AA fixed number of dceimal digits is stored in binary coded decimal (BCD) form. Advantage? accuracy. Disadvantage: limited range, wasteful of memory

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

Advantage of boolean types?

A

Readability

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

Character Types?

A

Stored as numeric codings. Most commonly used coding: ASCII, alternative 16-bit coding: Unicode.

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

String Types? Design issues?

A

Values are sequences of characters.

- is it a primitive type or just a special kind of array? Should the length of strings be static or dynamic?

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

What is an ordinal type?

A

Type in which the range of possible values can easily be associated with the set of possible integers. Examples of ordinal types in java: integer, char, Boolean.

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

What are enumeration types?

A

Provide a way of defining and groupling collections of named constants, which are called enumeration constants.

C# example:
enum days {mon, tue, wed, thu, fri, sat, sun};

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

Design issues with enumeration types?

A
  • is an enumeration constant allowed to appear in more than one type definition, and if so, how is the type of an occurrence of that constant checked?
  • Are enumeration values coerced to integer?
  • Can any other type be coerced to an enumeration type?
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Advantages of enumeration types?

A

Aids readability, e.g. , no need to code a weekday as a number>

  • Aids reliability, e.g., compiler can check
    • operations (days should not be added together)
    • No enumeration value can be assigned a value outside its defined range.
  • C++ poor support as it coerce enumerations into integer types.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

What is a subrange type?

A

An ordered contiguous subsequence of an ordinal type.

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

Problem with subrange types?

A

If the result of an arithmic operation is assigned into a variable of a subrange type, then a dynamic semantic check may be required.

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

Advantage of subrange type?

A

Aid to readability: makes it clear to readers that variables of subrange can store only certain range of values.
- Reliability, assigning a value to a subrange variable that is outside the specific range is detected as an error.
Odd how Ada is the only conteporary language that has subrange types other than integer.

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

What are some composite types?

A
  1. Records and Unions. Record consists of a collection of fields, each which belongs to a potentially different type. A union (variant record) consists of a collection of fields where only one field is valid at any given time.
  2. Array: collection of the same types.
  3. Set: Collection of unique elements.
  4. Pointer: an address, or reference, to a base type.
    List: recursively defined as a head and a list.
    File: represents data on a mass-storage device.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
36
Q

What is a record? Design issues?

A

A collection of related data that could have different data types..
Design issues: what is the syntactic form of references to the field?
- Are elliptical references allowed?

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

What is an elliptical reference and what are some of the problems with it?

A

Allows some of the identifiers along the path not to be explicitly stated versus fully qualified references. Problems if you have two of same named elliptical reference: what do you use?

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

When to use arrays versus records?

A

Arrays are used when all data values have the same type and/or processed the same way. Records are used when the collection of data values is heterogeneous and the different fields are not processed the same way.

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

What is a union?

A

A type whose variables are allowed to store different type values at different times during execution.

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

What are some design issues with union types?

A

Should type checking be required? Should unions be required to be embedded in records?

Free unions are construct for no type checking. Otherwise, type checking of unions require that each union include a type indicator called discriminant

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

What are array types?

A

A homogenous aggregate of data elements in which an element is identified by its position in the aggregate, relative to the first element.

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

Design issues of arrays?

A

What types are legal for subscripts? Are subscripting expressions in element reference range checked? When are subscript ranges bound? When does allocation take place? Are ragged or rectangular multidimensional arrays allowed, or both? What is the maximum number of subscripts? can array objects be initialized? are any kind of slices supported?

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

What are the five categories of arrays?

A
  1. Static
  2. Fixed stack-dynamic.
  3. Stack-dynamic.
  4. Fixed heap-dynamic
  5. Heap-dynamic
44
Q

Static array implementation, advantage and disadvantage.

A

subscript ranges are statically bound and storage allocation is static (b4 runtime). Advantage: efficiency (no dynamic allocation). Disadvantage: storage is fixed during duration of program. An array whose size is known, and whose storage is allocated, at compile time. int static_array[7].

45
Q

What is fixed static-dynamic? Advantage? Disadvantage?

A

Subscript ranges are statically bound, but the allocation is done at declaration time. Advantage: space efficiency. Disadvantage: required allocation and de-allocation time. You know the size of array at compile time, but allow it to be allocated automatically on the stack.

void foo()
{ 
   int stack_dynamic_array[n];
}
46
Q

What is stack-dynamic? Advantage? Disadvantage?

A

Subscript ranges are dynamically bound and the storage allocation is dynamic (both are done at runtime. Advantage is flexibility (the size of an array need not be known until the array is to be used). Disadvantage: array size cannot grow or shrink after allocation. You don’t know the size until runtime.

void foo(int n)
{
  int stack_dynamic_array[n];
  /* ... */
}
47
Q

What is fixed heap-dynamic array implementation? Advantage? Disadvantage?

A

Similar to fixed stack-dynamic: storage binding is dynamic but fixed after allocation. (binding done at runtime, and storage is allocated from the heap, not the stack). Advantage: flexibility (array size always fit problem). Disadvantage: allocation from heap takes longer than from the stack.

int * fixed_heap_dynamic_array = malloc(7 * sizeof(int));

48
Q

What is heap-dynamic? Advantage? Disadvantage?

A

binding of subscript ranges and storage allocation is dynamic and can change any number of times. Advantage: flexibility (arrays can grow or shrink during program execution). Disadvantage: allocation and de-allocation takes longer and may happen many times during execution of the program.

void foo(int n)
{
  int * heap_dynamic_array = malloc(n * sizeof(int));
}
49
Q

What is a rectangular array?

A

Multi-dimensional array in which all of the rows have the same number of elements and all columns have the same number of elements.

50
Q

What is a jagged matrix?

A

Has rows with varying number of elements. (Think arrays of arrays).

51
Q

Access function for a single-dimensional array:

A

address(list[k]) = address (list[lower_bound}) + ((K-lower_bound) * element_size)

52
Q

Common ways of accessing rectangular arrays?

A

Row major order or by column major order.

53
Q

What is an associative array?

A

An unordered collection of data elements that are indexed by an equal number of values called key. Mathematically same as a function.

54
Q

What are some design issues of associative arrays?

A

What is the form of references to elements? Is the size static or dynamic?

55
Q

What are pointer types?

A

A pointer type variable has a range of values that consists of memory addresses and a special value, nil. Pointers provide the power of indirect addressing, a way to manage dynamic memory. Can be used to access a location the area where storage is dynamically created (heap)

56
Q

What are some design issues of pointers?

A

Should language support pointer types, reference types, or both? What is the scope and lifetime of a pointer variable? Are pointers restricted as to the type of value to which they can point? Are pointers used for dunamic storage management, indirect addressing, or both?

57
Q

What are the pointer operations?

A

Assignment and dereferencing. Assaignment is used to set a pointer variable’s value to some useful address. Dereferencing yields the value stored at the location represented by the pointer’s value.

58
Q

Problems with pointers?

A

Dangling pointers - a pointer that contains the address of a heap-dynamic variable that has been deallocated.
int* p1 = new int[100];
int * p2 = p1;
delete p1

Lost heap-dynamic variable. An allocated heap-dynamic variable that is no longer accessible to the user program (often called garbage).
int *p1 = new int[100];
int newVar = 7;
p1 = &newVar;

59
Q

Thoughts on pointers in c and c++?

A

Extremely flexible but must be used with care. Can point to any variable regardless of when or where it was allocated. Used for dynamic storage management and addressing. Pointer arithmetic is possible. Domain type need not be fixed (void *). void * can point to any type and can be type checked.

They are like goto’s - widen the range of cells that can be accessed by a variable. Pointers or references are necessary for dynamic data structures.

60
Q

What is a reference type?

A

Advantage of both pass-by-reference and pass-by-value. They refer to objects.

61
Q

What are the two approaches to heap management?

A

Reference counters (eager approach). Reclamation is gradual.

Mark-and-sweep (lazy approach). Reclamation occurs when the list of variable space becomes empty.

62
Q

What is reference counters? Advantages/disadvantages?

A

Maintain a counter in every cell that stores the number of pointers currently pointing at the cell. Disadvantage? space required, execution time required, complications for cells connected circularly. Advantage: It is instrinsically incremental, so significant delays in the application execution are avoided.

63
Q

What is mark and sweep and the disadvantage?

A

the run-time system allocates storage cells as requested and disconnects pointers from cells as necessary; mark-and-sweep then begins. Every heap cell has an extra bit used collection algorithm, initial set to garbage. All pointers traced into heap, and reachable cells amrked as not garbage, and garbage cells are then returned to list of avail cells. Disadvantages? In its original form, it was done too infrequently. When done, it caused significant delays in application execution. Contemporary mark-and-sweep algos avoid this by doing it more often, called incremental mark-and-sweep

64
Q

A type system has rules for?

A

Type equivalence (when are the types of two values the same?), type compatibility (when can a value of type A be used in a context that expects type B?, and type inference (what is the type of an expression, given the types of the operands?)?

65
Q

What are the two principle ways of defining type equivalence?

A

Structural equivalence is based on the content of type definitions: two types are the same if they consist of the same components put together in the same way.
Name equivalence is based on the lexical occurrence of type definition. Each definition introduces a new type.

66
Q

What is strict name equivalence?

A

A language in which aliased types are considered distinct. A declaration such as TYPE A = B is considered a definition.

67
Q

What is loose name equivalence?

A

A language in which aliased types are considered to be the same. A declaration TYPE A = B is considered merely a declaration.

68
Q

Wat are three ways to allow different types to be compatible?

A
Type conversion (type cast)
Non-converting type cast (type pun)
Type coercion
69
Q

What is type conversion (cast)?

A
  1. If the languages uses name equivalence and the types are structurally equivalent, no code at runtime.
  2. If the types have different set of values, but the intersecting values are represented the same way, code must be executed at runtime to ensure the current value is valid.
  3. If the types have different low-level representations but there is a correspondence among their values: code must be executed at runtime because conversion is necessary.
70
Q

What is non-converting cast?

A

A change of type that does not alert the underlying bits

71
Q

What is type coercion?

A

Whenever a language allows a value of one type to be used in a context that expects another, the compiler must perform an automatic, implicit conversion to the expected type.

72
Q

Why is type coercion a controversial subject?

A

They allow types to be mixed without an explicit indication on the p art of the programmer. They represent a significant weakening of type security.

73
Q

What are the two fundamental abstraction facilities in programming languages?

A
  1. Data abstraction: Emphasized in programming languages from 1980s, the essence of code reuse via object-oriented programming.
  2. Process abstraction:Emphasized from the early days of programming languages
    The essence of code re-use via subprograms
74
Q

What are the two categories of subprograms?

A

Procedures: collection of statements that define parameterized computations. Functions: structurally resemble procedures but are semantically modeled on mathematical functions.

75
Q

What are the advantages and disadvantages of local variables (stack-dynamic).

A

Advantages: support for recursion, storage for locals is shared among some subprograms. Disadvantages: allocation/de-allocation, initialization time, indirect addressing, subprograms cannot be history sensitive.

76
Q

What is a formal parameter?

A

A dummy variable listed in the subprogram header and used in the subprogram.

77
Q

What is an actual parameter?

A

Represents a value or address used in the subprogram call statement.

78
Q

How can binding of parameters occur?

A

Positional - binding of actual parameters to formal parameters by position: safe and effective.

Binding can be by keyword. The name of the formal parameter to which an actual parameter is to be bound is specified with the actual parameter. Advantage: Parameters can appear in any order. Disadvantage: User must know the formal parameter’s name.

79
Q

What are the parameter-passing methods?

A

Pass-by-value(in), pass-by-result(out), pass-by-value-result (in and out), pass-by-reference (address), pass-by-name(text)

80
Q

What is Pass-By-Value?

A

The value of the actual parameter is used to initialize the corresponding formal parameter. Disadvantage: additional storage is required and the actual move can be costly if data is large. Must write-proect the value in the subprogram if access path method

81
Q

What is pass-by-result?

A

No value is transimitted to the subprogram. The corresponding formal parameter acts as a local variable. Value is transmitted to caller’s actual parameter when control is returned to the caller. Requires extra storage and copy operation. Potential problems? sub(p1,p1): whiever formal parameter is copied back last will represet the current value of p1.
sub(list[i],i): is the address of list[i] computed at the beginnning or end of subprogram?

82
Q

What is Pass-By-Value-Result?

A

A combination of pass-buy-value and pass-by-result, sometimes called pass-by-copy. Formal parameters have local storage. Disadvantages mirror that of pass-by-value and pass-by-result

83
Q

Pass-by-reference

A

Pass an access path; pass-by-sharing. Advantage: passing process is efficient (no copying and no dupliated storage). Disadvantages: slower accesses to formal parameters. Potential for unwanted side effects

84
Q

What is pass by name?

A

The actual parameter is textually substituted for the coreresponding formal parameter in all its occurances in the subprogram. Requires the referencing environment of the caller is passed with the parameter, creating a closure. The actual binding to a value takes place only when it is referenced or assigned inside of the subprogram. Allows flexibility in late binding.

85
Q

Implementing parameter-passing?

A

Usually takes place though the run-time stack, pass-by-reference simplest to implement as its only an address placed on the stack

86
Q

What are some issues with parameters that are subprograms?

A
  1. How are parameter types checked?
  2. What is the correct referencing environment for a subprogram that was sent as a parameter? - Which variable is being referred to?
87
Q

What are some possibilities to referencing environments?

A

Shallow binding: the environment of the call statement that enacts the passed subprogram.

  1. Deep binding: the environment of the textual definition of the passed subprogram.
  2. Ad hoc binding: the environment of the call statement that passed the subprogram.
function sub1() {
   var x = 1;
   function sub2() {
      print(x);
   };
   function sub3() {
      var x = 3;
      sub4(sub2);
   };
   function sub4(subx) {
      var x = 4;
      subx();
   };
   sub3();
};

For shallow binding, the referencing
environment is that of sub4; the output will be 4.

For deep binding, the referencing
environment is that of sub1; the output will be 1.

88
Q

What is a closure?

A

A subprogram and the referencing environment where it was defined.

89
Q

What are three kinds of generic subprograms?

A

Ad hoc polymorphism (overload subprograms (need not behave similarly), subtype polymorphism (an object can access methods of a compatible type(“has a” relationship) or methods of super type (“is-a” relationship).
3. Parametric polymorphism. A generic parameter T is used in a type expression that describes the type of the parameters.

90
Q

What is a coroutine?

A

Provide quasi-concurrent execution of program units; execution is interleaved, but not overlapped. It is a subprogram that have multiple entries which are controlled by the coroutines themselves. A coroutine call is named resume.

91
Q

What is a subprogram linkage?

A

The subprogram call and return operations of a language

92
Q

How to implement simple subprogram?

A
  1. Save the execution status of caller.
  2. Compute and pass the parameters.
  3. Pass the return address to the called.
  4. Transfer control to the called.
93
Q

How to implement returns from simple subprograms?

A

If pass-by-value-result or out mode parameters are used, move the current values of those parameters to their corresponding actual parameters. If the subprogram is a function, move the functional value to a place where the caller can get it. Restore the execution status of the caller. Transfer control back to the caller.

94
Q

What is the required storage for implementing subprograms>

A

Status information about caller, parameters, return address, return value for functions, temporaries.

95
Q

What is an activation record for a simple subprogram? For one with stack-dynamic local variables?

A

local variables
parameters
return address

local variables
parameters
dynamic link
return address

96
Q

Caller actions in activation records?

A
  1. Create an activation record instance?
  2. Save the execution status of the current program unit.
  3. Compute and pass the parameters.
  4. Pass the return address to the called.
  5. Transfer control to the called.
97
Q

Prologue actions of the called?

A

Save the old enviroment pointer in the stack as the dynamic link and create the new EP for the current executing subprogram. Allocate local variables.

98
Q

Epilogue actions of the called?

A

If there are pass-by-value-result or out-mode parameters, the current values of those parameters are moved to the corresponding actual parameters.If the subprogram is a function, its value is moved to a place accessible to the caller. Restore the stack pointer by setting it to the value of the current EP and set the EP to the old dynamic link. Restore the execution status of the caller. Transfer control back to the caller.

99
Q

Process of locating a non-local reference?

A
  1. Find the correct activation record instance.

2. Determine the correct local offset within that activation record instance.

100
Q

What is a static link?

A

A pointer to a subprogram activiation record’s static parent..

101
Q

What is a static chain?

A

A chain of static links that connects ancestors of activiation records.

102
Q

What is static depth?

A

depth of nesting of the activiation records.

103
Q

What is the chain_offset or nesting_depth of a nonlocal reference?

A

The difference between the static_depth of the reference and that of the scope where it is declared.

104
Q

How to implement dynamic scoping?

A

Deep access: non-local references are found by searching the activiation record instances on the dynamic chain.
The length of the chain cannot be statically determined
Every activation record must have variable names

105
Q

How to implement shallow access?

A

put locals in a central place.
One stack for each variable name
Central table with an entry for each variable name

106
Q

Deep vs Shallow access?

A

Deep-access provides fast subprogram linkage, but references to non-locals, especially distant ones (in terms of the call chain) are costly
Shallow access provides must faster references to non-locals, especially distant ones, but is more costly in terms of linkage