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,whileandprint - 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.
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: English-like, portable, one line becomes many instructions.
- Assembly: one short code per instruction, tied to one processor.
- Machine code: binary, the only thing the processor runs.
- The same sum at each level. A translator turns the top into the bottom.
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
| Compiler | Interpreter | |
|---|---|---|
| Translation | Whole program at once | One line at a time |
| When | Before running | While running |
| Speed of execution | Fast | Slower |
| Error reporting | All at the end | Stops at the first error |
| Source code needed to run | No | Yes |
| Output | An executable file | No separate file produced |
"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: translates everything first, then the program runs fast and the source stays private.
- Interpreter: translates and runs one line at a time, so it is easy to test and stops at the first error.
- Assembler: turns assembly into machine code, one line for one instruction.
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
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.
- Editor: colours the code and numbers the lines.
- Auto-complete: suggests names as you type, which saves typing and typos.
- Error check: underlines mistakes in red before you run the program.
- Debugger: breakpoints, stepping and a watch window to see what the variables hold.
- Console: where output and error messages appear.
- Project files: everything in one place.
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.
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
- 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.
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
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.
- 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
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.
- 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
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.
- 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
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.
- 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
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.
- 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
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.