Learning Outcomes:
By the end of this topic you should be able to:
• describe the following programming paradigms: – procedural programming; and – object-oriented programming;
• explain the significance of the following aspects of software development environments: – editing features; and – high-level code translation and execution;
• describe the following programming paradigms: – procedural programming; and – object-oriented programming;
A Paradigm is simply a method or way of doing something. In programming there are two main methods we need to be aware of.
A set of instructions performed one after the other which a computer follows in order to solve a problem or performs a certain task. Most of the code we have created in Python uses this method. A procedural language is imperative, meaning that it gives orders or instructions. A procedural language is sequential, meaning that instructions carried out one after another. These steps form the program flow.
An object-orientated program is designed as a collection of objects which interact by sending messages to each other . Each object has attributes (data) and methods/behaviours(things it can do). Each object belongs to a class and inherits attributes and methods/behaviours from its superclass. A subclass can have additional attributes and methods/ behaviours not contained in the superclass. Object classes can be used in other programs.
These programs are more reliable because the objects are self-contained, simple and so easier to program
• explain the significance of the following aspects of software development environments: – editing features; and – high-level code translation and execution;
A software development environment is a program or application which we use to create computer programs. IDLE is the programming environement we use to complete your coursework task.
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.
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.
What happens during the translation process?
Library code is included
Syntax analysis
errors identified
Semantic analysis
Machine code is generated
Lexical analysis
Possible Exam Questions.
1.Explain the two main programming paradigms. (4 Marks)
2.List 3 editing features available in a software development environment (3 Marks)
3. Why does program code need to be translated? (2 Marks)
4. List two tasks carried out by a language compiler before a program can be executed. (2 Marks)
5. Explain the difference between high level source code and low level machine code. (2 Marks)
6. Explain the similarities and differences between compilers and interpreters. (6 Marks)
7. Select the statement that is true about programming paradigms:
A Object-oriented programming uses objects and methods whereas procedural programming uses classes and top-down design.
B Object-oriented programming uses classes and methods whereas procedural programming uses procedures and objects.
C Object-oriented programming uses classes and objects whereas procedural programming uses methods and inheritance.
D Object-oriented programming uses classes and inheritance whereas procedural programming uses procedures and top-down design.
8 Program source code can be created in a software development environment.
(a) What is a software development environment? [2]
Provides an (integrated) set of tools for programmers
[1] which enables applications to be built from coding to testing [1]
Provides editing tools [1]
Accept examples of editing tools eg. clipboard, use of colour to highlight syntax error or key words, collapsible code, line numbering, code completion tool Provides debugging tools [1]
Provides compiling tools [1]
Provides GUI features for building forms [1]
9. Program source code must be translated before being executed. (b)
(i) Why must program source code be translated? [1]
So that it can be executed [1]/understood by the computer [1]/only understands 0s and 1s (binary) [1]/to change to object code
(ii) Describe what happens during the translation process. [3] Library code is included [1] pre-processing directives included [1] Syntax analysis [1] / errors identified [1] Semantic analysis [1] Machine code is generated [1] Lexical analysis [1]
10. John has written the code for the program using a software development environment. List three editing features provided by a software development environment. [3]
1.
2.
3.
Provides an (integrated) set of tools for programmers [1] which enables applications to be built from coding to testing [1] Provides editing tools [1] Accept examples of editing tools eg. clipboard, use of colour to highlight syntax error or key words, collapsible code, line numbering, code completion tool Provides debugging tools [1] Provides compiling tools [1] Provides GUI features for building forms [1]
11.The code for the program must be translated.
12.(i) Why does program code need to be translated? [2]
So that it can be executed [1]/understood by the computer [1]/only understands 0s and 1s (binary) [1]/to change to object code
(ii) List two tasks that are carried out by a language compiler before a program can be executed. [2]
1.
2.
Library code is included [1] pre-processing directives included [1] Syntax analysis [1] / errors identified [1] Semantic analysis [1] Machine code is generated [1] Lexical analysis [1]
13. Complete the paragraph below using words from the list provided. (Not all words will be used) [4]
Translated Source Compiler Library Optimised Machine Programmer
_______________________code must be ______________________into ______________________ code so that it can be understood by a computer. This is completed by a ____________________ .
(b) Tom has created a program using a text editor. List two features of a software development environment that would make creating a program easier for Tom. [2]
1.
2.