Programming paradigms · Paradigmes de programmation
| English | Français |
|---|---|
| paradigm/ˈpærədaɪm/ | paradigme |
| low-level/ləʊ ˈlevl/ | bas niveau |
| imperative/ɪmˈperətɪv/ | impératif |
| declarative/dɪˈklærətɪv/ | déclaratif |
| functional/ˈfʌŋkʃənl/ | fonctionnel |
| pure functions/pjʊə ˈfʌŋkʃnz/ | fonctions pures |
| logic/ˈlɒdʒɪk/ | logique |
The same program, written four ways
- Ask for all customers in the UK and a C programmer writes a loop over an array. A Haskell programmer writes a filter. A Prolog programmer states a rule and asks a question. An SQL user writes
SELECT * FROM Customer WHERE Country = 'UK'. - Only the first says how · comment to do it. The others say what · quoi is wanted and leave the how to the machine, which is free to reorder the work, use an index, or run it on eight cores.
- Neither is better in general. What differs is which decisions the language takes away from you, and that is exactly what a paradigm 范式 is.
- This lesson is the paradigms the syllabus names: low-level 低级, imperative 命令式 and · et declarative 声明式.
Low-level programming
- Low-level programming works close to the hardware, in machine code or assembly language, with direct access to registers, memory addresses and individual instructions.
- Benefits: maximum control · contrôle and · et speed · vitesse, and the smallest possible code, which matters when there are only kilobytes of memory.
- Drawbacks: it is architecture-specific, so it must be rewritten for a different processor, and it is slow to write and hard to maintain.
- Used where the hardware must be commanded exactly: device drivers, firmware, embedded controllers, and the innermost loop of a real-time system.
- Practise immediate, direct, indirect, indexed and relative addressing in the assembly-language lesson. Its worked trace shows why the same operand can produce different results.
Which are true of low-level programming? Select all · tout that apply. · Quelles affirmations sont vraies concernant la programmation bas niveau ? Sélectionnez toutes celles qui s'appliquent.
Control is bought with effort: assembly is slow to write and hard to maintain, which is why it is confined to drivers and firmware. · Le contrôle s'obtient au prix d'un effort : l'assemblage est lent à écrire et difficile à maintenir, ce qui explique qu'il soit limité aux pilotes et au firmware.
Imperative programming
- Imperative programming, also called procedural, is a sequence of commands that change the program's state: assignments, conditionals, loops and calls to procedures.
- The programmer specifies how · comment the result is to be computed, step by step. The variables holding the state are the point.
- It is the style of Python, C, Java and pseudocode, and it is what almost everyone learns first.

One command after another, each changing what is stored
Imperative (procedural) programming is based on: · La programmation impérative (procédurale) est basée sur :
Imperative code gives step-by-step commands (assignments, loops, calls) that change state. · Le code impératif donne des commandes étape par étape (affectations, boucles, appels) qui changent l'état.
Declarative programming
- Declarative programming states what · quoi is to be computed, not how · comment. The runtime works out the steps.
- Functional 函数式 programming composes pure functions 纯函数, which have no side effects: the same input always produces the same output, and nothing outside the function changes. Haskell and Lisp are the examples.
- Logic 逻辑式 programming states facts and rules, and an engine answers queries by inference. Prolog is the example.
- SQL is the declarative language nearly everyone has met: the query says which rows are wanted, and the database decides how to find them.
Programming concept lab · Laboratoire de concepts de programmation
Connect examples to the programming idea they show. · Reliez les exemples au concept de programmation qu'ils illustrent.
Declarative programming means you specify: · La programmation déclarative signifie que vous spécifiez :
Declarative code (functional, logic, SQL) states the goal; the runtime decides the steps. · Le code déclaratif (fonctionnel, logique, SQL) énonce l'objectif ; le runtime décide des étapes.
A pure function (functional programming): · Une fonction pure (programmation fonctionnelle) :
Purity means no side effects and a deterministic result, which makes functional code easy to reason about. · La pureté signifie absence d'effets de bord et résultat déterministe, ce qui rend le code fonctionnel facile à raisonner.
Declarative paradigms (functional, logic, SQL) state WHAT to compute and let the runtime decide how, whereas imperative code spells out every step. · Les paradigmes déclaratifs (fonctionnel, logique, SQL) énoncent QUOI calculer et laissent au runtime décider COMMENT, alors que le code impératif détaille chaque étape.
A SQL query says which rows you want, not how to scan the tables — the opposite of step-by-step imperative code. · Une requête SQL dit quelles lignes vous voulez, pas comment parcourir les tables — l'opposé du code impératif étape par étape.
A pure function always gives the same output for the same input and has no ____. · Une fonction pure donne toujours la même sortie pour la même entrée et n'a aucun ____.
That is what lets it be tested in isolation, run in parallel safely and have its result cached. · C'est ce qui permet de la tester isolément, de l'exécuter en toute sécurité en parallèle et de mettre son résultat en cache.
Worked example: identify the paradigm
FOR i ← 1 TO n : total ← total + A[i] : NEXT i— imperative: a sequence of commands changing the state held intotal.SELECT Name FROM Customer WHERE Country = 'UK'— declarative: it says which rows are wanted and not how to search for them.LDD 200 : ADD 201 : STO 202— low-level: assembly instructions addressing memory locations directly.parent(X, Y) :- father(X, Y).— declarative, specifically logic programming: a rule from which the engine infers answers.- Name the paradigm and · et the feature of the code that shows it.
Match each fragment to its paradigm. · Faites correspondre chaque fragment à son paradigme.
Commands changing state, a statement of what is wanted, instructions addressing memory, and a rule for inference. · Commandes changeant l'état, une déclaration de ce qui est souhaité, des instructions pointant vers la mémoire, et une règle pour l'inférence.
Comparing them
| Paradigm | Says | Strength · Force | Typical use |
|---|---|---|---|
| low-level | exact instructions | control, speed, size | drivers, firmware |
| imperative | how, step by step | direct and familiar | general programming |
| declarative | what is wanted | concise, the runtime optimises | queries, rules, data transformation |
- Modern languages mix · mélange them. Python is imperative but has functional features; SQL sits inside programs written imperatively. A paradigm is a style, not a wall.
Match each paradigm to its core idea. · Faites correspondre chaque paradigme à son idée centrale.
Imperative says how step by step; OO models objects; functional uses pure functions; declarative states the goal. · L'impératif dit COMMENT étape par étape ; OO modélise des objets ; le fonctionnel utilise des fonctions pures ; le déclaratif énonce l'objectif.
What is the essential difference between imperative and declarative programming? · Quelle est la différence essentielle entre la programmation impérative et déclarative ?
Because the declarative version does not fix the how, the runtime may reorder the work, use an index or parallelise it. · Parce que la version déclarative ne fixe pas le COMMENT, le runtime peut réordonner le travail, utiliser un index ou le paralléliser.
Worked example: why side effects matter
- A pure function has no side effects. Explain one benefit.
- Because the same input always gives the same output and nothing outside changes, a pure function can be tested in isolation: no setup, no hidden state to arrange.
- It can also be run in parallel · parallèle safely, since two calls cannot interfere with each other, and its result can be cached.
- The contrast: an imperative routine that updates a global variable behaves differently depending on what ran before it, which is what makes such bugs hard to find.
Marks that slip away
- Imperative says how · comment; declarative says what · quoi. That contrast is the answer to most questions here.
- Low-level's drawback is that it is architecture-specific and hard to maintain, not that it is "old".
- A pure function has no side effects and gives the same output for the same input. Both halves are needed.
- SQL is declarative. It is the example the exam most often uses, so recognise it.
You've got it
- a paradigm is a style of structuring code, and modern languages mix several
- low-level: machine code or assembly, direct hardware access, maximum control and speed, but architecture-specific and hard to maintain
- imperative: a sequence of commands changing state, specifying how · comment; the style of Python, C and pseudocode
- declarative: states what · quoi is wanted and leaves the how to the runtime, as functional programming with pure functions, logic programming with facts and rules, and SQL