Programming paradigms
Programming paradigms
- A paradigm is a style of programming — a way of structuring code.
- Four styles are in the syllabus, and modern languages often mix them.
- This lesson covers low-level, imperative and declarative; OOP gets its own.
Low-level and imperative
- Low-level programming works close to the hardware in machine code or assembly — fast and compact, with direct access to registers and memory, but architecture-specific and hard to maintain (drivers, firmware).
- Imperative (procedural) programming writes a sequence of commands that change the program's state — assignments, conditionals, loops, function calls. This is the style of Python and C.
Practice
Imperative (procedural) programming is based on:
Imperative code gives step-by-step commands (assignments, loops, calls) that change state.
Practice
Low-level programming is used for:
Low-level (assembly/machine code) gives direct hardware control — ideal for drivers, firmware, bootloaders.
Declarative programming
- Declarative programming says what to compute, not how — the runtime works out the steps.
- Functional programming composes pure functions (no side effects — same input → same output): Haskell, Lisp.
- Logic programming states facts and rules; an engine answers queries by inference: Prolog.
- A familiar example is SQL:
SELECT * FROM Customer WHERE Country = 'UK'says what you want, not how to fetch it.
Practice
Declarative programming means you specify:
Declarative code (functional, logic, SQL) states the goal; the runtime decides the steps.
Practice
A pure function (functional programming):
Purity means no side effects and a deterministic result, which makes functional code easy to reason about.
Practice
SQL is an example of which paradigm?
A SQL query states what data you want, not how to traverse the tables — declarative.
Comparing paradigms
| Paradigm | Strength | Languages |
|---|---|---|
| Low-level | maximum control, speed | assembly |
| Imperative | direct, intuitive | C, Python |
| Object-oriented | modular, models entities | Java, C# |
| Functional | clear, no side effects | Haskell, F# |
| Logic | inference, rules | Prolog |
- Many languages mix paradigms (Python supports procedural, OOP and functional) — the right one depends on the problem.
You've got it
Key idea
- low-level = machine/assembly, close to hardware; imperative = commands that change state
- declarative = say what, not how: functional (pure functions), logic (facts/rules), SQL
- a pure function has no side effects (same input → same output)
- modern languages mix paradigms