Show understanding of the characteristics of a number of programming paradigms: Imperative (Procedural)

Published by Patrick Mutisya · 14 days ago

Cambridge A-Level Computer Science 9618 – 20.1 Programming Paradigms

20.1 Programming Paradigms

Objective

Show understanding of the characteristics of a number of programming paradigms, with particular focus on the Imperative (Procedural) paradigm.

Imperative (Procedural) Paradigm

The imperative paradigm describes programs as a sequence of commands that change the state of the computer. The procedural style groups these commands into procedures (also called functions or sub‑routines) that can be called from other parts of the program.

Key Characteristics

  • State and mutable variables: Programs maintain a set of variables whose values can be altered.
  • Sequential execution: Statements are executed one after another unless altered by control structures.
  • Control structures: Use of selection (if‑else, switch) and iteration (for, while, do‑while) to direct flow.
  • Procedures / functions: Encapsulation of a set of statements that can be invoked with arguments and may return a value.
  • Top‑down design: Problems are broken down into smaller sub‑problems, each solved by a procedure.
  • Modularity: Procedures can be developed, tested, and reused independently.
  • Explicit side‑effects: Procedures may modify global or passed‑by‑reference variables.

Typical Structure of a Procedural Program

  1. Define global constants and variables.
  2. Declare prototypes (if required by the language).
  3. Implement procedures/functions.
  4. Write a main routine that orchestrates the overall flow.

Example (Pseudo‑code)

procedure readData()

// reads input and stores in global array

end procedure

procedure sortData()

// sorts the global array using a chosen algorithm

end procedure

procedure displayData()

// outputs the sorted array

end procedure

procedure main()

readData()

sortData()

displayData()

end procedure

Advantages

  • Simple to understand for beginners – follows natural step‑by‑step reasoning.
  • Efficient execution; low overhead because the model maps closely to hardware.
  • Wide language support (C, Pascal, BASIC, Python in procedural style).

Disadvantages

  • Difficulty managing large code bases – mutable state can lead to bugs.
  • Limited support for abstraction compared with object‑oriented or functional paradigms.
  • Reusability can be hindered if procedures are tightly coupled to specific data structures.

Comparison with Other Paradigms

AspectImperative (Procedural)Object‑OrientedFunctionalLogical
Primary abstractionProcedures / functionsObjects (state + behaviour)Pure functions (no side‑effects)Relations / predicates
State handlingMutable variables, global stateEncapsulated within objectsImmutable dataImplicit via logical inference
Control flowExplicit (if, loops, goto)Method calls, inheritance, polymorphismFunction composition, recursionGoal‑driven search
Typical languagesC, Pascal, BASIC, Python (procedural style)Java, C++, Python (OO style)Haskell, Lisp, Scala (functional style)Prolog
Ease of reasoning about stateHarder as programs growImproved via encapsulationStraightforward – no side‑effectsDepends on logical rules

Typical Use Cases

  • System programming where direct hardware manipulation is required.
  • Embedded systems with limited resources.
  • Algorithms that are naturally expressed as step‑by‑step procedures (e.g., sorting, searching).
  • Educational contexts for introducing fundamental programming concepts.

Key Points to Remember for Exams

  1. Identify the use of mutable variables and how they change over time.
  2. Explain how procedures promote modularity and reuse.
  3. Contrast procedural flow (top‑down) with other paradigms’ flow (e.g., data‑driven in functional).
  4. Provide examples of control structures that alter the sequential execution.
  5. Discuss the impact of side‑effects on program correctness and debugging.

Suggested diagram: Flowchart showing the sequence of procedure calls (readData → sortData → displayData) with arrows indicating the flow of control.