Computer ScienceExam code: 0984

Programming Languages and Translators

Software

A uses English-like statements that are far closer to how humans think than to how the CPU works. Each high-level instruction usually corresponds to many machine-code instructions.

Examples named in the syllabus: Python, Java, C++, BASIC. Many others exist (JavaScript, C#, Ruby, Swift, Go, etc.).

A typical high-level program looks like:

FOR i = 1 TO 10
   PRINT i * 2
NEXT i

This program would translate into dozens of machine-code instructions under the hood, but the programmer never has to see or write those instructions.

Why high-level languages exist

High-level languages were developed once processors became fast enough and memory cheap enough that the slight loss of efficiency was worth the huge gain in programmer productivity. They let the programmer focus on what the program should do, rather than on the details of how the CPU does it.

Advantages and disadvantages of high-level languages

AdvantagesDisadvantages
Easier to read, write and maintainCannot directly manipulate hardware without special features or libraries
Easier to debug thanks to clearer syntaxMust be translated to machine code before running
Portable: the same source code can run on many different computers after re-translationMay be less efficient than equivalent low-level code
One line can do a lot: a single statement may correspond to many machine-code instructionsHides hardware details, which can hurt when fine control matters

Common exam question

Picking the benefit of a high-level language

Question: Tick the one statement that is a benefit of, or is correct about, writing a program in a high-level language rather than a low-level language (1 mark).

Asked in 2 of the 17 papers, and both times the credited statement was that the program is machine independent: the same source code can run on different computers once it has been translated for each. The wrong options describe low-level code instead (mnemonics are used, the hardware can be directly manipulated, the program is more memory efficient and quicker to execute), so any statement about mnemonics, closeness to the hardware or raw efficiency is the wrong level. The option that calls a high-level program harder to debug than a low-level one is the reverse of the truth: high-level code is easier to read, write and debug.

Side-by-side

FeatureLow-level (assembly)High-level (Python, Java)
Closeness to hardwareVery closeFar away
Closeness to human languageFar awayClose
Instructions per machine-code instructionOneMany
PortabilityMachine-specificPortable across CPUs
Speed of executionVery fastSlower (but the gap is small for most tasks)
Speed of developmentSlowMuch faster
Translator neededAssemblerCompiler or interpreter

Quick check

4 short questions on this note. See what has stuck, and where to look if something hasn't.

About 2 minutes

Build on this topic