Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
7 views

Programming Language Generations Handout trial

Uploaded by

wyangaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Programming Language Generations Handout trial

Uploaded by

wyangaming
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Information Technology

Topic: Programming Language Generations

Form 4 Jan 15-19, 2024

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

Example: 10010011 10001110


Second generation programming- In the second-generation programming language exist the
Assembly language. This language is written using short codes that suggest their meaning and
are therefore easier to remember than machine language. It is machine dependent. An
assembler is used to convert assembly language to machine language.

Advantages

o Easier to write than machine language

o Easier to remember than machine language

Disadvantages

o Had to be converted to machine language

o Could only work on the computer it was designed for

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

Third generation (High Level Languages)


This generation of languages was designed so that it was even easier for humans to
understand. It uses English words and symbols, and is therefore even easier to write. It is
machine independent, which means it can run on any computer. Some examples of third
generation programming languages are:
• BASIC • Perl
• COBOL • Ada. JAVA
• Pascal
• Fortran
• C
• C++
To convert a 3rd generation program into object code requires a Compiler or an Interpreter.
A Compiler translates of all program instructions at one time and produces a stand-alone
object program that can be executed on its own. Error checks are performed, and an error
summary is issued.
An Interpreter translates the source program and executes it line by line.

Advantage

• Easy to write programs


• Uses English words and symbols that are easy to understand
• Programming code can be reused

Disadvantage

• Easy to steal programming codes


• Have to be converted to machine language

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:

• SQL- Structured Query Language


• ACCESS
• Informix
• FOCUS.
• Python
• Ruby

Advantage

• Uses English statements so it is very easy to understand


• It has a wizard that assist to generate code

Disadvantage

• Has to be converted to machine language

Sample code Structured Query Language(SQL)

USE STOCKLIST

SELECT ALL Items WHERE


Price > $10.00

A diagram Outlining the Compilation Process

Source Code Compiler Object Codes

There are two types of computer translators:

1. Interpreters

2. Compilers

Difference Between an Interpreter and a Compiler

An interpreter translates and executes one instruction at a time as it is encountered.

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.

Commonly Used Terms and Concepts in Programming

• 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.

• Debugging – is the process of correcting or removing errors from a program before it is


put into operation.

• Program Errors – A program error is a mistake/error in a program and is also known as


a bug.

During program development, three types of errors may be encountered as followed:

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:

If (gender = F) and (age <= 18) then


Writeln(name);

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

if we used a reserved word incorrectly, such as in:

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.

You might also like