Imperative programming describes how a program proceeds: it gives step-by-step instructions that change data or produce side effects. The focus is on the sequence of operations rather than only the final result. section 1.4.1
Common building blocks and design concerns include:
- Loops, mutable data structures, pointers, procedures, and eager computations. section 1.4.1
- Modularity and opaque data types, which separate a stable public interface from a private implementation. section 1.4.1
Imperative code remains common in system software and is also present under the hood of object-oriented programming. Managing state and side effects can make parallel and distributed programming difficult. section 1.4 section 1.5
Listing 3.3 Temperature sensor readings scenario
Scenario: readThermometer #1
Description: monitor outside thermometer temperature
Given: outside thermometer @therm
Invocation: once a second
Read @therm, #2
Result: @reading(@time, @temp, @therm)
If @temp < -10C Then #3
register @reading #4
Log @reading #5
Raise alarm "Temperature is too low" #6
Else If @temp > 50C Then #7
register @reading
Log @reading
Raise alarm "Temperature is too high"
Else register @reading #8
Return @reading #9
This thermometer scenario reads a value, branches on temperature bounds, and registers readings, logs problems, or raises alarms. section 3.1.4
A stream-based alternative represents thermometer readings as a stream and lets a monitor react to each value, rather than organizing the whole scenario as one sequence of instructions. section 3.1.4














