Types of Programming Language — OCR A-Level Computer Science
Types of Programming Language explained
Types of Programming Language covers 5 specification points, including (a) Need for and characteristics of a variety… and (b) Procedural languages..
Read the full explanation
Open a point below for its explanation and revision guidance.
(a) Need for and characteristics of a variety of programming paradigms.
This statement asks why several programming paradigms exist and what characterises each one. A paradigm is a style of programming, and different problems suit different styles. Imperative (procedural) programming describes a program as a sequence of statements that change state, such as a loop updating a total. Object-oriented programming groups data and the methods acting on it into objects, so a Customer object holds its own name and balance. Declarative styles, such as functional and logic programming, state the result wanted rather than how to compute it; a function in a functional style returns a value without changing data. Choose a paradigm by matching these characteristics to the problem.
(b) Procedural languages.
Procedural languages are high-level languages in which a program is a list of instructions that the processor carries out in order, one step after another. Programmers group a reusable task into a procedure or function, use IF statements for selection, and use WHILE or FOR loops for iteration. Variables store values that change as the program runs. Take a program that reads two numbers, adds them and outputs the total; each statement changes the contents of memory in turn. Languages such as C and Pascal are typically written this way, and Python code can also be written in a procedural style. In an answer, define the term, name one procedural feature and apply it to a simple example.
(c) Assembly language (including following and writing simple programs with the Little Man Computer instruction set). See appendix 5d.
Assembly language is a low-level language that uses mnemonics, such as LDA and ADD, which correspond closely to the machine code instructions a processor executes, so each line usually maps to one instruction. The Little Man Computer (LMC) is a teaching model with 100 mailboxes numbered 0 to 99, an accumulator and a program counter. To follow an LMC program, trace the program counter, read each instruction, and record the accumulator and mailbox contents after each step. To write one, use the instruction set and syntax given in appendix 5d, which includes INP, OUT, STA, LDA, ADD, SUB, BRA, BRZ, BRP, HLT and DAT; check the exact mnemonics there, as some versions of the LMC use COB in place of HLT. Keep programs simple, for example one that inputs two numbers, adds them and outputs the result.
(d) Modes of addressing memory (immediate, direct, indirect and indexed).
You must explain four ways a processor finds the data an instruction uses: immediate, direct, indirect and indexed addressing. In immediate mode the operand is the data itself, so LDA #5 loads the value 5. In direct mode the operand is the address where the data is stored, so LDA 200 loads the contents of address 200. Indirect mode adds one step: the operand is the address of a location holding the address of the data, so the processor reads a pointer first. Indexed mode adds an index register to a base address, so base 200 with index 3 reads address 203. Trace each mode by listing the operand, each memory read and the final value. Notation varies between assembly languages, so learn the logic.
(e) Object-oriented languages (see appendix 5d for pseudocode style) with an understanding of classes, objects, methods, attributes, inheritance, encapsulation and polymorphism.
This statement requires understanding of object-oriented languages in the pseudocode style of appendix 5d. A class is a blueprint defining attributes (data) and methods (behaviour); an object is an instance with its own attribute values. Encapsulation bundles attributes and methods together and limits direct access to attributes. Inheritance lets a subclass reuse and extend a superclass, so Dog might inherit from Animal. Polymorphism lets one method call behave differently depending on the object, such as speak() giving different output for a Dog and a Cat. Practise tracing which method runs for each object.
Your focus
- Explain why different problems suit different programming paradigms.
- Describe the characteristics of imperative and object-oriented programming with examples.
- Distinguish declarative programming from imperative programming using a suitable example.
Show all 15 objectives
- Define a procedural language in your own words, including the idea of an ordered sequence of instructions.
- Identify procedural features such as procedures, selection, iteration and variables in short code.
- Explain how the value of a variable changes as a procedural program runs.
- Trace a given LMC program and state the accumulator value after each instruction.
- Write a short LMC program that inputs, processes and outputs values using the instruction set in appendix 5d.
- Identify the purpose of the accumulator, program counter and mailboxes in the LMC.
- Trace the memory accesses needed by immediate, direct, indirect and indexed addressing for a given instruction.
- Calculate an effective address from a base address and an index register value.
- Distinguish between an operand that is data, an address and a pointer in a given instruction.
- Explain the difference between a class and an object using an example from a given program.
- Trace which method runs for each object in a program that uses inheritance and polymorphism.
- Identify the attributes and methods that a class encapsulates in a given pseudocode definition.
Types of Programming Language exam tips
Marking Points
- Explains that different problems suit different paradigms, giving a reason tied to a specific problem type.
- Describes imperative programming as a sequence of statements that change state, supported by a suitable example.
- Describes object-oriented programming in terms of classes, objects, attributes and methods.
- Distinguishes declarative paradigms by stating the result wanted rather than the steps needed to compute it.
- Identifies that functional programming uses functions that return values without changing data.
- Defines a procedural language as a high-level language whose programs are ordered sequences of instructions.
- Identifies procedures or functions as a way of grouping a reusable task.
- Names selection and iteration as control structures that change the order in which instructions are executed.
- Explains that variables hold values which the program updates during execution.
- Applies the features to a short piece of code rather than only listing them.
- Explains that assembly language uses mnemonics that correspond closely to machine code instructions.
- Identifies the purpose of the LMC accumulator, program counter and mailboxes numbered 0 to 99.
- Traces the program counter and accumulator through a given LMC program, recording mailbox contents at each step.
- Writes a simple LMC program using the mnemonics and syntax set out in appendix 5d.
- Checks that DAT storage and the halt instruction are placed so the program would run to a correct end.
- Defines immediate addressing as an operand that is the data itself, for example LDA #5 loading the value 5.
- Explains direct addressing as an operand that holds the memory address where the data is stored.
- Describes indirect addressing as a two-stage lookup in which the operand gives the address of a location containing the address of the data.
- Calculates an indexed effective address by adding the index register value to the base address, for example 200 + 3 = 203.
- Traces the memory reads each mode requires, stating the value obtained at each stage.
- Defines a class as a blueprint that declares attributes and methods, and an object as an instance created from that class.
- Distinguishes attributes, which store data, from methods, which define behaviour.
- Explains encapsulation as grouping data with the methods that act on it and restricting direct access to attributes.
- Describes inheritance as a subclass reusing and extending the attributes and methods of a superclass.
- Explains polymorphism as one method call producing different behaviour depending on the type of object.
Examiner Tips
- 💡Choose one problem type and justify which paradigm suits it, linking a named characteristic to the problem.
- 💡Use precise terms such as state, class, object and side effect, and define each one briefly in your answer.
- 💡Give a short example for each paradigm, such as a loop for imperative programming or a Customer object for object-oriented programming, to show the characteristic.
- 💡Learn a one-sentence definition that includes instruction sequence, procedures and changing state, then practise restating it in your own words.
- 💡When a question gives code, look for sequence, procedures, selection, iteration and variable updates, and state which ones you can see.
- 💡Eliminate options that describe a different paradigm, such as declarative or object-oriented, unless the question links them to the code shown.
- 💡Trace programs in a table with columns for program counter, instruction, accumulator and the mailboxes you need, and update it after every step.
- 💡Before finishing a written LMC program, check each mnemonic and operand against appendix 5d.
- 💡Test the program mentally with a simple input, such as 2 and 3, to confirm it outputs the value you expect.
- 💡Write each memory read as a separate step so you can check how many accesses each mode requires.
- 💡For indexed questions, add the base address and index value first, then state the resulting address before reading memory.
- 💡Before answering, decide whether the operand in an instruction is data, an address or a pointer to an address.
- 💡Learn the paired terms class with object and superclass with subclass, and state the difference between each pair in one sentence.
- 💡When tracing a program, write the object name before each method call so you can see which object's attributes change.
- 💡When explaining inheritance or polymorphism, use a small example with clearly named classes and show the relevant method in each class.
Common Mistakes
- Treats one paradigm as best for every problem; explain that each paradigm suits particular problem types.
- Describes object-oriented programming as simply using functions; explain that it bundles data and methods into objects and classes.
- Confuses declarative with imperative by describing the steps to compute a result; state the desired result instead.
- Treats procedural as meaning the same as object-oriented; define it by ordered instructions, procedures and state changes instead of classes and objects.
- Claims a language is procedural simply because it appears in a list of languages; judge the code by the features it uses, such as sequence, procedures, selection, iteration and variables.
- Describes variables as fixed constants; in procedural code, variables store values that the program changes as it runs.
- Treats assembly language as a high-level language with English-like statements; describe it as low-level and close to machine instructions.
- Numbers LMC mailboxes from 1 to 100; correct the range to 0 to 99.
- Skips updating the accumulator while tracing; record its value after every instruction that changes it.
- Writes a program that uses stored values without a DAT line for them; add DAT with an initial value for each stored item.
- Uses mnemonics from memory without checking appendix 5d, so the program may use unsupported syntax; check each instruction against the appendix.
- Treats the operand in direct addressing as the data itself rather than its address; the operand locates the data in memory.
- Confuses indirect with direct addressing by stopping after one memory read; indirect addressing needs a second read through the pointer.
- Ignores the index register value and uses only the base address; the effective address is the base address plus the index value.
- Treats a class and an object as the same thing; a class is the template and an object is an instance created from it.
- Confuses inheritance with copying code; a subclass inherits superclass members, which are defined once in the superclass.
- Assumes encapsulation means keeping all code in one file; encapsulation means restricting direct access to attributes.