Languages
x

Revision notes for OCR GCSE Computer Science Languages. Open the guide for explanations and worked examples. Written against the OCR GCSE Computer Science (J277) specification, so the content matches what's examinable rather than general Computer Science background.

Languages

What you'll learn

  • The difference between high-level and low-level programming languages.
  • Why programs often need a translator before they can run.
  • How compilers and interpreters work.
  • The main benefits and drawbacks of using a compiler or an interpreter.

The big picture: humans and CPUs do not “speak” the same way

A programming language is a language used to write instructions for a computer.

When you write a program in a language such as Python, the text you write is called source code. Source code is designed to be understandable by programmers.

A CPU, however, can only directly execute machine code: binary instructions made from 0s and 1s. So, if you write code in a human-friendly language, something must convert it into a form the CPU can run.

Definition

Machine code

Machine code is a low-level programming language made of binary instructions that the CPU can execute directly.

Diagram comparing high-level languages, low-level machine code, compilers and interpreters

Key Idea

The core idea

Programmers usually write code in a language that is easier for humans to understand, but the CPU ultimately needs machine code.

Levels of programming language

Programming languages can be described by their level.

The level tells you how close the language is to human language or to the computer hardware.

High-level languages

A high-level language is a programming language that is closer to natural human language and further away from the hardware.

Examples include Python, Java, JavaScript and C#.

High-level languages often use words and structures that are easier for humans to read, such as IF, WHILE, PRINT, variables and meaningful procedure names.

High-level languages are usually:

  • Easier to read and write than machine code.
  • Easier to debug, which means find and fix errors.
  • Easier to maintain, meaning easier to update later.
  • More portable, meaning the same source code can often be translated for different types of computer.
  • Less directly connected to the hardware.
Definition

Portability

A program is portable if it can be used on different types of computer system with little or no change to the source code.

The drawback is that high-level language code cannot usually be executed directly by the CPU. It needs a translator.

Low-level languages

A low-level language is a programming language that is close to the hardware.

For GCSE J277, the key low-level idea is machine code: binary instructions that the CPU can run directly.

Low-level languages are usually:

  • Harder for humans to read and write.
  • More closely linked to a specific CPU or type of hardware.
  • Less portable.
  • Useful when very direct control of hardware is needed.
  • Potentially efficient, because the instructions are close to what the CPU actually runs.

You do not need to explain assemblers for this sub-topic.

High-level vs low-level languages

FeatureHigh-level languageLow-level language
Closeness to humansEasier for humans to understandDifficult for humans to understand
Closeness to hardwareFurther from the CPUClose to the CPU
PortabilityUsually more portableUsually hardware-specific
Translation needed?Yes, before or during executionMachine code can be executed directly
Ease of debuggingUsually easierUsually harder
Typical useGeneral software developmentDirect hardware control or very specific low-level tasks
Common Mistake

High-level does not mean more powerful

Do not assume “high-level” means “better” and “low-level” means “worse”. The words describe distance from the hardware, not quality.

Example

Choosing a language level

A company is making a simple booking app that must run on different operating systems.

  1. The app needs to be developed quickly and maintained by programmers, so readability and maintainability matter.
  2. It must run on different systems, so portability is important.
  3. It does not need direct control of hardware, so a low-level language is not necessary.
  4. A high-level language is the better choice because it is easier to write, easier to maintain and more portable.

Why translators are needed

A translator is a program that converts code from one programming language into another.

In this topic, translators are needed because high-level source code must be converted into machine code so that the CPU can execute it.

Definition

Translator

A translator is software that converts program code into another language, usually from high-level source code into machine code.

Translators are needed because:

  • The CPU only directly understands machine code.
  • High-level languages are designed for humans, not CPUs.
  • Translation allows programmers to write readable code while still producing instructions the computer can run.
  • Translators can also report some errors in the source code.

A syntax error is an error where the code breaks the grammar rules of the programming language, such as a missing bracket or misspelled keyword.

Compilers

A compiler is a translator that translates the whole program into machine code before the program is run.

The translated result is often saved as an executable file. An executable file is a program file that can be run by the computer.

Definition

Compiler

A compiler translates the whole source program into machine code before execution, usually creating an executable file.

Benefits of using a compiler

A compiler has several advantages:

  • The program usually runs quickly after it has been compiled.
  • The executable can often be run many times without translating the source code again.
  • The user does not usually need the compiler or the source code to run the program.
  • The source code can be kept private, because users receive the executable rather than the original code.
  • The compiler can report errors found during compilation.

Drawbacks of using a compiler

A compiler also has disadvantages:

  • The whole program must be compiled before it can run.
  • If the compiler finds errors, it may not create an executable.
  • Testing small changes can be slower because you may need to recompile.
  • The executable may be specific to a particular operating system or type of processor.

Interpreters

An interpreter is a translator that translates and runs code one instruction at a time.

It does not usually create a separate executable file. Instead, the source code is translated as the program runs.

Definition

Interpreter

An interpreter translates and executes a program one instruction at a time, without producing a separate executable file.

Benefits of using an interpreter

An interpreter is useful because:

  • It is good for testing and debugging.
  • It can stop at the exact instruction where an error is found.
  • You can run small sections or changes quickly.
  • It is often convenient while developing a program.

Drawbacks of using an interpreter

An interpreter also has disadvantages:

  • The program usually runs more slowly because translation happens during execution.
  • The interpreter is needed each time the program runs.
  • The source code is usually needed, so it is harder to keep the code private.
  • The program is not distributed as a standalone executable in the same way as compiled code.
Tip

Fast clue for exam questions

If the question says the whole program is translated before running, think compiler. If it says code is translated and executed one instruction at a time, think interpreter.

Compiler vs interpreter

FeatureCompilerInterpreter
Translation methodTranslates the whole program at onceTranslates and runs one instruction at a time
When execution happensAfter compilationDuring translation
OutputUsually creates an executable fileUsually no separate executable file
Speed when runningUsually fasterUsually slower
DebuggingErrors reported after compilationCan stop when an error is reached
Source code needed by userUsually not neededUsually needed
Best suited forFinished programs to distributeDeveloping, testing and debugging
Example

Choosing a translator

A student is still developing a program and wants to test each change quickly.

  1. The program is not finished yet, so the student needs quick testing and easy debugging.
  2. If an error occurs, it would be useful for translation to stop at the instruction causing the problem.
  3. An interpreter is suitable because it translates and runs one instruction at a time, making it helpful during development.
  4. A compiler may be better later when the program is finished, because the final program can run faster as an executable.
Common Mistake

Translation does not prove the program is correct

A compiler or interpreter can find some syntax errors, but a translated program can still have logic errors, where it runs but gives the wrong result.

Key vocabulary to remember

  • Source code: the program code written by a programmer.
  • Machine code: binary instructions the CPU can execute directly.
  • High-level language: closer to human language and easier to read.
  • Low-level language: closer to hardware and harder for humans to read.
  • Translator: software that converts code from one language to another.
  • Compiler: translates the whole program before it runs.
  • Interpreter: translates and runs one instruction at a time.
  • Executable file: a translated program file that can be run.
Exam technique

In the exam

  1. When comparing language levels, mention both sides: high-level is easier for humans and more portable; low-level is closer to hardware and less portable.
  2. When asked why translators are needed, link your answer to the CPU only executing machine code.
  3. For compiler vs interpreter questions, structure your answer around translation method, output, speed, debugging and whether source code is needed.
Self review

Check yourself

  • Why can a CPU not directly run most high-level source code?
  • Give two benefits and one drawback of using a compiler.
  • Why might an interpreter be useful while a programmer is developing a program?

Recap questions

Test yourself with 5 quick questions on this guide. Answer them all correctly to complete it.

You've reached the end

Test yourself on this topic, or move on to the next guide.

Practice questionsTake a quick quiz on this topicFlashcardsSelf-test with active recall
The Integrated Development Environment (IDE)Up next

How was this guide?

Languages Revision Guide

  1. GCSE
  2. /Computer Science
  3. /Languages