🔒 Pro · Component 1 · 1.2.4 Types of Programming Language
1.2.4d Programming Paradigms
OCR H446 · A Level Computer Science · ~12 min read
Notes
Video
Slides
Worksheet
Quiz

What is a Programming Paradigm?

A programming paradigm is a style or approach to programming — a way of thinking about and structuring programs. Different paradigms provide different models of computation and different ways of organising code.

OCR H446 requires knowledge of four paradigms: imperative/procedural, declarative, functional, and object-oriented (OOP).

1. Imperative / Procedural Paradigm

The imperative paradigm is the most traditional approach. Programs are sequences of statements that tell the computer how to do something step by step. The programmer specifies the exact steps and control flow.

  • Programs use: variables, assignments, loops, conditionals, and procedures/functions.
  • Procedural programming is a sub-type of imperative programming that uses procedures (subroutines/functions) to structure code into reusable blocks.
  • Examples: C, Pascal, early Python scripts, BASIC.
  • Advantages: intuitive — maps closely to how computers execute instructions; efficient; straightforward for sequential tasks.
  • Disadvantages: can become difficult to manage in very large programs; state (variables) is shared globally, making bugs harder to trace.

2. Declarative Paradigm

The declarative paradigm specifies what the desired result is, rather than how to achieve it. The programmer describes the problem and the language/runtime figures out how to solve it.

  • Examples: SQL (Structured Query Language), HTML, Prolog, CSS.
  • SQL example: SELECT name FROM students WHERE grade = 'A'; — the programmer states what data is wanted, not how to search for it.
  • Declarative languages often use logic and rules (Prolog) or query specifications (SQL).
  • Advantages: simpler and more concise for certain problems; the runtime can optimise how to achieve the result; easier to read intent.
  • Disadvantages: less control over performance; may be less efficient than procedural code for some tasks; not suitable for all problems.

3. Functional Paradigm

In the functional paradigm, programs are composed of mathematical functions. The focus is on applying and composing functions. Key characteristics:

  • Pure functions: a function always returns the same output for the same input and has no side effects (does not modify external state). This makes programs easier to reason about and test.
  • Immutability: data is not modified after creation — instead, new data structures are created.
  • No mutable state: programs avoid shared mutable variables, reducing bugs from unintended state changes.
  • First-class and higher-order functions: functions can be passed as arguments to other functions, returned as values, and stored in variables.
  • Function composition: combining simple functions to build more complex behaviour.
  • Examples: Haskell, Erlang, ML, F#; Python and JavaScript support functional features (map, filter, lambda).
  • Advantages: easier to debug/test (pure functions); naturally thread-safe (no shared state); code is concise.
  • Disadvantages: can be difficult to learn; some problems map more naturally to imperative style; performance can be a concern (immutability requires creating new copies of data).

4. Object-Oriented Paradigm (OOP)

In object-oriented programming, programs are structured as collections of objects that combine data (attributes) and behaviour (methods). OOP is covered in detail in 1.2.4e — key concepts below:

  • Class: a blueprint/template defining the attributes and methods of objects of that type.
  • Object: an instance of a class — a specific entity created from the class blueprint.
  • Encapsulation: data and methods are bundled inside a class; internal data is hidden from outside (private attributes).
  • Inheritance: a subclass inherits attributes and methods from a parent (superclass) — promotes code reuse.
  • Polymorphism: objects of different classes can be treated through the same interface — e.g. different animals all have a makeSound() method that behaves differently.
  • Examples: Python, Java, C++, C#, Ruby.

Comparison of Paradigms

ParadigmFocusKey ConceptExamplesBest For
Imperative / ProceduralHOW to do it (step by step)Sequence of statements, procedures, loopsC, Pascal, Python scriptsSequential tasks, systems programming
DeclarativeWHAT to achieve (not how)Rules, queries, logicSQL, HTML, Prolog, CSSDatabase queries, web styling, logic problems
FunctionalFunction application and compositionPure functions, immutability, first-class functionsHaskell, F#, ErlangData transformation, concurrent systems
Object-OrientedObjects with data and behaviourClasses, inheritance, encapsulation, polymorphismJava, Python, C++, C#Large systems, GUI applications, simulations

Declarative vs Procedural: Key Contrast

A critical distinction for the exam:

  • Procedural: the programmer specifies every step — e.g. a loop to search through a list item by item.
  • Declarative: the programmer specifies the desired result — e.g. SELECT in SQL: the database engine decides how to find the data.

Prolog: A Declarative/Logic Language

Prolog is a logic programming language (sub-type of declarative). The programmer defines facts and rules, then asks queries. Prolog's inference engine determines how to answer the query.

  • Fact: parent(tom, bob). — tom is a parent of bob.
  • Rule: grandparent(X, Z) :- parent(X, Y), parent(Y, Z). — X is grandparent of Z if X is parent of Y and Y is parent of Z.
  • Query: ?- grandparent(tom, ann). — asks the engine if tom is a grandparent of ann.
Exam tip: Know the four paradigms: imperative/procedural (how), declarative (what), functional (functions/no side effects), OOP (objects with data+behaviour). Be able to identify which paradigm a given code snippet belongs to and justify why.
Exam tip: For functional programming: key terms are pure functions (same input → same output, no side effects), immutability, first-class functions, higher-order functions. These are commonly examined.
⚠ Common Mistakes
  • Confusing declarative with functional — both describe 'what' at a high level, but functional focuses on mathematical function composition; declarative includes SQL and logic languages like Prolog.
  • Saying procedural is the same as imperative — procedural IS a subset of imperative. All procedural programs are imperative, but not all imperative programs are procedural.
  • Not knowing what a 'pure function' is — a pure function always returns the same output for the same input AND has no side effects (doesn't modify any external state/global variables).
✓ Notes completed!
Video coming soon
Click to advance · Arrow keys also work
Click slide or press arrow keys to navigate

Worksheet — 1.2.4d Programming Paradigms

8 questions · 20 marks · instantly marked

Q1Define the term 'programming paradigm' and name the four paradigms required for OCR H446.[2 marks]
✓ Mark scheme
A programming paradigm is a style or fundamental approach to programming — a way of thinking about and structuring programs [1]; the four required paradigms are: imperative/procedural, declarative, functional, and object-oriented [1].
Q2Distinguish between the imperative and declarative paradigms. Give an example of a language for each and explain how they differ in approach.[4 marks]
✓ Mark scheme
Imperative: the programmer specifies exactly HOW to achieve the result — a sequence of steps telling the computer what operations to perform; example: C or Python [1]. Declarative: the programmer specifies WHAT the desired result is, leaving the runtime to determine how to achieve it; example: SQL or Prolog [1]. Difference: a SQL query like SELECT name FROM students WHERE grade='A' states what is wanted without specifying how to search; an imperative equivalent would use a loop to iterate through each student and check the grade [1]; in declarative code, the language system optimises how the result is achieved [1].
Q3What is a 'pure function' in functional programming? Give two advantages of using pure functions.[3 marks]
✓ Mark scheme
A pure function always returns the same output for the same input (deterministic) AND has no side effects — it does not modify any external state, global variables, or produce I/O [1]; advantages: easier to test — you can test the function in isolation by checking output for a given input, without worrying about external state [1]; naturally thread-safe — since no shared state is modified, pure functions can run concurrently in parallel without risk of race conditions [1].
Q4Explain what is meant by 'first-class functions' in functional programming and give an example of a higher-order function.[3 marks]
✓ Mark scheme
First-class functions mean that functions are treated like any other data value — they can be passed as arguments to other functions, returned from functions, and stored in variables [1]; a higher-order function is a function that takes other functions as arguments or returns a function [1]; example: map(f, list) applies function f to every element of a list — f is passed as an argument to map; filter(pred, list) returns elements for which predicate function pred returns True [1].
Q5Explain how Prolog, as a logic/declarative language, differs from a procedural language in the way programs are written. Use the terms 'facts', 'rules', and 'queries' in your answer.[3 marks]
✓ Mark scheme
In Prolog, the programmer defines facts (e.g. parent(tom, bob).) stating true relationships [1]; rules that define how new facts can be inferred from existing facts (e.g. grandparent(X, Z) :- parent(X, Y), parent(Y, Z).) [1]; and queries submitted to the inference engine to find answers (e.g. ?- grandparent(tom, ann).). The programmer does not specify how to find the answer — Prolog's engine searches through facts and rules automatically, unlike procedural code where the programmer writes the search algorithm [1].
Q6What is the principle of 'immutability' in functional programming, and why is it considered beneficial?[2 marks]
✓ Mark scheme
Immutability means that once a data structure (variable/list/object) is created, it cannot be modified — instead, operations produce new data structures [1]; this is beneficial because it eliminates a whole class of bugs caused by unintended modification of shared data; it also makes concurrent programming safer since multiple threads can read the same data without risk of one thread modifying it while another reads it [1].
Q7State which paradigm would be most appropriate for each scenario and justify your choice:[2 marks]
a) Querying a database to find all customers who spent over £100 last month.
b) Writing a program that simulates a bank with accounts, customers, and transactions.
✓ Mark scheme
a) Declarative (SQL) — the programmer specifies what data is wanted (customers with spending > £100) without detailing how the database should search for them; the SQL engine optimises the query [1]. b) Object-oriented — a bank has natural entities (Account, Customer, Transaction) that map to classes with attributes and methods; OOP's encapsulation protects account balances from direct modification, and inheritance allows different account types (Savings, Current) to extend a base Account class [1].
Q8Procedural programming is sometimes described as a special case of imperative programming. Explain why, and describe what distinguishes procedural programming from general imperative programming.[3 marks]
✓ Mark scheme
Procedural is a sub-type of imperative — all procedural programs are imperative (they specify steps HOW to achieve a result) [1]; but imperative also includes programs without structured subroutines (e.g. early BASIC with GOTO) which are harder to manage [1]; procedural programming introduces procedures/functions/subroutines — named, reusable blocks of code that can be called with parameters, making large programs more structured, modular, and maintainable [1].
Topic Quiz
1 of 15
You scored
out of 15
🎯

Mini Test — 1.2.4d Programming Paradigms

  • 10 questions · 10 marks · 10 minutes
  • 5 MCQ + 5 short answer
Card 1 of 15
Click to reveal
🎉
Complete!
TermDefinition
← 1.2.4c Translators 1.2.4 Types of Programming Language Next: 1.2.4e OOP →
🔒
Pro Content
Subscribe to access all 69 OCR H446 A Level lessons.
£7.99/month
or £59/year
Subscribe now →