Intro to 4th Generation Programming Languages

Lesson I : Programming

Program

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 particulardish. It describes the ingredients (the data) and the sequence of steps (the process) needed toconvert 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 differentdialects of it - which is why that cool iMac program won't run on your PC and vice versa. Binary isunfortunately very difficult for humans to read or write so we have to use an intermediatelanguage and get it translated into binary for us. This is rather like watching the American andRussian presidents talking at a summit meeting - One speaks in English, then an interpreterrepeats what has been said in Russian. The other replies in Russian and the interpreter againrepeats the sentence, this time in English. Surprisingly enough the thing that translates our intermediate language into binary is alsocalled an interpreter. And just as you usually need a different interpreter to translate English intoRussian than you do to translate Arabic into Russian so you need a different computer interpreterto 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 isknown as machine code programming and is incredibly difficult. The next stage was to create atranslator that simply converted English equivalents of the binary codes into binary so that insteadof having to remember that the code 001273 05 04 meant add 5 to 4 programmers could nowwrite ADD 5 4. This very simple improvement made life much simpler and these systems ofcodes were really the first programming languages, one for each type of computer. They wereknown as assembler languages and Assembler programming is still used for a few specializedprogramming 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. Itwas 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 thejob easier. This was just as well because at the same time users were inventing ever morecomplex jobs for computers to solve! This competition between the computer scientists and theusers is still going on and new languages keep on appearing. This makes programminginteresting but also makes it important that as a programmer you understand the concepts ofprogramming 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 structuredprogramming. 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.

Branches

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

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.

Modules

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 themuseful: Φ 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 theuser - an executable file that is installed and can be run repeatedly to perform a task. Forexample users speak of running their "word processor program". The other concept is theprogram as seen by the programmer, this is the text file of instructions to the computer, written insome programming language, that can be translated into an executable file. So when you talkabout a program always be clear about which concept you mean. Basically a programmer writes a program in a high level language which is interpretedinto the bytes that the computer understands. In technical speak the programmer generatessource code and the interpreter generates object code. Sometimes object code has other nameslike: P-Code, binary code or machine code. The interpreter has a couple of names, one being the interpreter and the other being thecompiler. These terms actually refer to two different techniques of generating object code fromsource code. It used to be the case that compilers produced object code that could be run on itsown (an executable file - another term) whereas an interpreter had to be present to run itsprogram as it went along. The difference between these terms is now blurring however sincesome compilers now require interpreters to be present to do a final conversion and someinterpreters 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 toallow the computer to read, translate and execute it.

Structure of a Program

The exact structure of the program depends on the programming language and theenvironment 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 settingits internal state, perhaps setting totals to zero, opening the needed filesetc. Once it is ready to startwork it will read data either fromthe user by displaying promptson a screen or from a data file.Most commonly a combination isused whereby the user providesthe name of the data file and the real data is read from the file. Then the program does the actualdata 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 program.

Programming Computer programming (often shortened to programming or coding) is the process ofwriting, 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 thevery simplest level it consists of issuing a sequence of commands to a computer to achieve anobjective.

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 writingprograms, because there wasn’t any software for sale. And writing programs required writing outthe strings of ones (1) and zeros (0) that the computer could understand. There is still a smallamount 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 writeinstructions 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 ofmachine language code over and over. They began inventing shorthand symbols to representthese strings. The result of their efforts was the first symbolic computer languages, known asassembly 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 onlylanguage a microprocessor can understand directly. Currently, programmers almost never writeprograms directly in machine code, because not only does it (like assembly language) requireattention to numerous details which a high-level language would handle automatically, but it alsorequires memorizing or looking up numerical codes for every instruction that is used, which inassembly language would be written as something more readable like "ADD CX INTEREST" or"RET". 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 ofthe computer system. The main benefit of programming in a first-generation programming language is that thecode 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 generationalprogramming 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 findsa use in several areas of modern programming. First and foremost, any native-code compilercreates 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 nativelanguage, an assembly language programmer must still understand the microprocessor's uniquearchitecture (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 beread and written fairly easily by a human, but it must be converted into a machine readable formin order to run on a computer. The conversion process is simply a mapping of the assemblylanguage code into binary machine code (the first-generation language). The language is specificto and dependent on a particular processor family and environment. Since it is a one-to-onemapping to the native language of the target processor it has significant speed advantages, but itrequires more programming effort and is difficult to use effectively for large applications.

The primary niche for these languages are in kernels, device drivers, and systemlibraries. Compilers usually use these as intermediate languages between a higher levellanguage 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 thirdgeneration. Most 3GLs support structured programming.

Features

There are three primary features of 3GL. First, they are largely machine-independent. Inother words, a program written in a 3GL is not written for a specific type of processor. If you writea 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 translatethe program into machine language. An interpreter is a program that translates the languagewhile 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 programmera 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 aninterpreter 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 notcontain conditionals (if-then-else) and loops (for, while, do), though some languages arecombinations of third generation languages and 4GLs. The term was invented by Jim Martin to refer to non-procedural high level languagesbuilt around database systems. The first three generations were developed fairly quickly, but itwas still frustrating, slow, and error prone to program computers, leading to the first "programmingcrisis", in which the amount of work that might be assigned to programmers greatly exceeded theamount of programmer time available to do it. Meanwhile, a lot of experience was gathered incertain areas, and it became clear that certain applications could be generalised by adding limitedprogramming languages to them. Thus were born report generator languages, which were fed adescription of the data format and the report to generate and turned that into a COBOL (or otherlanguage) program which actually contained the commands to read and process the data andplace 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 methodscan be slow and error prone. It became clear that some applications could be developed morerapidly by adding a higher-level programming language and methodology which would generatethe equivalent of very complicated 3GL instructions with fewer errors. In some senses, softwareengineering arose to handle 3GL development. 4GL and 5GL projects are more oriented towardproblem solving and systems engineering.

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