# A-level Computing 2009/AQA/Computer Components, The Stored Program Concept and the Internet/Fundamentals of Computer Systems/Generations of programming language

There are many types of programming languages out there and you might already have heard of a few of them, for example: C++, VB.NET, Java, Python, Assembly. We will now look at the history of how these languages came about and what they are still useful for. In all cases keep in mind that the only thing a computer will execute is machine code or object code when it has been converted from a language to run on a processor.
| Generation | First | Second | Third | Fourth |
| Code example | 1010101001100010 1001101010000001 1111111110100010 | LDA 34 ADD #1 STO 34 | x = x + 1 | body.top { color : red; font-style : italic } |
| Language | (LOW) Machine Code | (LOW) Assembly Code | (HIGH) Visual Basic, C, python etc. | (HIGH) SQL, CSS, Haskell etc. |
| Relation to Object Code (generally) | -- | one to one | one to many | one to many |

## First generation

The first generation program language is pure machine code, that is just ones and zeros, e.g.$0010010010101111101010110$. Programmers have to design their code by hand then transfer it to a computer by using a punch card, punch tape or flicking switches. There is no need to translate the code and it will run straight away. This may sound rather archaic, but there are benefits:
And of course drawbacks

## Second generation programming

As you can imagine, writing in 1s and 0s all day will leave you prone to mistakes. Second-generation programming languages are a way of describing Assembly code which you may have already met.
By using codes resembling English, programming becomes much easier. The usage of these mnemonic codes such as LDA for load and STA for store means the code is easier to read and write. To convert an assembly code program into object code to run on a computer requires an Assembler and each line of assembly can be replaced by the equivalent one line of object (machine) code:
| Assembly Code | | Object Code |
| LDA A ADD #5 STA A JMP #3 | -> Assembler -> | 000100110100 001000000101 001100110100 010000000011 |
Assembly code has similar benefits to writing in machine code, it is a one to one relationship after all. This means that assembly code is often used when writing low level fast code for specific hardware. Until recently machine code was used to program things such as mobile phones, but with the speed and performance of languages such as C being very close to Assembly, and with C's ability to talk to processor registers, Assembly's use is declining.
As you can hopefully see there are benefits to using Second-Generation Languages over First-Generation, plus a few other things that makes Assembly great:
And of course drawbacks

## Third generation (High Level Languages)

Even though Assembly code is easier to read than machine code, it is still not straightforward to perform loops and conditionals and writing large programs can be a slow process creating a mish-mash of goto statements and jumps. Third-generation programming languages brought many programmer-friendly features to code such as loops, conditionals, classes etc. This means that one line of third generation code can produce many lines of object (machine) code, saving a lot of time when writing programs.
Third generation (High Level Languages) codes are imperative. Imperative means that code is executed line by line, in sequence. For example:
Would output: 8
Third generation languages can be platform independent, meaning that code written for one system will work on another. To convert a 3rd generation program into object code requires a Compiler or an Interpreter.
To summarise:
However
* Extension: Programming Paradigms
* There are several types of Third-generation languages that you will cover in more detail at A2. They include:
* Object Orientated
* Event driven

## Fourth generation

Fourth-generation languages are designed to reduce programming effort and the time it takes to develop software, resulting in a reduction in the cost of software development. They are not always successful in this task, sometimes resulting in inelegant and hard to maintain code. Languages have been designed with a specific purpose in mind and this might include languages to query databases (SQL), languages to make reports (Oracle Reports) and languages to construct user interface (XUL). An example of 4th generation programming type is the declarative language
An example of a declarative language is CSS which you might learn more about when completing any web design unit
* Exercise: Generations of programming language
* Describe what is meant by an imperative language:
* Answer:
* code is executed line by line, in sequence
* What is the relationship between lines of object code and lines of 2nd generation language code
* Answer:
* one line of 2nd generation = one line of object code
* What is the relationship between lines of object code and lines of 3rd generation language code:
* Answer:
* one line of 3rd generation = many lines of object code
* Give two benefits of using 3rd generation over using assembly. Give one drawback
* Answer:
* quicker and easier to write and maintain
* hardware independent, written once, can be used many times
* may lack the low level, processor specific functionality, meaning slower code
* Give the definition of a declarative language
* Answer:
* describes what computation should be performed and not how to perform it. Not imperative!
* For 2nd and 3rd generation languages give the program translator required to convert the language generation to object code:
* Answer:
* 2nd (Assembly) requires an assembler
* 3rd requires an interpreter or a compiler