Imperative
by John Backus
Origin
Imperative programming cannot be attributed to a single individual as it is one of the earliest forms of programming, derived from machine languages and assembly languages. The central idea of managing state through sequential instructions emerged with the development of the first computers.
Historical Context
The foundations of imperative programming were established in the mid-20th century with the creation of languages like Assembly and Fortran (1950s), developed by various research teams, including John Backus, who is considered one of the creators of Fortran.
In the source code of a program, instructions (commands) are written.
Imperative programming is based on direct instructions that the computer must execute. The programmer defines a sequence of steps that must be performed to achieve a specific result. These steps usually include operations with variables, control of execution flow (such as loops and conditional operators), as well as function or procedure calls.
Instructions Must Be Executed Sequentially
One of the key characteristics of the imperative paradigm is the sequential execution of instructions, which implies that the program’s outcome depends on the order in which these instructions are executed. A disruption in sequence can lead to unexpected results, requiring careful control over the execution flow by the programmer.
Data From Previous Instructions Can Be Read by Subsequent Instructions
Imperative programming actively uses the concept of changing the program’s state. This means that each instruction can change the values of variables, which are then used in subsequent instructions. These variables are stored in memory, and their state changes as the program executes.
Data From an Instruction Can Be Written to Memory
The program’s state is changed by writing data to memory. For example, the result of an arithmetic operation can be saved in a variable for future use. This state change is a defining characteristic of imperative programming languages like C, Python, or Java.
The imperative paradigm is well-suited for tasks where it is important to closely control the execution of steps and manage the program’s state. However, complexity can increase as the number of states and branches grows, requiring the programmer to take a more thoughtful approach to code design and debugging.
Examples of Languages
- Assembly
- BASIC
- JavaScript
imperative paradigm