The Power of the Declarative

Steven Pemberton, CWI and W3C, Amsterdam

About me

Researcher at CWI in Amsterdam (first non-military internet site in Europe - 1988, whole of Europe connected to USA with 64kb link!)

Co-designed the programming language ABC, that was later used as the basis for Python

At the end of the 80's built a system that you would now call a browser.

Organised 2 workshops at the first Web conference in 1994

Chaired the first style and internationalization workshops at W3C.

Co-author of HTML4, CSS, XHTML, XML Events, XForms, RDFa, etc

Activity lead of W3C HTML and Forms Activities, co-chair of XHTML2 Working Group

The <a> element: the poster child of declarative markup

<a href="http://www.w3.org/">W3C</a>

Presentation

Icons/hover feedback

Information about whether visited earlier

Activate: Locate IP address, scheme, send details of user agent, request document, deal with redirections/errors/content negotiation, receive document and display it

The Web: some principles

Simplicity * Usability * Accessibility * Device-independence

Device independence

Views

Views application environmentLate 80's after designing a programming language designed on usability principles (ABC - Python is based on it), we designed an 'application environment' that investigated usability at the system level (not just the application level).

This system had an extensible markup language, vector graphics, style sheets, a DOM, client-side scripting...today you would call it a browser (it didn't use TCP/IP though).

It ran on an Atari ST (amongst others).

Programming Clocks

The shortest code I could find of an analogue clock was something over 1000 lines of C (the longest was over 4000 lines):

1000 lines of C code

Clock

Here is the essence of the code used for the Views clock example.

type clock = (h, m, s)
displayed as 
   circled(combined(hhand; mhand; shand; decor))
   shand = line(slength) rotated (s × 6)
   mhand = line(mlength) rotated (m × 6)
   hhand = line(hlength) rotated (h × 30 + m ÷ 2)
   decor = ...
   slength = ...
   ...
clock c
c.s = system:seconds mod 60
c.m = (system:seconds div 60) mod 60
c.h = (system:seconds div 3600) mod 24

We live in an exponential world

How has computing power developed since the start of the web?

To demonstrate Moore's Law.

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

Paper

2009

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

Paper

2009
2007

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

2009
2007
2006

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

Paper

2009
2007
2006
2004
2003
2001
2000
1998
97
95
94
92
91
89

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?

(It's not the first time I've said that)

High-level programming languages

Interpreted programming languages

Declarative approach

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.

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.

Applications over the Web

Google maps One of the big advantages of applications over the web is that everyone has always got the most recent version.

Declarative Applications

A world clock written using XFormsSome 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:

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.

Another data point

A certain company makes BIG machines (walk in): user interface is very demanding — needs 5 years, 30 people

This became: 1 year, 10 people with XForms

The Approach

Declarative markup

Late binding of user interface

If you want to see it in action, have a look at Joost (TV over IP): it is actually running on Firefox, using SVG widgets via XBL.

Conclusion

The advantages of this approach are:

In other words: everything you need for the web!