The Power of Declarative Thinking

Steven Pemberton, CWI and W3C, Amsterdam

We live in an exponential world

To demonstrate Moore's Law

Take a piece of paper, divide it in two, and write this year's date in one half:

Paper

2007

Now divide the other half in two vertically, and write the date 18 months ago in one half:

Paper

2007
2005

Now divide the remaining space in half, and write the date 18 months earlier (or in other words 3 years ago) in one half:

Paper

2007
2005
2004

Repeat until your pen is thicker than the space you have to divide in two:

Paper

2007
2005
2004
2002
2001
1999
1998
1996
95
93
92
90
89
87

This demonstrates that your current computer is more powerful than all other computers you have had put together (and the original Macintosh (1984) had tiny amounts of computing power available.)

So how are we using all that extra power?

Badly...

Mostly for pixel pushing.

Most computers spend most of their active life idle.

Our Idle Computers

Twice as idle

Why aren't we using the extra power to make people's (our!) lives better?

The cost of producing applications

According to the DoD, 90% of the cost of software is debugging.

According to Fred Brookes, in his classic book The Mythical Man Month, the number of bugs increases quadratically according to code size: L1.5.

In other words, a program that is 10 times longer is 32 times harder to write.

Or put another way: a program that is 10 times smaller needs only 3% of the effort.

Applications over the Web

Recent interest generated by Google Maps and GMail. One of the big advantages is that everyone has always got the most recent version. Hard to write though: Google maps is more than 200k of code.

Google maps

Constructing Applications

The problem is, no one writes applications except programmers.

Interesting exception: spreadsheets

Mostly because they use a declarative programming model.

The nice part about declarative programming is that the computer takes care of all the boring fiddly detail.

Declarative Applications

Some of the most interesting work in this area is being done by xport.net with their Sidewinder rich web browser.

What they have done is combined XHTML, XForms, SVG and XBL. The SVG is essentially a stylesheet for XHTML+XForms content, being applied using XBL. For instance:

A world clock written using XForms

The code says:

<xf:output value="..."
    appearance="fp:analogue-clock" class="clock">

The output is then something like 11:30:00, and the SVG turns this into an analogue clock (the XBL keys off the 'appearance' attribute).

Google maps in XForms

Google maps in XForms

Google maps as Declarative Application

Although the example shown above is not quite complete, it does more than Google maps does and yet it is only 25Kbytes of code (instead of the 200+K of Javascript).

Remember, empirically, a program that is an order of magnitude smaller needs only 3% of the effort to build.

Conclusion

The advantages of this approach are: