Learning Outcomes:
• describe the purpose of a computer program;
• describe the main features of an integrated development environment (IDE);
• explain the process of translation;
Computer programs are created for a range of different purposes. They allow computers to solve the problems of humans. A computer program is a set of instructions which have been designed to solve a particular problem.
Computer programs can be written in high level programming languages such as C#, Java, Visual Basic and Python. They can also be written in low level languages such as machine code and assembly language. A series of language statements are written to solve a problem, this is called the source code or source program.
Create a simple program in Python to calculate the average of 5 numbers.
An integrated development environment is a piece of software which helps humans to create computer programs.
There are a range of editing features available within a typical software development environment. Each one is intended to make it easier for human beings to create computer programs.
1. Clipboard: Programmers can copy items and choose one to paste into the current file.
2. Code Outlining: Programmers can collapse/ expand selected regions of code under their first lines. This means that long programs can be viewed in small logical sections.
3. IntelliSense: As you enter a function or statement in the Code Editor, its complete syntax and arguments are shown in a ToolTip. When items are needed to complete a statement, IntelliSense provides popup insertion lists of available functions, statements, constants, or values to choose from.
4. Line Numbering: Line numbers help programmers to distinguish between lines in lengthy coding sections
5. Syntax error assistance: As code is entered, the Code Editor will place ‘wavy lines’ beneath code that is incorrect or could cause a problem.
6. Source Code Editor: This allows the human to enter the text commands to create the computer program.
Graphical User Interface (GUI) builder with an associated toolbox of controls The GUI builder allows a programmer to create windows applications by positioning controls on screen. Controls such as textboxes, combo-boxes and radio buttons can be added to forms by dragging them from a toolbox.
There are usually two views: a graphical design view and a code view. Design view allows programmers to specify the location of controls and other items on the user interface.
Solution Explorer This is a graphical representation of the entire solution. The window displays solutions, their projects, and the items in those projects.
Usually, files can be opened for editing, new files can be added and item properties can be viewed.
Debugging and break points Programs can contain logic problems which become apparent at run-time. This is where the code, although syntactically correct, is not providing the correct results. The debugger can be used to help detect and correct such problems. Programmers can set breakpoints where the program will stop during execution and allow the programmer to examine the value of different variables.
The code we create when we write instructions (source code) in a programming language such as Python is known as high level. The closer the instructions are to the English language the "higher" they are described as. Machines only process low level instruction known as machine code which is essentially a long sequence of 1's and 0's.
Computers can not directly understand machine code and so we need something to translate the high level instructions we write in a programming language such as Python into machine code that the computers can actually understand and execute (carry out). A Transator is used to convert our source code into machine code. There are two different types of translators.
Interpreter:
• An interpreter translates source code line by line.
• The processor executes a line of code before proceeding to translate the next line of code.
• Errors are displayed as soon as they are found so it can be easier to debug than compiled code.
• Source code is generated each time it runs, therefore it can be slower to execute than compiled code.
Compiler:
• A compiler translates the whole program into machine code before the program is run.
• All bugs are reported after the program has been compiled so it is difficult to test individual lines of code.
• All errors must be removed before the code is fully compiled.
• The machine code is saved and stored separately to the high-level code.
• Compilation is slow but machine code can be executed quickly.
A compiler may perform:
• Lexical analysis – converting the incoming source code into fixed length binary code items called tokens;
• Pre-processing – including library code for classes and methods used within the source code;
• Parsing or syntax analysis – checking the statements within the code to ensure they conform to the rules of grammar for the language;
• Semantic analysis – this includes checking to see that variables are declared before being used and type checking;
• Code Generation – creating the machine code version of the source code;
• Code optimisation – making the executable program as efficient as possible.
Possible Exam Questions
An Integrated Development Environment (IDE) includes the facility to translate programs.
(a) List four other facilities provided by an IDE. (4 Marks)
Explain why a program might need to be translated (4 Marks)
3. (a) A program written in a high level language can be translated using an interpreter or a compiler.
(i) Explain two differences between an interpreter and a compiler. (4 Marks)
(ii) State one advantage of using an interpreter instead of a compiler. (1 Mark)
(iii) State one advantage of using a compiler instead of an interpreter. (1 Mark)
4. Explain the key features of a source code editor (4 marks)
5. Explain the key features of a complier (4 Marks)