This site is 100% ad supported. Please add an exception to adblock for this site.

Ada Final Exam


undefined, object
copy deck
Variant Record
A record type that can have different sets of fields (ie variations) in different variables.
Motivation of Variant Records
Ability to have a common type that can be used for a number of different, related types.
Variant Records in Other Languages
C and C++ have Union - similar but less or no checking Similar to Class Inheritance in Java
Security Issues of Variant Records
# Compile time: Descriminant must be given a value when creating an instance of the record # Compile time: When changing the descriminant, the entire record must be assigned # Runtime test: compiler generates code for runtime tests that verify that the descriminant is consistent with any fields that are accessed
Formal Parameter
The parameters given in the declaration of the procedure.
Actual Parameter
The variables or values that are used when the procedure is called.
Generic Packages
"cookiecutter" packages that can be used to create other (regular) packages
Differences of Generic Packages
1. You use them to create regular packages. A given generic package can be used to make as many packages as you want. 2. Generic packages have parameters that are given values when the generic package is used to create a regular package. This means that by varying the parameters, a given generic package can be used to create different regular packages that have different properties.
Generics in other languages
C++: templates Java: parameterized types (can't have primitive types)
private types vs. limited private types
differ in whether or not the assignment and equality are automatically provided and/or can be defined for values of the type
private types
hides the implementation details, which are included in the private section of the package. automatically have := and = and /=. Equal can be redefined (which gives a new /=). Assignment cannot be redefined.
limited private types
also hides the implementation details, which are included in the private section of the package. do not have := or = or /=. Equal can be defined (which gives /=). Assignment cannot be defined. does NOT automatically have an equality operator (or an inequality).
Motivation for limited private types
The built in operation of assignment can give different results for different implementations of a data type. To maintain safety, we make it possible to disallow assignment.
Enumerated Types
Create a new type whose values are a set of NAMES!
Motivation for enumerated types
# Write program at level of problem rather than level of machine # More readable code # Better type checking to catch more errors
enumerated types in other languages
Java: final static int for constants, no type checking. C has enums, which are just like ints (no type checking) C++ has enums with some type checking. Java 1.5 provides enums, which are implemented using a parameterized class (generic) called enum...They are objects, not primitives.
When to use functionality oriented
- data types are well known - adding new data variants will happen infrequently - will add lots of functionalities on exisiting data types
when to use OO
- functionalities are well understood - adding new functionality will happen infrequently - will add lots of new data types with the same functionality
A program is...
Made up of data structures and algorithms.
The functionality in FO is
The functionality in OO is
Ada's scope rule for variable declarations
A variable is visible from the end of declaration to corresponding end statement.
What is a type?
A set of values + a set of operations.
A variable is global to a procedure if it is...
Visible but not declared.
What is a side effect?
An expression that changes memory/state of the program.
Java classes ____ types
Ada packages _____ types
Parnas' Principle
Maximize cohesion, minimize coupling.
Benefits of ADTs
* Simplicity: Client programmer does not have to be concerned with details that underlie the implementation of the ADT (eg keeping track of the front and back of a queue) * High level operations: Design solutions in terms of the problem (ie think in terms of stacks, not arrays and array indices) * Abstractions on top of abstractions (eg stacks of words) * Reliability: user cannot corrupt ADT values * Reliability: encourage reuse of well-tested ADT's * Flexibility for client programmer: can choose from among several implementations of an ADT * Independence: separating specification and implementation allow client and ADT to be programmed simultaneously * Independence: ADT programmer can change implementations of ADT without changing client
What is held in static memory?
Variables declared in a pkg, & ADTs.
What is held in the stack?
Local variables.
What is held in the heap?
Dynamically allocated with new.
What is a dangling reference?
a pointer that points to an area of memory that is not valid

Deck Info