Programming Paradigms

Computer Science A2 · Further Programming. The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science A2 topics

The idea

A programming paradigm is a style of programming, a way of thinking about how to build a solution. Low-level programming uses the instruction set of the processor, and each instruction finds its data through an addressing mode.

Imperative (procedural) programming gives the steps in order, using variables, selection, loops, procedures and functions. Object-oriented programming (OOP) builds a program from objects, which hold data (attributes) together with the methods that work on that data.

Declarative programming states facts and rules. The programmer asks a query (a goal) and the language finds the values that satisfy it, without being told the steps.

In simpler words

A programming paradigm is a style of writing programs. Low-level programs use the processor's own instructions and addressing modes. Imperative programs give steps in order. Object-oriented programs are built from objects that hold data and the methods that use it. Declarative programs state facts and rules, then ask a question. The language works out the answer itself.

An everyday comparison

Imperative programming is like giving a friend turn-by-turn directions. Declarative programming is like giving them the address and letting the map app find the route. OOP is like a car: its parts and controls come together, and you use the pedals without touching the engine. The comparison stops working because programs have strict rules, such as inheritance between classes.

Rules to remember

Common mistake

Students stop one step early with indirect addressing and load the address instead of the data. With LDI, go to the operand address, read the address stored there, then go to that second address for the value.

In the exam

For addressing modes, name the mode and trace where the data comes from. For indirect addressing, go to the operand address, read the address stored there, then load from that second address. For OOP, define the term then give a short code example: encapsulation means private attributes reached through getters and setters. For inheritance and polymorphism, use the class names in the question. For declarative code, write facts and rules in the syllabus format and remember that capital letters start variables.

Worked example

Address 40 holds 62, address 62 holds 17 and address 63 holds 90. The index register IX holds 1. What is in the accumulator after each of LDM #40, LDD 40, LDI 40 and LDX 62?

  1. LDM #40 is immediate: the number 40 itself is loaded.
  2. LDD 40 is direct: the contents of address 40 are loaded, which is 62.
  3. LDI 40 is indirect: address 40 holds 62, so the contents of address 62 are loaded, which is 17.
  4. LDX 62 is indexed: 62 + 1 = 63, so the contents of address 63 are loaded, which is 90.

Answer: 40, 62, 17 and 90.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← RecursionFile Processing and Exception Handling →Take a Computer Science A2 test