Programming paradigms
| English | Chinese | Pinyin |
|---|---|---|
| paradigm | 范式 | fàn shì |
| low-level | 低级 | dī jí |
| imperative | 命令式 | mìng lìng shì |
| declarative | 声明式 | shēng míng shì |
| functional | 函数式 | hán shù shì |
| pure functions | 纯函数 | chún hán shù |
| logic | 逻辑式 | luó jí shì |
Different ways to write code
- 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.
Programming concept lab
Connect examples to the programming idea they show.
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.

Imperative programming: each command changes the program's state
Imperative (procedural) programming is based on:
Imperative code gives step-by-step commands (assignments, loops, calls) that change state.
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.
Match each paradigm to its core idea.
Imperative says how step by step; OO models objects; functional uses pure functions; declarative states the goal.
Declarative programming means you specify:
Declarative code (functional, logic, SQL) states the goal; the runtime decides the steps.
A pure function (functional programming):
Purity means no side effects and a deterministic result, which makes functional code easy to reason about.
Declarative paradigms (functional, logic, SQL) state WHAT to compute and let the runtime decide how, whereas imperative code spells out every step.
A SQL query says which rows you want, not how to scan the tables — the opposite of step-by-step imperative code.
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.
- Also know: Object-Oriented Programming uses getters, setters and properties, with aggregation and containment between objects; low-level code uses addressing modes (immediate, direct, indirect, indexed, relative); declarative logic programming proves a goal; structural programming is the procedural style.
You've got it
- 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