Normally, when you write a computer program, you not only instruct the machine what you want it to achieve, you also tell it how to achieve it. Thus, the following code fragment shows how to calculate the average of three numbers:
double average (int num1, int num2, int num3) {
int sum = num1 + num2 + num3;
double avg = sum/3;
return avg;
}
Note that in the above, we have to specify not only what is to be computed; we also have to specify how it is to be computed. Clearly, this is a very simple example but, as you know, for large programs this gets more and more complicated, and we typically have to comment the code to remind ourselves and others what the code is meant to achieve.
An alternative style of programming is called "declarative programming", in which we tell the program what we want it to determine for us, but leave it up to the program itself, or rather the interpreter or compiler for the programming language in question, to determine how the result is computed.
We briefly discuss two examples of declarative programming languages, namely SQl and Prolog. Depending on the major you are in, you will already have come accross at least one of them or will do so in the near future.