Language Evaluation Criteria
Readability: the ease with which programs can be read and understood.
Writability: the ease with which a language can be used to write programs.
Reliability: performs to its specifications.
Cost: the ultimate total cost.
What are some language design trade-offs?
Reliability vs Cost. (e.g. java checks that all references to array elements are properly index, increasing execution cost.)
Readability vs Writability. (e.g. APL has many powerful operators that allow complex computations but lacks readability.)
Writability vs Reliability. (e.g. C++ pointers are powerful/flexible but unreliable).
Data Type
Defines a collection of data objects and a set of predefined operations on those objects.
Type Checking
The activity of ensuring that the operands of an
operator are of compatible types.
Type Error
The application of an operator to an operand of an
inappropriate type.
Strongly Typed
The quality of a program that type errors are always identified.
Type System
Defines how a type is associated with each expression in the
language and includes its rules for type equivalence and type compatibility.
What are some uses of the type system of a programming language?
Error detection, ensuring consistency of the interfaces among modules, and documentation of a program’s data and behavior.
Descriptor
The collection of the attributes of a variable that
are used for type checking and performing allocation and deallocation operations.
Descriptors of Static Attributes
Only needed at compile time, built as part of the symbol table.
Descriptors of Dynamic Attributes
Must be used and maintained by the run-time system.
Data types or either…
scalar or structured.
Scalar Types
Ordinal types (e.g. integer, char, enumerated), real, complex, etc.
Structured Types
Records/classes, unions, arrays, pointers, lists, sets, and files.
Primitive Data Types
Not defined in terms of other data types. Includes numeric (e.g. integer, floating point, complex, and decimals), Boolean, and character types. Some primitive data types are mere reflections of hardware. Others require little non-hardware support for implementation.
sizeof Operator
A unary operator in C++ that determines the size of an operand in bytes, the operand being either a variable name or a data type.
Primitive Data Type: Integer
Almost always a reflection of hardware; mapping is trivial. C/C++ integers include char, short, int, long, long long (non-decreasing order). Java integers include byte, short, int, long (1, 2, 4, 8 bytes respectively). An integer can be made positive or negative by using one of the bits as a sign bit. C++ allows the declaration of unsigned integers.
Primitive Data Types: Floating Point
Approximations of real numbers. IEEE Floating-Point Standard 754 made floats = sign * mantissa * 2^exp, where mantissa = 1.fract. C++ includes float, double, and double long (increasing order).
Primitive Data Types: Boolean
Either true or false. Can be implemented in bits but is often implemented in bytes for readability. Allowable operators for Booleans are logical (!, &&, ||) and relational operators.
Primitive Data Types: Character
Stored as numeric codings, most commonly ASCII (128 characters) or extended ASCII (256 characters). In C++, char is a 1-byte ASCII coding. A byte in Java is an 8-bit quantity. Alternatives include 16-bit coding: Unicode (USC-2 or UFT-16) (Originally used in Java, where a char was a 16-bit quantity. In C++, data type wchar_t is used for Unicode characters) and 32-bit Unicode (USC-4 or UTF-16) (Supported by Fortran since 2003).
Character String Types
Sequence of characters. Design issues involve whether strings are primitive or not and whether string length is static or dynamic. In C/C++, strings are not primitives. C uses char arrays while C++ has a string class. Fortran and Python have a primitive string type. Java provides its own string class (sequence of Java char) using UTF-16 encoding.
What are typical operations for strings?
Assignment, copying, concatenation, substring reference, and pattern matching.
What are some character string length options in different programming languages?
Static: Java’s string class, C++ standard string class, and Python strings.
Limited Dynamic Length: C/C++ allows a special character to indicate the end of a string as opposed to maintaining a string’s length.
Dynamic: SNOBOL4, Perl, JavaScript.
Enumeration Types
Internally represent values as constant integers. An enumeration is not allowed to appear in more than one type definition and can be coerced into an integer in C++. However, other types cannot be coerced into an enumerated type. Aids in readability and reliability.