Programming Language Generations Handout trial
Programming Language Generations Handout trial
Computer stores and manipulates data in the form of electronic pulses (high and low
voltages). There are several generations of computer languages. Namely:
▪ First generation
▪ Second Generation
▪ Third Generation
▪ Fourth Generation
The first two generation languages are low-level languages or machine dependent, while the
other two are High-level languages or machine independent. Machine dependent means the
program can only work on the type of computer it was designed for a while Machine
independent means the program can work on any computer system.
Machine language is a first-generation language written using 1s and 0s. It was hard for
humans to use and they made mistakes easily. It is a low-level language that is machine
dependent. This means it can only work on the computer it was designed for. It is the only
language the computer understands; therefore, all other languages have to be converted to
machine language.
Advantage
o It executes the fastest
o Difficult to reverse engineer
Disadvantage
o Difficult to write
o Easy for the programmer to make mistakes
o Only advance programmers can use it
Advantages
Disadvantages
Example
An example of a program code to add and store two numbers would be:
LDA A, 20
LDA B, 30
Assembly Code Object Code
ADD A, B
STO C
LDA A 000100110100
ADD #5 001000000101
-> Assembler ->
STA A 001100110100
JMP #3 010000000011
Advantage
Disadvantage
Examples
Read A,B #include <stdio.h> C Programming Language
m=A+B
Write Sum int main() {
int a = 5, b = 10, c;
c = a + b;
return 0;
Fourth generation
These are designed for the development of commercial business software. It uses English like
statements that are very user-friendly and tells the computer what to do, hence programs are
easier to write. This reduces the time taken to write programs. Fourth generation languages
contain a built in ‘function wizard’ to assist the user in solving problems. Some examples of
fourth generation programming languages are:
Advantage
Disadvantage
USE STOCKLIST
1. Interpreters
2. Compilers
Advantages
• It translates one instruction at a time, therefore it uses a minimum amount of the
computer’s memory
• It is also helpful in the debugging process, as the interpreter can relate error messages to
the instruction being executed.
Disadvantage
• The interpreter takes longer to run a program as time is spent interpreting the source code
every time the program needs to be run.
Compiler
A compiler translates the entire program (source code) to machine code, and then the machine
code is executed. The translated codes are known as object codes.
Advantage
• It can be executed faster than when using an interpreter, as the object codes are saved and
can be run at any time
Disadvantage
• As the entire program is translated to object code, it uses much more of the computer’s
memory.
• Loading – is reading a program from the hard disk into main memory (RAM)
• Testing - a completed program must be tested for errors to prevent crashing or stalling.
The programmer must make sure the program works for any correct input data that the
user gives it. The testing phase is to detect any problems in the program. Dry runs and
computer testing could reduce the chance of error, before releasing the program to its
final users.
• Dry runs/Manual testing - a manual traversal of the logic of a program. After the
development of a program, the programmer should examine the code to see how it would
run.
A dry run is carried out when the action of an algorithm is examined with a set of input
values.
A trace table is a useful tool for a dry run, to check how the program would behave.
• Test Data – a wide range of data should be used to test a program. This data should
include normal data values and extreme values e.g. large, small and negative numbers.
Using this wide range would help detect which values might cause a program to fail.
1. Logic errors
2. Syntax errors
3. Run-time errors
Logic errors – arise when the sequence of the instructions is not correct and there are flawed
comparisons and selection statements.
For example, let’s suppose we wanted to print the names of all girls who are under the
age of 18 and we wrote the following program:
This code would result in the printing of the names of girls who are 18 as well as those
who are under 18. This is because in the if statement, we used <= instead of = . This is
a common error in the logic that will give undesirable results.
Syntax errors – occur when the source code has not been written in accordance with the rules of
the programming language. For example, if we omit to terminate an assignment statement with a
semi-colon. The following statement would result in a syntax error during compilation:
total:=total + X
or
var := a + b;
Syntax errors can be easily located and corrected as the compiler usually issue messages
which identify the location and cause of the errors.
Run-time errors – are generated during execution of the program. They result when the
processor encounters an instruction that violates the processing rules. For example, if we had an
instruction that attempts to divide by 0, such as:
Number: =1;
Number:= Number - 1;
Answer: = total/Number; {illegal}
The last statement would generate a run-time error as an attempt is being made to divide
by a value of 0.