Roles of Variables Home Page

Roles of Data Entities

This document contains descriptions of roles of data entities as found in novice-level programs.

Note: Role lists suitable for novice use can be found in the page describing how roles can be utilized in teaching.

This document describes version 2 of the role set; the old role set can be found here. Differences between role sets are described here.

Roles in Different Programming Paradigms

The roles listed below apply to data entities in procedural, object-oriented, and functional programming. However, data entities having roles differ in these paradigms.

Procedural programming: Roles apply to variables, and parameters.

Object-oriented programming: Roles apply to variables, parameters, atttributes, and objects that encapsulate a single conceptual attribute.

Functional programming: Roles apply to the recursive behavior of parameters and return values

Notation Used in the Role List

Procedural examples are given in Pascal, object-oriented examples in Java. Procedural examples are whole programs because Pascal provides a possibility for short and at the same time complete example programs. Object-oriented examples assume the existence of other classes.

Notes that are in italics describe special cases and can be skipped on first reading. Technical definitions and properties provide more exact information about the roles, and they are not expected to be used in, e.g., teaching programming to novices.

Technical definitions may be needed in, e.g., role analysis. They are meant for human classifiers who are able to use their understanding of a program to capture the data flow through a data entity and identify main phases of this flow. For example, a one-way flag may be reset to its initial value at the beginning of the main loop (and changed within a nested loop) yielding the one-way behavior within the main loop even though the flag goes both ways during the entire program execution.

Properties are descriptions of actual use in novice-level programs or consequences of the technical definitions. They can be used in, e.g., devising pictorial representations for roles.

List of Roles

Roles can be grouped according to the way they relate to data flow:

Role chart

Fixed value and organizer contain the same data throughout the program; only the order of data elements may be changed. Most-recent holder and stepper record data flow sources; either coming from outside or generated internally. The net effect of all items in a data flow is represented by a one-way flag, most-wanted holder, or gatherer; while a manipulation of a single element is recorded in a follower or temporary. Data may be stored in a container which can be traversed with a walker. Finally, a data entity not covered by any of the previous roles is considered to have the role other.

The roles are described in the following order:

The role images are examples only. In actual use, they should be replaced by images better suiting the cultural backgrounds of users.


Icon for the role Fixed value

A data entity whose value does not change after initialization.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity whose value does not change after initialization (e.g., an input value stored in a data entity that is not changed later) possibly done in several alternative assignment statements (e.g., a data entity that is set to true if the program is executed during a leap year, and false otherwise), possibly corrected immediately after initialization (e.g., an input value that is replaced by its absolute value if it is negative), and possibly set to null if the item denoted ceases to exist.

Properties:

  • Impossible to change after initialization.

  • May have two distinct values during its lifetime.


Icon for the role Organizer

A data structure which is only used for rearranging its elements after initialization.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data structure which is only used for rearranging its elements after initialization (e.g., an array used for sorting input values).

Properties:

  • Individual elements cannot be changed but they can be moved around.


Icon for the role Stepper

A data entity stepping through a succession of values that can be predicted as soon as the succession starts.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity going through a succession of numeric or enumerated values depending on its own previous value and possibly on other steppers, stepper followers, and fixed values (e.g., a counter of input values, a data entity that doubles its value every time it is updated, a data entity that alternates between two values, or an index to an array that sweeps through the array using varying densities).

Properties:

  • Most often the step between successive values is constant.

  • Future values can usually be predicted if past values are known.

  • Usually there is a direction for successive values; either upwards or downwards.

  • The validity of the stepper's value it is usually repeatedly tested against the same limit.


Icon for the role Most-recent holder

A data entity holding the latest value encountered in going through a succession of values.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity holding the latest value encountered in going through a succession of values (e.g., the latest input read, a copy of an array element last referenced using a stepper, or the latest result of a computation made within a loop and used in the entire loop) and possibly corrected immediately after obtaining a new value (e.g., to scale into internal data representation format).

Properties:

  • Successive values are obtained from some data succession but they have no fixed relationship.

  • Each value may consist of two distinct values: the original and the scaled/corrected.


Icon for the role One-way flag

A two-valued data entity that cannot get its initial value once its value has been changed.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A two-valued data entity that can be effectively changed only once (e.g., a data entity stating whether the end of input has been encountered) even though the new value may be re-assigned several times (e.g., a data entity initialized to false and set to true each time an error occurs during a long succession of operations).

Properties:

  • Only two possible values.

  • Impossible to regain the initial value once changed.


Icon for the role Most-wanted holder

A data entity holding the best value encountered so far in going through a succession of values.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity holding the best value encountered so far in going through a succession of values with no restriction on how to measure the goodness of a value (e.g., largest input seen so far, or an index to the smallest array element processed so far).

Properties:

  • The current value is better than any previous value.

  • Successive values are obtained from some data succession but new values are discarded if they are worse than any of those seen before.


Icon for the role Gatherer

A data entity accumulating the effect of individual values in going through a succession of values.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity accumulating the effect of individual values in going through a succession of values (e.g., a running total, or the total number of cards in hand when the player may draw several cards at a time).

Properties:

  • The new value is obtained by combining some new data with the previous value.


Icon for the role Container

A data structure where elements can be added and removed.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data structure where new elements can be added and existing elements possibly changed and removed.

Properties:

  • Typically the physical implementation of a logical data store.


Icon for the role Walker

A data entity that traverses a data structure.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity that traverses a data structure in some systematic way. The traversal may cover only part of the data structure. The traversal order may be related either to the structure of the (logical) data structure or to the structure of the (physical) container implementing that (logical) data structure.

Properties:

  • Connected to some container.

  • Traverses through a systematic path within a container (or logical data structure).


Icon for the role Follower

A data entity that gets its values by following another data entity.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity which, apart from initialization, goes through a succession of values depending on the value of a single data entity that is updated immediately after being used for updating the follower, and possibly on fixed values (e.g., the previous pointer when going through a linked list, or the low index in a binary search).

Properties:

  • Tightly connected to another data entity; usually its previous value.


Icon for the role Temporary

A data entity holding some value for a very short time only.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    A data entity holding the value of some other data entity, input value, or the result of a computation for a very short time only, usually for efficiency reasons (e.g., executing a computation, whose value is needed in several places, only once), to clarify the program (e.g., computing the result in a variable even though the use of a variable would not be absolutely necessary), or for intermediate storage (e.g, in a swap operation).

Properties:

  • Exists for short time periods only.

  • Tightly connected to the values of other data entities or input just read.


Icon for the role Other

Any other data entity.

Procedural example:

Object-oriented example:

Examples of use:

Notes:

Technical definition:

    All other data entities.

Properties:

  • No fixed properties.

  • Actual need is rare in novice-level programs.


Last updated: February 8, 2006

Jorma.Sajaniemi@UEF.Fi