Tuesday, April 9, 2013

Concepts of Programming Languages ---- Chapter 6 Data Types

Concepts of Programming Languages ---- Chapter 6 Data Types

Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 6 Data Types


Review Questions
1.      What is a descriptor?
A descriptor is the collection of the attributes of a variable.
2.      What are the design issues for character string types?
-          Should strings be simply a special kind of character array or a primitive type?
-          Should strings have static or dynamic length?

3.      Describe the three string length options.
-          Static length string : the length can be static and set when the string is created
-          Limited Dynamic length strings : allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition.
-          Dynamic lingth strings : allow strings to have varying length with no maximum.

4.      What are the design issues for arrays?
-          What types are legal for subscripts?
-          Are subscripting expressions in element references range checked?
-          When are subscript ranges bound?
-          When does array allocation take place?
-          Are ragged or rectangular multidimensioned arrays allowed or both?
-          Can arrays be initialized when they have their storage allocated?
-          What kinds of slices are allowed, if any?

5.       Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic arrays. What are the advantages of each?
-          Static array : the subscript ranges are statically bound and storage allocation is static.
Advantage : efficiency(no dynamic allocation and deallocation is required).
-          Fixed stack-dynamic : the subscript ranges are statically bound, but the allocation is done at declaration elaboration time during execution
Advantage : space efficiency.
-          Stack dynamic array : both the subscript ranges and the storage allocation are dynamically bound at elaboration time.
Advantage : flexibility. (the size of an array need not be known until the array is to be used).
-          Fixed heap dynamic array : the subscript ranges and the storage binding are both fixed after storage is allocated.
Advantage : flexibility(the array’s size always fits the problem).
-          Heap dynamic array : the binding of subscript ranges and storage allocation is dynamic and can change an number of times during the array’s lifetime,
Advantage : flexibility (arrays can grow or shrink during program execution).

6.      What happens when a nonexistent element of an array is referenced in Perl?
When a nonexistent element of an array is referenced in perl, an array can be made to shrink to no elements by assigning it the empty list. So, the length of an array is defined to be the largest subscript plus one.

7.       What languages support array slices with stepsizes? 
-          Ruby 
-          Python
-          Perl

8.      What array initialization feature is available in Ada that is not available in other common imperative languages?
 array initialization feature is available in Ada is by directly assigning them to an index position using the => operator, which in Ada is called an arrow.

9.      What is an aggregate constant
Aggregate constant is the parenthesized list of constant value.

10.  What is the structure of an associative array?
An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. User-defined keys must be stored in structure.

11.  What is the purpose of level numbers in COBOL records?
the purpose of level numbers in COBOL records is to divide of a COBOL program.
The example:
01                EMPLOYEE-RECORD
02        EMPLOYEE-NAME
            05 FIRST
            05 LAST
02        HOURLY-RATE

12.  Define fully qualified and elliptical references to fields in records.
-          Fully qualified references must include all record names.
-          Elliptical references allow leaving out record names as long as thereference is unambiguous.

13.  What the two common problems with pointers?
Dangling pointers (dangerous) and Lost heap-dynamic variable.
14.  What is a C++ reference type, and what is its common use?
C++ includes a special kind of pointer type called a reference type that is used primarily for formal parameters.

Problem set
1.      What are the arguments for and against four signed integer sizes in Java?

bytes (1 byte), short(2 bytes), integer (4 bytes), long (8 bytes). As a result,
depending on the domain of the variable required, data types are used.

2.      Compare the pointer and reference type variable in C++

A pointer can be re-assigned any number of times while a reference can not be reassigned after initialization. A C++ reference type variable is a constant pointer that is always implicitly dereferenced.

3.      In the Burroughs Extended ALGOL language, matrices are stored as a single-dimensioned array of pointers to the rows of the matrix, which are treated as single-dimensioned array of pointers to the rows of the matrix, which are treated as single-dimensioned arrays of values. What are the advantages and disadvantages of such a scheme?

The advantage of this scheme is that accesses that are done in order of the rows can be made very fast; once the pointer to a row is gotten, all of the elements of the row can be fetched very quickly. If, however, the elements of a matrix must be accessed in column order, these accesses will be much slower; every access requires the fetch of a row pointer and an address computation from there.

4.      What are the arguments for and against Heap management’s single-size cells and variable-size cells?

Single-size Allocation Heap: all available cells are linked together using the pointers in the cells, forming a list of available space. Allocation is a simple matter of taking the required number of cells from this list when they are needed. Deallocation is a much more complex process. A heap-dynamic variable can be pointed to by more than one pointer, making it difficult to determine when the variable is no longer useful to the program. Simply because one pointer is disconnected from a cell.

Variable-size Allocation Heap: The initial setting of the indicators of all cells in the heap to indicate that they are garbage is difficult. Because the cells are different sizes, scanning them is a problem. One solution is to require each cell to have the cell size as its first field. Then the scanning can be done, although it takes slightly more space and somewhat more time than its counterpart for fixed-size cells.

5.      In what way is dynamic type checking better than static type checking?
Dynamic type checking is better than static because dynamic checking happens in compile time not in run time, Static checking reduces programmer flexibility.

No comments:

Post a Comment