The first computers had to be programmed directly in machine code. Binary numbers were placed in the memory by setting switches.
Programs were completely machine dependent and writing a program was a very time consuming task. In order to simplify the writing of programs, small sections of commonly used code were collected together into libraries.
There would be libraries for maths and input/output operations amongst other things. The program responsible for combining a program and the libraries is called linker.
To run the program, another program called the loader was used to put the program into memory and start it (something like the main function of assignment 2).
The original program is called the source code. The program before linking is called the object code. The program after linking is called the executable.
These languages are called high level languages. A program written in a high level language will almost certainly need to be linked with libraries.
Source code --Translate--> Object code --Link--> Executable --Load--> Running Program.
C is an example of a third generation compiled language.
Another approach to executing a program is called interpretation. A program called an interpreter translates source directly by emulating a machine which has the source language as its machine code. In assignment 2 you wrote an interpreter for a RISC machine.
Interpretation is often considerably slower than compilation, this is because translation must be performed each time the program is run. It is possible to write a program that is a combination of interpreter and compiler. This is sometimes called a Just In Time (JIT) compiler because it compiles sections of the program as it is being executed, i.e. just in time.
Java is an example of an interpreted language.
Machine Languages FORTRAN COBOL ALGOL BASIC C PASCAL ADAImperative languages use sequence, selection and iteration to write programs that tell the machine how to perform a task. The following program solves the 8 queens problem - how can you arrange 8 queens on a chess board so that they don't attack one another. Don't worry about the algorithm, just notice that the program uses sequence, selection, iteration and recursion.
SIMULA Smalltalk C++ JavaObject-oriented languages force the programmer to concentrate on abstract data types.This is done by having imperative code associated with variables (called objects) and having a hierarchy of variable types (called classes).
LISP ML Scheme HaskellFunctional languages have no variables and use recursion to perform computation. The advantage of functional languages is that it is easier to prove that a functional program is correct than an imperative program. The following solution to 8 queens is written in Haskell, notice that queens is a recursive definition, qu 0 is an empty list. qu m+1 is defined in terms of qu m, 'safe' checks for all attacks and 'check' checks for a single attack.
PROLOGA declarative or logic programming language is one that is based on a subset of mathematical logic. The computer is programmed to infer relationships between values rather than compute output values from input values.