1. Understanding Programming Paradigms
A programming paradigm is a fundamental style or 'way of thinking' about programming. It's not a specific language, but rather an approach to structuring code to solve problems. Different paradigms are suited to different types of tasks. The main paradigms you need to know are:
- Imperative: This is the most common paradigm. It uses statements that change a program's state. You write a sequence of commands for the computer to perform. High-level imperative languages include Python, Java, and C++.
- Declarative: Instead of describing *how* to do something, you describe *what* you want to achieve. The language itself figures out how to get the result. SQL (for databases) and Prolog (for logic programming) are key examples.
- Object-Oriented (OOP): An extension of imperative programming. It organises code into 'objects' which bundle data (attributes) and the methods (procedures) that operate on that data. This promotes code reuse and helps manage complexity in large systems.
- Low-Level: This programming style is very close to the computer's own machine code. It deals directly with memory addresses and processor registers. Assembly language is the primary example. It gives the programmer fine-grained control but is difficult and time-consuming to write.
Key term
Examiner insight
Fun fact
Worked example 13 marks
A programmer writes the following SQL statement: `SELECT StudentName FROM Students WHERE Course = 'Computer Science'`. Which programming paradigm is being used and why?
- 1
- Identify the paradigm: The paradigm being used is Declarative programming.
- 2
- Justify the choice: The programmer has stated *what* data they want (the names of students in Computer Science), not the step-by-step process of how to find it.
- 3
- Contrast with other paradigms: An imperative approach would involve opening the student file, looping through each record, checking if the course is 'Computer Science', and if so, adding the name to a list, before finally printing the list. The SQL statement abstracts all of this away.
Recap
- A programming paradigm is a style of programming.
- Imperative programming uses a sequence of commands to change program state.
- Declarative programming focuses on the desired result, not the process.
- Object-Oriented Programming (OOP) bundles data and methods into objects.
- Low-level programming works directly with the computer's hardware architecture.
Quick check
- Which paradigm focuses on describing 'what' the result should be, rather than 'how' to achieve it?1 mark
- Give one example of a low-level language.1 mark