Final Exam Flashcards
System langages vs scripting languages?
System programming languages has an emphasis on computing a result, high performance compilers. Scripting languages emphasis on automating a process, highly-portable interpreters.
What is a scripting language?
One that coordinates other programs.
Traditional programming vs scripting langues stress different priorities…
traditional programming stress efficiency, maintainability, portability, and the static detection of errors.
Scripting languages stress flexibility, rapid development, local customization, and dynamic runtime checking
General thumb of rule on speed of traditional “system languages” and scripting languages:
Code can be developed 5 to 10 times faster in a scripting language, but will run 10 to 20 times slower.
What are some common characteristics of a scripting language?
- Both batch and interactive use
- Economy of expression.
- Lack of declarations; simple scoping rules
- Flexible dynamic typing.
- Easy access to other programs.
- Sophisticated pattern matching and string manipulation.
- High level data types.
Tend to find their principal use in well-defined problem domains
General purpose languages widely used for scripting?
Scheme, visual basic
Scripting languages intended to be general purpose:
Perl, python, ruby.
Ancestors of modern scripting languages:
- Command interpreters or “shells” of traditional batch and “termina” computing.
Varios tools for text processing and repot generation: Unix sed and awk
Problem domains of scripting languages
Mathematics and Statistics (Matlab), Extension Languages, General-Purpose scripting Languages
Lua is Portuguese for?
Moon
Advantages of Lua?
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.
What are the basic types in Lua?
nil, number, string, boolean, table, function, thread, userdata
How to define default values in functions?
the or operator:
function Hello(str)
str = str or “World”
end
How to create own blocks in lua?
Use do end
How to do variable number of parameters in lua?
... function printLines(...) for i = 1, select("#", ...) do print((select(i, ...))) end end
What are closures?
Function bound by scope preserving local variables accessed by the function.
What are types good for?
- Implicit context: programmer does not need to know the exact size of a block of memory to set aside for a variable.
- Checking to make sure that certain meaningless operations do not occur. Does not catch all but enough of them to be useful.
What is strong typing and what is static typing?
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.
What is orthogonality?
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.
Why is orthogonality considered good?
Makes a language easy to understand, easy to use, and easy to reason about.
What are primitive data types?
Those not defined in terms of other data types.
What is the integer type?
Almost always exact reflection of hardware.
Floating-Point Types?
Model real numbers, but only as approximations. Usually exactly like the hardware, but not always.
Decimal Types?
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
Advantage of boolean types?
Readability
Character Types?
Stored as numeric codings. Most commonly used coding: ASCII, alternative 16-bit coding: Unicode.
String Types? Design issues?
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?
What is an ordinal type?
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.
What are enumeration types?
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};
Design issues with enumeration types?
- 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?
Advantages of enumeration types?
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.
What is a subrange type?
An ordered contiguous subsequence of an ordinal type.
Problem with subrange types?
If the result of an arithmic operation is assigned into a variable of a subrange type, then a dynamic semantic check may be required.
Advantage of subrange type?
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.
What are some composite types?
- 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.
- Array: collection of the same types.
- Set: Collection of unique elements.
- 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.
What is a record? Design issues?
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?
What is an elliptical reference and what are some of the problems with it?
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?
When to use arrays versus records?
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.
What is a union?
A type whose variables are allowed to store different type values at different times during execution.
What are some design issues with union types?
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
What are array types?
A homogenous aggregate of data elements in which an element is identified by its position in the aggregate, relative to the first element.
Design issues of arrays?
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?