4.2 Types of programming language, translators and integrated development environments (IDEs)

← Topic 4.1 Types of software and interruptsComputer Science contentsTopic 5.1 The internet and the World Wide Web (WWW) →
Chapter 4 · Software

4.2 Types of programming language, translators and integrated development environments (IDEs)

Computers execute machine code, but programmers normally write instructions in languages that are much easier for people to understand. This topic explains high-level and low-level languages, assembly language, the translators that convert programs into machine code, and the IDE tools that help programmers write, test and debug software.

High-level languagesLow-level languagesAssembly languageCompiler & interpreterAssemblerIDEs & debugging

What you need to understand

You should be able to compare high-level and low-level languages; explain why assembly language is used; distinguish a compiler, interpreter and assembler; compare the advantages and disadvantages of compilers and interpreters; and explain how common IDE features make program development easier.

4.2.1

High-level languages and low-level languages

A computer program is a sequence of instructions that makes a computer perform a particular task. Programs may be written using different programming languages, but the processor ultimately executes machine code. This means that programs written in other languages must be translated before the computer can use them.

Course-book Figure 4.14 showing a Scratch multiplication table test program

High-level languages

A high-level language (HLL) is designed around the needs of programmers rather than the details of one particular processor. A programmer can concentrate on the problem being solved without needing to know the exact hardware architecture or instruction set of the computer that will eventually run the program.

Many high-level languages are portable. The same source program can often be used on different computer systems, provided that a suitable translator is available for each system. High-level statements are also closer to human language than machine code, so they are normally easier to read and understand.

Sum := FirstNumber + SecondNumber

The statement above expresses the task of adding two values in a form that is much easier for a programmer to follow than the equivalent machine instructions.

Why high-level languages are easier to develop with

  • Programs are easier to read and understand.
  • Programs can usually be written in less time.
  • Errors are easier to locate and correct during development.
  • Programs are easier to maintain after they have been put into use.

Examples

The textbook gives examples such as C++, Delphi, Java, Pascal, Python and Visual Basic. Programming techniques learned in one high-level language can often be transferred to another.

Low-level languages

A low-level language is closely related to the architecture and hardware of a particular computer. Low-level languages include machine code and assembly language. Because they are machine dependent, a program written for one processor family may not work on another without being changed.

Machine code

Machine code is the binary instruction language that the processor can execute directly. It is very difficult for people to read and write, especially in long programs, so programmers rarely create complete programs directly in machine code. Machine code is often displayed in hexadecimal because hexadecimal is more compact than a long sequence of binary digits.

Typical hexadecimal instructionEquivalent binary
1 120001 00010010
4 130100 00010011
0 1A0000 00011010

High-level compared with low-level

Language typeAdvantagesDisadvantages
High-levelUsually independent of one computer type; easier to read, write and understand; quicker to develop; easier to debug; easier to maintain.Programs can be larger; translated programs may execute more slowly; the programmer may not be able to use special hardware features directly.
Low-levelCan use special hardware and machine-dependent instructions; can produce compact code; can produce code that performs a task very quickly.Programs usually take longer to write and debug; the code is harder for people to understand; programs are machine dependent.
Exam distinction: high-level languages are mainly problem oriented and easier for humans; low-level languages are closely tied to the machine and can give more direct control over hardware.
Explore further: identify several tasks carried out by programs in your school, then research what kinds of problems different high-level languages are commonly used to solve. The textbook also suggests comparing machine-code instruction sets for different processor families.
Check high-level, low-level and machine code.
4.2.2

Assembly languages

Assembly language is a low-level programming language that uses short mnemonic instructions instead of writing the processor's binary machine code directly. It is still closely connected to a particular processor and its instruction set, but it is more readable for a programmer than raw binary.

Programmers may choose assembly language when they need close control over the hardware, when a special machine-dependent instruction is required, when memory use must be kept very small, or when a particular task must execute very quickly.

Example: adding two values in assembly language

LDA First
ADD Second
STO Sum
  • LDA First - load the value stored in First into the accumulator.
  • ADD Second - add the value stored in Second to the value already in the accumulator.
  • STO Sum - store the accumulator's result in Sum.

Assembly language cannot normally be executed directly. It must first be translated into machine code by an assembler. Because assembly instructions are designed around the target processor's instruction set, assembly language is machine dependent.

Remember: assembly language is not the same as machine code. Assembly uses meaningful mnemonics such as LDA, ADD and STO; machine code is the binary form the CPU executes.
Explore further: compare two assembly languages and identify the computer or processor family for which each one is designed.
Check assembly language and mnemonics.
4.2.3

Translators

People write programs in forms that trained programmers can understand, but a processor performs operations in binary machine code. A translator is system software that converts a program into a form that the computer can execute. The three translators in this topic are the compiler, interpreter and assembler.

Course-book Figure 4.15 illustrating translation from a human-readable program into binary machine code

Compiler

A compiler translates an entire program written in a high-level language into machine code in one operation. If the program can be compiled successfully, an executable machine-code file is produced. That executable can then be used repeatedly without compiling the source program each time.

If the compiler finds errors, it produces an error report rather than a usable final executable. One high-level language statement may be translated into several machine-code instructions.

High-level statement translated to machine instructions

Sum := FirstNumber + SecondNumber

0001 00010010
0100 00010011
0000 00011010

The high-level instruction is clear to a programmer; the processor uses the translated machine instructions.

Interpreter

An interpreter reads a high-level language program one statement at a time. It translates a statement, carries out the action, and then moves to the next statement. If an error is encountered, execution stops at that point and an error message may be shown, sometimes with a suggested correction.

An interpreted program must be interpreted again every time it is run. No separate executable machine-code file is produced.

Assembler

An assembler translates a program written in assembly language into machine code. Once assembly source code has been assembled successfully, the produced machine code can be used repeatedly without running the assembler again. An assembly instruction normally corresponds closely to one machine-code instruction.

LDA First   →   0001 00010010
ADD Second →   0100 00010011
STO Sum    →   0000 00011010

Compiler, interpreter and assembler compared

CompilerInterpreterAssembler
Translates a high-level language program into machine code.Translates and executes a high-level program one statement at a time.Translates a low-level assembly-language program into machine code.
Produces an executable machine-code file.Does not produce a separate executable machine-code file.Produces machine code that can be executed.
One HLL statement may become several machine instructions.One HLL statement may require several machine instructions while it is being executed.One assembly instruction usually maps closely to one machine instruction.
The compiled program can run without the compiler.The source program needs the interpreter each time it runs.The assembled program can run without the assembler.
Commonly used to prepare a program for general distribution.Often useful while a program is being developed and tested.Used where a low-level assembled program is required.
Fast way to distinguish them: compiler = whole high-level program; interpreter = high-level program one statement at a time; assembler = assembly language to machine code.
Check the three translators.
4.2.4

Advantages and disadvantages of compilers and interpreters

Compilers and interpreters both allow high-level programs to be used, but they suit different stages and purposes. The textbook emphasises the trade-off between ease of development and execution of the finished program.

TranslatorAdvantagesDisadvantages
Interpreter
  • Easier and quicker to debug and test while developing the program.
  • Easier to edit and immediately try changes during development.
  • Stops when it reaches an error, helping the programmer locate the problem.
  • The program cannot be run without the interpreter.
  • The program can take longer to execute because translation happens during each run.
Compiler
  • The compiled program can be stored ready for use.
  • The finished program can run without the compiler.
  • The compiled program can use less memory while it is executing.
  • The compiled program normally executes in a shorter time.
  • During development it can take longer to write, test and debug because the program must be compiled before the result of changes can be tested.
Development versus distribution: an interpreter is often convenient while code is being created and corrected. A compiler is commonly used when a finished program needs to run quickly and be distributed without requiring the user to have the compiler.
Choose the most suitable translator for a situation.
4.2.5

Integrated Development Environment (IDE)

An Integrated Development Environment (IDE) is a collection of tools provided together to help programmers write and develop programs. Some IDEs are designed mainly for one language while others support several languages. The textbook gives PyCharm, Visual Studio and BlueJ as examples.

An IDE places the tools needed for development in one environment, so the programmer does not need to keep switching between separate programs for editing, translating, executing and debugging code.

Code editor

The code editor is where source code is written and changed. Having the editor inside the IDE speeds up development because corrections and additions can be made directly in the same environment used for testing and running the program.

Course-book Figure 4.16 showing a Visual Studio code editing window

Translator inside the IDE

Most IDEs provide a translator, which may be a compiler, an interpreter, or both. An interpreter can be useful during development because changes can be tested quickly, while a compiler may be used to produce the final executable version.

Course-book Figure 4.17 showing a Visual Studio code editor and program running

Runtime environment and debugger

A debugger runs the program under controlled conditions so the programmer can investigate how it behaves. The programmer can single step through the program one line at a time, or set a breakpoint that pauses execution at a chosen point in the source code.

When the program pauses, a report or variables window can show the current values of variables and the results of expressions. This helps the programmer identify logic errors by comparing what the program actually does with what it was intended to do.

Course-book Figure 4.18 showing a PyCharm debugger and current variable values

Error diagnostics and auto-correction

Dynamic error checking can examine code while the programmer is typing it. The IDE can highlight a possible error immediately and may suggest how it could be corrected. This allows many mistakes to be discovered during writing and editing rather than waiting until the whole program is run.

Course-book Figure 4.19 showing Visual Studio errors underlined and suggested corrections

Auto-completion

Auto-completion provides context-sensitive suggestions while code is being entered. It can complete reserved words and variable names, reducing typing and helping the programmer select valid identifiers or language keywords.

Course-book Figure 4.20 showing auto-completion for a reserved word and variable name

Auto-documenter

An auto-documenter supplies information about the purpose or function of programming code. This can help the programmer understand available commands, methods or routines without leaving the IDE to search elsewhere.

Course-book Figure 4.21 showing an auto-documenter explaining the purpose of Console.WriteLine

Prettyprinting

Prettyprinting displays source code using meaningful layout, indentation and colours. Different parts of a program can be shown in different colours so the structure is easier to read and understand.

Course-book Figure 4.22 showing Visual Studio prettyprinting with strings displayed in red
IDE featureHow it helps the programmer
Code editorWrite and edit source code in the same environment.
Compiler / interpreterTranslate or execute the program without leaving the IDE.
Runtime environment + debuggerRun code, single step, use breakpoints and inspect variables to find logic errors.
Error diagnosticsHighlight possible errors while code is being written.
Auto-correctionSuggest possible corrections to detected errors.
Auto-completionSuggest or complete reserved words and variable names.
Auto-documenterExplain the purpose or use of code elements.
PrettyprintingUse layout and colour to make source code easier to read.
Explore further: identify the programming language and IDE used in your school. Check which of the IDE features above are available and whether other IDEs can be used for the same language.
Check IDE tools and debugging.

Topic 4.2 revision checklist

Define a computer program and explain why translation to machine code is needed.
Compare high-level and low-level programming languages.
Explain portability and machine dependence.
Explain why machine code is difficult for people and why hexadecimal is often used to display it.
Explain why a programmer may choose assembly language.
Interpret simple assembly mnemonics such as LDA, ADD and STO.
Distinguish compiler, interpreter and assembler.
Explain whether an executable machine-code file is produced by each translator.
Compare the advantages and disadvantages of compilers and interpreters.
Define an IDE and explain why it helps program development.
Explain code editing, translation, runtime environments, single stepping, breakpoints and variable inspection.
Explain error diagnostics, auto-correction, auto-completion, auto-documentation and prettyprinting.
Ready for a mixed Topic 4.2 check?
← Topic 4.1 Types of software and interruptsComputer Science contentsTopic 5.1 The internet and the World Wide Web (WWW) →