8/30/2021
Today we learned a more complete definition of imperative programming languages and studied the defining characteristics of variables. Unfortunately we did not get as far as I wanted during the class which means that there is some new material in this edition of the Daily PL!
Imperative Programming Languages
Any language that is an abstraction of the von Neumann Architecture can be considered an imperative programming language.
There are 5 calling cards of imperative programming languages:
- state, assignment statements, and expressions: Imperative programs have state. Assignment statements are used to modify the program state with computed values from expressions
- state: The contents of the computer’s memory as a program executes.
- expression: The fundamental means of specifying a computation in a programming language. As a computation, they produce a value.
- assignment statement: A statement with the semantic effect of destroying a previous value contained in memory and replacing it with a new value. The primary purpose of the assignment statement is to have a side effect of changing values in memory. As Sebesta says, “The essence of the imperative programming languages is the dominant role of the assignment statement.”
- variables: The abstraction of the memory cell.
- loops: Iterative form of repetition (for, while, do … while, foreach, etc)
- selection statements: Conditional statements (if/then, switch, when)
- procedural abstraction: A way to specify a process without providing details of how the process is performed. The primary means of procedural abstraction is through definition of subprograms (functions, procedures, methods).
Variables
There are 6 attributes of variables. Remember, though, that a variable is an abstraction of a memory cell.
- type: Collection of a variable’s valid data values and the collection of valid operations on those values.
- name: String of characters used to identify the variable in the program’s source code.
- scope: The range of statements in a program in which a variable is visible. Using the yet-to-be-defined concept of binding, there is an alternative definition: The range of statements where the name’s binding to the variable is active.
- lifetime: The period of time during program execution when a variable is associated with computer memory.
- address: The place in memory where a variable’s contents (value) are stored. This is sometimes called the variable’s l-value because only a variable associated with an address can be placed on the left side of an assignment operator.
- value: The contents of the variable. The value is sometimes call the variable’s r-value because a variable with a value can be used on the right side of an assignment operator.
Looking forward to Binding (New Material Alert)
A binding is an association between an attribute and an entity in a programming language. For example, you can bind an operation to a symbol: the + symbol can be bound to the addition operation.
Binding can happen at various times:
- Language design (when the language’s syntax and semantics are defined or standardized)
- Language implementation (when the language’s compiler or interpreter is implemented)
- Compilation
- Loading (when a program [either compiled or interpreted] is loaded into memory)
- Execution
A static binding occurs before runtime and does not change throughout program execution. A dynamic binding occurs at runtime and/or changes during program execution.
Notice that the six “things” we talked about that characterize variables are actually attributes!! In other words, those attributes have to be bound to variables at some point. When these bindings occur is important for users of a programming language to understand. We will discuss this on Wednesday! blob:https://1492301-4.kaf.kaltura.com/903896d9-2341-4dd3-9709-ca344de08719