Professional Documents
Culture Documents
Programming languages come in many forms or 'paradigms'. Each form of language offers
advantages over other types and each one of course has some limitations as well.
Furthermore there are many languages available within each form. Sometimes the choice of a
particular language is personal preference and familiarity or sometimes it is imposed by the
company you are working for.
You need to know the main classes of programming and why you would use one type over
another.
The main classes of programming languages are
low level languages,
object-orientated languages
declarative languages
procedural
functional languages.
Pros.
Low level languages are excellent for close control of the CPU, for example many device
drivers are coded in assembly language.
They can be very efficient. Well-optimised code written in a low level language can be
made to run very quickly compared to other programming paradigms.
Cons
They are difficult to use as the programming commands can be quite obscure
Procedural concepts
With procedural languages, you code specific instructions for the computer to carry out - it is all
about the 'do-this, then-this, then-this' style of programming.
This is one of the commonest programming paradigms in use.
The main points to know about procedural programming languages are:
Imperative Languages
They are sometimes called imperative languages. Imperative means 'to give orders, or
instructions' and so procedural languages are all about telling the computer what to do, step by
step.
Sequential instructions
All imperative languages lay out their instructions in sequence.
z = y + x;
Here, the first instruction tells the database management software to create a table called Parts,
then it makes a request for all records from the Customer table.
The SQL programmer does not need to know the precise detail of how a table is made or the
details behind pulling down all records from a table.
Pros
Excellent for general purpose programming
Many books and references available on well-tried and tested coding algorithms - no need
to re-invent the wheel.
Good level of control without having to know precise target CPU details - unlike low
level languages
Portable source code - use a different compiler to target a different CPU
Cons
As there are so many procedural languages, a programmer tends to have to specialise in a
particular language in order to get work. A COBOL specialist has a different clientele to a
'C' specialist.
Need to be very precise and knowledgeable about programming instructions, and so a
fully de-bugged working program takes more time to put together compared to fourth
generation languages such as Simulink.
Not as efficient as hand-crafted source code written in a low level language
Poor at handling fuzzy conditions as found in Artificial Intelligence applications - unlike
declarative languages such as PROLOG.
function A() {
X = 20;
}
function B() {
X = 1000;
}
In the clip above, one part of the main software may call function A to set the global variable X,
but then another part of the software could call function B at the wrong time and X gets
unintentionally changed. De-bugging this kind of problem can be difficult as the conditions that
made it happen can be very obscure.
So the main idea of object oriented languages is to gather the data and all the methods
(functions) that act upon that data into one entity called a 'class', so making data hiding, code re-
use and maintenance much easier.
Pro
OOP makes it easier to provide working code. A class can be fully tested and released for
other coders in the team to use
Classes can be treated as 'black boxes'. Other coders do not need to know how the class
works internally. They just need to know how to manipulate it through its methods.
There are many 'design patterns' available, developed over the years, that solve common
programming tasks. A coder can pick up a design pattern for perhaps an user interface and
begin coding straight away.
Code re-use. Easy to move a class from one application and re-use it on another project
Code portability. Just get the right compiler for the target CPU and the source code can be
run on an entirely different hardware platform
Con
Steep learning curve, becoming proficient in an object-oriented language can take a long
time as it is more complicated than a standard procedural language.
Complex - it needs skill to craft efficient and flexible classes.
Not as compact and efficient as writing code directly in a low level language
The software will seek an answer to the question (goal) by interrogating a database containing
Facts and Rules. It does not matter what order the facts and rules are arranged within the
database - unlike procedural languages - the computer will find the best path towards the answer.
There will either be a matching answer - for example the question / goal might be 'who is David's
wife?" or a 'False' is returned where there was no answer to be found.
This type of language is geared more towards applications such as artificial intelligence and
expert systems where inexact data has to be handled or general decisions have to be made.
PROLOG is a declarative language that was developed for artificial intelligence. There are others
such as 'D' also under development.
Example
Consider a Prolog database containing the following facts and rules:
1. Fact: spouse (john, jane)
2. Fact: spouse (david, mary)
3. Fact: spouse(george, susan)
4. Fact: female (jane)
5. Fact: female (mary)
6. Fact: female (susan)
7. Fact: male (john)
8. Fact: male (david)
9. Fact: male (george)
10. Rule: husband(A,B) IF spouse(A,B) AND male (A)
11. Rule: wife (A,B) IF spouse(A,B) AND female(B)
A query could then be written:
wife(david,mary)?
The formal name for this statement is 'goal' . And the work of finding the answer is called
'satisfying the goal'.
Effectively this is asking if Mary is the wife of David. In order to provide an answer the
following takes place:
1. Prolog will first of all scan the Rules looking for a match.
2. Rule 11 fits, where A and B can be any two names.
wife (A,B)
3. Then it applies the rule by looking to see if it can find a match to the spouse(A,B)
condition and yes - Fact 2 fits.
4. Next it looks to see if the second condition female(B) has a match and yes Fact 5 is a
match.
Fact: female (mary)
Functional Languages
These types of languages are mostly concerned with providing answer to problems purely
through applying calculations to input data.
They do not change anything else other than the input data provided at that point in time. The
technical term is that functional languages have no 'side effects' unlike procedural languages.
These calculations are called 'functions'. Hence the description 'functional language'.
These types of languages are used extensively in highly mathematical areas such as engineering
and financial markets and even network engineering.
Example 1: Mathematica
Mathematica is a powerful functional language to solve mathematical problems.
The following Mathematica statement calculates the root of the equation ex = x2 + 3, starting at
the point x = -2.
In[2] := FindRoot(Exp[x] == x^2 + 3, (x, -2))
Mathematica has a clear syntax with which to write mathematical statements. In this case it is
making use of a built-in function called 'FindRoot' and passing the relevant arguments into it.
Example 2: LISP
Short for 'List Processing'. The first computers were used as pure calculation machines and so
LISP was developed as an efficient way of coding calculations.
LISP is one of the oldest computer languages (1958) and it is still in use today. It specializes in
carrying out calculations and operations across data stored as linked lists. This is called 'list
processing'.
List processing means that the same calculation is carried out over a linked list. The list itself
can be altered during program execution
LISP has been used for a long time in artificial intelligence applications for problems such as
image processing.
Summary
Type Comment
Excellent for producing hardware drivers and other software
Low Level requiring a close link to the CPU on which they run such as a linker /
loader / translator
The most common type of programming language, Excellent for
Procedural
general programming jobs. Languages include 'C', FORTRAN
Another very popular type of computer language. Excellent for
Object producing re-usable code and for use in large software projects where
Orientated data and the methods acting upon that data are kept together.
Languages include C++, Java
Designed for applications such as Artificial Intelligence and Pattern
Declarative Recognition applications where deductions need to be made based on
a set of rules. Languages include Prolog
Excellent for programming the computer to act with its original
Functional purpose: calculating. Used for mathematical and simulation
applications. Languages include LISP, Mathematica.