<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml-stylesheet href="http://duncan-cragg.org/css/atom.css" type="text/css" ?>
<!-- Copyright (c) 2006 Duncan Cragg -->

<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
    <id>http://duncan-cragg.org/blog/</id>
    <title>What Not How - Posts tagged 'json'</title>
    <subtitle>Duncan Cragg on Declarative Architectures</subtitle>
    <author><name>Duncan Cragg</name></author>
    <logo>/favicon.gif</logo>
    <icon>/favicon.ico</icon>
    <rights>All content including photos and images by Duncan Cragg. Copyright (c) Duncan Cragg, your rights preserved: see /CXL.html</rights>
    <generator uri="http://www.djangoproject.com">A Django Production.</generator>
    <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/" title="What Not How" />
    <link rel="self" type="application/atom+xml" href="http://duncan-cragg.org/blog/atom/json/" />

    <updated>2010-03-18T16:58:00Z</updated>


    <entry>
        <id>http://duncan-cragg.org/blog/post/json-mash/</id>
        <title>JSON-Mash</title>
        <published>2010-03-18T16:58:00Z</published>
        
        <updated>2010-03-18T16:58:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/json-mash/" title="JSON-Mash" />
        
        <category term="declarative" />
        
        <category term="event-driven" />
        
        <category term="rest" />
        
        <category term="json" />
        
        <category term="rest-observer" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Around the middle of February I completed a basic persistence and networking
implementation for
<a href="http://duncan-cragg.org/blog/post/fjord-in-memory/">Fjord</a>,
then had to do other things for a month.  Just recently I
fixed Fjord to work with the latest version of the 
<a href="http://nodejs.org/">Node.js</a> APIs.
</p><p>
Next project: I&#39;m going to use Fjord in a Web Framework to be called &quot;JSON-Mash&quot;.
</p><p>
I intend to show that JSON-Mash will be a great framework for rapidly building
truly interoperable and truly scalable online and distributed functionality.
</p><p>
Here&#39;s how JSON-Mash will work.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Around the middle of February I completed a basic persistence and networking
implementation for
<a href="http://duncan-cragg.org/blog/post/fjord-in-memory/">Fjord</a>,
then had to do other things for a month.  Just recently I
fixed Fjord to work with the latest version of the 
<a href="http://nodejs.org/">Node.js</a> APIs.
</p><p>
Next project: I&#39;m going to use Fjord in a Web Framework to be called &quot;JSON-Mash&quot;.
</p><p>
I intend to show that JSON-Mash will be a great framework for rapidly building
truly interoperable and truly scalable online and distributed functionality.
</p><p>
Here&#39;s how JSON-Mash will work.
</p></div><p>
<b>Juggling Data Formats</b>
</p><p>
In traditional Web Frameworks, the developer has to juggle up to five different data
formats. 
</p><p>
At the front end, you may be working in HTML or HTML chunks sent via Ajax. Then your
domain logic may use object classes. You&#39;ll no doubt map those objects to relations in
your database layer. That&#39;s three data representations (also known as
<a href="http://research.microsoft.com/en-us/um/people/emeijer/papers/xml2003/xml2003.html">Circles, Triangles and Rectangles</a>).
</p><p>
But there may be even more: if you call out to integration points such as a search
service or other API, you&#39;ll probably be using XML. And if you did application-level
cacheing, you would probably consider casting your data into key-value form.
</p><p>
This is not unrealistic - at a current ThoughtWorks client, I was faced with exactly
these five data formats - in an extremely simple application.
</p><p>&#160;</p><p>
<b>JSON Everywhere</b>
</p><p>
JSON-Mash will do away with all that. It uses JSON objects everywhere. 
</p><p>
JSON-Mash sends JSON data to a script in the browser that builds the page declaratively
from its understanding of a number of stable, generic JSON types. It uses Ajax and Comet
to pull JSON chunks in, to composite into the page.
</p><p>
JSON-Mash uses Fjord to process its JSON: transforms, map-reduce, etc. It uses Fjord to
persist objects in a JSON NoSQL database, and Fjord to provide shared JSON cacheing
functionality with cache updating via Fjord&#39;s
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
integration style.
</p><p>
Finally, if there&#39;s any external system to be integrated, that too will be accessed via
an adaptor that converts its API, etc., into JSON-Mash stabilised JSON. There will be
Twitter and Flickr adaptors at first, I should imagine.
</p><p>&#160;</p><p>
<b>JSON-Mash and Fjord</b>
</p><p>
Using Fjord means that JSON-Mash treats its JSON as a first-class hyperdata type: lots
of little JSON chunks all with URLs and all linked up. I 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">suggested</a>
that one day it may have the media type of &quot;<code>application/fjord+json</code>&quot;.  JSON-Mash Nodes
communicate in the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
style.
</p><p>
Of course, the main benefit of using Fjord is that you get a great, declarative mashup
language to describe your logic in. 
</p><p>
Fjord is still very new, of course, so some goodness is yet to be rounded out. For
example, it comes with a very basic, but highly improvable, NoSQL JSON datastore and
already allows some powerful map-reduce and other query and transformation modes, with
more to come.
</p><p>
Finally, Fjord gives a dynamic view of JSON data: caches get updates pushed into them
and Comet pull will also come as part of the package.
</p><p>&#160;</p><p>
<b>CSI and SSI</b>
</p><p>
Now, one of the great things about Node.js is that you can run the same code on the
server as you run in the browser.
</p><p>
My previous attempts at doing things the JSON-Mash way have met with some resistance
when I suggested building duplicate logic server-side to render pages statically, for
accessibility and search engines. 
</p><p>
But with Node, this problem goes away: you can use the exact same Javascript to convert
JSON to HTML on the server side as you do on the browser.
</p><p>
I use the phrases &#39;Client-Side Include&#39; and &#39;Server-Side Include&#39; or CSI and SSI as
easily-understood shorthand for this kind of page assembly from JSON elements.
</p><p>
Settling on a number of stable JSON types means that - once the types and their
rendering are stable and coded - you never need to write any Javascript yourself in
JSON-Mash. It&#39;s all done declaratively, and looks the same whether generated by an SSI
Node or the CSI in the browser. For example, you can trigger calendars and maps in the
browser view, with just small JSON declarations.
</p><p>
This approach differs from &quot;progressive enhancement&quot; as long as you have both full CSI
and full SSI to render your site. But you could also have a &#39;CSI-SSI slider&#39;, where an
initial page is generated by SSI, then CSI takes over to fill in the funky stuff: the
dynamic widgets and Comet-driven elements.
</p><p>&#160;</p><p>
<b>Users Exploring a Dynamic Web of JSON</b>
</p><p>
The way JSON-Mash works is that you get a view into a hyperlinked Web of JSON data, and
can explore it from any point outwards. In the CSI version, each JSON chunk is loaded
lazily as it is encountered, then reloaded when it changes.  Even the SSI version of the
site would allow this form of exploration, although in a less efficient and dynamic way,
of course. 
</p><p>
In JSON-Mash, the user is also a first-class object; the stable JSON types also include
a type representing the user. This user is driving their browser, subscribing to events
on visible JSON page components via Comet, and POSTing their own user state to a
server-side cache copy.
</p><p>
Hence, if that user state contains a message, you can get simple chat functionality,
without any code, just by linking to a user and viewing them.
</p><p>&#160;</p><p>
<b>Conclusion</b>
</p><p>
JSON-Mash is a Web Framework that will use, re-use, assemble, mash, transform, store,
share, push, pull and render JSON from end to end and top to bottom; from Ajax to NoSQL.
</p><p>
Most domain-logic programming will be done in simple, powerful declarative functions,
with adaptors, drivers or renderers written in Javascript for Node.js or the browser.
Cross-host exchange is done in the FOREST style.
</p><p>
SSI or CSI page assembly are very flexible ways of mashing up new functionality from multiple
back-end sources of RESTfully-sourced, interlinked JSON data.  And with cache updates
telling SSI and CSI when the back-end data has changed, you get a very dynamic yet
scalable system.
</p><p>
JSON-Mash will be a framework for rapidly building truly interoperable and truly
scalable online and distributed functionality. 
</p><p>
I&#39;ll write more on the benefits once I&#39;ve got some code to prove it!  Follow me on 
<a href="http://twitter.com/duncancragg">Twitter</a>
and I&#39;ll let you know when I&#39;ve got something up on 
<a href="http://github.com/duncancragg">GitHub</a>.

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/fjord-in-memory/</id>
        <title>Fjord in Memory</title>
        <published>2010-01-26T13:46:00Z</published>
        
        <updated>2010-01-26T13:46:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/fjord-in-memory/" title="Fjord in Memory" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Right, I&#39;m pleased to say that I&#39;ve now implemented enough of the 
<a href="http://duncan-cragg.org/blog/post/fjord-node/">Fjord language</a>
on <a href="http://nodejs.org/">Node.js</a> to be able to run the 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Instrument example</a>
that I introduced it with.  As yet, this runs in memory only - i.e., no disk, no
network.
</p><p>
<a href="http://github.com/DuncanCragg/Fjord/">Here&#39;s the code on GitHub</a> with tests
that show how it works. The language has changed a little so I&#39;ll show the example here
again, copied over from the test code, in order to explain the differences.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Right, I&#39;m pleased to say that I&#39;ve now implemented enough of the 
<a href="http://duncan-cragg.org/blog/post/fjord-node/">Fjord language</a>
on <a href="http://nodejs.org/">Node.js</a> to be able to run the 
<a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Instrument example</a>
that I introduced it with.  As yet, this runs in memory only - i.e., no disk, no
network.
</p><p>
<a href="http://github.com/DuncanCragg/Fjord/">Here&#39;s the code on GitHub</a> with tests
that show how it works. The language has changed a little so I&#39;ll show the example here
again, copied over from the test code, in order to explain the differences.
</p></div><p>
Starting with the instrument rules:
</p><pre>
inrl1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;%owid&quot;: &quot;/$this/&quot;,&#39;+
                       &#39;  &quot;%refs&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],&#39;+
                       &#39;             &quot;%owid&quot;: &quot;/$bid/&quot;,&#39;+
                       &#39;             &quot;on&quot;: &quot;/$this/&quot; },&#39;+
                       &#39;  &quot;buyers&quot;: &quot;/array/has($bid)/&quot; }&#39;);
// -------------------------------------------------------------------
inrl2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;%owid&quot;: &quot;/$this/&quot;,&#39;+
                       &#39;  &quot;%refs&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ],&#39;+
                       &#39;             &quot;%owid&quot;: &quot;/$ask/&quot;,&#39;+
                       &#39;             &quot;on&quot;: &quot;/$this/&quot; },&#39;+
                       &#39;  &quot;sellers&quot;: &quot;/array/has($ask)/&quot; }&#39;);
</pre><p>
These are the rules that add - or, rather, ensure the presence of - referring bids and
asks in the instrument&#39;s buyers and sellers lists. The big difference here is that
referrers are now accessed through the &#39;%refs&#39; tag. Both &#39;%refs&#39; and &#39;%owid&#39; are
available on all Fjord objects: %owid is the Object Web ID of the object, and %refs has
a list of the OWIDs of all currently referring objects.
</p><p>
But, of course, you can&#39;t see the list or the OWIDs under %refs! This rule shows how
Fjord can match single items to lists of items, and how it transparently jumps any OWIDs
it comes across, to continue matching. In this case there is a pattern for a bid or ask
object that refers to the instrument - notice the  &quot;on&quot;: &quot;/$this/&quot; match. 
</p><p>
Every object in %refs must have some such link to the referred-to object that triggered
the referral in the first place. This referrer becomes an observer: its rules are run
again if any object it refers to changes.
</p><p>
More instrument rules:
</p><pre>
inrl3=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;buyers&quot;:  { &quot;price&quot;: &quot;/$bids;number/&quot; },&#39;+
                       &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/number/max($bids)/&quot; } }&#39;);
// -------------------------------------------------------------------
inrl4=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                       &#39;  &quot;sellers&quot;: { &quot;price&quot;: &quot;/$asks;number/&quot; },&#39;+
                       &#39;  &quot;bid-ask-spread&quot;: { &quot;low-ask&quot;:  &quot;/number/min($asks)/&quot; } }&#39;);
</pre><p>
These are the rules that set the bid-ask-spread of the instrument from the prices of the
bids or asks in each list. It shows how, when a single match instance binds to a list,
it can give a match set in any bound variables - here, &#39;$bids&#39; and &#39;$asks&#39; - which can
then be reduced - here, using &#39;max()&#39; and &#39;min()&#39;.
</p><p>
The rules are now separated into two, as there was a historic <i>first ever bug in
public Fjord code</i>: the original rule wouldn&#39;t match unless at least one buyer <i>and</i>
one seller were present, and we&#39;re adding them one by one from scratch this time!
</p><p>
Here is the actual instrument object:
</p><pre>
inst=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                      &#39;  &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,&#39;+
                      &#39;  &quot;buyers&quot;: [ ],&#39;+
                      &#39;  &quot;sellers&quot;: [ ],&#39;+
                      &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;10.0&quot;, &quot;low-ask&quot;:  &quot;20.0&quot; } }&#39;,
                      [ inrl1, inrl2, inrl3, inrl4 ] );
</pre><p>
Notice the list of rules that the object will be animated by: inrl1, etc., which are the
rule object OWIDs, not the actual rule objects. The bid-ask-spread is set to some seed values.
</p><p>
On to bid and ask rules:
</p><pre>
bidrule=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],&#39;+
                         &#39;  &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                         &#39;          &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/$hibid;number/&quot; } },&#39;+
                         &#39;  &quot;price&quot;: &quot;/null/fix(2, $hibid * 1.10 )/&quot; }&#39;);
// -------------------------------------------------------------------
askrule=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ],&#39;+
                         &#39;  &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                         &#39;          &quot;bid-ask-spread&quot;: { &quot;low-ask&quot;: &quot;/$loask;number/&quot; } },&#39;+
                         &#39;  &quot;price&quot;: &quot;/null/fix(2, $loask * 0.90 )/&quot; }&#39;);
</pre><p>
Here we have rules for setting the price of a bid or an ask as a ratio of the
instrument&#39;s bid-ask-spread numbers. These are not meant to be realistic business rules
of course - they&#39;re for illustration purposes. The only real difference here is fixing
the result to 2 decimal places, since Javascript was adding ugly rounding errors.
</p><p>
Now we go ahead and create two bids and two asks, pointing at the instrument by simply 
including its OWID:
</p><pre>
bid1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ bidrule ]);
bid2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ bidrule ]);
ask1=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ askrule ]);
ask2=WebObject.create(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;ask&quot; ], &quot;on&quot;: &quot;&#39;+inst+&#39;&quot;, &quot;price&quot;: &quot;&quot; }&#39;, [ askrule ]);
</pre><p>
This fires off all the rules and notifications .. and rules and notifications .. giving
the final result:
</p><pre>
exp=new WebObject(&#39;{ &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],&#39;+
                  &#39;  &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,&#39;+
                  &#39;  &quot;buyers&quot;:  [ &quot;&#39;+bid1+&#39;&quot;, &quot;&#39;+bid2+&#39;&quot; ],&#39;+
                  &#39;  &quot;sellers&quot;: [ &quot;&#39;+ask1+&#39;&quot;, &quot;&#39;+ask2+&#39;&quot; ],&#39;+
                  &#39;  &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;12.1&quot;, &quot;low-ask&quot;:  &quot;16.2&quot; } }&#39;)
// -------------------------------------------------------------------
test.objectsEqual(&quot;Instrument example works&quot;, Cache[inst], exp);
</pre><p>
Here the buyers and sellers correctly list the referring bids and asks, and the
bid-ask-spread has been set to the values you get after two ratios are applied to the
original seed numbers.
</p><p>
Rewrite rules are run on object construction, they&#39;re run whenever an object has a new
referrer in its &#39;refs&#39; list, and also whenever another object that&#39;s being referred to
changes. The latter isn&#39;t exercised in this example, as all events are propagated by
referral alone. The tests of Fjord have examples of the full Observer Pattern in operation.
</p><p>&#160;</p><p>
<b>Next Up</b>
</p><p>
Now, this is living code, so it will no doubt be different again, soon. Watch this space, and
<a href="http://twitter.com/duncancragg">follow me on Twitter</a>, to keep up to date with developments.
</p><p>
Next, I&#39;ll be working on simple disk persistence of Fjord JSON objects and rules,
followed by distribution in the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a> style...

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/fjord-node/</id>
        <title>Fjord in Node</title>
        <published>2010-01-06T17:03:00Z</published>
        
        <updated>2010-01-06T17:03:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/fjord-node/" title="Fjord in Node" />
        
        <category term="event-driven" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Well, I&#39;ve put together the first few lines of <a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Fjord</a>, implemented on <a href="http://nodejs.org/">Node.js</a>.
</p><p>
Here&#39;s the description on <a href="http://github.com/DuncanCragg/Fjord">GitHub</a>: <i>Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects</i>.
</p><p>
I&#39;m developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Well, I&#39;ve put together the first few lines of <a href="http://duncan-cragg.org/blog/post/introducing-fjord/">Fjord</a>, implemented on <a href="http://nodejs.org/">Node.js</a>.
</p><p>
Here&#39;s the description on <a href="http://github.com/DuncanCragg/Fjord">GitHub</a>: <i>Fjord is a language for expressing domain logic as match-rewrite functions over mashable JSON Web objects</i>.
</p><p>
I&#39;m developing Fjord very openly, in the hope someone out there will be interested in getting involved in helping guide its design and implementation. I suppose code speaks louder than blog posts.
</p></div><p>
It&#39;s going to be slow progress, with a wife, two kids, and Thoughtworks all together getting 99% of my life, but at least people will be able to keep up with what I&#39;m trying to do... I only got the project started at all because I&#39;m off sick right now!
</p><p>
Here&#39;s the GitHub link: <a href="http://github.com/DuncanCragg/Fjord">http://github.com/DuncanCragg/Fjord</a>.
</p><p>
Follow me on Twitter if you want all the latest news .. <a href="http://twitter.com/duncancragg">http://twitter.com/duncancragg</a>
</p><p>
Oh - I was lying about FOREST being GET-only, that was just to engage the REST community, but since I got zero reaction from anyone I may as well admit that I intended FOREST to use POST all along - to push updated resources into subscriber caches as I have always done. Or to use long-GETs to pull them in. Both are tunnelling cache refreshes over HTTP. Neither are Official REST.
</p><p>
Cheers!

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/introducing-fjord/</id>
        <title>Introducing Fjord</title>
        <published>2009-12-11T08:22:00Z</published>
        
        <updated>2009-12-11T08:22:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/introducing-fjord/" title="Introducing Fjord" />
        
        <category term="declarative" />
        
        <category term="json" />
        
        <category term="forest" />
        
        <category term="fjord" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Following on from my recent article where I
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">derived FOREST</a>,
this article offers the beginnings of a JSON unification and rewriting language that
can be used in a FOREST architecture.
</p><p>
Why JSON, not XHTML, now? Well, I recently discovered that
<a href="http://www.google.com/trends?q=json%2C+xhtml">JSON is overtaking XHTML</a>
in interest, and I was further inspired by Kris Zyp&#39;s recent announcement of his
<a href="http://www.ietf.org/id/draft-zyp-json-schema-01.txt">JSON Schema</a>
Internet-Draft.
</p><p>
Fjord is a language for describing how the state of a JSON resource at any time depends
on both its current state and on the state of other JSON resources that it links to via
hyperlinks.  
</p><p>
Fjord is a Norwegian word, probably pronounced &#39;fiyourd&#39;, and might stand for some
combination of the words: &#39;Functional JSON Object/Observer Resource/Rule/Rewrite
Dependencies/Declarations&#39;. Or maybe it&#39;s just because they&#39;re
<a href="http://images.google.co.uk/images?q=fjord">truly awesome</a>, an&#39; I wanna go.
</p><p>
Fjord also gives me an opportunity to show some examples of the &quot;end-user&quot; view of a FOREST
interaction; starting with a simple finance example.
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Following on from my recent article where I
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">derived FOREST</a>,
this article offers the beginnings of a JSON unification and rewriting language that
can be used in a FOREST architecture.
</p><p>
Why JSON, not XHTML, now? Well, I recently discovered that
<a href="http://www.google.com/trends?q=json%2C+xhtml">JSON is overtaking XHTML</a>
in interest, and I was further inspired by Kris Zyp&#39;s recent announcement of his
<a href="http://www.ietf.org/id/draft-zyp-json-schema-01.txt">JSON Schema</a>
Internet-Draft.
</p><p>
Fjord is a language for describing how the state of a JSON resource at any time depends
on both its current state and on the state of other JSON resources that it links to via
hyperlinks.  
</p><p>
Fjord is a Norwegian word, probably pronounced &#39;fiyourd&#39;, and might stand for some
combination of the words: &#39;Functional JSON Object/Observer Resource/Rule/Rewrite
Dependencies/Declarations&#39;. Or maybe it&#39;s just because they&#39;re
<a href="http://images.google.co.uk/images?q=fjord">truly awesome</a>, an&#39; I wanna go.
</p><p>
Fjord also gives me an opportunity to show some examples of the &quot;end-user&quot; view of a FOREST
interaction; starting with a simple finance example.
</p></div><p>
<b>Instrument, Bids, Asks</b>
</p><p>
Let&#39;s take the simplest possible view of a
<a href="http://www.livemint.com/2009/04/05215410/Ask-Mint--Bidask-spread-all.html">financial market</a>.
</p><p>
There&#39;s an Instrument, and there are Bids and Asks on that Instrument. The Instrument
summarises all the Bids and Asks into the &#39;bid-ask spread&#39;, taking the highest bid price
and the lowest ask price.  Forget volumes, trades and any other detail. 
</p><p>
The Instruments, Bids and Asks are on various servers across various organisations.
That&#39;s the &#39;symmetric REST&#39; part.
</p><p>
Here&#39;s a JSON Instrument resource at the URL shown. It holds three Bid or Ask objects:
</p><pre>
http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,
    &quot;buyers&quot;: [ 
        &quot;@http://a-bank.com/fjord/equity-bid-9ac0d1-88ce1.json&quot;
    ],
    &quot;sellers&quot;: [ 
        &quot;@http://c-bank.com/fjord/equity-ask-510efb-cca62.json&quot;,
        &quot;@http://d-bank.com/fjord/equity-ask-8560ae-33eff.json&quot;
    ],
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;10.00&quot;,
        &quot;low-ask&quot;:  &quot;14.00&quot;
    }
}
</pre><p>
The &#39;@&#39; character is the flag that this string is a link or a URL.  The meaningful names
in those links are really just for humans and the layers below us - Fjord itself won&#39;t
let you see inside them.
</p><p>
</p><blockquote class="others-content"><div><p>
So now that we&#39;ve introduced a JSON extension making it a hypermedia or hyperdata
type, perhaps we should announce this convention in a media type string. How about 
&quot;<code>application/fjord+json</code>&quot;?  This media type will also serve to set expectations on
everything else about Fjord JSON objects, once the notation is stable.
</p></div></blockquote><p>
</p><p>
Notice that, instead of &#39;class&#39; or &#39;type&#39; or a top-level tag, we have a list of tags.
In Fjord, class is in the eye of the beholder - but, of course, must be a stable grammar
in the eye of the generator!
</p><p>
Right, so here is a new Bid object held at &#39;B&#39; Bank, that the Instrument hasn&#39;t seen yet:
</p><pre>
http://b-bank.com/fjord/equity-bid-0043ee-419ac.json
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: &quot;@http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json&quot;,
    &quot;price&quot;: &quot;&quot;,
    &quot;by&quot;: &quot;@http://b-bank.com/fjord/hcard-b-bank-4990cd-232b0.json&quot;
}
</pre><p>
It has a pointer to the Instrument it is a bid on, a bid price that isn&#39;t yet set, and a
link to the hCard object of the bank offering the bid and serving this Bid object.
</p><p>
So Bids and Asks can see Instruments and vice-versa, and each can set their own state
accordingly, as part of a FOREST interaction.
</p><p>
The &#39;animation&#39; of Bid, Ask and Instrument JSON object resources is driven by three
simple Fjord rules...
</p><p>&#160;</p><p>
<b>Rule One: Bid Sets Price From Instrument</b>
</p><p>
Here is a rule setting the price of a new Bid to be 10% more than the highest current
Bid on the instrument, hopefully ensuring this Bid is now the high bid:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: { &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
            &quot;bid-ask-spread&quot;: { &quot;high-bid&quot;: &quot;/$hibid;decimal/&quot; }
          },
    &quot;price&quot;: &quot;/null/( $hibid * 1.10 )/&quot;
}
</pre><p>
This is a template that matches the Bid object and its dependencies and rewrites part of
the Bid.
</p><p>
<i>Notice how the Bid object&#39;s link to the Instrument object is jumped transparently: the
Bid can &#39;see&#39; right into the Instrument in order to do its matching.  However, it cannot
itself rewrite the Instrument - only Instrument rules can do that.</i>
</p><p>
In Fjord, matching is written with the &#39;/ ; /&#39; notation: each part of this
semicolon-separated list must match. In this case, the high bid has to bind to the
identifier &#39;$hibid&#39; and has to be a decimal. The price must not be set yet. 
</p><p>
The keys &#39;decimal&#39; and &#39;null&#39; are, of course, special reserved words for matching in
patterns.  The &#39;null&#39; matches empty strings, lists and hashes.
</p><p>
The rewrite part follows at the end of a match and is also wrapped in slashes. Here, the
price is being set to the high-bid plus 10%.  The parentheses introduce an expression.
</p><p>
This rule only matches if the price is empty - once set, the rule will not refire.
</p><p>
For more complex rewrites, the following forms can also be used: 
</p><pre>
    &quot;price&quot;: { &quot;/null//&quot;: &quot;( $hibid * 1.10 )&quot; }
    &quot;price&quot;: { &quot;when&quot;: &quot;/null/&quot;, &quot;then&quot;: &quot;( $hibid * 1.10 )&quot; }
</pre><p>
which allow full hashes and lists to be both matched and set.
</p><p>&#160;</p><p>
<b>Rule Two: Instrument Puts New Bid into its Buyers List</b>
</p><p>
The Instrument adds the new Bid to its buyers list with this rule:
</p><pre>
{   &quot;#url&quot;: &quot;/$bid/&quot;,
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: { &quot;#url&quot;: &quot;/this/&quot;,
            &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
            &quot;buyers&quot;: &quot;/list/has($bid)/&quot;,
    }
}
</pre><p>
This is a rule on the Instrument, that &#39;looks up to&#39; and matches the enclosing Bid.
</p><p>
The &#39;#url&#39; is an optional, reserved-word entry that can only appear at the top of a JSON
resource and holds that resource&#39;s URL. Here, it is bound to &#39;$bid&#39;, picking up the URL
of the Bid object that refers to and encloses this Instrument.
</p><p>
Further down, the &quot;#url&quot; reserved-word value of &quot;this&quot; indicates the start of the
object that this rule applies to. If &quot;this&quot; is absent, then, of course, this is a rule
on the top-level object, as in the first rule above.
</p><p>
The rewrite part matches the buyers list of the Instrument and applies the &#39;has()&#39;
operator which ensures the list now contains the wrapping Bid; it rewrites the list to
include its argument if it doesn&#39;t already. 
</p><p>
If this rule matches two wrapping Bids simultaneously, then &#39;$bid&#39; is set to a &#39;match
set&#39; - a simultaneous binding to the URLs of all of those Bids, and &#39;has()&#39; must ensure
that all of these Bids are now in the list at once.
</p><p>
If there is no change after a rule is applied, the resource&#39;s Etag isn&#39;t incremented, and
dependent rules won&#39;t fire. <i>Fjord may re-apply any rule at any time, usually on an
incoming state change indicated by Etag, so matches have to be designed accordingly.</i>
</p><p>
That&#39;s why we say &#39;has&#39;, not &#39;add&#39;, which would add the Bid again and again each time
the rule is applied. We could say <code>&quot;/list;hasNo($bid)/add($bid)/&quot;</code>, but that&#39;s
uglier and more imperative than declarative.
</p><p>&#160;</p><p>
<b>Rule Three: Instrument Sets Bid-Ask Spread from Bids and Asks</b>
</p><p>
This is what the instrument looks like, now, with the new link to our Bid:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;long-name&quot;: &quot;Acme Co., Inc&quot;,
    &quot;buyers&quot;: [ 
        &quot;@http://a-bank.com/fjord/equity-bid-9ac0d1-88ce1.json&quot;,
        &quot;@http://b-bank.com/fjord/equity-bid-0043ee-419ac.json&quot;
    ],
    &quot;sellers&quot;: [ 
        &quot;@http://c-bank.com/fjord/equity-ask-510efb-cca62.json&quot;,
        &quot;@http://d-bank.com/fjord/equity-ask-8560ae-33eff.json&quot;
    ],
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;10.00&quot;,
        &quot;low-ask&quot;:  &quot;14.00&quot;
    }
}
</pre><p>
And here is what the new B-Bank Bid looks like with its competitive price:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;bid&quot; ],
    &quot;on&quot;: &quot;@http://the-bank.com/fjord/equity-instrument-23ab33-2319f.json&quot;,
    &quot;price&quot;: &quot;11.00&quot;,
    &quot;by&quot;: &quot;@http://b-bank.com/fjord/hcard-b-bank-4990cd-232b0.json&quot;
}
</pre><p>
So now the Instrument has to adjust its bid-ask spread to accomodate the new Bid. This
happens when the following rule matches, which it always does - but only fires when a
change is detected:
</p><pre>
{
    &quot;tags&quot;: [ &quot;equity&quot;, &quot;instrument&quot; ],
    &quot;buyers&quot;:  { &quot;price&quot;: &quot;/$bids;decimal/&quot; },
    &quot;sellers&quot;: { &quot;price&quot;: &quot;/$asks;decimal/&quot; },
    &quot;bid-ask-spread&quot;: {
        &quot;high-bid&quot;: &quot;/decimal/max($bids)/&quot;,
        &quot;low-ask&quot;:  &quot;/decimal/min($asks)/&quot;
    }
}
</pre><p>
This rule matches as many times as there are Bids and Asks, meaning that the local
identifiers $bids and $asks are each bound to match sets. 
</p><p>
Notice how the &#39;{ price .. }&#39; patterns match elements of a list, in the same way an
XPath can match either one or several elements in a sequence of XML elements.
</p><p>
The &#39;max()&#39; and &#39;min()&#39; operators take the highest and lowest values in a match set
(or in a physical list, come to that). Once again, this rewrite means &#39;set this value
and increment the Etag, but only if there&#39;s a change&#39;. 
</p><p>
Here, the high-bid becomes our new Bid&#39;s &#39;11.00&#39;.
</p><p>&#160;</p><p>
<b>Fjord</b>
</p><p>
So that&#39;s a quick intro to some of my ideas for JSON matching and rewriting in a FOREST
architecture.
</p><p>
Fjord is a declarative, JSON-encoded language for expressing how the state of a JSON
resource is a function of both its own state and the state of peer JSON resources that
it can see via links in a hyperdata Web.
</p><p>
Fjord objects are &#39;masters of their own destiny&#39;, not allowing other objects to tell
them what to do except via declarative intention.
</p><p>
Further articles will give more proposals for the syntax and semantics of Fjord,
including true unification, and put it into the set of languages that are ideal for
programming parallel and distributed systems, as well as for integration.
</p><p>
Since Fjord is very young and I&#39;m still implementing it (in Java), I would certainly
welcome comments about it, or about the 
<a href="http://duncan-cragg.org/blog/post/deriving-forest/">FOREST</a>
style that it supports. You can chat with me on 
<a href="http://twitter.com/duncancragg">Twitter</a>, too!

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/universe-web/</id>
        <title>The Universe Web</title>
        <published>2008-07-18T19:49:00Z</published>
        
        <updated>2008-07-18T19:49:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/universe-web/" title="The Universe Web" />
        
        <category term="cyberspace" />
        
        <category term="architecture" />
        
        <category term="declarative" />
        
        <category term="socialsoftware" />
        
        <category term="publishsubscribe" />
        
        <category term="p2p" />
        
        <category term="rest" />
        
        <category term="scalability" />
        
        <category term="json" />
        
        <category term="metaverse" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Since the 
<a href="http://www.virtualworldsnews.com/2008/07/ibm-and-linden.html">announcement</a>
by 
<a href="http://www.ibm.com/virtualworlds/index.shtml">IBM</a>
and
<a href="http://lindenlab.com/">Linden Lab</a>
that
<a href="http://opensimulator.org/wiki/Main_Page">OpenSim</a>
can talk to 
<a href="http://secondlifegrid.net/">Second Life</a>,
I&#39;ve been thinking again about RESTful Virtual Reality.
</p><p>
I&#39;m not the first, of course. Others have been motivated by the same
goal: To bring the Web&#39;s scalability, linkability and interoperability
into Virtual World platforms.
</p><p>
Ultimately, how to use the same techniques as the Web to link
Virtual Worlds together into a single, massive &#39;Virtual Universe&#39;.
</p><p>
Here&#39;s how I would architect the Universe Web...
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Since the 
<a href="http://www.virtualworldsnews.com/2008/07/ibm-and-linden.html">announcement</a>
by 
<a href="http://www.ibm.com/virtualworlds/index.shtml">IBM</a>
and
<a href="http://lindenlab.com/">Linden Lab</a>
that
<a href="http://opensimulator.org/wiki/Main_Page">OpenSim</a>
can talk to 
<a href="http://secondlifegrid.net/">Second Life</a>,
I&#39;ve been thinking again about RESTful Virtual Reality.
</p><p>
I&#39;m not the first, of course. Others have been motivated by the same
goal: To bring the Web&#39;s scalability, linkability and interoperability
into Virtual World platforms.
</p><p>
Ultimately, how to use the same techniques as the Web to link
Virtual Worlds together into a single, massive &#39;Virtual Universe&#39;.
</p><p>
Here&#39;s how I would architect the Universe Web...
</p></div><p>
<b>Entities</b>
</p><p>
The Universe Web needs Entities. (I&#39;m going to be capitalising
Significant Things a lot here to help the Web comparison - hope you
don&#39;t mind). There&#39;s no need to make the Entity list too complicated
since we&#39;re not doing online games yet - just a world like Second Life.
</p><p>
Here&#39;s a list of different kinds of Entity:
</p><ul>
<li>   Places: buildings, streets, hills, lakes</li>
<li>   Things: trees, books, birds, clocks</li>
<li>   People</li>
</ul><p>
</p><p>&#160;</p><p>
<b>State, Links and animation</b>
</p><p>
Entities aren&#39;t exactly the Objects of Object-Oriented programming:
they have lots of public State. In a Virtual World, you can directly
experience their colour, position, orientation, physical relation to
each other, etc., thanks to the local render engine.
</p><p>
The basic structure of the Universe Web is made up of Linked
Entities. A tree is Linked to its ground which is Linked to a
building which is Linked to its occupants which are Linked to their
clothing. Kneebones may even be Linked to thighbones.
</p><p>
Entities are often animated. Actually, Places are generally static,
and People generally animate themselves. So, when talking in general,
we should look at the animation of Things, like trees, books, birds
and clocks.
</p><p>
There are two ways an Entity&#39;s animation can be guided: by Laws and
by Rules.
</p><p>&#160;</p><p>
<b>Laws</b>
</p><p>
Springiness is a handy Law. For example, tree branches, pages in a
book and birds&#39; wings and legs can all have springiness. We can
declare a mid-air location in a bird&#39;s State and a springiness in
its legs, then if the bird lands on a branch, the springiness can
trigger the bird and branch waving gently to a halt.
</p><p>
We could even allow a single bird to become part of a flock Entity,
where the flock only knows how many birds it has and the coordinates
of its centre. Each bird will then be animated by global flock Laws.
</p><p>
The book can have a State of open or closed. If bookness was
elevated to a global Law, then a book deciding that its State was
now simply closed could trigger the elaborate, springy closing of
its pages with a nice &#39;shlump&#39; sound at the end.
</p><p>
The clock&#39;s current time may be set by the clock Entity itself, then
the Law of time take over in between the clock updating its own time
directly.
</p><p>
A Law can be invoked over an Entity&#39;s animation by simply adding the
Law&#39;s name and parameters to its State. Such Laws can be handled by
the physics engine in the same way surface texture is handled by the
render engine: States such as &#39;red&#39; need global meaning, Law
applications such as &#39;springy&#39; need global meaning.
</p><p>&#160;</p><p>
<b>Rules</b>
</p><p>
When a clock reaches its alarm time, it rings.  When its wizard
master approaches, a magic book may glow and open.  Birds fly away
from danger (if a fox is too close, fly away from it). In between
danger, birds and foxes look for food (if a bird is close, run
towards it). 
</p><p>
These are Rules.  Rules are driven by the Observation of one Entity
by another. The fox Observes the bird, the book Observes the wizard.
Rules apply to Entity types: fox Rules, bird Rules, book Rules, etc. 
Rules can guide the animation of an Entity by evolving its State.
</p><p>
State evolution depends on the current State plus the States of the
Observed Entities: Rules make an Entity change from one State to the
next by taking the Entity&#39;s own State, Observing the States of the
Entities around that it cares about, then deciding what the next,
new State should be.  If an Entity changes State, those Entities
Observing it may themselves change State according to their own
Rules, and so-on.
</p><p>
Links are part of an Entity&#39;s State, and Links may therefore change
on the application of Rules. In other words, the virtual world may
restructure when a Rule is run.
</p><p>
An Entity may either Observe another Entity, or Link to it, or both.
An Entity that Links to another needn&#39;t Observe it. Trees don&#39;t
bother to Observe the ground they grow from. Conversely, an Entity
that Observes another needn&#39;t Link to it. A fox would only Link to a
bird if she was lucky enough to catch it. Meanwhile, it is true that
there&#39;s probably a <i>chain</i> of Links to everything that&#39;s Observed.
</p><p>
Unlike Laws, Rules can&#39;t or shouldn&#39;t be second-guessed, so have to
be run &#39;at source&#39; or &#39;inside the Entity&#39;, then the new State
distributed to both the Observing Entities and to all the render
engines.
</p><p>
But render engines are actually Observing People Entities..
</p><p>&#160;</p><p>
<b>People are First Class</b>
</p><p>
In Virtual Worlds, we have People avatars: People are first class
Entities.  People can Observe and can change State, but it&#39;s a real
user doing the animation, not a set of Rules. Observation and State
change by a Person is implemented through the render engine.
</p><p>
Although self-animated, People can still make use of Laws. For
example Laws can be invoked to allow gestures to be easier to make
and to look better, and to allow People to &#39;run forward&#39; rather than
putting their &#39;left foot forward, ..&#39;.  Avatar skills become global
Laws which can be triggered by an avatar&#39;s State animated by a user.
</p><p>&#160;</p><p>
<b>The Universe Wide Web</b>
</p><p>
The Universe Web I&#39;ve just described is a lot like the World Wide Web:
</p><ul>
<li>   An Entity is like a Web Resource</li>
<li>   The State of an Entity is like an HTML Web Representation of a Web Resource</li>
<li>   A Link in an Entity&#39;s State is like a Web URL inside an HTML Web Representation</li>
<li>   Laws are like Javascript, Flash, link hover, blink tags and animated GIFs</li>
<li>   Rule sets are like PHP scripts or Java servers</li>
<li>   A State Observation is like a Web Representation Transfer</li>
</ul><p>
A crucial difference between the Resource Web and the Entity Web is
that, here <i>it&#39;s another Entity doing the Observation</i>.  One
Entity transfers its State to another. 
</p><p>
It&#39;s as if the GET or POST has another Entity &#39;at the client end&#39;.
GET is like an Entity subscribing or Observing; POST is like an
Entity publishing or notifying its State to another (an HTML form
has a content type, too).
</p><p>
People are just examples of that Entity &#39;at the client end&#39;.
Instead of a user hidden behind a client browser, we have
first-class People Entities doing &#39;GET&#39;s and &#39;POST&#39;s: Observing
the Virtual World and acting (i.e., changing State) within it.
Other examples are foxes and clocks.
</p><p>&#160;</p><p>
<b>Notation and Protocol</b>
</p><p>
There are two open standards we need to have in progress while
implementing the Universe Web: the notation and the protocol (our
HTML/URI and HTTP).
</p><p>
Firstly, we have to define the notation for Entities and their
Rules. Both the State of Entities and the Rules that animate them
will be written in the same notation: a Rule talks directly about
State. To me, basing that on JSON (rather than XML) is a clear
choice. Add inter-JSON Entity Links (essentially UUIDs), then work
out a simple JSON Rule language. We will then need to define JSON
&#39;schemas&#39; for the kinds of Entity we would model. These can be
written in the Rule language itself.
</p><p>
Secondly, to define the protocol for Entities to Observe or
subscribe to one another. It will be a &#39;symmetric, asynchronous
HTTP&#39; - a Peer-to-Peer, Publish-Subscribe protocol. UDP and
Multicast stand out for this kind of interaction. A packet will
subscribe, a packet will return current State, a subsequent packet
will multicast State updates. We can re-use all the HTTP cache
headers, only now we can push updates into caches and into render
programs. Packets will inevitably end up tunnelled through TCP and
HTTP, mind...
</p><p>
This lighter notation, which also breaks the data up into smaller
pieces, and this multicast pushing of State change into caches, along
with P2P-style operation, will mean the Universe Web scales even
better than its parent. 
</p><p>
Also, programming declaratively using Rules is both highly
productive and further cleanly scalable through parallel processing. 
</p><p>
Of course, it will be pretty trivial to allow inter-Web cross-over
such as referring to PNG texture images via URL and pulling Universe
Web Entities into a Javascript application that subscribes to them
via Comet.
</p><p>&#160;</p><p>
</p><p>
<b>Building the Universe Web</b>
</p><p>
So that&#39;s my Universe Web. It&#39;s basically the same as the World Wide
Web and thus as scalable, linkable and interoperable. It comes with
added symmetry: Entities, including People as avatars, exchange
State in each direction.
</p><p>
It&#39;s a two-way data Web, not a one-way document Web.
</p><p>
I&#39;ve started work on the Universe Web: the notation, the protocol
and the implementation (in C, for portability across platforms,
including mobile).  Contact me if you want to help!
</p><p>

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/google-micro-conference/</id>
        <title>Google Micro Conference</title>
        <published>2007-10-05T11:22:00Z</published>
        
        <updated>2007-10-05T11:22:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/google-micro-conference/" title="Google Micro Conference" />
        
        <category term="web2.0" />
        
        <category term="atom" />
        
        <category term="ajax" />
        
        <category term="rest" />
        
        <category term="event-driven" />
        
        <category term="publishsubscribe" />
        
        <category term="p2p" />
        
        <category term="architecture" />
        
        <category term="declarative" />
        
        <category term="app" />
        
        <category term="microformats" />
        
        <category term="scalability" />
        
        <category term="json" />
        
        <category term="openid" />
        
        <category term="microweb" />
        
        <category term="google" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

Last night&#39;s 
<a href="http://osjam.truemesh.com/">Google London Open Source Jam</a>
(also <a href="http://www.red-bean.com/ospowiki/LondonOpenSourceJam05Talks">here</a>)
was on the subject of the &#39;Web&#39; (didn&#39;t they invent that? Oh no,
that was Microsoft).
</p><p>
This event has been getting better and better each time I&#39;ve
attended. There were some very interesting lightning talks held
together with a tight structure and plenty of chance to chat,
drink cold Leffe and eat cold pizza. And nick [<i>transatlantic
translation: &#39;steal&#39;</i>] the 
<a href="http://www.greenandblacks.com/uk/productdetails.php?pageid=27&amp;cid=6&amp;pid=11">Green &amp; Black&#39;s chocolate</a>.
</p><p>
An ideal Micro Conference...
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
Last night&#39;s 
<a href="http://osjam.truemesh.com/">Google London Open Source Jam</a>
(also <a href="http://www.red-bean.com/ospowiki/LondonOpenSourceJam05Talks">here</a>)
was on the subject of the &#39;Web&#39; (didn&#39;t they invent that? Oh no,
that was Microsoft).
</p><p>
This event has been getting better and better each time I&#39;ve
attended. There were some very interesting lightning talks held
together with a tight structure and plenty of chance to chat,
drink cold Leffe and eat cold pizza. And nick [<i>transatlantic
translation: &#39;steal&#39;</i>] the 
<a href="http://www.greenandblacks.com/uk/productdetails.php?pageid=27&amp;cid=6&amp;pid=11">Green &amp; Black&#39;s chocolate</a>.
</p><p>
An ideal Micro Conference...
</p></div><p>
I arrived late (it starts at 6pm) and spent some time catching up with
<a href="http://www.flickr.com/photos/92443667@N00/1488471991/in/set-72157602268864450/">ex-Thoughtworks colleagues</a>,
so I missed Dion &quot;Ajaxian&quot; Almaer&#39;s 
<a href="http://www.slideshare.net/dion/future-of-web-apps-google-gears">Google Gears slideset from FOWA</a>.  
Go there now and check it out.
</p><p>
Thus the first talk I saw
was a nifty piece of widgetry by Steven Goodwin called 
<a href="http://www.bluedust.com/minerva/">WARP</a>. In WARP, interacting with a page of
&#39;applets&#39; changed the URL to encode those applets&#39; current state. If
you link to the current page, it will always show that state.
Very long URLs, you can imagine. None of that fancy Ajax stuff.
RESTful, dare I say. Nice API server-side for unpacking your
applet params. 
</p><p>
A trip to the lavatories [<i>transatlantic translation:
&#39;restroom&#39;/&#39;bathroom&#39;</i>] revealed that they are, indeed, doing that
<a href="http://googletesting.blogspot.com/2007/01/introducing-testing-on-toilet.html">Testing in the Toilet</a>
project in Google. It works, too! I learned something. Other intelligence on
Google&#39;s Inner Workings include confirmation of the beanbags and of
the high quality, free grub to which I have already alluded.
</p><p>
A nice bloke from Yahoo! (<a href="http://kid666.com/blog">Tom Hughes-Croucher</a>:
another spy?) came along to sell his idea that, in the
collaborative world of open-minded hackers, we who run websites
could help each other with our 404s. If I get a 404, I use the
referrer link to tell you, via some RESTful POST, that your link to
me is bust (assuming I don&#39;t intend to fix it myself).
</p><p>
I think the world is a little more selfish, so you need to decide
who hurts more - the site who sends their visitors to a dead-end,
or the site delivering that dead-end to a new visitor. I suspect
the latter, by a small margin, as it&#39;s not exactly a nice welcome.
So it&#39;s up to them to let the new visitor down more gently, and to
notify the publisher of the broken link with little or no cost to
them. For example, a really sociable 404-ing site could just
redirect the hapless visitor back to the referring page, adding
&#39;?broken=links&#39; to the URL - hopefully to be picked up by log
scanning scripts at the referring site.
</p><p>
Next up, <a href="http://duncan-cragg.org/">yours truly</a> taking 
<a href="http://www2007.org/prog-Developers.php#saturday">yet another chance</a>
to promote his excellent 
<a href="http://the-u-web.org">Micro Web</a> thingy. 
Couple of people asked about it afterwards - including that nice
chap from Yahoo! Also, a smart - and nice - chap called Toby 
(<a href="http://www.thetobe.com/">this one?</a>) got me into a deep discussion
on imperative vs. event-driven vs. state-driven programming. He was
apparently an old-timer like me, as he was able to engage in
dewy-eyed Functional Programming recollections. I managed to give
out about four full colour printouts about the
<a href="http://the-u-web.org">Micro Web</a>, 
and to collect some good calling cards.
</p><p>
However, <a href="http://joe.truemesh.com">Joe Walnes</a>, even a pint down in
the pub afterwards, still refused to sign up for Micro Web duties.
This in spite of over three years of intensive lobbying, including
eight months of me working Trojan-horse-like in his kitchen, on The 2005
Implementation.
</p><p>
Another ex-Thoughtworks colleague, 
<a href="http://www.pubbitch.org/blog">Simon Stewart</a>
took yet another chance to promote his promising
<a href="http://code.google.com/p/webdriver/">Webdriver</a> thingy. And a very
interesting project it is becoming. Still needs more work - on IE
support, etc - but I&#39;ll probably be using it in my new job at the
<a href="http://www.ft.com">Financial Times</a>.
</p><p>
Another ex-Thoughtworks colleague, 
<a href="http://abc.truemesh.com/">Chris Matts</a> took a chance to promote
his and Andy Pols&#39; interesting new
<a href="http://demo.pols.co.uk/dream/">Dream Machine</a> thingy.
Perhaps a bit like <a href="http://www.cambrianhouse.com">Cambrian House</a> - you put 
your dreams and ideas into it and people expand on them.
Chris is a natural on-stage - and even used the age-old trick of
promising lots of money for no effort, to get our attention at the start.
</p><p>
All I could come up with for the <a href="http://the-u-web.org">Micro Web</a>
was &#39;Cheaper, Wider, Faster&#39;...
</p><p>&#160;</p><p>
<i>Updated: added reference to Dion Almaer, details about WARP, swapped in the 
picture of TWers that I was waiting for and fixed a minor blunder thanks to that 
ever-sharp ThoughtWorker,  
<a href="http://dan.bodar.com/">Dan Bodart</a>..</i>

</p>

            </div>
        </content>
    </entry>
    
    <entry>
        <id>http://duncan-cragg.org/blog/post/how-ruby-can-enable-web-20-platform/</id>
        <title>How Ruby can enable the Web 2.0 Platform</title>
        <published>2007-06-26T15:17:00Z</published>
        
        <updated>2007-06-26T15:17:00Z</updated>
        
        <link rel="alternate" type="text/html" href="http://duncan-cragg.org/blog/post/how-ruby-can-enable-web-20-platform/" title="How Ruby can enable the Web 2.0 Platform" />
        
        <category term="django" />
        
        <category term="web2.0" />
        
        <category term="atom" />
        
        <category term="ajax" />
        
        <category term="yaml" />
        
        <category term="rest" />
        
        <category term="event-driven" />
        
        <category term="publishsubscribe" />
        
        <category term="architecture" />
        
        <category term="declarative" />
        
        <category term="socialsoftware" />
        
        <category term="strest" />
        
        <category term="app" />
        
        <category term="microformats" />
        
        <category term="scalability" />
        
        <category term="json" />
        
        <category term="openid" />
        
        <category term="redux" />
        
        <category term="ruby" />
        
        <summary type="xhtml">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>

<a href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html">Web 2.0&#39;s definition</a>
includes seeing the Web as an application platform. Which means it
is in competition with Java and .Net, and with SOA, for both local
and widely distributed applications.
</p><p>
If the Web is going to be a platform, the skills you need to learn
to program it are the core Web 2.0 technologies such as Ajax, JSON,
Atom, Microformats and OpenID.
</p><p>
And Ruby. This language, that&#39;s capturing the hearts of many Web 2.0
programmers, is ideal for easing the transition from the Java
and .Net platforms to the Web platform, as I will show.
</p><p>
Even if you&#39;re part of a big company that is generally immune to the
latest trends, the marriage of Ruby and the Web-as-platform may be
something to prepare for. It could even displace your SOA agenda...
 &#160; ...
</p>

            </div>
        </summary>
        <content type="xhtml" xml:space="preserve">
            <div xmlns="http://www.w3.org/1999/xhtml">

<p>
</p><div class="summary"><p>
<a href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html">Web 2.0&#39;s definition</a>
includes seeing the Web as an application platform. Which means it
is in competition with Java and .Net, and with SOA, for both local
and widely distributed applications.
</p><p>
If the Web is going to be a platform, the skills you need to learn
to program it are the core Web 2.0 technologies such as Ajax, JSON,
Atom, Microformats and OpenID.
</p><p>
And Ruby. This language, that&#39;s capturing the hearts of many Web 2.0
programmers, is ideal for easing the transition from the Java
and .Net platforms to the Web platform, as I will show.
</p><p>
Even if you&#39;re part of a big company that is generally immune to the
latest trends, the marriage of Ruby and the Web-as-platform may be
something to prepare for. It could even displace your SOA agenda...
</p></div><p>
Few would disagree that the Ruby language is riding the wave generated
by Ruby-on-Rails. In turn, Rails is riding the Web 2.0 wave, coming
as it does from underpinning the very Web 2.0 
<a href="http://www.37signals.com">37signals</a> 
product suite.  
</p><p>
Rails and Ruby have tapped into the tech Zeitgeist of friendly,
simple and powerful. The speed with which the Ruby and Rails
communities have delivered the key components of Web 2.0 is matched
by the speed at which 
<a href="http://radar.oreilly.com/archives/2007/05/state_of_the_co_10.html">Ruby and Rails books are leaving the shelves</a>.
</p><p>
What is the ideal platform of Web 2.0? Will it be Rails and Ruby?
Will Ruby ride the Web 2.0 wave into the mainstream in the same way
Java rode the Web 1.0 wave?
</p><p>
Well, here&#39;s the problem with that question: Web 2.0 is supposed to
be primarily about the <i>Web</i> itself as the platform, as 
<a href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html">explained first</a>
by Tim O&#39;Reilly and then by a thousand Web 2.0 vendors and industry
watchers after him.
</p><p>
Web-as-platform is not just vendor hype or pundit hand-waving.
Let&#39;s think about what O&#39;Reilly meant by that.
</p><p>&#160;</p><p>
<b>Web as Platform</b>
</p><p>
Web 2.0 is about making the Web more interactive, and thus able to
support applications where Java and .Net would once have been
considered the sole delivery platforms.
</p><p>
The fact that the technologies of the Web can be turned to this
use is a shift with far-reaching implications.
</p><p>
Broadly, the shift we are seeing is from the one-way, static
document delivery of Web 1.0 towards the two-way, dynamic data
exchange of Web 2.0.
</p><p>
This fundamental repurposing is delivering more complex, interactive
applications that work inside our browsers and which fully leverage
the benefits of online operation. 
</p><p>
Web 2.0 is bringing the user and their stuff <i>into</i> the very Web
that they hitherto only passively consumed.  This network-enablement
of the user in turn enables their <i>social</i> networking and their
shared creativity and self-expression. 
</p><p>
Web 2.0 has tapped into a deep human need - a fact reflected in the
vast traffic volumes and correspondingly vast valuations of Web 2.0
startups that we&#39;re currently seeing.
</p><p>
But Web 2.0 is not just for the startups: Enterprise Web 2.0 is
coming! The bigco.com site is going to be looking a little, well,
static and lifeless when compared to the new sites that are
springing up everywhere, and that most of BigCo&#39;s employees are
using. Further, BigCo can gain huge benefits from Web 2.0 approaches
empowering and connecting those employees on the Intranet. And that
Intranet is an ideal platform for deploying company-wide, interactive
applications.
</p><p>
This shift in the Web to two-way dynamic data is being powered by a
set of technologies that a Web platform programmer is going to have
to learn.
</p><p>&#160;</p><p>
<b>Web 2.0 Platform Technologies</b>
</p><p>
Anything that claims to be an application platform must support
data. Web 2.0 is above all the data Web. Web 2.0 is about
semantics, not free text and font sizes. Hence, it inevitably starts
with data-oriented formats such as 
<a href="http://en.wikipedia.org/wiki/XHTML">XHTML</a>, 
<a href="http://www.yaml.org/">YAML</a> and 
<a href="http://json.org/">JSON</a>.  In Web 2.0
more than ever, we talk about data not documents and about
separating data from its presentation.  CSS is big in Web 2.0, for
good reason (not just for gradient fills). Inside the page of a
self-respecting Web 2.0 application, you&#39;ll often find 
<a href="http://microformats.org/">Microformats</a> - again, 
semantics in the page: publishing concise data of widely-understood
standard formats. Some of those Microformats may be 
<a href="http://support.technorati.com/support/siteguide/tags">tags</a>, and in
Web 2.0 the simplest and most powerful semantics are those little
pivot points in Webspace.
</p><p>
Again, if you&#39;re going to be a general purpose platform, you need to
be able to fetch, update, notify and display that data.  Web 2.0
integration usually happens via JSON data structures and 
<a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>
interfaces (some of which, especially those based on 
<a href="http://atompub.org/">AtomPub</a>,
are true REST).  Following on from the data-like pages we serve to
browsers, come the data-like feeds we publish to feed readers and to
other applications.  After feeds, the core technology that gives
Web 2.0 its dynamism and interactivity is 
<a href="http://en.wikipedia.org/wiki/Ajax_(programming)">Ajax</a> and 
<a href="http://en.wikipedia.org/wiki/DHTML">DHTML</a>, and
increasingly 
<a href="http://en.wikipedia.org/wiki/Comet_(programming)">Comet</a>
(server push to the browser). The core technology
that gives Web 2.0 its users is increasingly 
<a href="http://openid.net/">OpenID</a>.
</p><p>
All of the above are open technologies. You can do Web 2.0 without
proprietary technologies, just like Web 1.0. Indeed, keeping to the
principles that made the Web successful is also essential to the
success of Web 2.0. The Web platform is the first application
platform that has to consider scalability and interoperability, and
will ignore them at its cost.  I have written before about open
data, use of standard data formats and using REST properly to avoid
creating unscalable, walled-garden sites. You don&#39;t need Flash or
SilverLight, you don&#39;t need vast amounts of custom Javascript, you
don&#39;t need function calls tying you to your servers.
</p><p>&#160;</p><p>
<b>Programming the Web 2.0 Platform</b>
</p><p>
So, we&#39;ve got the dynamic data that you&#39;d expect of a would-be
platform. But how to drive changes in those data? How do we
program the Web platform to animate all this data?
</p><p>
All Rails programmers will know the above technology list; it comes
with the territory. The Web 2.0 Platform can be very succesfully
powered by Rails and Ruby. Ruby and Rails make Web 2.0
applications simple and quick to program, addressing many of the
needs of simple Web 2.0 applications out of the box. There&#39;s little
doubt that Ruby and Rails will have a secure future riding the
Web 2.0 wave.
</p><p>
However, for many Web 2.0 applications, programming may not even be
necessary, at least not in the procedural or imperative style
programmers expect. 
</p><p>
Look back to the early 90&#39;s: &#39;Web 1.0&#39; made a whole class of
applications easy to write without programming: applications for
navigating information. You just wrote in HTML, declaratively.
</p><p>
Now look back at the long path of evolution of Java, through J2EE,
Spring, AOP, IoC, Domain Driven Design, POJOs. All trying to
achieve the simple goal of &#39;remove all that MVC and persistence
stuff and let us concentrate on business or domain objects&#39;. But
they never quite seemed to get it right. 
</p><p>
But then Rails comes along, and has succeeded by simple virtue of
concentrating on easy manipulation of the 
&#39;<a href="http://www.oreillynet.com/pub/a/oreilly/tim/news/2005/09/30/what-is-web-20.html?page=3">Intel Inside</a>&#39;
of Web 2.0 - data. 
</p><p>
It&#39;s reminiscent of the 
&#39;<a href="http://nakedobjects.org/wiki/Main_Page">Naked Objects</a>&#39;
approach to application building with minimal programming (just
business or domain code in POJOs that expose state into the GUI and
are transparently persisted). The 
<a href="http://ajaxian.com/archives/streamlined-naked-objects-for-the-web">Streamlined</a>
project takes Rails even further down this path. Rails&#39; nearest
competitor, <a href="http://www.djangoproject.com/">Django</a>,
has an admin interface that works in a similar way, automatically
generating edit pages based on the data model.
</p><p>
Web 2.0 is about data, about semantics. Web 2.0 is inherently
declarative.  So Web 2.0 applications can be written declaratively -
Web 2.0 mashups can be just wired together and their data animated
by business rules. A bit like programming spreadsheets. 
</p><p>
<a href="http://www.techcrunch.com/2007/03/02/5-ways-to-mix-rip-and-mash-your-data/">Teqlo</a>, 
<a href="http://www.techcrunch.com/2007/04/16/coghead-announces-17000-developers-building-applications-visually/">Coghead</a>, 
<a href="http://www.techcrunch.com/2007/03/02/5-ways-to-mix-rip-and-mash-your-data/">Pipes</a>, 
<a href="http://www.techcrunch.com/2006/03/11/dabbledb-online-app-building-for-everyone/">DabbleDB</a>, 
<a href="http://www.techcrunch.com/2007/06/19/new-site-jumps-into-the-application-creation-space/">LongJump</a>, 
<a href="http://www.techcrunch.com/2007/05/18/microsoft-launches-popfly-mashup-app-creator-built-on-silverlight/">Popfly</a>, 
<a href="http://www.techcrunch.com/2006/08/21/salesforce-dives-deep-into-google-adwords/">AppExchange</a> and
<a href="http://www.techcrunch.com/2006/04/30/wyaworks-app-builder-for-non-coders/">Wyaworks</a> 
are all examples of the different ways to program the new Web 2.0
platform without imperative code.
</p><p>
That&#39;s what we mean by Web-as-platform - not only is the underlying
programming language irrelevant, it will often not even be needed,
certainly for simple data manipulation applications and for many
simple mashups. Being RESTful gives you a massive head start in
this, of course.
</p><p>
While Rails is already in the game with its innate understanding of
Web 2.0 techniques and philosophies, Ruby itself has a huge amount
to offer the would-be declarative programmer, who is making the
transition to this new Web platform from their traditional Java
or .Net platform.  In particular, it is easy to write your domain
logic in a declarative style in Ruby: they call them &#39;DSLs&#39; these
days, but the idea is the same in most examples I&#39;ve seen.
</p><p>&#160;</p><p>
<b>Web 2.0 - The Web Redux</b>
</p><p>
Now, if you&#39;ve been following this blog, you&#39;ll know I have a
few opinions on 
<a href="http://duncan-cragg.org/blog/post/right-way-to-do-ajax-is-declaratively/">Declarative Web 2.0</a> and on
<a href="http://duncan-cragg.org/blog/post/distributed-observer-pattern-rest-dialogues/">patterns for programming REST</a>.
Essentially I argue that, if you want to play in the Web 2.0
platform game, you don&#39;t want to be writing screeds of Javascript
functions that call more functions on your servers. 
</p><p>
I recently presented some ideas along these lines at
the WWW2007 conference, entitled 
&#39;<a href="http://www2007.org/prog-Developers.php#saturday">The Micro Web: putting the Web back into Web 2.0</a>&#39;,
where I also showed a demo written in Python.
</p><p>
This approach combines my 
<a href="http://duncan-cragg.org/blog/post/distributed-observer-pattern-rest-dialogues/">Distributed Observer Pattern</a>
with Comet push to enable highly dynamic Web 2.0 applications to be
coded RESTfully and declaratively, with zero Javascript.  The
Distributed Observer Pattern offers a clean programming model for
animating the Web 2.0 dynamic-data technology set I described above. 
</p><p>
I believe the Observer Pattern is core to the way we&#39;ll be
programming when the Web 2.0 Platform hits mainstream.  It enables
the kind of event- and rule-driven programming that matches the
characteristics of the Web 2.0 dynamic data platform. As a 
further killer benefit, it also directly addresses the optimal
utilisation of multicore processors.
</p><p>
I am currently porting my Python implementation of this approach to
Ruby, in the
<a href="http://rubyforge.org/projects/redux/">Redux</a> 
project on Rubyforge.  Redux stands for &#39;Ruby Event-Driven Update
Exchange&#39;.  It uses the highly scalable
<a href="http://rubyforge.org/projects/eventmachine">EventMachine</a>
epoll-based event loop to power its event-driven architecture.
This will be essential when Redux is asked to scale up a 
Comet-based application.
</p><p>
Like Rails, Redux will be a Web (2.0) application framework, but
unlike Rails, it puts the Observer Pattern and event- and
rule-driven programming at its core. 
</p><p>
Redux&#39;s headline is &#39;Web 2.0 in-a-box&#39; or &#39;Naked Objects on the Web&#39;.
</p><p>&#160;</p><p>
<b>Conclusion</b>
</p><p>
If you&#39;re in BigCo, and are responsible for setting BigCo&#39;s
technical strategy, then train your Java devs up on Web 2.0 core
technologies such as Ajax, JSON, Atom, Microformats and OpenID.  
</p><p>
And fire up their enthusiasm by tapping into Ruby (perhaps via
JRuby) on your way to the Web 2.0 platform. 
</p><p>
Learn patterns for mashing and integrating. Learn about REST and
event- and rule-driven programming, including declarative DSLs.
</p><p>
When this Web platform hits BigCo, you will probably find that its
REST or ROA style make your SOA integration strategy look rather
complex and unweildy.
</p><p>
Check out the
<a href="http://duncan-cragg.org/blog/post/distributed-observer-pattern-rest-dialogues/">Distributed Observer Pattern</a>,
and download
<a href="http://rubyforge.org/projects/redux/">Redux</a>
when it&#39;s done (I&#39;ll let you know if you subscribe here!).
</p><p>
In 2007 and beyond, its the Web itself that&#39;s the platform, not
Java or .Net. But if you want to get there via a language-based
platform, Ruby could be the best way to transition to it.
</p><p>
<i>Note: Everything I said about Ruby and Rails applies equally in
technical terms to Python and Django, but regardless of the
significant benefits of the latter, Ruby and Rails have the Web 2.0
market and mindshare. I&#39;ll probably switch this blog from Django to
Redux sometime this year..</i>
</p><p>
<i>(c) 2007 Duncan Cragg</i>
</p><p>

</p>

            </div>
        </content>
    </entry>
    
</feed>

