You are on page 1of 8

Intro to 4th Generation Programming Languages

Lesson I : Programming


A computer program is simply a set of instructions to tell a computer how to perform a

particular task. It's rather like a recipe: a set of instructions to tell a cook how to make a particular
dish. It describes the ingredients (the data) and the sequence of steps (the process) needed to
convert the ingredients into the cake or whatever. Programs are very similar in concept.

Short History

Just as you speak to a friend in a language so you 'speak' to the computer in a language.
The only language that the computer understands is called binary and there are several different
dialects of it - which is why that cool iMac program won't run on your PC and vice versa. Binary is
unfortunately very difficult for humans to read or write so we have to use an intermediate
language and get it translated into binary for us. This is rather like watching the American and
Russian presidents talking at a summit meeting - One speaks in English, then an interpreter
repeats what has been said in Russian. The other replies in Russian and the interpreter again
repeats the sentence, this time in English.
Surprisingly enough the thing that translates our intermediate language into binary is also
called an interpreter. And just as you usually need a different interpreter to translate English into
Russian than you do to translate Arabic into Russian so you need a different computer interpreter
to translate Python into binary from the one that translates VBScript into binary.
The very first programmers actually had to enter the binary codes themselves, this is
known as machine code programming and is incredibly difficult. The next stage was to create a
translator that simply converted English equivalents of the binary codes into binary so that instead
of having to remember that the code 001273 05 04 meant add 5 to 4 programmers could now
write ADD 5 4. This very simple improvement made life much simpler and these systems of
codes were really the first programming languages, one for each type of computer. They were
known as assembler languages and Assembler programming is still used for a few specialized
programming tasks today.
Even this was very primitive and still told the computer what to do at the hardware level -
move bytes from this memory location to that memory location, add this byte to that byte etc. It
was still very difficult and took a lot of programming effort to achieve even simple tasks.
Gradually computer scientists developed higher level computer languages to make the
job easier. This was just as well because at the same time users were inventing ever more
complex jobs for computers to solve! This competition between the computer scientists and the
users is still going on and new languages keep on appearing. This makes programming
interesting but also makes it important that as a programmer you understand the concepts of
programming as well as the pragmatics of doing it in one particular language.

Common Features of All Programs

A long time ago a man called Edsger Dijkstra came up with a concept called structured
programming. This said that all programs could be structured in the following four ways:
Sequence of Instructions

Here the program flows from one step to the next in strict sequence.


Here the program reaches a decision point and if the result of the test is true then
the program performs the instructions in Path 1, and if false it performs the actions in
Path 2. This is also known as a conditional construct because the program flow is
dependent on the result of a test condition.

In this construct the program steps are repeated continuously until some test
condition is reached, at which point control then flows past the loop into the next piece of
program logic.


Here the program performs an identical sequence of actions several times. For
convenience these common actions are placed in a module, which is a kind of mini-
program which can be executed from within the main program.

Other Features

Along with these structures programs also need a few more features to make them
Φ Data (raw materials)
Φ Operations (add, subtract, compare, etc)
Φ Input / Output capability ( display results)
Clearing some Terminologies

We already said that programming was the art of making a computer do what you want,
but what is a program?
In fact there are two distinct concepts of a program. The first is the one perceived by the
user - an executable file that is installed and can be run repeatedly to perform a task. For
example users speak of running their "word processor program". The other concept is the
program as seen by the programmer, this is the text file of instructions to the computer, written in
some programming language, that can be translated into an executable file. So when you talk
about a program always be clear about which concept you mean.
Basically a programmer writes a program in a high level language which is interpreted
into the bytes that the computer understands. In technical speak the programmer generates
source code and the interpreter generates object code. Sometimes object code has other names
like: P-Code, binary code or machine code.
The interpreter has a couple of names, one being the interpreter and the other being the
compiler. These terms actually refer to two different techniques of generating object code from
source code. It used to be the case that compilers produced object code that could be run on its
own (an executable file - another term) whereas an interpreter had to be present to run its
program as it went along. The difference between these terms is now blurring however since
some compilers now require interpreters to be present to do a final conversion and some
interpreters simply compile their source code into temporary object code and then execute it.
From our perspective it makes no real difference, we write source code and use a tool to
allow the computer to read, translate and execute it.

Structure of a Program

The exact structure of the program depends on the programming language and the
environment that you run it on. However there are some general principles:

A loader – every program needs to be loaded into memory by the operating system. The
loader does this and is usually created by the interpreter for you.
Data definitions – most programs operate on data and somewhere in the source code
we need to define exactly what type of data we will be working with. Different languages
do this very differently.
Statements – these are the core of your program. The statements actually manipulate
the data we define and do the calculations, print the output, etc.

Most programs follow one of two structures:

Batch Programs

These are typically started from a command line and tend to follow a pattern of:

That is, the program

will typically start off by setting
its internal state, perhaps
setting totals to zero,
opening the needed files
etc. Once it is ready to start
work it will read data either from
the user by displaying prompts
on a screen or from a data file.
Most commonly a combination is
used whereby the user provides
the name of the data file and the real data is read from the file. Then the program does the actual
data processing involving math or data conversion or whatever. Finally the results are produced,
either to a screen display or, perhaps, by writing them back to a file.

Event-driven Programs

Most GUI systems (and embedded control systems - like your Microwave,
camera etc) are event driven. That is the operating system sends events to the program
and the program responds to these as they arrive. Events can include things a user does
- like clicking the mouse or pressing a key - or things that the system itself does like
updating the clock or refreshing the screen.

In this configuration the program again starts off by setting up its internal state,
but then control is handed off to the event loop - which is usually provided by the
operating environment (sometimes referred to as the runtime). The program then waits
for the event loop to detect user actions which it translates to events. These events are
sent to the program to deal with one at a time. Eventually the user will perform an action
that terminates the program, at which point an Exit Event will be created and sent to the

Computer programming (often shortened to programming or coding) is the process of
writing, testing, and maintaining the source code of computer programs.
Computer Programming is the art of making a computer do what you want it to do. At the
very simplest level it consists of issuing a sequence of commands to a computer to achieve an

Example: Create a batch file

Lesson II : Programming Language

The Early Days of Programming

In the early days of computing – back in the 1940s – using a computer required writing
programs, because there wasn’t any software for sale. And writing programs required writing out
the strings of ones (1) and zeros (0) that the computer could understand. There is still a small
amount of programming that’s done this way. It is known as programming in machine language,
because it involves writing codes that the machine understands.
In general, a programming language is any set of words or symbols used to write
instructions for a computer. Code is just a short word for program instructions.
It didn’t take long before programmers realized that they were writing certain strings of
machine language code over and over. They began inventing shorthand symbols to represent
these strings. The result of their efforts was the first symbolic computer languages, known as
assembly language.

First Generation Programming Languages (1GL)

A first-generation programming language is a machine-level programming language. It

consists of 1s and 0s.
The first-generation programming language, or 1GL, is machine code. It is the only
language a microprocessor can understand directly. Currently, programmers almost never write
programs directly in machine code, because not only does it (like assembly language) require
attention to numerous details which a high-level language would handle automatically, but it also
requires memorizing or looking up numerical codes for every instruction that is used, which in
assembly language would be written as something more readable like "ADD CX INTEREST" or
Originally, no translator was used to compile or assemble the first-generation language.
The first-generation programming instructions were entered through the front panel switches of
the computer system.
The main benefit of programming in a first-generation programming language is that the
code a user writes can run very fast and efficiently, since it is directly executed by the CPU.
However, machine language is somewhat more difficult to learn than higher generational
programming languages, and it is far more difficult to edit if errors occur.

Current Uses

1GL is mainly used on now very ancient computers, machine level programming still finds
a use in several areas of modern programming. First and foremost, any native-code compiler
creates machine language.

Second Generation Programming Languages (2GL)

The second-generation programming language, or 2GL, is assembly language. It is

considered a second-generation language because while it is not a microprocessor's native
language, an assembly language programmer must still understand the microprocessor's unique
architecture (such as its registers and instructions).

A second-generation programming language is a term usually used to refer to some

form of assembly language. Unlike first-generation programming languages, the code can be
read and written fairly easily by a human, but it must be converted into a machine readable form
in order to run on a computer. The conversion process is simply a mapping of the assembly
language code into binary machine code (the first-generation language). The language is specific
to and dependent on a particular processor family and environment. Since it is a one-to-one
mapping to the native language of the target processor it has significant speed advantages, but it
requires more programming effort and is difficult to use effectively for large applications.

The primary niche for these languages are in kernels, device drivers, and system
libraries. Compilers usually use these as intermediate languages between a higher level
language and machine code. Besides those, they are almost never used directly.

Third Generation Programming Language

A third generation language (3GL) is a programming language designed to be easier for a

human to understand, including things like named variables. A fragment might be:

let b = c + 2 * d

Fortran, ALGOL and COBOL are early examples of this sort of language. Most "modern"
languages (BASIC, C, C++, Delphi, Java, and including COBOL, Fortran, ALGOL) are third
generation. Most 3GLs support structured programming.


There are three primary features of 3GL. First, they are largely machine-independent. In
other words, a program written in a 3GL is not written for a specific type of processor. If you write
a program in BASIC, you can use that program on a Mac, or a PC.
The second feature is that program require either an interpreter or a compiler to translate
the program into machine language. An interpreter is a program that translates the language
while the program is running. A compiler translates the program before it can be run.
Finally the 3GL are known as procedural languages because they force the programmer
a develop a structures series of procedures or steps to accomplish the goal.
In general then, a 3GL is a machine-independent procedural language that requires an
interpreter or a compiler.

Fourth Generation Programming Language

4GL) An "application specific" language, one with built-in knowledge of an application

domain, in the way that SQL has built-in knowledge of the database domain. Pure 4GLs do not
contain conditionals (if-then-else) and loops (for, while, do), though some languages are
combinations of third generation languages and 4GLs.
The term was invented by Jim Martin to refer to non-procedural high level languages
built around database systems. The first three generations were developed fairly quickly, but it
was still frustrating, slow, and error prone to program computers, leading to the first "programming
crisis", in which the amount of work that might be assigned to programmers greatly exceeded the
amount of programmer time available to do it. Meanwhile, a lot of experience was gathered in
certain areas, and it became clear that certain applications could be generalised by adding limited
programming languages to them. Thus were born report generator languages, which were fed a
description of the data format and the report to generate and turned that into a COBOL (or other
language) program which actually contained the commands to read and process the data and
place the results on the page.
Lesson III : 4GL

The natural-language, block-structured mode of the third-generation programming

languages improved the process of software development. However, 3GL development methods
can be slow and error prone. It became clear that some applications could be developed more
rapidly by adding a higher-level programming language and methodology which would generate
the equivalent of very complicated 3GL instructions with fewer errors. In some senses, software
engineering arose to handle 3GL development. 4GL and 5GL projects are more oriented toward
problem solving and systems engineering.

All 4GLs are designed to reduce programming effort, the time it takes to develop
software, and the cost of software development. They are not always successful in this task,
sometimes resulting in inelegant and unmaintainable code.