Cambridge AS & A Level · Part 4 · Chapter 25
Programming Paradigms
A paradigm is a style of programming: a way of thinking about a problem before you write a single line. This chapter compares four of them, low-level, imperative, object-oriented and declarative, and points you to the chapters where you program in each one. Every section, the reflection point and both tasks from the chapter are here, with a lab that solves one problem four ways.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to:
- show understanding of what is meant by a programming paradigm
- show understanding of the characteristics of a number of programming paradigms: low-level, imperative, object-oriented and declarative.
🧭 25.01 Programming paradigms
A programming paradigm is a fundamental style of programming. Each paradigm supports a different way of thinking about a problem and solving it.
- Paradigms are supported by programming language features.
- Some languages support more than one paradigm. Python, for example, can be written imperatively or in an object-oriented way.
- There are many paradigms, and some of them overlap. This chapter looks at just four.
💭 Reflection point
Why are there different paradigms?
Think about it before you open my notes.
- Different problems suit different ways of thinking. Driving a sensor at the hardware level, processing records step by step, modelling a world of interacting things and querying a database are very different jobs.
- Different levels of control. Low-level code gives exact control of memory and registers, but is slow to write and tied to one processor family. Higher-level paradigms trade some control for programs that are faster to write and easier to read.
- Managing size and change. Object-oriented features (classes, encapsulation, inheritance) grew up to help teams build and maintain very large programs.
- Some answers are easier to describe than to compute by hand. In SQL or Prolog you state what you want and the system searches for it.
- History. Languages and hardware developed over time, and each new paradigm built on, rather than replaced, the earlier ones.
🧩 The four paradigms in this chapter
⚙️ Low-level
talks straight to the processorLow-level languages let you manipulate the contents of memory addresses and registers directly and exploit the architecture of a given processor. You solve problems in a very different way from a high-level language.
Each type of processor has its own language. Processors in the same family share similar architectures and similar languages: the Intel family in many PCs uses the x86 instruction set.
See Chapter 6 and Chapter 28.
👣 Imperative
how: do this, then thatA program is a sequence of explicit steps executed by the processor. It tells the computer how to get the result, in contrast to declarative programming, which describes what the result should be.
The procedural paradigm belongs to the imperative paradigm. Most programs in this book are imperative.
See Chapters 12 to 15 and Chapters 23, 24 and 26.
📦 Object-oriented
objects send each other messagesBased on objects interacting with one another. Objects are data structures with associated methods.
Many imperative languages were developed further to support it: Pascal (as Delphi or Object Pascal) and Visual Basic (the .NET version was the first fully object-oriented one). Newer languages such as Python and Java were object-oriented from the beginning.
See Chapter 27.
🔎 Declarative
what: here is the problem, find the answerThe programmer writes down, in the language of logic, a specification of the situation: what the problem is. To get information they pose a query (set a goal), and the logic programming system works out how to answer it.
Programs are expressed as formal logic, and computations are deductions from the logic statements.
See Chapter 11 (SQL) and Chapter 29 (Prolog).
🆚 Side by side
| Paradigm | You write… | The basic unit | Tied to one processor? |
|---|---|---|---|
| Low-level | instructions from the processor's instruction set | an instruction acting on a register or address | Yes (one processor family) |
| Imperative | a sequence of statements that change data | a statement / procedure | No |
| Object-oriented | classes, then objects that call each other's methods | an object (data + methods) | No |
| Declarative | facts and rules, then a query (goal) | a relation / logic statement | No |
🎮 Name that paradigm
Read the clue, then pick the paradigm it shows best.
🧪 One problem, four paradigms
The task is the same every time: add up three test marks (12, 15 and 9) and get the total, 36. Switch paradigm and compare what the programmer has to write.
The same total, four ways
📝 Tasks from the chapter
The book says to do these after you have studied Chapters 26 to 29.
Task 25.01
Draw a line between a statement on the left and its matching programming paradigm on the right. Here, choose the paradigm for each statement, then check.
| Statement | Paradigm |
|---|
Task 25.02
Task 25.02
For each of the four programming paradigms in this chapter, give one programming statement example that is characteristic for this paradigm. State the programming language you used for each example.
| Paradigm | Language | Example statement | Why it is characteristic |
|---|---|---|---|
| Low-level | Cambridge assembly language | LDD 200 | Loads the contents of address 200 straight into the accumulator: direct use of memory and a register. |
| Imperative | Python | total = total + mark | An explicit step that changes the value of a variable. |
| Object-oriented | Python | player.move(3) | Calls a method of an object; the object's data is changed only through its own methods. |
| Declarative | Prolog | capitalCity(paris). | A fact. You then pose a goal such as ?- capitalCity(X). and the system finds the answers. |
Other good answers: MOV EAX, 5 (x86), FOR i ← 1 TO 10 (pseudocode), class Car(Vehicle): (Python inheritance), SELECT Name FROM Student WHERE Age > 16; (SQL).
📌 Recap
- A programming paradigm is a fundamental style of programming; each supports a different way of thinking and problem solving.
- Low-level: direct use of memory addresses and registers; each processor (family) has its own language, e.g. x86.
- Imperative: a sequence of explicit steps saying how; procedural programming belongs here.
- Object-oriented: objects (data structures with associated methods) interacting with one another.
- Declarative: describe what the problem is in logic, then pose a query; e.g. SQL and Prolog.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
My own questions on the chapter.
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 25 Programming Paradigms · Figure and tasks from the Cambridge coursebook (Langfield & Duddell) · Notes, examples, lab and quiz are my own