The need for and characteristics of programming paradigms
A history of the development of programming languages
Before you begin, note that the strange word 'paradigms' simply means 'methods'. 'Programming paradigms' are the 'programming methods' available to you. (NOTE: Paradigm is pronounced para-dime.) The paradigms discussed here are OOP, procedural and declarative languages. To understand how these languages have come about, you'll need to do some background reading. You should use your textbooks and search the Internet for different points of view.
In this section, we are going to classifying languages according to their historical and functional development. Then we will classify languages according to their paradigm-type: OOP, Procedural and Declarative.

First generation languages

Computers are digital devices. They use patterns of binary numbers (ones and zeros). This is known as 'machine code'. Originally, you would write programs by writing patterns of ones and zeros! You can imagine how boring that was; it was difficult to write, easy to make errors, difficult to debug and took ages! Slightly (only just) better than this was to write programs using hex codes rather then binary! Hex codes were simply groups of bits. Instead of typing in 0111 1111, you could type in 7F. Great! These programming languages, while having many drawbacks, didn't need translation because they were written in the language of the processor - machine code. They have applications in areas such as control, where fast processing is needed. Binary and Hex programming languages are known as ‘first generation languages’. Programs written in these languages run very quickly compared to programs written in high-level languages.
Second generation languages

It was recognised that writing in binary or hex was far from ideal. Languages were written to get over some of the problems of first generation languages. They were much closer to English but further from machine code. These 'second generation' languages were known as assembly languages or low-level languages. They contained shortened English instructions called 'mnemonics. Examples of instructions include ADD, SUB, NOP, LDA, STA and so on. When a program was written, however, you couldn't just run it as before, because it wasn't in machine code, the language that the processor used. You had to convert (or 'translate') it first back to machine code and then you could run it. The type of program that translated assembly code into machine code was called an ‘assembler’. Second generation languages are used for real-time applications and where the programmer needs to manipulate the hardware inside a computer.
Third generation languages

Second generation languages were an improvement on what existed previously, but were still far from ideal. They were not particularly user-friendly and excluded people who had little training from using them. There was also a need to make programming focus more on specific applications, with an instruction set that helped get specific tasks done easily (such as file processing, for example). A whole range of third generation languages (also known as high-level languages) were written to do this; BASIC and PASCAL for teaching, COBOL for data processing, FORTRAN for scientists and so on. These languages require the user to specify all the steps needed to solve a problem. Think of your own experience of writing in a third generation language. Keywords are closely related to English. Your ‘Integrated Development Environment’ (IDE) enabled code to be developed easily, debugged and finally translated into machine code (now known as 'object code') quickly and effectively.
Fourth generation languages (4GL)

As computers became more powerful, software emerged that reduced the time it took to produce programs for users. Report Program Generator is an example of this type of program. This language is used to increase the speed of report production. It takes the actual format of the data and combines it with instructions on how to format a report. It then produces the report. Later on, you will learn about CASE tools. These are used to help an analyst analysis and design new systems. 4GL have been used to turn CASE designs into actual software or parts of the final product.
Fifth generation languages

Expert systems are considered 5th generation programs. They could be written in PROLOG, for example, which is considered a 5th generation programming language. You write applications by giving your computer a set of facts and then telling the computer how those facts relate to each other. You can then query the program by asking questions. It will search for facts based upon the rules you have declared and the search you are doing. What you don't do with an expert system is to tell it how to solve the problem (by writing a program that tells it what to do step-by-step, as in procedural languages such as COBOL or Pascal). You simply tell expert systems facts and rules and then ask it a question!
For an expert system to work, you need:
-
- An interface to let you enter facts and rules.
- A method of storing facts and rules.
- An interface to allow you to update facts and rules periodically.
- An interface to allow you to ask questions.
- An 'inference engine' - software that can actually perform queries.
Other ways to classify languages: Low Level and High Level, Procedural and OO
There are other ways to classify programming languages apart from their generation. For example, we can talk about 'Low Level Languages (LLL) such as machine code or assembly languages and 'High Level Languages (HLL) such as Python, C++ and BASIC. Low level languages are much closer to the workings of the CPU and include instructions that easily allow you to manipulate the registers in the CPU. HLLs use keywords, which are much closer to English and a lot easier to learn and use. Another way to classify languages is by their type. For example, there are procedural languages, like Pascal and BASIC and there are OO languages like Java and Python. (There are others, such as Declarative languages and Functional languages, which are not part of this syllabus). Just to confuse matters, some languages like Python can be used purely as a procedural language or as an OO language!
Procedural languages (also known as Imperative languages)
With these kinds of languages, you must tell the computer exactly what to do, instruction by instruction. You will see later that this is not the only way to write a program! The computer will start at the first instruction, carry out the command and then move on to the next one. The programmer writes programs by using only three basic building blocks:
-
- Sequence.
- Selection.
- Iteration.
In Pascal, conditional branching (selecting which code to do) is possible using the IF statement and the CASE statement. Iteration is possible using FOR, WHILE and REPEAT. Procedural languages also make heavy use of functions and procedures. This promotes modular programming, which allows code to be reused, better understood and better designed amongst other benefits. This approach isn't perfect, however, because the variables that are used within procedures and functions can always be accidentally changed elsewhere in the program and finding these kinds of bugs can be very difficult and time-consuming!
PASCAL was written as a teaching language, to teach the elements of structured programming. COBOL has commands that make it excellent at data processing applications. FORTRAN focuses on scientific and engineering applications and so on. Other procedural languages have also been written. Each one provides the programmer with the instructions and facilities that enable programs for particular application areas to be written.
Object-oriented languages
Good programming using a procedural language will employ a modular approach. There are many good reasons for this. One of them is that procedures and functions can be written which can then be stored in a library and used in other programs. That will save time and money developing future programs. Unfortunately, problems can still arise when you try to use library modules. Variables used in a module, for example, may get changed in an unexpected way by a program, or vice versa. This may cause a bug and if it does, they can be very hard indeed to find.
A different way of programming is the object-oriented approach. In this kind of paradigm, objects are defined. An object is a real-world thing. It might be a car, a person or a command button in Visual Basic. The programmer, before writing the program, asks:
-
- What objects exist in the problem area?
- What events can happen to those objects?
- What should happen, the methods, when a particular event occurs?
The data needed to define an object, the things that can happen to that object (events) and the actions that need to take place when a particular event occurs (methods) are bound together (called encapsulation). Once an object has been encapsulated, it cannot fail as a result of the actions of other parts of the program, as procedural programs can.
OOP is conceptually much closer to the real world than procedural programming. It is much easier to think about what objects there are in a program and what might happen to an object than to try to break down a problem into modules and then write down a sequence of instructions that work through the modules. A later chapter deals with the concepts behind OOP in much more detail.