module 2 Flashcards
(159 cards)
data type
defines a collection of data objects and a set of predefined
operations on those objects
descriptor
collection of the attributes of a variable
object
an instance of a user-defined (abstract data) type
One design issue for all data types
What operations are defined and how are
they specified?
primitive data types
- Almost all programming languages provide a set of primitive data types
- not defined in terms of other data types
- Some primitive data types are merely reflections of the hardware
- Others require only a little non-hardware support for their implementation
primitive data type examples
Integer
Floating Point
Complex
Decimal
Boolean
Character
Value
sequences of characters
design issues of character strings
Is it a primitive type or just a special kind of array?
Should the length of strings be static or dynamic?
typical string operations
§Assignment and copying
§Comparison (=, >, etc.)
§Catenation
§Substring reference
§Pattern matching
ordinal type
one in which the range of possible values can be easily
associated with the set of positive integers
examples of ordinal types in java
§integer
§char
§boolean
Enumeration Types
All possible values, which are named constants, are provided in the definition
design issues of enumeration
§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?
§Any other type coerced to an enumeration type?
array design issues
- What types are legal for subscripts?
- Are subscripting expressions in element references 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?
4 categories of arrays
- Static: subscript ranges are statically bound and storage allocation is static
(before run-time):
§Advantage: efficiency (no dynamic allocation) - Fixed stack-dynamic: subscript ranges are statically bound, but the allocation is
done at declaration time:
§Advantage: space efficiency - Fixed heap-dynamic: similar to fixed stack-dynamic: storage binding is dynamic
but fixed after allocation (i.e., binding is done when requested and storage is
allocated from heap, not stack) - Heap-dynamic: 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)
rectangular array
multi-dimensioned array in which all of the rows have
the same number of elements and all columns have the same number of
elements
F# and C# support rectangular arrays and jagged arrays
jagged matrix
has rows with varying number of elements:
§Possible when multi-dimensioned arrays actually appear as arrays of arrays
C, C++, and Java support jagged arrays
slice
some substructure of an array; nothing more than a referencing
mechanism
Slices are only useful in languages that have array operations
Access function
maps subscript expressions to an address in the array
for single-dimensioned arrays:
address(list[k]) =
address (list[lower_bound]) + ((k-lower_bound) * element_size)
record
a possibly heterogeneous aggregate of data elements in which the
individual elements are identified by names
design issues for records
§What is the syntactic form of references to the field?
§Are elliptical references allowed
tuple
data type that is similar to a record, except that the elements are not
named
Used in Python, ML, and F# to allow functions to return multiple values
Python:
§Closely related to its lists, but immutable
Lists
in Lisp and Scheme are delimited by parentheses and use no commas
union
a type whose variables are allowed to store different type values at
different times during execution