pdf: 600KB - Potsdam Institute for Climate Impact Research
pdf: 600KB - Potsdam Institute for Climate Impact Research
pdf: 600KB - Potsdam Institute for Climate Impact Research
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
21<br />
functions that can calculate volume. Or we could print a catalogue of all the functions, one which<br />
is always up-to-date and 100% guaranteed consistent with the functions used to per<strong>for</strong>m the<br />
calculations.<br />
5.4 More examples of shifting the declarative:procedural boundary<br />
We'll now consider in less detail a number of other examples of moving in<strong>for</strong>mation from a<br />
procedural to a declarative <strong>for</strong>m.<br />
Electronic circuits<br />
In the early days of computing, the behaviour of an electronic circuit was simulated by writing a<br />
program specific to the design of a particular circuit. Change the circuit, and you needed to<br />
change and re-compile the program. Then people developed CAD (computer-aided design) tools<br />
<strong>for</strong> electronics which enabled the circuit to be specified in terms of electronic components<br />
(resistors, capacitors etc, and how they are connected). The design of the circuit thus changed<br />
from being encoded procedurally in a program, to being represented declaratively as a circuit<br />
diagram. For example, the following could be 'data' <strong>for</strong> an electronics simulator:<br />
resistor(r1,220).<br />
capacitor(c3,100pF).<br />
connected(r1,c1).<br />
Again, it is obvious that it is far better to separate out the representation of the circuit from one<br />
particular <strong>for</strong>m of reasoning we might wish to do with it. Once you have the data in this <strong>for</strong>m, it<br />
is possible to simulate the behaviour of the circuit, as be<strong>for</strong>e. But it is possible to do many other<br />
things with the design: <strong>for</strong> example, prepare a layout <strong>for</strong> a printed circuit board; work out its heat<br />
budget; and calculate the cost of manufacture.<br />
Spreadsheets<br />
A spreadsheet is an example of a declarative data processing/modelling environment. Prior to<br />
spreadsheets, people wrote programs <strong>for</strong> working out their accounts and processing their data. In<br />
a spreadsheet, both the data and the calculations to be per<strong>for</strong>med on it are held in one declarative<br />
representation: that's what you save to file. The only procedural part is now in the spreadsheet<br />
software itself, which is capable of processing the values in some cells using the functions in other<br />
cells to produce the results.<br />
Logic programming<br />
Appendix A2.3 presents a very brief introduction to Prolog, an example of a logic programming<br />
language. This differs from conventional (procedural, imperative) programming languages in<br />
that the 'program' is actually just a collection of facts and rules. It does nothing: it simply<br />
contains knowledge. For example, the facts could be about a road network, and the rules could be<br />
about how to reason with such in<strong>for</strong>mation. Instead of 'running the program', one asks a question<br />
(e.g. "How do I get from A to B?"). The Prolog interpreter reasons with this collection of facts<br />
and rules to answer the query. Prolog is thus an example of a declarative programming language.<br />
UML (Unified Modelling Language) and declarative programming<br />
UML [see URLs] is a design methodology <strong>for</strong> object-oriented software engineering (Rumbaugh et<br />
al, 1999; Stevens and Pooley, 2000). It is based around a number of types of diagram, which<br />
jointly specify the software system being developed.<br />
Originally, these diagrams were simply bits of paper that were given to programmers to guide the<br />
programming task. Companies developed UML modelling tools (such as Rational Rose:<br />
Quatrani, 2000) to help in drawing the diagrams. These software tools were extended so that they<br />
could generate skeleton code <strong>for</strong> the program: <strong>for</strong> example, to generate the text <strong>for</strong> all the classes,<br />
attributes and method wrappers. Some tools have the ability to reverse engineer: to produce the