1. Understanding Programming Paradigms
A programming paradigm is a fundamental style or approach to programming. It's not a specific language, but a way of thinking about and structuring code. Different paradigms are suited to different types of problems. The A-Level course focuses on four main types: low-level, imperative, object-oriented, and declarative. A single language, like Python, can often support multiple paradigms.
Key term
Examiner insight
Common pitfall
Worked example 14 marks
A programmer is writing code that consists of a sequence of commands that change the program's state. For example, `X = X + 1`. Another programmer is writing code that describes the desired result without specifying the step-by-step procedure, for example, `SELECT Name FROM Students WHERE Age > 18`. Identify the paradigm used by each programmer and justify your answer.
- 1
Programmer 1 is using the Imperative paradigm.
- 2
Justification: Imperative programming focuses on describing 'how' to achieve a result through a sequence of explicit commands that modify the program's state (e.g., changing the value of variable X).
- 3
Programmer 2 is using the Declarative paradigm.
- 4
Justification: Declarative programming focuses on describing 'what' the result should be, leaving the 'how' to the language implementation. The SQL query states the desired outcome (a list of names) without detailing the steps to find and filter them.
Recap
- A programming paradigm is a style of programming.
- Low-level programming deals with machine-specific instructions.
- Imperative programming uses a sequence of commands to change program state.
- Object-oriented programming bundles data and methods into objects.
- Declarative programming describes the desired result, not the steps to get there.
Quick check
- Name the four programming paradigms you need to know.2 marks
- Which paradigm is SQL (Structured Query Language) an example of?1 mark