KS4J277 2.5 24 min read 10 question quiz 19 exam marks

Programming Languages and IDEs

High and low level languages, translators and the exact difference between a compiler and an interpreter, plus the four IDE features you must name.

High and low level languages

High level languages

Examples: Python, Java, C#, JavaScript, VB.

  • Close to human language, using words like if, while and print
  • Easy to read, write and debug
  • Portable, so the same code can run on different types of processor once translated
  • Must be translated into machine code before the processor can run it
  • The programmer has less direct control over the hardware
  • Code may be less memory efficient, because the translator makes general purpose decisions

Low level languages

Machine code is binary instructions the processor executes directly. Assembly language uses short mnemonics such as LDA, ADD and STO, with one instruction usually corresponding to one machine code instruction.

  • Difficult to read, write and debug
  • Specific to one type of processor, so not portable
  • Gives complete control over the hardware
  • Can be highly optimised for speed and memory use

When each is used

High level for almost everything: applications, websites, games, business systems.

Low level where absolute control or efficiency matters: device drivers, embedded systems with tiny memory, and performance critical sections of operating systems.

The trade off

High level languages are easier and faster to develop in and are portable. Low level languages give precise control over hardware and can be more efficient, at the cost of being far harder to write and processor specific.

High-level, assembly and machine codeThree levels of programming language drawn as a ladder. At the top is high-level language, such as Python, Java or C sharp: it is English-like, one line becomes many machine instructions and it runs on any machine. Below it is assembly language, with short codes such as LDA, ADD and STA: one line is one instruction and it is tied to one type of processor. At the bottom is machine code, binary such as 1011 0001, the only thing a processor can run, and very hard for people to read. A green arrow up the left side points towards easier to write, and a coral arrow down points towards closer to the hardware. The panel on the right shows the same sum, total equals a plus b: one line of Python, three lines of assembly, load a, add b, store total, and three binary machine instructions. A translator turns the top form into the bottom one.High-levelPython, Java, C#English-like.One line, many instructions.Runs on any machine.Assembly languageLDA 7, ADD 3, STA 9Short codes, one perinstruction: one line,one instruction. One CPU.Machine code10110001 00000111Binary: the only thinga processor can run.Hard for people to read.easierto writecloser tohardwareThe same sumtotal = a + b1 line of PythonLDA aADD bSTA total3 lines of assembly1010 0001 0000 01010001 1000 0000 01101011 0001 0000 01113 machine instructionsa translator turns the topone into the bottom one1234
  1. High-level: English-like, portable, one line becomes many instructions.
  2. Assembly: one short code per instruction, tied to one processor.
  3. Machine code: binary, the only thing the processor runs.
  4. The same sum at each level. A translator turns the top into the bottom.
High-level is for people to write. Machine code is for the processor to run. Translators connect them.

Translators

Processors only execute machine code, so any high level program must be translated.

Assembler

Translates assembly language into machine code. The relationship is close to one to one.

Compiler

Translates the whole program into machine code in one go, producing an executable file.

  • Translation happens once, before the program is distributed or run
  • The resulting executable runs quickly, since no translation happens at run time
  • The source code is not needed by the end user, which protects the developer's work
  • All errors are reported together at the end of compilation, which can be overwhelming
  • Compiled code is specific to one platform, so a separate version is needed for each

Interpreter

Translates and executes the program one line at a time, every time it runs.

  • Stops at the first error, reporting it immediately, which makes debugging much easier
  • Runs more slowly, because translation happens every time the program runs
  • The source code and the interpreter are both needed to run the program
  • The same source runs on any platform that has a suitable interpreter
CompilerInterpreter
TranslationWhole program at onceOne line at a time
WhenBefore runningWhile running
Speed of executionFastSlower
Error reportingAll at the endStops at the first error
Source code needed to runNoYes
OutputAn executable fileNo separate file produced
The classic question

"Give one advantage of using an interpreter during development." The answer is that it stops and reports the first error it finds, making it far easier to locate and fix errors than receiving a long list at the end of compilation.

Compiler, interpreter and assemblerThree translators, one card each. A compiler takes the source code and translates all of it at once into a separate executable file of machine code. The file can then be run again and again without the compiler, and it runs fast and keeps the source code private. An interpreter translates and runs the source code one line at a time, line 1 then line 2 then line 3, so it runs straight away, which makes it easy to test, but it stops at the first error and is slower because the translation happens every time. An assembler translates assembly language into machine code, with one line of assembly becoming one machine instruction, which gives low-level control of the hardware but produces code that only fits one type of processor.CompilerInterpreterAssemblersource codecompileall of it, oncesource codeinterpretone line at a timeassembly codeassembleone to oneprogram.exemachine codeline 1runline 2runline 3run10110001 00000111machine code, one to onetranslates it all firstthen it runs fast, again and againsource code stays privatetranslates as it goesruns straight away, so easy to teststops at the first errorone line is one instructionfor low-level control of hardwareoutput only fits one processor123
  1. Compiler: translates everything first, then the program runs fast and the source stays private.
  2. Interpreter: translates and runs one line at a time, so it is easy to test and stops at the first error.
  3. Assembler: turns assembly into machine code, one line for one instruction.
Compiled code runs faster. Interpreted code is quicker to try out. Learn one point for each.

Integrated development environments

An IDE is software that provides a set of tools for writing, testing and debugging programs in one place. Examples include IDLE, Visual Studio, PyCharm and Thonny.

You must know four features.

1. Editor

Where the code is written. Features that help:

  • Syntax highlighting, colouring keywords, strings and comments so structure is visible and typing errors stand out
  • Automatic indentation and bracket matching
  • Auto complete, suggesting names and reducing spelling errors
  • Line numbers, which matter because error messages refer to them

2. Error diagnostics

Reports problems in the code.

  • Identifies the line number and the type of error
  • Often highlights the offending code as you type
  • Suggests likely causes

3. Run time environment

Allows the program to be run and tested within the IDE, without leaving it or manually invoking a translator, so the write, run, fix cycle is fast.

4. Translator

The IDE includes the compiler or interpreter needed to convert the code so it can run, so no separate installation or command is required.

5. Debugging tools

  • Breakpoints pause the program at a chosen line so variables can be inspected
  • Stepping runs one line at a time so the flow can be watched
  • Variable watch shows values changing live
Why an IDE matters

All the tools needed to write, translate, run and debug a program are in one place, which speeds up development and makes errors far easier to find and fix.

What an integrated development environment gives youA mock up of an integrated development environment, an IDE, with six features picked out. The editor colours the code and numbers the lines. Auto-complete offers names as you type, here suggesting prices and print. The error check underlines a mistake in red before the program is run: in the picture totl is underlined with the message totl is not defined, because the function is called total. The debugger lets you set a breakpoint, shown as a red dot beside line 4, run to it, step through the code and watch the values of the variables, here t equal to 2, p equal to 3 and prices equal to the list 2, 3. The console shows output and error messages. A file explorer keeps all the project files in one place. A Run button runs the program, a Debug button runs it under the debugger, and Stop ends it.my_project — IDERunDebugStopFILESmain.pyutils.pydata.txt1def total(prices):2    t = 03    for p in prices:4        t = t + p5    return t67print(totl([2, 3]))totl is not definedpricesprintWATCHt2p3prices[2, 3]consolepaused at line 4NameError: name'totl' is not definedEditorcolour and line numbersAuto-completesuggests as you typeError checkred line before you runDebuggerbreakpoint, step, watchConsoleoutput and error messagesProject filesall in one place123456123456
  1. Editor: colours the code and numbers the lines.
  2. Auto-complete: suggests names as you type, which saves typing and typos.
  3. Error check: underlines mistakes in red before you run the program.
  4. Debugger: breakpoints, stepping and a watch window to see what the variables hold.
  5. Console: where output and error messages appear.
  6. Project files: everything in one place.
An IDE is an editor, a translator and a debugger in one window. Learn the features it gives you.

Key terms you must be able to define

High level language
A programming language close to human language, which must be translated before a processor can run it.
Low level language
Machine code or assembly language, working directly with the processor's own instruction set.
Machine code
Binary instructions that a processor can execute directly.
Assembly language
A low level language using short mnemonics, with roughly one instruction per machine code instruction.
Translator
Software that converts program code from one language into another.
Compiler
A translator that converts an entire program into machine code before it is run, producing an executable.
Interpreter
A translator that converts and executes a program one line at a time, each time it runs.
Assembler
A translator that converts assembly language into machine code.
IDE
Integrated development environment. Software combining an editor, translator, run time environment and debugging tools.
Breakpoint
A marker that pauses a running program at a chosen line so variables can be inspected.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineHigh level language
AnswerA programming language close to human language, which must be translated before a processor can run it.
DefineLow level language
AnswerMachine code or assembly language, working directly with the processor's own instruction set.
DefineMachine code
AnswerBinary instructions that a processor can execute directly.
DefineAssembly language
AnswerA low level language using short mnemonics, with roughly one instruction per machine code instruction.
DefineTranslator
AnswerSoftware that converts program code from one language into another.
DefineCompiler
AnswerA translator that converts an entire program into machine code before it is run, producing an executable.
DefineInterpreter
AnswerA translator that converts and executes a program one line at a time, each time it runs.
DefineAssembler
AnswerA translator that converts assembly language into machine code.

Reach the top grade on this topic

This topic is factual, so accuracy is everything.

Do not say a compiler is 'faster'. Compiled code executes faster, but compilation itself takes time. Say that the resulting executable runs faster because no translation is needed at run time.

Be exact about error reporting. A compiler reports all errors together after attempting to translate the whole program. An interpreter stops at the first error it encounters. The interpreter's behaviour is the advantage during development.

Link IDE features to a benefit. Not "it has syntax highlighting", but "syntax highlighting colours keywords and strings differently, so a misspelled keyword or an unclosed quotation mark is immediately visible".

Know why high level languages are portable. The same source code can be translated for different processors, whereas assembly and machine code are written for one specific instruction set.

  • Give three differences between a compiler and an interpreter
  • Explain why low level languages are used for embedded systems
  • Name four IDE features and give a benefit for each
  • Explain why a program written in a high level language must be translated

Mistakes that cost marks here

Avoid these
  • Saying 'compilers are faster than interpreters' without specifying that it is the resulting program that runs faster.
  • Saying an interpreter 'finds all the errors'. It stops at the first one.
  • Confusing an assembler with a compiler. An assembler translates assembly language specifically.
  • Saying a high level language 'runs directly on the processor'. It must be translated to machine code first.
  • Listing IDE features without saying what each one does for the programmer.
Fun fact

The first compiler was written by Grace Hopper in 1952, and she had to convince people it was even possible. The prevailing view was that computers could only do arithmetic, and that the idea of a program writing a program was nonsense.

Knowledge check

0 of 10 answered
1Which is a characteristic of a high level language?
2What does a compiler do?
3Which is an advantage of an interpreter during program development?
4Why is assembly language not portable?
5Which IDE feature pauses a program at a chosen line so variables can be inspected?
6What does an assembler translate?
7What is the main benefit of syntax highlighting?
8Why might a developer choose a low level language for an embedded system?
9Which statement about a compiled program is correct?
10Which of these is NOT typically a feature of an IDE?
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

19 marks
1State two differences between a compiler and an interpreter.2 marks
State

Mark scheme0 / 2
  • LA compiler translates the whole program at once, an interpreter translates line by line
  • LA compiler reports all errors at the end, an interpreter stops at the first error
Model answer

A compiler translates the entire program into machine code in one operation before it is run, whereas an interpreter translates and executes the program one line at a time each time it is run. In addition, a compiler reports all the errors it has found together once translation is complete, while an interpreter stops as soon as it reaches the first error and reports that one immediately.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain one advantage of using an interpreter and one advantage of using a compiler.4 marks
Explain

Mark scheme0 / 4
  • LInterpreter advantage: errors are reported one at a time as they are reached
  • LWhich makes it easier to locate and correct errors during development
  • LCompiler advantage: the resulting executable runs faster as no translation happens at run time
  • LOr: the source code does not need to be given to the user, protecting it
Model answer

An advantage of an interpreter is that it stops at the first error it encounters and reports it immediately, along with the line it occurred on. This makes it much easier to develop and debug a program, because the programmer deals with one problem at a time in the context of where it happened, rather than being presented with a long list of errors after attempting to translate the whole program. An advantage of a compiler is that the program is fully translated into machine code before it is distributed, so when it is run there is no translation overhead and the resulting executable runs considerably faster. A further advantage is that only the executable needs to be given to the user, so the developer's source code remains private.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Explain why a program written in a high level language must be translated before it can be executed.3 marks
Explain

Mark scheme0 / 3
  • LA processor can only execute machine code
  • LHigh level languages use English-like statements the processor cannot execute directly
  • LA translator such as a compiler or interpreter converts it into machine code
Model answer

A processor is built to execute only machine code, which consists of binary instructions drawn from its own instruction set. A high level language uses English-like keywords and statements such as if, while and print, which are designed to be readable by people rather than by hardware, and the processor has no way of acting on them directly. A translator, either a compiler or an interpreter, is therefore required to convert the high level source code into the machine code instructions that the processor can actually execute.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Describe three features of an integrated development environment and explain how each helps a programmer.6 marks
Describe

Mark scheme0 / 6
  • LAn editor for writing code
  • LWith features such as syntax highlighting and auto indentation that make errors visible
  • LError diagnostics that identify problems
  • LGiving the line number and type of error so it can be located quickly
  • LA run time environment allowing the program to be run and tested inside the IDE
  • LDebugging tools such as breakpoints and variable watches
Model answer

The first feature is the editor, which is where the code is written. It provides syntax highlighting, colouring keywords, strings and comments differently so that the structure of the code is immediately visible and a misspelled keyword or an unclosed quotation mark stands out, along with automatic indentation, bracket matching and line numbers that correspond to those quoted in error messages. The second feature is error diagnostics, which identifies problems in the code and reports the line number and the type of error, often highlighting the offending code as it is typed. This lets the programmer locate and fix errors far more quickly than searching manually. The third feature is the run time environment together with debugging tools, which allows the program to be executed and tested from within the IDE without leaving it or invoking a translator manually. Debugging tools such as breakpoints, which pause execution at a chosen line, and variable watches, which show values changing as the program runs, allow the programmer to inspect exactly what the program is doing at the moment a fault occurs, which is the only reliable way to find logic errors.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5A company is writing software to control a medical device with very limited memory and strict timing requirements. Explain why they might write part of the software in a low level language.4 marks
Explain

Mark scheme0 / 4
  • LLow level languages give direct control over the hardware
  • LCode can be optimised to use very little memory
  • LExecution can be made faster and timing more predictable
  • LAcknowledges the drawback that it is harder to write and not portable
Model answer

A low level language such as assembly gives the programmer direct control over the processor's registers and memory locations, which is exactly what is needed when a device has very limited memory. The programmer can decide precisely how every byte is used rather than relying on a compiler to make general purpose decisions, so the code can be made far more compact than the equivalent high level program. Timing is the other reason: each assembly instruction corresponds closely to one machine code instruction, so the programmer knows exactly how long a section of code takes to execute, which matters enormously in a medical device that must respond within a guaranteed time. The drawbacks are significant, since low level code is much harder to write, read and debug, and it is specific to one processor so it cannot be reused if the hardware changes. For that reason the company would most likely write the bulk of the software in a high level language and use low level code only for the small, timing critical sections where it is genuinely needed.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 19