Saturday, 26 April 2008

The spread of knowledge in a large game world

part of the role of Dandelion, in The Witcher games,
is to provide the player with news
These days we have television, and news. But in a late bronze age world there are no broadcast media. News spreads by word of mouth. If non-player characters are to respond effectively to events in the world, knowledge has to spread.

How to model this?

Some non-player characters - doesn't need to be many - are news-spreaders. News-spreaders need to travel. They have to travel even when there are no player characters in the vicinity. But, they don't have to travel very often - once or twice every game day. When a news-spreader is in the immediate vicinity of another character, the pair may (with some degree of randomness) exchange news. There needs to be a hierarchy in the exchange of news, so that 'I-saw' events need to be more likely to be passed on than 'I-heard' events; there needs to be a counter which counts the number of times a knowledge item has been passed on, and also an age counter so that knowledge items are less likely to be passed on as they get older.

One obvious class of news-spreader is a merchant. Merchant agents can either shuttle mechanically between a fixed group of markets or else possibly respond intelligently to supply and demand. Provided that there is a mesh of merchant routes covering the markets of the game world, and that a useful subset of non-merchant characters are required to visit a market every few game days, this should give a reasonably realistic framework for news spreading.

What else? What things qualify as news items? I think at least the following:
  • Deaths of sentient characters, especially if violent
  • Commodity prices
  • Changes of rulers in cities
  • Marriages of sentient characters
  • Plot events, flagged as events by the game designer
Obviously, news is more valuable if the people involved are important or notorious: the significance of a story is probably the product of the significance of the people concerned.

So a news item becomes a tuple

(days-old nth-hand significance action (actors))

for example

(54 2 10 'killed '(fred joe))

meaning 'I spoke to a man who'd spoken to a man who said he saw notorious fred kill well-liked joe on 54 days ago'. Obviously, the non-player character must be able to construct a natural language sentence from the tuple when speaking within the hearing of a player character, but there's no need for a non-player character to produce a natural language sentence for another non-player character to parse; instead they can just exchange tuples.

But if we're exchanging knowledge between agents, then agents must have a means of representing knowledge. This knowledge is an association between subjects and sets of statement, such that when the agent learns the statement

(54 2 10 'killed '(fred joe))

it adds this statement (with the 2 incremented to 3) to the set of statements it knows about fred and also to the set of statements it knows about joe. It's possible that the receiving agent could then challenge for further statements about fred and/or joe, the automated equivalent of a 'who's joe?' question.

There could be feedback in this. Fred's and joe's significance scores could be incremented for each character to whom the statement is passed on, increasing the likeliness that fred, at least, would feature in more news stories in future. There needs also to be some means of managing how the non-player character's attitude to the subjects of the statement are affected. For example, If fred kills joe, and the character (say bill) receiving the news feels positively towards joe, then bill's attitude to fred should become sharply more hostile. If bill feels neutral about joe, then bill's attitude to fred should still become a bit more hostile, since killing people is on the whole a bad thing. But it bill feels very hostile towards joe, then bill's attitude to fred should become more friendly.

Obviously the rate of decay, and the degree of randomness, of the news-passing algorithm would need to be tuned, but this schema seems to me to describe a system with the following features:
  • Non-player characters can respond to questions about significant things which happen in the world - without it all having to be scripted
  • If you travel fast enough, you can keep ahead of your notoriety
  • Characters on major trade routes will know more about what is happening in the world than characters in backwaters
This seems to me a reasonably good model of news spread.

Scaling of the algorithm

Let's work around the idea that a 'game day' equates to about two hours of wall clock time. Let's work around the idea that there are of the order of fifty markets in the game world, and that for each market there are two or three merchants whose 'home base' it is.

Obviously non-player characters who are within the vicinity of a player character have to be 'awake', in order that the player can see them interacting with their world and can interact with them. Those characters have to be in working memory and have to be in the action polling loop in any case. So there's no extra cost to their gossiping away between each other - around the player there's a moving bubble of gossip, allowing each character the player interacts with to have a high probability of having some recent news.

But the merchants who aren't in the vicinity of a player don't have to be in working memory all the time. Each merchant simply requires to be 'woken up' - loaded into memory - once per game day, move a day's journey in one hop, and then, if arriving at an inn or at a market, wake and exchange news with one resident character - an innkeeper or a gossip. So the cost of this algorithm in a fifty-market game is at worst the cost of loading and unloading two non-player characters from memory every minute, and copying two or three statements from the knowledge set of one to the knowledge set of the other. If you're dynamically modifying significance scores, of course, you'd need to also load the characters about whom news was being passed on; but this still doesn't seem unduly onerous.

Obviously, if memory is not too constrained it may be possible to maintain all the merchants, all the innkeepers and all the characters currently being talked about in memory all the time, further reducing the cost.

Friday, 4 April 2008

Worlds and Flats

Of Compartmented Worlds

Playing The Witcher has got me thinking again about an algorithm for rendering a world which I first thought of twenty-five years ago. Then, it was a hack for dealing with the fact that the computers of the day didn't have much memory or horsepower. Now, it's a hack for dealing with the fact that - when considered against the complexity of a world - the computers of today still don't have enough memory and horsepower. Mind you, today I'm contemplating photorealistic scenes, whereas then simple line and wash would have been good enough, but...

The algorithm for rendering I'll call 'flats'. But before we get to discussing flats, lets discuss worlds.
The world of The Witcher (and other games based on the Aurora engine) is composed of areas. One area is loaded into memory at a time; when the player reaches an area boundary, the area is unloaded in toto, and the next area loaded, also in toto. The result is a noticeable interruption in game play. There's also, normally, a noticeable visual disjunction at the boundary; the new area uses a different 'tileset', which is to say, set of bits of scenery. When you look across a boundary, the scenery often appears different from what you find when you cross the boundary and arrive at the other side.

Finally, you can only cross boundaries at specific gateway points. For example, Chapter Four of The Witcher takes place in a continuous rural space composed of three main areas: the lakeside, the village, and the fields. Between the lakeside and the other two regions there's a wooded escarpment, which provides some logical justification for the fact that there are actually only two places you can actually cross it - from the lake shore, either up the road to the village or else through a series of glades to the fields. But between the village and the fields there's no such logic. There are a pair of gateposts, and you must cross between those gateposts - but the landscape appears continuous, with no visible barrier. It's an artifact of the game engine.

So, how to deal with this?

My interest, let's be frank, is in story telling; and the nature of story telling is moderately constrained plots. In computer mediated story telling the reader/player can and should be able to explore the plot in his own way, make his own choices, take his own path through the environment, encounter the elements of the plot as he encounters them on that path, and it's the job of the story teller to make that engaging whatever path the reader takes. But if the reader chooses to ignore your hints and wander out of the area you've populated with plot altogether, there's two things you can do. One is put up physical barriers which stop him (although the silly field fences in Chapter One of The Witcher do /not/ count, as it's obvious that Geralt could simply hurdle them; they are just another artifact.

Of Finite and Infinite Worlds

But an infinite world is not required for the sort of stories I'm interested in; the sort of stories I'm interested in take place in, at best, regions of infinite worlds. Just because I don't choose to use all of it, of course, is not a reason that a world should not be infinite.

There are plenty of fractal mathematical equations which map an infinite three dimensional surface with landscape like features. If such an equation gives you land heights, then altitude, steepness and orientation will give you soil type and vegetation cover. There is no need to store a whole world in order to be able to reproduce it exactly when the player follows the same route through it for a second time; it is sufficient to start with the same seed. So a world need not take up vast amounts of disk space for pre-mapped scenery; scenery need only be mapped as it comes in sight. This is fundamentally the trick used by Elite to pack a large, reproducible universe into less than 32K of RAM, and it still works today.

Of River Systems

However, there are reasons to prefer that a world be pre-mapped, at least at coarse grain. One example of why is river systems. It's trivial that we render a river at the bottom of a valley, but it isn't trivial to compute how wide and deep that river should be. To calculate that we have to explore the extent of the watershed upstream of any given point, and sum the rainfall on it, which in turn is a factor of exposure to prevailing airflow and the proximity of ocean to windward. It's computable, but it's much more efficient to compute it once and cache the results, especially since for any given river system it's a recursive function.

Furthermore, rivers cause erosion, changing the landscape through which they pass, cutting gorges on steep slopes (especially if soft), building up flood-plains in flatter areas downstream. Some fractals are naturally extremely landscape-like, but it seems to me - better mathematicians might prove me wrong - to realistically render river systems requires some degree of post processing, and post processing which would be expensive to do repeatedly in realtime.

Of Human Settlement

Human settlement is a separate issue. Many years ago I wrote a program which modelled the spread of human settlement over a landscape.

Human settlement is not random. Human settlement follows rules and patterns. Pioneers settle in places which have a sufficient spread of resources to meet their year round needs; they settle near to easy routes from their parent settlement. Pastoralists need grazing land and water; they spread up river systems, but avoid marshy areas. They settle where there is open grazing, but often close to a forest edge for access to timber. Second wave settlers prefer to settle close to existing settlers, for mutual protection and help. Cereal growers join these settlements where the depth of soil is optimal for crops. As the settlement grows and pressure on land increases, the forest edge is cut back both for building material and to increase the available agricultural land. If a settlement fails, the forest may reclaim this land

Road networks develop. People travel between settlements by the easiest route - but the very fact a route is travelled makes it easier. A path gets cleared; later, people fill in boggy bits and bridge streams, to make their own passage easier or to encourage trade through their lands. Because as a road grows more important, so the settlements along it grow more important, and as the settlements along it grow more important so the roads between them grow more important. The road network, then, is a dynamic fractal which interacts with another dynamic fractal, the distribution of human settlement.
The program I wrote was a cellular automaton which modelled human settlement in only thirty states. It did a remarkably good job. Settlement would spread across a landscape; settlements in strategically beneficial areas would grow faster, develop temples and markets sooner, and thus become important foci of the roads system; other settlements would wax and wane, some falling into ruin; new waves of settlers might settle in slightly different areas.

More states would be better, give a richer, more subtle model, But this demonstrates that it's easy to design a program which will settle a landscape in a realistic way automatically. Once again, though I think it can be done more realistically if it is precomputed and cached rather than if it is generated from the landscape fractal.

In summary: yes, I think it's possible to have an infinite world which is satisfying and can be reproduced at will from a seed, but the stories I want to tell do not call for infinite worlds and if the world is finite I believe it can be made still more satisfyingly realistic by pre-computing and caching things like river systems, afforestation and settlement patterns. Either way, though, the world can be very large - much larger than the worlds of current near-photo-realistic games. The world of The Witcher, for example, is a few hundred hectares; I'm envisaging storing hundreds or thousands of square kilometres in similar data size and with a similar expenditure of artist's effort.

Rendering, and the Flats idea

Rendering a convincing distant view in computer-generated virtual environment is hard. There's an enormous amount of data in a distant view, and if the viewer is moving in real time it becomes computationally unaffordable, even on machines with a great deal of horsepower. Games typically work around this problem by either angling the camera downwards, or else rendering a high degree of atmospheric haze - it's always slightly foggy - so there is never a distant horizon.

Movies shot in studios often have wonderful, detailed backgrounds to their sets. Vistas of far mountains and great cities... of course, the far mountains and great cities don't exist in the set. They're painted on large canvases called 'flats'. The flats illusion depends on the camera not moving too much, because of parallax - nearer things should appear to move relative to further things, and on a flat they don't.

But. But.

For a player moving in a computer game the field of view is quite restricted - it's no more than thirty degrees, typically straight ahead as he moves. Parallax movements are less significant straight ahead. A single flat still isn't going to work, but in many animated films a system of multiple flats is used, with the nearer flat moved relative to the further flat to give an illusion of parallax. This can work very well.
Suppose one projects onto the world a hexagonal grid - it doesn't have to be hexagonal, but I think that is likely to work best - with a cell size of about 100 metres (the exact cell size depends a bit on the speed of movement of the player, for reasons which will become apparent). Cells are grouped into metacells of seven cells (if square, then metacells of nine cells). For each cell, there are six inner flats. Each inner flat consists of a rendering from the centre of the cell of everything more than one cell distant, but less than five cells distant, over a 60 degree arc of view.

For a given area of the world the distant view doesn't change very much. We don't, therefore, have to compute a set of outer flats for every cell, just for every metacell. The outer flats each consist of a rendering of the scenery more than one whole metacell away, from the centre of the metacell.
To render a scene, then, we first paint the outer flat for the metacell the player is in, in the direction the player is looking. Over that we paint the inner flat for the cell the player is in. Over that we render the actual objects in the adjacent cells which fall within the viewing area. Over that we render the objects in the current cell. Thus we only have to render in real time certainly no more objects than can already be rendered by systems which clip for distance either by angling the camera down or by using fog, and yet still manage a realistic distant view.

Rendering the Flats

OK, so when do the flats get rendered? After all, if you're going to pre-render six full colour full screen resolution flats for every hundred metre cell in the world, then either your data volume is going to get enormous or your world is going to get pretty constrained - which was just what we were trying to get away from. And if you're going to multiply that with flats rendered for every time of day and every weather condition - well, it's not feasible.

You cannot realistically pre-render the flats, in my opinion. Or if you can, you're going to have to give them so much real time post processing that you will lose the benefit. Pre-rendering the flats is not the idea. But if they are rendered in real time, where is the benefit...?

There's a middle way. Running straight forward at top speed a player crosses a hundred metre cell in about a minute, during which to give an illusion of continuous movement at least nine hundred full screen frames must have rendered. But the flats don't change in a minute. The flats don't change in five minutes. They don't need to. Even if rain clouds are sweeping across the landscape, it's OK for the distant view still to be sunny five minutes after the rain reaches you, or vice versa. If you can render a high proportion of the detail in a view only once every nine hundred frames, you've saved a lot of processing.

So there is a continuous background process running which renders flats. It does it all the time. It prioritises making sure that a flat exists for every direction the player may look in in the next minute - that is, every direction from the cells and metacells he's currently heading towards. Having done that, it renders flats for cells to either side which he might turn to. It maintains in memory a small stock of flats from recently visited cells, so that if the player turns back they don't have to be repainted in a hurry; and if a flat is more than about five minutes - 4,500 frames - old, it may repaint it to update time-of-day lighting or weather effects.

Obviously, quite a lot of the time the join between two adjacent flats will be in view. I don't see this as a problem. Just naturally, the rendering of the flats should essentially form segments of a hoop, so the join between two adjacent flats should not be perceptible.

Artifacts

Inevitably, there will be undesired artifacts of this system. Significantly, mobile objects - 'non-player characters', the avatars of other players, monsters and computer mediated creatures in the landscape - more than two cells away will not be visible. The flat is static, so it can't have moving characters on it. There may be some algorithmic way round this, since one hundred and fifty metres away is rather close for people to suddenly vanish; but it is not a problem I have a solution for.

Again, if the player is looking sideways as they cross a metacell boundary, there will be a jarring sudden shift in parallax. I acknowledge that and think it just can't be helped; that the benefits in terms of quality of view for given computer power, will render it acceptable.

Wednesday, 27 February 2008

The Witcher: Story telling of a high order

This isn't, by any means, a final review of The Witcher. I've played it fairly intensely over three weeks, and am only into the fourth chapter. Which is great, because there is more to come.

But, what do I think of the show so far?

I'm extraordinarily impressed. I'll come back later to talking about it as a game, but I want to stand back and talk about it in comparison with other media. It's worth comparing it with Kurosawa's Seven Samurai, or - perhaps especially - with Eastwood's High Plains Drifter. It is story telling of the same order, but more than that it is story telling about the same issues; about worlds so tainted with violence and cruelty that all moral actors are tainted. Geralt, the hero whose role you play, is himself a tainted character, edgy, over-aggressive, harsh in judgment. And you will play him like that, no matter how much you want not to. But he's not an amoral character. He's trying to make the best choices he can in a murky and uncertain world.

Again - comparing to cinema, it's only by comparing this with cinema that you can do it justice - the scenery is gorgeous. The quality of the light at dawn and at sunset is just stunning. The trees are so lifelike that you can easily recognise each different species. The representation of a medieval European city, with all its grandeur and all its squalor, is extraordinary. You can almost smell it.

So what is not to like?

Somewhere in the production process a decision was taken that every word spoken by every character should be voice acted - and they are. The voice acting is extremely good (as a Scot, I enjoyed the gag that all the dwarves have Scots accents). It isn't just the significant characters who are voiced, either - people you pass in the street are having conversations with one another, and if you eavesdrop on those conversations you pick up valuable plot clues.

But the decision to voice all the characters has curious effects that aren't entirely good. As a player you expect these beautifully rendered, beautifully spoken characters to have a much richer conversational repertoire than they have. Indeed, I suspect that if the dialogue had been largely text, it would have been economic to provide much richer dialogue.

Most of the characters have been individually modelled - and many are individually motion captured. Old people move rheumatically, children skip, dwarves stomp, whores sway and drunks weave. And that makes the few cases where significant character models are reused (the naiad and the dryad, for example; the cannibal and the fisher king) stand out awkwardly.

Also, and more seriously, I suspect the game's creators have been poorly served by the English translation. Very often the English language dialogue seems anachronistic, over-modern.

Which brings me to the game's Polish roots. I think to fully understand this game and the books on which it is based you need an understanding of Polish history. Yes, it's a fantasy about elves and dwarves and magic. But it's very easy to read the Order of the Flaming Rose as being the Teutonic Order, and the elves and dwarves as the indiginous Prussians and Slavs; or equally, to see the Flaming Rose as being the Nazis (who, after all, consciously emulated the Teutonic Order) and the elves and dwarves as representing the Poles and the Jews. I don't know to what extent that is what the authors intend, but at some level this story is rooted in Poland's long history of genocidal war.

It benefits from that. Its creators understand what genocide means, about how hard it is to stand aside; about the scale and devastation that this sort of war brings. This is a deeply felt story, in a way in which little modern fantasy really is.

For the rest: combat? Yes, if all you want to do is hack and slash this game is not for you. The camera? Yes, sometimes the camera movement is disconcerting. Where in other game engines the game will happily remove walls and whole buildings if they get in the way of the camera, the Witcher's camera manouvers around buildings and trees and sometimes that movement is awkward. To be fair, there are alternative camera was modes available, but I didn't find the camera a problem.

The interactive video game is a young artform. I've been engaged in discussion recently about whether fantasy fiction can ever be literature - needless to say, I argue that it can. Can a video game be literature, or at least art of high quality? Experience the Witcher, and find out

Saturday, 8 December 2007

The best wee act of hegemony in the world

We're all familiar with Jack McConnell's slogan for Scotland's airports. We're all familiar with the incoming nationalist government's dislike of it, and rapid deletion of it. But Jack McConnell must be laughing up his sleeve; we, the nationalists, have missed a trick - badly - and Jack has achieved all he set out to achieve.

Because we didn't challenge the truth of the slogan; we didn't notice that it needed to be challenged. So the idea - the meme - the hegemonic masterstroke that McConnell set out to achieve has been achieved. We have cast our national debate in terms of being a small nation. If you went out in any street in Scotland and asked ten passers by whether Scotland was a big country, a middle sized country, or a small country, all ten would agree, Scotland is 'wee'.

We like the notion. It's romantic, the small band against the world. Our national myth - our stories of Wallace and Bruce are cast as the brave few against the might of a much more powerful hostile world. And so we let it pass unchallenged, and thus give an unnecessary gift to the unionists. Like James the Fourth at Flodden Field, we march down off the strong hill to face our opponents on their territory.

The unionists, of course, are all too happy to present Scotland as a wee nation. Awfy cute, of course; Awfy couthie. But ower wee to stand on its own two feet in the world. Needing the generously offered protection - oh, and 'subsidy' - of our larger, stronger, more viable neighbour.

So what's the truth of it?

Scotland has a population of 5.1 million people.

That's small, isn't it?

No.

Scotland is just slightly smaller than Finland, one hudred and eleventh in the world, and slightly bigger than Turkmenistan, one hundred and twelth. One hundred and twelth? Isn't that awfy far down the league? No, actually, it's not. There are two hundred and twenty one nations and self governing territories in the world, ranging from the Republic of China (1.3 billion people) to the Pitcairn Islands (50 people). One hundred and twelth places us exactly - exactly - in the middle. The median population of all the countries in the world is 5,299,000.

So those 110 countries that are smaller than Scotland, are they all 'too wee' to be viable? Iceland (population 312,851), is that big enough to defend its cod stocks against the combined might of Britain and Spain? Errr... yes, actually. Malta (population 407,000) and Luxembourg (467,000), are they big enough to be full members of the European Union, with seats on the Council of Ministers? Errr... yes, they are, actually.

Looking at the European Union as a whole, Finland, as I said earlier, is just one place up the table from Scotland. Below us are Ireland, Lithuania, Latvia, Slovenia, Estonia and Cyprus, not to mention Malta and Luxembourg. Are all these ower wee to govern themselves? Ower wee to be full members of the European Union? They do not seem to think so. And among our other European neighbours outside the union (and in no hurry to join it) are Iceland (see above), Norway (4,727,777) and Switzerland (slightly bigger than us at 7,508,700). Are they 'ower wee' to stand alone in the world? They, clearly, don't think so.

Indeed, if you look at those three European nations outside the EU, each plays a very significant role in the world. Iceland provided the neutral venue for the USA and the Soviet Union to meet and negotiate the end of the cold war. Norway has made significant and very positive interventions in the Middle East. Switzerland hosts the Red Cross and many United Nations agencies. They can do these things precisely because they're not great powers and don't pretend to be great powers; and thus can be trusted to be honest brokers.

So let's squash this 'small nation' nonsense. Scotland is not 'wee', no matter how couthie and romantic that may feel. Mid table respectability - or mediocrity - is our position, at least on size. We're exactly average. 'The least self-confident medium sized country in the world' may sound a lot less romantic than 'the best wee country', but that's what we are. Medium sized, with well above average resources, well above average potential, well above average wealth. And we lack the courage to take our independence, because we allow other people to characterise us as 'wee'.

It's time that stopped.

Monday, 21 May 2007

Of Size, and Governance


If you set out from Langholm, in Eskdale, and drive in a car to Drummore in the Rhinns of Galloway, you will drive 119 miles, and - according to Google's mapping system - it will take you 4 hours and eight minutes. If you didn't fancy Drummore, you could get to Stafford, in Staffordshire, in one minute less; or Dunkeld, in Perthshire, in five minutes less.
 
From Drummore, driving by road (and taking ferries where appropriate), you could get to Dunoon in Argyle or Dunblane in Perthshire quicker than you could get to Langholm. Even with the ferry, getting to Dundalk in the Republic or Ireland would only take 21 minutes longer.
 
So what's amazing or shocking about that?
 
Well, to get from Langholm to Stafford you pass through Dumfries and Galloway, Cumbria, Lancashire, Manchester, Cheshire and finally Staffordshire. Six separate local government units. To get to Dunkeld you pass through Dumfries and Galloway, South Lanarkshire, Glasgow, East Dumbartonshire, Stirling, and Perth and Kinross; again, six local government areas.
 
To get from Drummore to Dunoon, you pass through five separate local government areas. Drummore to Dunblane is eight...
 
But Drummore to Langholm is only one: Dumfries and Galloway all the way. It's simply a perversion of language that a councillor from Langholm overseeing decisions which affect Drummore (or vice versa) is in any sense 'local' government. Dumfries and Galloway, if it were a nation, would be by no means the worlds smallest. At 6500 square kilometres it's larger than Palestine; larger than Brunei; larger than Trinidad and Tobago; more than twice as large as Samoa or Luxembourg; more than six times as large as Hong Kong; more than ten times as large as Singapore or Bahrain; more than 40 times as large as Liechtenstein; more than four thousand times the size of Monaco. In fact quarter of all the nations and self governing territories in the world have a land area smaller than Dumfries and Galloway.
 
Ah, you might say, but we have a sparse population. That's true, of course. Only 43 nations and self governing territories are less populous than Dumfries and Galloway.
 
But that's talking about nations, about independence. We don't have independence and we don't aspire to it. Let's look at how other small northern European countries organise local democracy. Take Iceland, for example. Iceland has a population twice the size of Dumfries and Galloway. It is divided into 'municipalities' which have responsibility for  kindergartens, elementary schools, waste management, social services, public housing, public transportation, services to senior citizens and handicapped people and so on. Not so very different, in fact, from the responsibilities of our local government. So, with a population twice that of Dumfries and Galloway, how many of these municipalities does Iceland have?
 
Two?
 
No.
 
The answer is seventy nine.
 
Iceland is an extreme case, of course; a nation of proud and independent people with an ancient history of democratic organisation, and strong civil society. But Denmark, with a population roughly equal to Scotland's, has three times as many local authorities. Norway, with three quarters our population, has 400 more local authorities than Scotland has.
 
Put it differently: Dumfries and Galloway has three times the population of the average Danish local authority; four times of the average Swedish or Dutch; twelve times the average for Norway; thirty six times the average for Iceland. I said Iceland was an extreme case, didn't I? Get this. Dumfries and Galloway has eighty four times the population of the average - the average - French commune.



Monday, 20 February 2006

Post-scarcity Software

From http://aturingmachine.com/
For years we've said that our computers were Turing equivalent, equivalent to Turing's machine U. That they could compute any function which could be computed. They aren't, of course, and they can't, for one very important reason. U had infinite store, and our machines don't. We have always been store-poor. We've been mill-poor, too: our processors have been slow, running at hundreds, then a few thousands, of cycles per second. We haven't been able to afford the cycles to do any sophisticated munging of our data. What we stored - in the most store intensive format we had - was what we got, and what we delivered to our users. It was a compromise, but a compromise forced on us by the inadequacy of our machines.

The thing is, we've been programming for sixty years now. When I was learning my trade, I worked with a few people who'd worked on Baby - the Manchester Mark One - and even with two people who remembered Turing personally. They were old then, approaching retirement; great software people with great skills to pass on, the last of the first generation programmers. I'm a second generation programmer, and I'm fifty. Most people in software would reckon me too old now to cut code. The people cutting code in the front line now know the name Turing, of course, because they learned about U in their first year classes; but Turing as a person - as someone with a personality, quirks, foibles - is no more real to them than Christopher Columbus or Noah, and, indeed, much less real than Aragorn of the Dunedain.

In the passing generations we've forgotten things. We've forgotten the compromises we've made; we've forgotten the reasons we've made them. We're no longer poor. The machine on which I'm typing this - my personal machine, on my desk, used by no-one but me - has the processor power of slightly over six thousand DEC VAXes; it has the one hundred and sixty two thousand times as much core store as the ICL 1900 mainframe on which I learned Pascal. Yet both the VAX and the 1900 were powerful machines, capable of supporting dozens of users at the same time. Compared to each individual user of the VAX, of the 1900, I am now incalculably rich. Vastly. Incomprehensibly.

And it's not just me. With the exception of those poor souls writing embedded code for micro-controllers, every programmer now working has processor and store available to him which the designers of the languages and operating systems we still use could not even have dreamed of. UNIX was designed when 32 bit machines were new, when 16,384 bytes was a lot of memory and very expensive. VMS - what we now call 'Windows XP' - is only a few years younger.

The compromises of poverty are built into these operating systems, into our programming languages, into our brains as programmers; so deeply ingrained that we've forgotten that they are compromises, we've forgotten why we chose them. Like misers counting grains on the granary floor while outside the new crop is falling from the stalks for want of harvesting, we sit in the middle of great riches and behave as though we were destitute.

One of the things which has made this worse in recent years is the rise of Java, and, following slavishly after it, C#. Java is a language which was designed to write programs for precisely those embedded micro-controllers which are still both store and mill poor. It is a language in which the mind-set of poverty is consciously ingrained. And yet we have adopted it as a general purpose programming language, something for which it is not at all suitable, and in doing so have taught another generation of programmers the mind-set of poverty. Java was at least designed; decisions were made for reasons, and, from the point of view of embedded micro-controllers, those reasons were good. C# is just a fit of pique as software. Not able to 'embrace and extend' Java, Microsoft aped it as closely as was possible without breaching Sun's copyright. Every mistake, every compromise to poverty ingrained in Java is there in C# for all the world to see.

It's time to stop this. Of course we're not as wealthy as Turing. Of course our machines still do not have infinite store. But we now have so much store - and so many processor cycles - that we should stop treating them as finite. We should program as if we were programming for U.

Store, Name and Value

So let's start with what we store, what we compute on: values. For any given column within a table, for every given instance variable in a class, every record, every object is constrained to have a value with a certain format.

This is, of course, historical. Historically, when storage was expensive we stored textual values in fields of fixed width to economise on storage; we still do so largely because that's what we've always done rather than because there's any longer any rational reason to. Historically, when storage and computation were expensive, we stored numbers in twos-complement binary strings in a fixed number of bytes. That's efficient, both of store and of mill.

But it is no longer necessary, nor is it desirable, and good computer languages such as LISP transparently ignores the difference between the storage format of different numbers. For example:

(defun factorial (n)
  (cond 
    ((eq n 1) 1)
    (t (* n (factorial (- n 1))))))

;; a quick way to generate very big numbers...

We can add the value of factorial 100 to an integer, say 2, in just
the same way that we can add any other two numbers:

(+ (fact 100) 2)
933262154439441526816992388562667004907159682643816214685929638952 175999932299156089414639761565182862536979208272237582511852109168 64000000000000000000000002

We can multiply the value of factorial 100 by a real number, say pi, in just the same way as we can add any other two numbers:

(* (factorial 100) pi)
2.931929528260332*10^158

The important point to note here is that there's no explicit call to a bignum library or any other special coding. LISP's arithmetic operators don't care what the underlying storage format of a number is, or rather, are able transparently to handle any of the number storage formats - including bignums - known to the system. There's nothing new about this. LISP has been doing this since the late 1960s. Which is as it should be, and, indeed, as it should be in storage as well as in computation.

A variable or a database field (I'll treat the two as interchangeable, because, as you will see, they are) may reasonably have a validation rule which says that a value which represents the longitude of a point on the Earth in degrees should not contain a value which is greater than 360. That validation rule is domain knowledge, which is a good thing; it allows the system to have some vestige of common sense. The system can then throw an exception when it is asked to store 764 as the longitude of a point, and this is a good thing.

Why then should a database not throw an exception when, for example, a number is too big to fit in the internal representation of a field? To answer, here's a story I heard recently, which seems to be apocryphal, but which neatly illustrates the issue just the same.
The US Internal Revenue Service have to use a non-Microsoft computer to process Bill Gate's income tax, because Microsoft computers have too small an integer representation to represent his annual income.
Twos complement binary integers stored in 32 bits can represent plus or minus 2,147,483,648, slightly over two US billion. So it's easily possible that Bill Gates' income exceeds this. Until recently, Microsoft operating systems ran only on computers with a register size of 32 bits. Worryingly, the default integer size of my favourite database, Postgres, is also 32 bits.

This is just wrong. Nothing in the domain of income places any fixed upper bound on the income a person may receive. Indeed, with inflation, the upper limit on incomes as quantity is likely to continue to rise. Should we patch the present problem by upping the size of the integer to eight bytes?
In Hungary after the end of World War II inflation ran at 4.19 ? 1016 percent per month - prices doubled every 15 hours. Suppose Gates' income in US dollars currently exceeds the size of a thirty two bit integer, it would take at most 465 hours - less than twenty days - to exceed US$9,223,372,036,854,775,808. What's scary is how quickly you'd follow him. If your present annual salary is just thirty three thousand of your local currency units, then given that rate of inflation, you would overflow a sixty-four bit integer in just 720 hours, or less than a month.

Lots of things in perfectly ordinary domains are essentially unbounded. They aren't shorts. They aren't longs. They aren't doubles. They're numbers. And a system asked to store a number should store a number. Failure to store a number because it's size violates some constraint derived from domain knowledge is desirable behaviour; failure to store a number because it size violates the internal storage representation of the system is just bad, outdated, obsolete system design. Yes, it's efficient of compute power on thirty-two bit processors to store values in thirty-two bit representations. Equally, it's efficient of disk space for a database to know in advance just how mush disk it has to reserve for each record in a table, so that to skip to the Nth record it merely has to skip forward (N * record-size) bytes.

But we're no longer short of either processor cycles or disk space. For a database to reject a value because it cannot be stored in a particular internal representation is industrial archaeology. It is a primitive and antiquated workaround from days of hardware scarcity. In these days of post-scarcity computing, it's something we should long have forgotten, long have cast aside.

This isn't to say that integers should never be stored in thirty-two bit twos complement binary strings. Of course they should, when it's convenient to do so. It's a very efficient storage representation. Of course, when a number overflows a thirty two bit cell, the runtime system has got to throw an exception, has got to deal with it, and consequently the programmer who writes the runtime system has still got to know about and understand the murky aspects of internal storage formats.

Perhaps the language designer, and the programmer who writes the language compiler should, too, but personally I don't think so. I think that at the layer in the system - the level of abstraction - at which the compiler writer works, the operator 'plus' should just be a primitive. It takes two numbers, and returns a number. That's all. The details of whether that's a float, a double, a rational or a bignum should not be in the least relevant at the level of language. There is a difference which is important between a real number and an integer. The old statistical joke about the average family having 2.4 children is funny precisely because it violates our domain knowledge. No family has 2.4 children. Some things, including children, are discrete, however indiscreet you may think them. They come in integral quantities. But they don't come in short quantities or long quantities. Shorts and longs, floats and doubles are artefacts of scarcity of store. They're obsolete.

From the point of view of the runtime designer, the difference between a quantity that can be stored in two bytes, or four, or eight must matter. From the point of view of the application designer, the language designer, even the operating system designer, they should disappear. An integer should be an integer, whether it represents the number of toes on your left foot (about 5), the number of stars in the galaxy (about 1x1011) or the number of atoms in the universe (about 1x1079). Similarly, a real number should be just a real number.

This isn't to say we can't do data validation. It isn't to say we can't throw a soft exception - or even a hard one - when a value stored in a variable or field violates some expectation, which may be an expectation about size. But that should be an expectation based on domain knowledge, and domain knowledge alone; it should not be an expectation based on implementation knowledge.

Having ranted now for some time about numbers, do you think I'm finished? I'm not. We store character values in databases in fields of fixed size. How big a field do we allocate for someone's name? Twenty four characters? Thirty-two? We've all done it. And then we've all found a person who violates our previous expectation of the size of a name, and next time we've made the field a little bigger. But by the time we've made a field big enough to store Charles Philip Arthur George Windsor or Sirimavo Ratwatte Dias Bandaranaike we've negated the point of fixed width fields in the first place, which was economy. There is no natural upper bound to the length of a personal name. There is no natural upper bound to the length of a street address. Almost all character data is a representation at some level of things people say, and the human mind doesn't work like that.

Of course, over the past fifty years, we've tried to make the human mind work like that. We've given addresses standardised 'zip codes' and 'postcodes', we've given people standardised 'social security numbers' and 'identity codes'. We've tried to fit natural things into fixed width fields; we've tried to back-port the inadequacies of our technology onto the world. It's stupid, and it's time we stopped.

So how long is a piece of string? How long is a string of characters? It's unbounded. Most names are short, because short names are convenient and memorable. But that does not mean that for any given number of characters, it's impossible that there should be something with a normal name of that length. And names are not the only things we store in character strings. In character strings we store things people say, and people talk a lot.

At this point the C programmers, the Java programmers are looking smug. Our strings, they say, are unbounded. Sorry lads. A C string is a null terminated sequence of bytes. It can in principle be any length. Except that it lives in a malloced lump of heap (how quaint, manually allocating store) and the maximum size of a lump of heap you can malloc is size_t, which may be 231, 232, 263 or 264 depending on the system. Minus one, of course, for the null byte. In Java, similarly, the size of a String is an int, and an int, in Java, means 231.

Interestingly, Paul Graham, in his essay 'The Hundred YearLanguage', suggests doing away with stings altogether, and representing them as lists of characters. This is powerful because strings become S-expressions and can be handled as S-expressions; but strings are inherently one-dimensional and S-expressions are not. So unless you have some definite collating sequence for a branching 'string' it's meaning may be ambiguous. Nevertheless, in principle and depending on the internal representation of a CONS cell, a list of characters can be of indefinite extent, and, while it isn't efficient of storage, it is efficient of allocation and deallocation; to store a list of N characters does not require us to have a contiguous lump of N bytes available on the heap; nor does it require us to shuffle the heap to make a contiguous lump of that size available.

So; to reprise, briefly.

A value is just a value. The internal representation of a value is uninteresting, except to the designer and author of the runtime system - the virtual machine. For programmers at every other level the internal representation of every value is DKDC: don't know, don't care. This is just as true of things which are fundamentally things people say, things which are lists and things which are pools, as it is of numbers. The representation that the user - including the programmer - deals with is the representation which is convenient and comfortable. It does not necessarily have anything to do with the storage representation; the storage representation is something the runtime system deals with, and that the runtime system effectively hides. Operators exposed by the virtual machine are operators on values. It is a fundamental error, a failure of the runtime designer's most basic skill and craft, for a program ever to fail because a value could not be represented in internal representation - unless the store available to the system is utterly exhausted.

Excalibur and the Pool

A variable is a handle in a namespace; it gives a name to a value, so that we can recall it. Storing a value in a variable never causes an exception to be thrown because the value cannot be stored. But it may, reasonably, justifiably, throw an exception because the value violates domain expectations. Furthermore, this exception can be either soft or hard. We might throw a soft exception if someone stored, in a variable representing the age of a person in years, the value 122. We don't expect people to reach one hundred and twenty two years of age. It's reasonable to flag back to whatever tried to set this value that it is out of the expected range. But we should store it, because it's not impossible. If, however, someone tries to store 372 in a variable representing longitude in degrees, we should throw a hard exception and not store it, because that violates not merely a domain expectation but a domain rule.

So a variable is more than just a name. It is a slot: a name with some optional knowledge about what may reasonably be associated with itself. It has some sort of setter method, and possibly a getter method as well.

I've talked about variables, about names and values. Now I'll talk about the most powerful abstraction I use - possibly the most powerful abstraction in software - the namespace. A namespace is a sort of pool into which we can throw arbitrary things, tagging each with a distinct name. When we return to the pool and invoke a name, the thing in the pool to which we gave that name appears.

Regularities: tables, classes, patterns

Database tables, considered as sets of namespaces, have a special property: they are regular. Every namespace which is a record in the same table has the same names. A class in a conventional object oriented language is similar: each object in the class has the same set of named instance variables. They match a pattern: they are in fact constrained to match it, simply by being created in that table or class.
Records in a table, and instance variables in a class, also have another property in common. For any given name of a field or instance variable, the value which each record or object will store under that name is of the same type. If 'Age' is an integer in the definition of the table or class, the Age of every member will be an integer. This property is different from regularity, and, lacking a better word for it, I'll call it homogeneity. A set of spaces which are regular (i.e. share the same names) need not be homogeneous (i.e. share the same value types for those names), but a set which is homogeneous must be regular.

But records in a table, in a view, in a result set are normally in themselves values whose names are the values of the key field. And the tables and views, too, are values in a namespace whose names are the table names, and so on up. Namespaces, like Russian dolls, can be nested indefinitely. By applying names to the nested spaces at each level, we can form a path of names to every space in the meta-space and to each value in each space, provided that the meta-space forms an acyclic directed graph (this is, after all, the basis of the XPath language. Indeed, we can form paths even if the graph has cycles, provided every cycle in the graph has some link back to the root.

Social mobility

It's pretty useful to gather together all objects in the data space which match the same pattern; it's pretty useful for them all to have distinct names. So the general concept of a regularity which is itself a namespace is a useful one, even if the names have to be gensymed.

To be in a class (or table), must a space be created in that class (or table)? I don't see why. One of my earlier projects was an inference engine called Wildwood, in which objects inferred their own class by exploring the taxonomy of classes until they found the one in which they felt most comfortable. I think this is a good model. You ought to be able to give your dataspace a good shake and then pull out of it as a collection all the objects which match any given pattern, and this collection ought to be a namespace. It ought to be so even if the pattern did not previously exist in the data space as the definition of a table or class or regularity or whatever you care to call it.

A consequence of this concept is that objects which acquire new name-value pairs may move out of the regularity in which they were created either to exist as stateless persons in the no-man's land of the dataspace, or into a new regularity; or may form the seed around which a new regularity can grow. An object which acquires a value for one of its names which violates the validation constraints of one homogeneity may similarly move out into no-man's land or into another. In some domains, in some regularities, it may be a hard error to do this (i.e. the system will prevent it). In some domains, in some regularities, it may be a soft error (i.e. the system allows it under protest). In some domains, in some regularities, it may be normal; social mobility of objects will be allowed.

Permeability

There's another feature of namespaces which gets hard wired into lots of software structures without very often being generalised, and that is permeability, semi-translucency. In my toolkit Jacquard, for example, values are first searched for in the namespace of http parameters; if not found there, in the namespace of cookies; next, in the namespace of session variables, then in local configuration parameters, finally in global configuration parameters. There is in effect a layering of semi-translucent namespaces like the veils of a dancer.

It's not a pattern that's novel or unique to Jacquard, of course. But in Jacquard it's hard wired and in all the other contexts in which I've seen this pattern it's hardwired. I'd like to be able to manipulate the veils; to add, or remove, of alter the layering. I'd like this to be a normal thing to be able to do.

The Name of the Rose: normativeness and hegemony

I have a friend called Big Nasty. Not everyone, of course, calls him Big Nasty. His sons call him 'Dad'. His wife calls him 'Norman'. People who don't know him very well call him 'Mr Maxwell'. He does not have one true name.

The concept of a true name is a seductive one. In many of the traditions of magic - and I have always seen software as a technological descendant or even a technological implementation of magic - a being invoked by its true name must obey. In most modern programming languages, things tend to have true names. There is a protocol for naming Java packages which is intended to guarantee that every package written anywhere in the world has a globally unique true name. Globally unique true names do then have utility. It's often important when invoking something to be certain you know exactly what it is you're invoking.

But it does not seem to me that this hegemonistic view of the dataspace is required by my messy conception. Certainly it cannot be true that an object has only one true name, since it may be the value of several names within several spaces (and of course this is true of Java; a class well may have One True Name, but I can still create an instance variable within an object whose name is anythingILike, and have its value is that class).

The dataspace I conceive is a soup. The relationships between regularities are not fixed, and so paths will inevitably shift. And in the dataspace, one sword can be in many pools - or even many times in the same pool, under different names - at the same time. We can shake the dataspace in different ways to see different views on the data. There should be no One True hegemonistic view.

This does raise the question, 'what is a name'. In many modern relational databases, all primary keys are abstract and are numbers, even if natural primary keys exist in the data - simply because it is so easy to create a table with an auto-incrementer on the key field. Easy, quick, convenient, lazy, not always a good thing. In terms of implementation details, namespaces are implemented on top of hash tables, and any data object can be hashed. So can anything be a name?

In principle yes. However, my preference would be to purely arbitrarily say no. My preference would be to say that a name must be a 'thing people say', a pronounceable sequence of characters; and also, with no specific upper bound, reasonably short.

The Problem with Syntax

Let me start by saying that I really don't understand the problem with syntax. Programming language designers spend a lot of time worrying about it, but I believe they're simply missing the point. People say 'I can't learn LISP because I couldn't cope with all the brackets'. People - the Dylan team, for one - have developed systems which put a skin of 'normal' (i.e., ALGOL-like) syntax on top of LISP. I personally won't learn Python because I don't trust a language where white space is significant. But in admitting that prejudice I'm admitting to a mistake which most software people make.

We treat code as if it wasn't data. We treat code as if it were different, special. This is the mistake made by the LISP2 brigade, when they gave their LISPs (ultimately including Common LISP) separate namespaces, one for 'code' and one for 'data'. It's a fundamental mistake, a mistake which fundamentally limits our ability to even think about software.

What do I mean by this?

Suppose I ask my computer to store pi, 3.14159265358979. Do I imagine that somewhere deep within the machine there is a bitmap representation of the characters? No, of course I don't. Do I imagine there's a vector starting with the bytes 50 46 49 51 49 53 57 ...? Well, of course, there might be, but I hope there isn't because it would be horribly inefficient. No, I hope and expect there's an IEEE 754 binary encoding of the form 01100100100001111...10. But actually, frankly, I don't know, and I don't care, provided that it is stored and that it can be computed with.

However, as to what happens if I then ask my computer to show me the value it has stored, I do know and I do care. I expect it to show me the character string '3.14159265358979' (although I will accept a small amount of rounding error, and I might want it to be truncated to a certain number of significant figures). The point is, I expect the computer to reflect the value I have stored back to me in a form which it is convenient for me to read, and, of course, it can.

We don't, however, expect the computer to be able to reflect back an executable for us in a convenient form, and that is in itself a curious thing. If we load, for example, the UNIX command 'ls' into a text editor, we don't see the source code. We see instead, the raw internal format. And the amazing thing is that we tolerate this.

It isn't even that hard to write a 'decompiler' which can take a binary and reflect back source code in a usable form. Here, for example, is a method I wrote:

    /**
     * Return my action: a method, to allow for specialisation. Note: this
     * method was formerly 'getAction()'; it has been renamed to disambiguate
     * it from 'action' in the sense of ActionWidgets, etc.
     */
    public String getNextActionURL( Context context ) throws Exception
    {
        String nextaction = null;

        HttpServletRequest request =
            (HttpServletRequest) context.get( REQUESTMAGICTOKEN );

        if ( request != null )
        {
            StringBuffer myURL = request.getRequestURL(  );

            if ( action == null )
            {
                nextaction = myURL.toString(  );

                // If I have no action, default my action
                // to recall myself
            }
            else
            {
                nextaction =
                    new URL( new URL( myURL.toString(  ) ), action ).toString(  );

                // convert my action into a fully
                // qualified URL in the context of my
                // own
            }
        }
        else
        { // should not happen!
            throw new ServletException( "No request?" );
        }

        return nextaction;
    }

and here is the result of 'decompiling' that method with an
open-source Java decompiler, jreversepro:

    public String getNextActionURL(Context context)
                throws Exception
    {
         Object object = null;
         HttpServletRequest httpservletrequest = 
              (HttpServletRequest)context.get( "servlet_request");
         String string;
         if (httpservletrequest != null) {
              StringBuffer stringbuffer = httpservletrequest.getRequestURL();
              if (action == null)
                   string = stringbuffer.toString();
              else
                   string = new URL(new URL(stringbuffer.toString()) ,
                                    action).toString();
         }
         else
              throw new ServletException("No request?");

         return (string);
    }

As you can see, the comments have been lost and some variable names
have changed, but the code is essentially the same and is perfectly
readable. And this is with an internal form which has not been
designed with decompilation in mind. If decompilation had been designed
for in the first place, the binary could have contained pointers to
the variable names and comments. Historically we haven't done this,
both for 'intellectual property' reasons and because of store
poverty. In future, we can and will.

Again, like so much in software, this isn't actually new. The microcomputer BASICs of the seventies and eighties 'tokenised' the source input by the user. This tokenisation was not of course compilation, but it was analogous to it. The internal form of the program that was stored was much terser then the representation the user typed. But when the user asked to list the program, it was expanded into its original form.

Compilation - even compilation into the language of a virtual machine - is much more sophisticated than tokenising, of course. Optimisation means that many source constructs may map onto one object construct, and even that one source construct may in different circumstances map onto many object constructs. Nevertheless it is not impossible - nor even hugely difficult - to decompile object code back into readable, understandable and editable source.

But Java syntax is merely a format. When I type a date into a computer, say '05-02-2005', and ask it to reflect that date back to me, I expect it to be able to reflect back to me '05-02-2006'. But I expect it to be able to reflect back to an American '02-05-2006', and to either of us 'Sunday 5th February 2006' as well. I don't expect the input format to dictate the output format. I expect the output format to reflect the needs and expectations of the person to whom it is displayed.

To summarise, again.

Code is data. The internal representation of data is Don't Know, Don't Care. The output format of data is not constrained by the input format; it should suit the use to which it is to be put, the person to whom it is to be displayed.

Thus if the person to whom my Java code is reflected back is a LISP programmer, it should be reflected back in idiomatic LISP syntax; if a Python programmer, in idiomatic Python syntax. Let us not, for goodness sake, get hung up about syntax; syntax is frosting on the top. What's important is that the programmer editing the code should edit something which is clearly understandable to him or her.

This has, of course, a corollary. In InterLISP, one didn't edit files 'out of core' with a text editor. One edited the source code of functions as S-expressions, in core, with a structure editor. The canonical form of the function was therefore the S-expression structure, and not the printed representation of it. If a piece of code - a piece of executable binary, or rather, of executable DKDC - can be reflected back to users with a variety of different syntactic frostings, none of these can be canonical. The canonical form of the code, which must be stored in version control systems or their equivalent, is the DKDC itself; and to that extent we do care and do need to know, at least to the extent that we need to know that the surface frosting can again be applied systematically to the recovered content of the archive.

If God does not write LISP

I started my professional life writing LISP on Xerox 1108s and, later, 1186s - Dandelions and Daybreaks, if you prefer names to numbers. When I wanted to multiply two numbers, I multiplied two numbers. I didn't make sure that the result wouldn't overflow some arbitrary store size first. When a function I wrote broke, I edited in its structure in its position on the stack, and continued the computation. I didn't abort the computation, find a source file (source file? How crude and primitive), load it into a text editor, edit the text, save it, check for syntax errors, compile it, load the new binary, and restart the computation. That was more than twenty years ago. It is truly remarkable how software development environments have failed to advance - have actually gone backwards - in that time.

LISP's problem is that it dared to try to behave as though it were a post-scarcity language too soon. The big LISP machines - not just the Xerox machines, the LMI, Symbolics, Ti Explorer machines - were vastly too expensive. My Daybreak had 8Mb of core and 80Mb of disk when PCs usually didn't even have the full 640Kb. They were out-competed by UNIX boxes from Sun and Apollo, which delivered less good software development environments but at a much lower cost. They paid the price for coming too early: they died. And programmers have been paying the price for their failure ever since.

But you only have to look at a fern moss, a frond of bracken, an elm sapling, the water curling over the lip of a waterfall, to know that if God does not write LISP He writes some language so similar to LISP as to make no difference. DNA encodes recursive functions; turbulent fluids move in patterns formed by recursion, whorls within whorls within whorls.

The internal structure, then, of the post scarcity language is rather lisp-like. Don't get hung up on that! Remember that syntax isn't language, that the syntax you see need not be the syntax I see. What I mean by saying the language is lisp-like is that its fundamental operation is recursion, that things can easily be arranged into arbitrary structures, that new types of structure can be created on the fly, that new code (code is just data, after all) can be created and executed on the fly, that there is no primacy of the structures and the code created by the programmer over the structures and code created by the running system; that new code can be loaded and linked seamlessly into a running system at any time. That instead of little discrete programs doing little discrete specialised things in separate data spaces each with its own special internal format and internal structures, the whole data space of all the data available to the machine (including, of course, all the code owned by the machine) exists in a single, complex, messy, powerful pool. That a process doesn't have to make a special arrangement, use a special protocol, to talk to another process or to exchange data with it.

In that pool, the internal storage representation of data objects is DKDC. We neither have nor need to have access to it. It may well change over time without application layer programs even being aware or needing to be aware of the change, certainly without them being recompiled.

The things we can store in the dataspace include:


  • integers of any size
  • reals to any appropriate degree of precision
  • rationals, complex numbers, and other things we might want to compute with
  • dates, times, and other such useful things
  • things people say of any extent, from names to novels
  • lists of any extent, branching or not, circular or not
  • slots associations of names with some setter and, perhaps, getter knowledge which determine what values can be stored under that name
  • namespaces collections, extensible or not, of slots
  • regularities collections of namespaces each of which share identical names
  • homogeneities collections of namespaces each of which share identical slots
  • functions all executable things are 'functions' in a lispy sense. They are applied to arguments and return values. They may or may not have internal expectations as to the value type of those arguments.
  • processes I don't yet have a good feeling for what a post-scarcity process looks like, at top level. It may simply be a thread executing a function; I don't know. I don't know whether there needs to be one specially privileged executive process.


Things which we no longer store - which we no longer store because they no longer have any utility - include


  • shorts, longs, doubles, etc specific internal representation types. You saw that coming.
  • tables, and with them, relational databases and relational database management systems no longer needed because the pool is itself persistent (although achieving the efficiency of data access that mature RDBMS give us may be a challenge).
  • files You didn't see that coming?


Files are the most stupid, arbitrary way to store data. Again, with a persistent data pool, they cease to have any purpose. Post scarcity, there are no files and there is no filesystem. There's no distinction between in core and out of core. Or rather, if there are files and a filesystem, if there is a distinction between in core and out of core, that distinction falls under the doctrine of DKDC: we don't know about it, and we don't care about it. When something in the pool wants to use or refer to another something, then that other something is available in the pool. Whether it was there all along, or whether it was suddenly brought in from somewhere outside by the runtime system, we neither know nor care. If things in the pool which haven't been looked at for a long time are sent to sulk elsewhere by the runtime system that is equally uninteresting. Things which are not referenced at all, of course, may be quietly dropped by the runtime system in the course of normal garbage collection.

One of the things we've overloaded onto the filesystem is security. In core, in modern systems, each process guards its own pool of store jealously, allowing other processes to share data with it only through special channels and protocols, even if the two processes are run by the same user identity with the same privilege. That's ridiculous. Out of core, data is stored in files often with inscrutable internal format, each with its own permissions and access control list.

It doesn't need to be that way. Each primitive data item in core - each integer, each list node, each slot, each namespace - can have its own access control mechanism. Processes, as such, will never 'own' data items, and will certainly never 'own' chunks of store - at the application layer, even the concept of a chunk of store will be invisible. A process can share a data item it has just created simply by setting an appropriate access policy on it, and programmers will be encouraged normally to be as liberal in this sharing as security allows. So the slot Salary of the namespace Simon might be visible only to the user Simon and the role Payroll, but that wouldn't stop anyone else looking at the slot Phone number of the same namespace.

Welcome, then, to post scarcity computing. It may not look much like what you're used to, but if it doesn't it's because you've grown up with scarcity, and even since we left scarcity behind you've been living with software designed by people who grew up with scarcity, who still hoard when there's no need, who don't understand how to use wealth. It's a richer world, a world without arbitrary restrictions. If it looks a lot like Alan Kay (and friends)'s Croquet, that's because Alan Kay has been going down the right path for a long time.

Saturday, 18 December 2004

A Journey to the turning of the year


Have you ever considered how nice it must be to live in Iceland? I mean, apart from the spectacular scenery and the friendly people. Just think, if I lived in Iceland I could have lounged in bed this morning. I could have slept in till the back of eleven, got up, had a leisurely breakfast, cycled round the block, and come home for a well earned bath in free geothermal hot water with the satisfaction of something significant achieved.


Unfortunately I don't.

I mean, the idea of cycling from sunrise until sunset is the sort of thing which sounds like a cool idea in the balmy days of September. It was a cool idea. Indeed, in parts, it was a shockingly cold idea, but I get ahead of myself. Back in September I had the idea of cycling from sunrise to sunset, and if you're going to cycle from sunrise to sunset the sensible time to do it is on the shortest day of the year. OK, so today wasn't quite the shortest day of the year, but let's not sweat the small stuff.

It wasn't my intention to do this on my own. Indeed, having announced it to my club back in September, I sent an email to the club's mailing list last week:

I'm looking for some very, very stupid people.


I'm looking for some very stupid people because, primarily, I'm even more stupid myself: I'm planning to go for a bike ride on Saturday. From the moment the sun comes up, to the moment the sun  sets. That's 8.43 am to 3.41 pm. It is going to be cold. It is going to be tough. It is going to be a long day. If you're really, really stupid, please come with me...


Surprisingly, I had a volunteer. Unsurprisingly, it wasn't for the whole distance. So when I arrived at the appointed meeting place in Castle Douglas at half past eight this morning I wasn't hugely surprised to find nobody there. I waited around for ten minutes in the cold and the rain, and then, knowing no-one else was coming, set off.

It was fairly light and growing lighter fast, which was just as well because within half a mile my headlight fell off and smashed (it was a cheap old one, so no huge loss - I hadn't taken my lumicycles on the grounds of weight). Within two miles the rain had cleared, and I was cycling along at a nice easy pace, crossing the Dee for the first time at Glenlochar. By Laurieston I was warmed up enough to stop and swap my big padded winter gloves for track mits. Down the shores of Woodhall it was a really beautiful morning, and just past Mossdale there was the most superb complete rainbow, spanning the landscape from horizon to horizon. Of course, a rainbow meant another shower, but once again it was light, thin, not very wetting, and soon past. And at fourteen miles out along the shore of Loch Ken I met Chris coming the other way to meet me.

This was a slightly mixed blessing. He was extremely good company, and we enjoyed pleasant conversation, but he was also significantly quicker than me up hill - and, indeed, the steeper the climb the greater the difference. I plead in mitigation that he had sensible hill-climbing gears on his bike, and I, errm, didn't.  But despite the fact that the route took us from below the 50 metre contour to above the 250 metre, the climb is on the whole gradual - with a few short, sharp shocks. At New Galloway we went straight on out by the kirk for the first of those short, sharp shocks, and thence up the west side of the river to the Earlstoun Loch dam for the second. The high hills were white with snow - the whole ridge of the Rhinns of Kells looked properly arctic, and the Cairnsmore of Carsphairn was a great white spike pointed at the sky. And thus to the long, slow, gruelling climb up to Carsphairn. But we reached Carsphairn much earlier than I had expected, and went straight on through, heading for what had been my personal goal - the Green Well of Scotland, allegedly the last place in Britain where pagan religion was openly practised, as late as the eighteenth century. We got there, and were going well, and were still ahead of schedule, so we headed on up towards the watershed. By now there was a little bit of snow down to the roadside - not a lot, but enough to make it bitterly cold. And by about 11:30 we got to the point where we were clicking up onto our big rings as the climb levelled out.

At the Ayrshire border we turned and blasted back down towards Carsphairn. Climbing, we'd had a north wind against us which hadn't felt strong enough to be much nuisance, but now with both wind and gradient helping we made exceedingly good speed, and were down into Carsphairn again about twelve. Carsphairn is not, let's face it, the world's most bustling metropolis, but it does boast a bar with a large sign inscribed 'meals served all day'. The sign lies. Fortunately - and remarkably for a place so small  - Carsphairn also boasts a tiny shop, which sold us rolls and polystyrene beakers of instant soup. We drank these sitting on a bench at the roadside; but we didn't sit for long, because if cycling in these conditions was cold, just sitting was colder.

Heading south we took the Moniaive road down the East bank of the river. The weather was getting decidedly colder, and Chris stopped to put his warmer gloves on. This struck me as a good idea, and I put mine on, too. Shortly we came to the junction where the Dalry road splits off, and Chris had planned to go home down this. I had sort of planned to cross the watershed down to Lochinvar and thus down the Urr, but neither of us were particularly keen to be cycling alone on those lonely upland roads, so I turned right with Chris.

And within a couple of miles we got a sharp lesson on why it's not clever to cycle them alone. The High Bridge of Ken is a narrow stone bridge, about three metres wide between its high stone parapets, and about fifty metres long. It sits at the bottom of a steep-sided east-west glen, with a sharp turn onto it and a sharp turn off it. Steep sided glen, high parapets, very cold day: you're ahead of me, aren't you? At the same time, face with a nice swoopy descent onto the bridge and a nice tight turn off it, what would you have done?

It was just as I cranked the bike over into the turn off the bridge at about twenty five miles an hour that both tyres let go, suddenly, together, and I had that awful moment of knowing.

Oh, shit, this is going to hurt - a lot.

Curiously, it helped that I was cranking into the bend. The back wheel tried to overtake the front, spinning the bike around to about 45 degrees to its direction of travel, and long after I thought I was at the point of no return got enough grip to bring me back towards upright. I steered into the skid and got the bike under control again, but for the next several miles I felt decidedly shaky and took it a lot slower. Which was a shame because we were dropping down through a series of deliciously swoopy back roads towards Ealstoun.

On one of these - which would have been a stiffish climb the other way - Chris stopped to show me a little roadside memorial, nicely kept with flowers:

'In memory of Johnny Stirling, who died here while cycling   in Bonny Galloway'


Looking at the hill, one could see how one might; but looking out over the glen with the lochs in the bottom and the high snow covered hills on the far side, it felt as though it would not be a bad way - or a bad place - to go.

And thus down to Earlstoun, and into St John's Town of Dalry, and to Chris's house, where I stopped for coffee. I left at three o'clock, and considered my onward route. It's 14 miles down the A713 into Castle Douglas, and I had been averaging 12 miles per hour. I was due to finish at 3:41. Chris advised me against riding down the A713 on the basis that it's busy; but busy is relative and busy by Galloway standards is not busy as understood elsewhere, and by Galloway standards the A 713 down Loch Ken is relatively flat. Also, I had come up the west side of Loch Ken, so going back down the west side didn't feel particularly interesting. So I started off down the A713 thinking I might cut across the watershed into the Urr valley later. However, when I reached the junction at Balmaclellan, it said Corsock 9 miles, and I knew those were nine pretty hilly miles. I didn't feel like it. I cycled on down Loch Ken, past the sailing centre, past the viaduct, through Parton, down through Crossmichael.

By now I was into the home stretch, with only a few miles to go. But I was also feeling it. There were a couple of little detours I could make to add a few miles to the route and get me closer to the magic 3:41, but I didn't take them partly because my legs didn't want to and partly because, as my speed was dropping off, it was beginning to look as if I wouldn't need to. At some point - way later than I should have - I realised I was just running out of blood sugar to burn, and stopped to switch on my lights and get a cereal bar out of my bag.

There's a state you get into (or at least, I get into) where you are just cycling, not doing anything else. I remember watching the trip click up to 63.59 miles, expecting it to change to 64.00 and being completely bewildered when it instead went to 63.60 and then to 63.61; I was so chilled and tired I was confusing miles with minutes. But miles and minutes both rolled on and very soon I was passing under the bypass, onto urban streets, track-standing in the congested traffic of King Street as motorists jostled for parking spaces, getting off the bike stumbling tired and practically staggering into the bike shop, to be greeted with hot sweet tea and a compulsory mince pie and scone. Which were most welcome.

OK, so I finished all of eight minutes early. So sue me. Total distance, just over 65 miles by my computer, or, in morale-boosting metric speak, 104 Km. Total time actually cycling, about six hours. And, despite my whingeing, I enjoyed it, and I'm glad I did it.

And thus back home to a bath with water heated with very expensive oil. I suppose I'd better get on the phone to the Icelandic consulate and talk to them about emigration...

Thursday, 16 December 2004

Let's hear it for the Mullwarchar!


Radio 4's 'Today' programme has been asking for nominations for a 'listeners peer', and I've been listening with half an ear to the suggestions. And what I've been hearing is more of the same old same old; the soi disant great and good, and, more particularly, the metropolitan great and good. So I thought I'd make a nomination completely outside the London box.


The Mullwarchar, admittedly, doesn't say a lot. The Mullwarchar is notoriously neither clubbable nor friendly; not a particularly sociable being. But the Mullwarchar has made a great contribution to our public life, taking a leading role in the campaign against the dumping of nuclear materials and a number of other environmental campaigns. The Mullwarchar has also made a significant contribution to leisure activities and to appreciation of wilderness, and thus to the spiritual life of the nation.

But the most important reason for nominating the Mullwarchar is this: this mountain will not come to Mahomet. The House of Lords is comprised entirely of urban people, of people not merely prepared but happy to spend their working lives in the most crowded, the  most polluted, the most unpleasant place on the island of Britain. Such people are by definition abnormal and unrepresentative.

It would do our parliamentarians good once a year to go to the mountain: to lift up their collective eyes to the hills, to be in a place where man and all his works are utterly insignificant. To get some sense of scale.

And perhaps, on their way into the wilderness and on their way out again, they would have the opportunity to pass through places where the people of Britin - the people they make the laws for - actually live.

So let's hear it for the Mullwarchar: certainly the most noble, unquestionably the most ancient, without doubt the most puissant lord ever nominated to the House. And very probably the wisest.

Let's hear it for the Mullwarchar!

Radio 4's 'Today' programme has been asking for nominations for a 'listeners peer', and I've been listening with half an ear to the suggestions. And what I've been hearing is more of the same old same old; the soi disant great and good, and, more particularly, the metropolitan great and good. So I thought I'd make a nomination completely outside the London box.

The Mullwarchar, admittedly, doesn't say a lot. The Mullwarchar is notoriously neither clubbable nor friendly; not a particularly sociable being. But the Mullwarchar has made a great contribution to our public life, taking a leading role in the campaign against the dumping of nuclear materials and a number of other environmental campaigns. The Mullwarchar has also made a significant contribution to leisure activities and to appreciation of wilderness, and thus to the spiritual life of the nation.

But the most important reason for nominating the Mullwarchar is this: this mountain will not come to Mahomet. The House of Lords is comprised entirely of urban people, of people not merely prepared but happy to spend their working lives in the most crowded, the most polluted, the most unpleasant place on the island of Britain. Such people are by definition abnormal and unrepresentative.
It would do our parliamentarians good once a year to go to the mountain: to lift up their collective eyes to the hills, to be in a place where man and all his works are utterly insignificant. To get some sense of scale.

And perhaps, on their way into the wilderness and on their way out again, they would have the opportunity to pass through places where the people of Britin - the people they make the laws for - actually live.

So let's hear it for the Mullwarchar: certainly the most noble, unquestionably the most ancient, without doubt the most puissant lord ever nominated to the House. And very probably the wisest.

Monday, 13 December 2004

Spectacle and courage


In trying to write a concise review of the extended edition of Peter Jackson's adaptation of The Return of the King, one is faced with three different topics each worthy of consideration. The first is this cut of The Return of the King as a movie; the second is the package with its appendices; the third is the total achievement of the whole project, which this set completes. It's going to be very hard to do justice to all three in just a thousand words.


The Movie



So firstly: The Return of the King, or more precisely this cut, as a movie. Consistently Peter Jackson's extended cuts have been, in my opinion, better movies as movies than the 'theatrical' cuts. There's a lot of new material here - not just extending scenes, but many scenes which were left out of the theatrical cut altogether, which add to characterisation, pacing and story telling.

So: the movie. It does not, of course, religiously follow Tolkien's text - nor could it. On the whole, however, it is reasonably true to the overall themes of Tolkien's text. The story-telling here is fine, and is worked on with great care. The acting, too, is fine. Among so many very fine performances, in this movie I particularly admired Billy Boyd's Pippin, Miranda Otto's Eowyn, Bernard Hill's Theoden. This is, however, very much an ensemble production. The general level of acting is high. People put their all into making this.

And not just into the acting. The costumes are spectacularly gorgeous, the sets spectacular and very largely believable, the scenery very much in keeping. In particular the presentation of the city of Minas Tirith is a tour de force, achieved by actually building quite a substantial part of the city at full scale.

But not all of that you see is real. What is particularly impressive in the CGI in this film (and there's a great deal of it) is the extent to which one simply does not notice it. Gollum, for example, is just there. The fell beasts which the Nazgul ride, and the 'great beasts' which draw Grond, are similarly so seamlessly in the piece that it is hard to believe they weren't there on the set when the camera rolled. With a critical eye you can see the CGI work in the great horse charge, and when the Rohirrim fight the Haradrim on their mumakil - but it isn't sufficiently obvious to be distracting. Indeed the one location in this book which seemed to me 'obviously' CGI - the Hall of Denethor, which seemd to me to have that hyper-reality that comes of ray-tracing - turned out to be a real (but beautifully constructed) set.

Finally, the score and sound design are again excellent.

In summary, this is a beautiful looking movie, telling a classic story and telling it well.

The package



Then the package. The Extended Edition pack comes with two disks of 'appendices', just as the extended editions of The Fellowship of the Ring and The Two Towers did; and they follow very much in the format already established in the earlier appendices, a series of documentary pieces about the background to the story and the making of the film. They don't strike me with the force that the earlier appendices did, but that is not, I think, because these are less good, simply because the format has been established and has lost its freshness. The fact remains that this is not space-filler material; for me, the 'appendices' disks of the Lord of the Rings extended editions set the standards by which all other DVD extra content is judged.

And in this case, you don't just get four disks, you get five. The fifth is about turning the film score into a symphony. Frankly, for me, that was less value for money; it didn't really work either as documentary (too much of it was simply the music) or as music (too often interrupted with commentary). But seeing it's a thrown in extra I wasn't disappointed.

The achievment



So, finally, the whole achievement. The scale and ambition of this project are staggering. Tolkien justifiably thought the Lord of the Rings unfilmable; Jackson has filmed the unfilmable and done it well. I don't quite think it's a masterpiece, but it is a very fine work of craftsmanship, with a coherent vision which produces a believable world.

Why not a masterpiece? Well, some aspects of the plot were clumsily handled. Jackson never really knew what to do with the character of Arwen, for example; and a number of the plot decisions in The Two Towers particularly just don't seem to make any sense (why drop the Grey Company and then import a whole bunch of Lothlorien elves? Why?). Part of this, of course, is a consequence of the need to cut the story into three chunks in order to be manageably marketable. I suspect that one of these days someone - perhaps even Jackson - will reshape this material into a single twelve hour of more movie which will correct some of the plot difficulties. But even so it will be flawed, because the plot really wallows around the problem of Arwen.

Finally, there are too many ham bits of movie cliche. I'd be the first to admit that Tolkien himself it rather given to having things that had lasted millenia destroyed as the fellowship passes through. You can forgive Jackson the collapse of the bridge of Khazad Dum, with Gandalf literally doing a cliff-hanger off the end. It's in the book. But to then repeat the same hammy cliche with Frodo dangling over the abyss in Sammath Naur is unforgivable. And why - why? - does the floor of the causeway in Sammath Naur collapse just behind the running feet of our heroes? Because that's the way it's been done in every hammy adventure film you've ever seen, and Jackson is too in much love with the B movie genre to rise above it.

And yet... what one remembers above all is spectacle and courage. The halls of Khazad Dum; the Argonath; Boromir's last fight on the slopes of Amon Hen; Edoras with its Golden Hall; the thunderous might of the Uruk Hai before Helm's Deep; the charge of the Mumakil; Eowyn standing alone against the Witch King of Angmar. What one remembers, despite the minor flaws, is a great piece of story-telling, telling a great story about friendship and courage.

Creative Commons Licence
The fool on the hill by Simon Brooke is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License