<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
 
 <title>Joe Geldart</title>
 <link href="http://www.joegeldart.com/atom.xml" rel="self"/>
 <link href="http://www.joegeldart.com/"/>
 <updated>2011-09-16T03:08:28-07:00</updated>
 <id>http://www.joegeldart.com/</id>
 <author>
   <name>Joe Geldart</name>
   <email>joe@joegeldart.com</email>
 </author>

 
 
 <entry>
   <title>The Adoption of Renewable Energy in Europe</title>
   <link href="http://www.joegeldart.com/2010/12/adoption-of-renewables"/>
   <updated>2010-12-17T00:00:00-08:00</updated>
   <id>http://www.joegeldart.com/2010/12/adoption-of-renewables</id>
   <content type="html">    &lt;style&gt;
#fig {
  position: relative;
  width: 800px;
  margin-top: 10px;
}
      
     #yearSlider {
  position: absolute;
  left: 100px;
  width: 610px;
  margin-top: -13px;
}
       
    &lt;/style&gt;
    &lt;div id=&quot;fig&quot;&gt;
        &lt;div id=&quot;container&quot;&gt;
          &lt;div id=&quot;yearSlider&quot;&gt;&lt;/div&gt;
        &lt;/div&gt;
        &lt;div id=&quot;vis&quot;&gt;&lt;/div&gt;
        &lt;script type=&quot;text/javascript&quot;&gt;

          total_primary_energy_production.forEach(function(row) {
            row.total_production = parseFloat(row.total_production);
            row.renewable_production = parseFloat(row.renewable_production);
            row.nonrenewable_production = parseFloat(row.nonrenewable_production);
          });

          var eu_borders_nested = pv.nest(eu_borders).key(function(d) { return d.code; })
            .rollup(function(v) { return v.map(function(d) { return d.code2; }); });
          eu_borders_nested[&quot;GB&quot;] = eu_borders_nested[&quot;UK&quot;];

          var countries = pv.nest(eu_borders).key(function(d) { return d.code; }).entries().map(function(d) { return { code: d.key == &quot;UK&quot; ? &quot;GB&quot; : d.key };  });

          var country_data = pv.nest(total_primary_energy_production)
            .key(function(d) { return d.year; })
            .key(function(d) { return d.code; })
            .rollup(function(v) { return v[0]; });


          var minYear = pv.min(total_primary_energy_production, function(d) { return d.year; });
          var maxYear = pv.max(total_primary_energy_production, function(d) { return d.year; });

          var minPop = pv.min(total_primary_energy_production, function(d) { return isNaN(d.total_production) ? 0 : d.total_production; });
          var maxPop = pv.max(total_primary_energy_production, function(d) { return isNaN(d.total_production) ? 0 : d.total_production; });

          var minRenewable = pv.min(total_primary_energy_production, function(d) { var res = d.renewable_production / d.total_production; return isNaN(res) ? 0.00001 : res; });
          var maxRenewable = pv.max(total_primary_energy_production, function(d) { var res = d.renewable_production / d.total_production; return isNaN(res) ? 0.00001 : res; });

          var currentYear = minYear;

          $(&quot;#yearSlider&quot;).slider({
            min: minYear,
            max: maxYear,
            value: minYear,
            slide: function(e, ui) {
              currentYear = ui.value;
              updateYear();
              vis.render();
            }
          });

          var i = 0,
              mapMargin = 30,
              w = 810,
              h = 400,
              scale = pv.Geo.scale().domain({lat: 69.9301, lng:-38.7813}, {lat: 31.5036, lng: 52.3828}).range(w, h);

          var legendMargin = 20,
              ease = null,
              yearsMargin = 100;

          var yearsScale = pv.Scale.linear()
              .domain(minYear, maxYear)
              .range(yearsMargin + 2, w - yearsMargin);

          var sizeScale = pv.Scale.linear()
              .domain(minPop, maxPop)
              .range(20,50);

          var nodes = [],
              codeToNode = {},
              links = [];

          countries.forEach(function(c) {
            if(country_data[currentYear][c.code]) {
              var country = country_data[currentYear][c.code];
              var coords = { lat: country.lat, lng: country.lng };
              var x = scale(coords).x,
                      y = scale(coords).y,
                      renewable = country.renewable_production / country.total_production,
                      renewableProportion = isNaN(renewable) ? 0 : renewable;
                      total = isNaN(country.total_production) ? 0 : country.total_production
                      n = {x: x, y: y, p: {x: x, y: y}, r: sizeScale(total), code:c.code};
                  nodes.push(n);
                  codeToNode[c.code] = n;
              var borders = eu_borders_nested[c.code];
              borders.forEach(function(b) {
                if (codeToNode[c.code] &amp;&amp; codeToNode[b] &amp;&amp; c.code != b) {
                  var nodeA = codeToNode[c.code];
                  var nodeB = codeToNode[b];
                  links.push({sourceNode:nodeA, targetNode:nodeB, length:(nodeA.r + nodeB.r + 2)});
                }
              });
            }
          });

          function updateYear() {
            nodes.forEach(function(n){ var total = country_data[currentYear][n.code].total_production; n.r = sizeScale(isNaN(total) ? 0 : total); });
            links.forEach(function(l){ l.length = (l.sourceNode.r + l.targetNode.r + 2); });
            i = 0;
            var stepSome = setInterval(function() {
              if (i++ &gt; 10) clearInterval(stepSome);
              sim.step();
              vis.render();
            }, 20);
          }
          
          var collisionConstraint = pv.Constraint.collision(function(d){ return d.r + 1; }),
              positionConstraint = pv.Constraint.position(function(d){ return d.p; }),
              linkConstraint = pv.Force.spring(100).links(links);

          var sim = pv.simulation(nodes)
              .constraint(collisionConstraint)
              .constraint(positionConstraint)
              .constraint(linkConstraint)
              .force(pv.Force.drag());

          var vis = new pv.Panel()
              .canvas(&quot;vis&quot;)
              .width(w)
              .height(h)
              .top(50)
              .bottom(30);

          // Add the ticks and labels for the year slider
          vis.add(pv.Rule)
               .data(pv.range(minYear, maxYear + .1))
               .left(yearsScale)
               .height(4)
               .top(-40)
             .anchor(&quot;bottom&quot;).add(pv.Label);

          var nodepanel = vis.add(pv.Panel)
              .data(nodes)
              .left(function(d){ return d.x; })
              .top(function(d){ return d.y; });

          nodepanel.add(pv.Wedge)
              .data(function(d) { var c = country_data[currentYear][d.code]; var total = c.total_production; return [{prop: c.renewable_production / total, r: d.r}, {prop: 1.0 - (c.renewable_production / total), r: d.r}]; })
                .left(0)
                .top(0)
                .visible(function(d) { return !isNaN(d.prop); })
                .outerRadius(function(d){ return d.r; })
                .angle(function(d){ return d.prop * 2 * Math.PI;})
                .title(function(d) { return [&quot;Renewable: &quot;, &quot;Non-Renewable: &quot;][this.index] + (d.prop*100).toFixed(2) + &quot;%&quot;; })
                .fillStyle(function(){ return [&quot;#76A3FC&quot;, &quot;#FFBA37&quot;][this.index]; })
                .strokeStyle(null);

          nodepanel.add(pv.Label)
          .left(0)
          .top(0)
             .text(function(d){ return d.code; })
              .textStyle(&quot;#433&quot;)
              .font(function(d){ return &quot;bold &quot; + (5*Math.log(d.r)).toFixed(0) + &quot;px 'Calibri', 'Helvetica Neue', sans-serif&quot;; })
              .textAlign(&quot;center&quot;)
              .textBaseline(&quot;middle&quot;);

          updateYear();
          
          ease = setInterval(function() {
            if (i++ &gt; 140) {
              clearInterval(ease);
              ease = null;
            }
            sim.step();
            positionConstraint.alpha(Math.pow(.7, i + 2) + .03);
            linkConstraint.damping(Math.pow(.7, i + 2) + .03);
            vis.render();
          }, 42);
          
        &lt;/script&gt;
    &lt;/div&gt;
    &lt;div class=&quot;data_source&quot;&gt;
      &lt;a href=&quot;http://epp.eurostat.ec.europa.eu/&quot;&gt;Eurostat&lt;/a&gt; (tables &lt;a href=&quot;http://ec.europa.eu/eurostat/product?code=ten00076&amp;mode=view&quot;&gt;ten00076&lt;/a&gt; and &lt;a href=&quot;http://ec.europa.eu/eurostat/product?code=ten00081&amp;mode=view&quot;&gt;ten00081&lt;/a&gt;), &lt;a href=&quot;http://www.freebase.com/&quot;&gt;Freebase&lt;/a&gt;.
    &lt;/div&gt;
    &lt;p&gt;
      This visualisation shows the adoption of renewable energy sources within the EU over the period 1997 to 2008.
      The orange wedges show the percentage of primary (i.e. produced within the country) energy that comes from
      non-renewable sources. The blue wedges that which is renewable. The size of each pie chart is proportional
      to the amount of primary energy produced within tha country.
    &lt;/p&gt;
    &lt;p&gt;
      It was written using &lt;a href=&quot;http://vis.stanford.edu/protovis/&quot;&gt;Protovis&lt;/a&gt;, with the code based on the &lt;a href=&quot;http://vis.stanford.edu/protovis/ex/cartogram.html&quot;&gt;Dorling cartogram example&lt;/a&gt;. The data was merged
      and exported to JSON using &lt;a href=&quot;http://code.google.com/p/google-refine/&quot;&gt;Google Refine&lt;/a&gt;.
    &lt;/p&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Energy Use per Year By Sector</title>
   <link href="http://www.joegeldart.com/2010/12/energy-use-by-sector"/>
   <updated>2010-12-16T00:00:00-08:00</updated>
   <id>http://www.joegeldart.com/2010/12/energy-use-by-sector</id>
   <content type="html">&lt;script type=&quot;text/javascript&quot;&gt;
var w = 600
h = 0.5 * w;

var vis = new pv.Panel()
    .width(w)
    .height(h)
    .bottom(25)
    .left(20)
    .right(20)
    .top(0);

  var min_year = pv.min(eu_energy, function(d){ return d.year; });
  var max_year = pv.max(eu_energy, function(d){ return d.year; });
  var min_energy = 15000;
  var max_energy = 1500000;

  var nested_data = pv.nest(eu_energy)
    .key(function(d){ return d.sector; })
    .key(function(d){ return d.year; })
    .rollup(function(v){ return pv.sum(v, function(d) { return d.consumption; })});
  var flat_data = pv.flatten(nested_data)
    .key(&quot;sector&quot;)
    .key(&quot;year&quot;)
    .key(&quot;consumption&quot;)
    .array();
  var data = pv.nest(flat_data).key(function(d) { return d.year }).entries().map(function(d) {
    var result = {};
    result.year = parseFloat(d.key);
    d.values.forEach(function(r) { result[r.sector] = parseFloat(r.consumption); });
    return result;
  });

  var x = pv.Scale.linear(min_year, max_year).range(0, w),
      y = pv.Scale.linear(min_energy, max_energy).range(0, h);
      fill = pv.Scale.ordinal(&quot;Households&quot;, &quot;Industry&quot;, &quot;Transport&quot;, &quot;Services&quot;, &quot;Other Sectors&quot;)
          .range(&quot;#336699&quot;, &quot;#003366&quot;, &quot;#99aaff&quot;, &quot;blue&quot;, &quot;#0033aa&quot;);


  var stack = vis.add(pv.Layout.Stack)
      .layers([&quot;Households&quot;, &quot;Industry&quot;, &quot;Transport&quot;, &quot;Services&quot;, &quot;Other Sectors&quot;])
      .values(data)
      .offset(&quot;silohouette&quot;)
      .x(function(d) { return x(d.year) })
      .y(function(d, p) { return isNaN(y(d[p])) ? 0 : y(d[p]); });

  stack.layer.add(pv.Area)
      .title(function(d,p) { return p })
      .fillStyle(function(d,p){return fill(p)})
      .strokeStyle(function(){ return this.fillStyle().alpha(.5)});

  vis.add(pv.Rule)
    .data(data)
    .left(function(d) { return x(d.year); })
    .strokeStyle(&quot;rgba(180,180,180,0.3)&quot;)
    .anchor(&quot;bottom&quot;).add(pv.Label)
      .text(function(d) { return d.year })
      .textStyle(&quot;rgba(0,0,0,0.5)&quot;)
      .textAngle(Math.PI/2);

  vis.render();
&lt;/script&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Validating with Verity</title>
   <link href="http://www.joegeldart.com/2010/11/validating-with-verity"/>
   <updated>2010-11-21T00:00:00-08:00</updated>
   <id>http://www.joegeldart.com/2010/11/validating-with-verity</id>
   <content type="html">&lt;p class=&quot;abstract&quot; property=&quot;dcterms:description&quot;&gt;
  Validations are important in many systems for maintaining data integrity with respect to some domain model.
  ActiveModel includes a set of validations which can be used in Rails for describing conditions on 
  model objects, but these are limited to persisted objects and lack expressiveness and reusability; slightly
  altering the nature of a validation often requires a new custom validation to be written. Verity provides
  a generic framework for validating any Ruby object, whether persisted or not, and composing validations
  with an expressive, readable DSL.
&lt;/p&gt;

&lt;section id=&quot;sec-why&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Why do we validate?&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
    Validation is important for expressing domain constraints, ensuring that the data which is stored in an 
    information system makes sense. In a stock control system (for example) it would be nonsense for the 
    weight (or quantity) of a stock item to be negative. Validations allow us to prevent such data from being 
    persisted. Validations also allow us to check the sanity of the results of operations as a form of in 
    process error check. Any errors from these validations can be presented to the users, or put into a log, 
    in a readable form that explains exactly what went wrong and how to fix it. These improves the usability
    of the system.
  &lt;/p&gt;
  &lt;p&gt;
    A good validation library makes it easy to express arbitrary aspects of the domain model. The complexity 
    of the code should be proportional to the complexity of the condition. A vital part of this is allowing 
    us to decompose complex conditions into small, reusable parts that may be glued back together in many 
    different ways.
  &lt;/p&gt;
  &lt;p&gt;
    &lt;a href=&quot;https://github.com/jgeldart/verity&quot;&gt;Verity&lt;/a&gt; is my attempt to provide an expressive validation system. Unlike &lt;a href=&quot;http://yehudakatz.com/2010/01/10/activemodel-make-any-ruby-object-feel-like-activerecord/&quot;&gt;ActiveModel&lt;/a&gt;, 
    the validations are expressed as a readable DSL. Unlike &lt;a href=&quot;https://github.com/cainlevy/semantic-attributes&quot;&gt;Semantic Attributes&lt;/a&gt;, there is no tie to ActiveRecord.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-humane&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;A humane validation library&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
    Verity’s aim is to make validations readable and composable and, therefore, more maintainable. After spending too 
    long writing complex, interdependent validations for a project with an (admittedly) tricky data model, I decided 
    that enough was enough. Validations are a vital part of the definition of a data model in any real-world 
    application, where data noise can be introduced by its users and code and must be prevented. As such, they should 
    be as nice to define as possible.
  &lt;/p&gt;
  &lt;p&gt;
    Verity accomplishes this in two main ways:
  &lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;It provides a DSL for defining the validations in a readable syntax similar to RSpec; and&lt;/li&gt;
    &lt;li&gt;It treats validations lazily, so that they can be composed to construct more complex validations out of simpler ones.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;
    The main inspirations for the project are &lt;a href=&quot;http://rspec.info/&quot;&gt;RSpec&lt;/a&gt; and &lt;a href=&quot;http://github.com/cainlevy/semantic-attributes/&quot;&gt;Semantic Attributes&lt;/a&gt;, 
    a similar attempt to define a DSL for validations (although without the composability).
  &lt;/p&gt;
  &lt;p&gt;
    As additional goals, Verity aims to:
  &lt;/p&gt;
  &lt;ul&gt;
    &lt;li&gt;Be agnostic as to what persistence framework, if any, is being used; it is as useful on plain Ruby objects as it is on ActiveRecord records;&lt;/li&gt;
    &lt;li&gt;Be easy to extend, with new predicates that can be shared with other developers and projects; and&lt;/li&gt;
    &lt;li&gt;Integrate well with whatever internationalisation framework is being used to support multi-lingual and multi-region applications.&lt;/li&gt;
  &lt;/ul&gt;
  &lt;p&gt;
    Possible future goals include integration with YARD, for easy documentation of model constraints, and RSpec and Cucumber, for testing these constraints.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-using&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Using Verity&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
    Enabling Verity's DSL and core API on an object is simply a matter of using the
    class method &lt;code&gt;verifiable&lt;/code&gt; in the class definition. This is an extension added
    to &lt;code&gt;Object&lt;/code&gt; when the gem is loaded:
  &lt;/p&gt;
  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class User
  verifiable
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;
  &lt;p&gt;
    Instances of this class now have a number of methods defined upon them for
    performing validations. &lt;code&gt;#valid?&lt;/code&gt; returns &lt;code&gt;false&lt;/code&gt; if and only if the
    instance fails to satisfy the defined conditions and &lt;code&gt;true&lt;/code&gt; otherwise (note
    that it will return &lt;code&gt;true&lt;/code&gt; if no validations are defined at all).
    &lt;code&gt;#validation_errors&lt;/code&gt; returns a &lt;code&gt;Hash&lt;/code&gt;, keyed by attribute name, of any errors
    found on the instance. This allows you to report failures back to your users
    in a natural fashion.
  &lt;/p&gt;

  &lt;p&gt;
    Validations are defined using the syntax &lt;code&gt;attribute_name_must&lt;/code&gt; (for
    positive validations) or &lt;code&gt;attribute_name_must_not&lt;/code&gt; (for negative ones).
  &lt;/p&gt;

  &lt;p&gt;
    These validations are built using &lt;em&gt;predicates&lt;/em&gt;, objects that represent abstract
    tests against values. The simplest predicate is a nil check, which matches
    values that are &lt;code&gt;nil&lt;/code&gt;:
  &lt;/p&gt;

  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class User
  verifiable

  attr_accessor :login
  login_must_not be_nil
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;

  &lt;p&gt;
    Multiple validations may be defined against an attribute and all will be tested:
  &lt;/p&gt;

  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class User
  verifiable

  attr_accessor :login
  login_must_not be_nil
  login_must have_length(:at_least =&amp;gt; 4)
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;

  &lt;p&gt;
    Predicates can take late-bound parameters, either positional or named:
  &lt;/p&gt;

  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class User
  verifiable

  attr_accessor :login, :star_count
  login_must have_length, :at_least =&amp;gt; 4
  star_count_must be_greater_than, 5
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;

  &lt;p&gt;
    Defining new predicates is as simple as defining a new class that inherits from
    &lt;code&gt;Verity::Predicates::Base&lt;/code&gt; and a class method (available to your class) that
    constructs an appropriate instance of your class. Methods defined within
    &lt;code&gt;Verity::Predicates&lt;/code&gt; are automatically available to all classes which define
    &lt;code&gt;verifiable&lt;/code&gt;. As with RSpec, it is through judicious use of these methods that
    we gain our readability, so think carefully about how your definitions 'read'.
    In particular, be sparing with positional parameters (and treat them like
    direct and indirect objects in English) and use named parameters with keys that
    read like prepositional phrases (such as &lt;code&gt;with_domain&lt;/code&gt; or &lt;code&gt;at_least&lt;/code&gt;).
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-lazy-params&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Lazy parameters&lt;/h2&gt;
  &lt;/header&gt;

  &lt;p&gt;
    Often we want to validate based on data only available at run-time, and often
    specific to the record being validated. Named predicate parameters in Verity
    support lazy evaluation using blocks. A block-valued parameter is evaluated at
    validation time to produce a value, which is then set on that predicate. The
    blocks may, optionally, take a parameter which is set to the record instance
    being validated. This may be used to retrieve attribute values at run-time.
  &lt;/p&gt;

  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class Message
  verifiable

  attr_accessor :length, :message
  message_must have_length, :exactly =&amp;gt; lambda{|r| r.length}
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;

  &lt;p&gt;
    In fact, this usage is so important that we have a sugar defined for it using
    a method &lt;code&gt;the&lt;/code&gt;:
  &lt;/p&gt;

  &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class Message
  verifiable

  attr_accessor :length, :message
  message_must have_length, :exactly =&amp;gt; the(:length)
end
&lt;/code&gt;&lt;/pre&gt;
  &lt;/blockquote&gt;

  &lt;p&gt;
    It is planned to support this for positional parameters as well very shortly
    but this hasn't been implemented yet.
  &lt;/p&gt;
&lt;/section&gt; 
&lt;section id=&quot;sec-future-work&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Future work&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
    This library is in a very early stage right now. There are lots of places it could go 
    depending on how I, and others, find use for it and the API is not settled yet. I have 
    considered a few of the possibilities, and have concrete plans for some.
  &lt;/p&gt;
  &lt;section id=&quot;subsec-activerecord&quot;&gt;
    &lt;header&gt;
      &lt;h3&gt;ActiveRecord integration&lt;/h3&gt;
    &lt;/header&gt;
    &lt;p&gt;
      Like it or not, ActiveRecord is a very important library that is used in many projects.
      Unfortunately, ActiveRecord’s validations (now provided through ActiveModel) are cumbersome
      and this was one of the main motivations for Verity. I plan to allow Verity to be used as 
      a drop-in replacement for ActiveModel’s validations. This will probably require some changes
      to the API to align the two. Ideally, I’d avoid an adapter library (such as many systems use)
      and a core dependency is out of the question; as mentioned previously, an aim of Verity is to 
      be usable with any Ruby object and definitely outside of Rails.
    &lt;/p&gt;
  &lt;/section&gt;
  &lt;section id=&quot;subsec-internationalisation&quot;&gt;
    &lt;header&gt;
      &lt;h3&gt;Internationalisation&lt;/h3&gt;
    &lt;/header&gt;
    &lt;p&gt;
      The world is full of variety, and especially linguistic variety. Verity’s message system is
      very crude at the moment, and it is a priority that it supports multiple locales. This does not
      only include translation of messages, but also localised validations for things such as dates, 
      currencies, addresses and telephone numbers. Localisation and internationalisation should be 
      supported in some form no matter what system Verity is used in, although we could still leave
      the translations to the outer system.
    &lt;/p&gt;
  &lt;/section&gt;
  &lt;section id=&quot;subsec-conditionals&quot;&gt;
    &lt;header&gt;
      &lt;h3&gt;Conditional validation&lt;/h3&gt;
    &lt;/header&gt;
    &lt;p&gt;
      Composability brings some exciting possibilities. One of these is allowing a boolean logic of 
      validations. A given validation can be said to apply (or not apply) only when another validation 
      passes. This could be used to avoid inundating the user with irrelevant messages or to define 
      complex domain constraints within a single model. As an example, imagine a validation on a
      message body that checks it doesn’t contain any links, but only if it is HTML:
    &lt;/p&gt;
    &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class Message
  verifiable
  body_must_not contain_selector(&quot;a&quot;), :if =&amp;gt; is_valid_html
end&lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;p&gt;
      Implementing these conditionals may require some changes to the core DSL to make them expressive 
      yet humane.
    &lt;/p&gt;
  &lt;/section&gt;
  &lt;section id=&quot;subsec-soft-validations&quot;&gt;
    &lt;header&gt;
      &lt;h3&gt;Soft validations&lt;/h3&gt;
    &lt;/header&gt;
    &lt;p&gt;
      We often deal with hard constraints, requiring that the user enter only perfect data. Sometimes,
      however, it can be useful to be more forgiving. I want to support soft validations that can be used 
      to present a warning to the user without blocking saving of the object. As an example, an email 
      should normally have a subject, but this is not required. Many email clients present a warning if you
      try to send an email without a subject. It would be useful to be able to express this warning in the 
      domain model:
    &lt;/p&gt;
    &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class Email
  verifiable
  subject_should_not be_nil
end&lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;p&gt;
      The violation of a soft constraint could trigger a confirmation message, or simply display a note 
      remarking that a non-critical validation failed.
    &lt;/p&gt;
  &lt;/section&gt;
  &lt;section id=&quot;subsec-quantifications&quot;&gt;
    &lt;header&gt;
      &lt;h3&gt;Quantifications&lt;/h3&gt;
    &lt;/header&gt;
    &lt;p&gt;
      Expressing constraints across collections can be difficult in non-composable systems. We often want
      to define the validity of some object in terms of the validity of some, or all, of the members of 
      a collection of associated objects. With a composable system, this becomes much easier:
    &lt;/p&gt;
    &lt;blockquote class=&quot;code&quot;&gt;
&lt;pre&gt;&lt;code class=&quot;language-ruby&quot;&gt;class Book
  verifiable
  chapters_must all, be_valid
  contact_emails_must some, be_verified
  reviewers_must none, be_banned
end&lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;p&gt;
      The use of quantificational modifiers like &lt;code&gt;all&lt;/code&gt;, &lt;code&gt;some&lt;/code&gt; or &lt;code&gt;none&lt;/code&gt; 
      allows us to apply validations to one-to-many associations without adding irrelevant validations to
      those model classes. In the above example, a user isn’t invalid if they are banned but they &lt;em&gt;are&lt;/em&gt;
      an invalid member of the reviewers association for a book.
    &lt;/p&gt;
  &lt;/section&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-conclusion&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Conclusions&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
    Verity provides an expressive, readable DSL for defining domain constraints on arbitrary Ruby objects. It
    does this by defining a composable framework of predicates, similar to RSpec, and combinators. A certain 
    amount of syntactic sugar is given to make it easy to not only use Verity to define validations, but also 
    to make writing new predicates as simple as possible.
  &lt;/p&gt;
  &lt;p&gt;
    There are many exciting directions that this library could go in, and I look forward to getting feedback 
    from others. I have outlined some of my ideas above. Composability gives some great opportunities for 
    defining new syntax.
  &lt;/p&gt;
  &lt;p&gt;
    This library is intended, above all else, to be useful. Currently its utility is limited by the paltry 
    number of predicates available. I hope to define, over time, a large library of predicates that will come
    out of the box. I also hope that others will build predicate libraries, and provide them to the community.
  &lt;/p&gt;
  &lt;p&gt;
    If you have any questions, remarks or constructive criticism please leave a comment on this essay. Even if
    you don’t plan on using the library yourself, or contributing any code, any help with firming up the DSL and
    API would be appreciated.
  &lt;/p&gt;
&lt;/section&gt;
</content>
 </entry>
 
 
 
 <entry>
   <title>Hypercode</title>
   <link href="http://www.joegeldart.com/2010/05/hypercode"/>
   <updated>2010-05-02T00:00:00-07:00</updated>
   <id>http://www.joegeldart.com/2010/05/hypercode</id>
   <content type="html">&lt;section id=&quot;sec-introduction&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Introduction&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  Yesterday, I read an &lt;a href=&quot;http://groups.google.com/group/whits/browse_thread/thread/3af4fe682836f2d3/88dcaf2ccd55df8e&quot; title=&quot;Hypercode&quot;&gt;essay&lt;/a&gt; by 
  &lt;a href=&quot;http://inamidst.com/&quot; title=&quot;Inamidst&quot;&gt;Sean B Palmer&lt;/a&gt; on his thoughts (and criticisms) 
  regarding &lt;a href=&quot;http://en.wikipedia.org/wiki/Literate_programming&quot;&gt;literate programming&lt;/a&gt;. 
  The main thrust of his criticism is that literate programming is, all too often, used in the style
  of a programming language tutorial. Rather than documenting the rationale behind the code, it
  instead documents the boilerplate. This is attributed to a fundamental mismatch between the syntax
  of natural language and the chaotic, woven nature of human thought.
  &lt;/p&gt;
  &lt;p&gt;
  The joy of programming for many, as this article rightly states, is solving problems. The joy is
  not in the syntax, but rather it is in the conception. As with mathematics, a good problem is one
  which makes conception clearer, allowing us to understand and solve other problems.
  &lt;/p&gt;
  &lt;p property=&quot;dcterms:descripton&quot;&gt;
  This article introduces an attempt to realise the vision of programming contained within that
  essay. By combining linked data, linked process and literate programming, I propose a more humane
  programming system comprising a development method and a new linked process language. This is only
  a first attempt at a solution to this problem, and no doubt my opinions will change as I explore 
  this space further, but I believe this captures my essential understanding of this fascinating 
  problem.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-linkedprocess&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;A Brief Introduction to Linked Process&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  &lt;a href=&quot;http://linkedprocess.org/Home.html&quot;&gt;Linked Process&lt;/a&gt; is the behavioural equivalent of
  the, currently, more common idea of &lt;a href=&quot;http://linkeddata.org/&quot;&gt;Linked Data&lt;/a&gt;. Linked data
  has begun to achieve a critical density on the Web with sites such as 
  &lt;a href=&quot;http://www.facebook.com/&quot;&gt;Facebook&lt;/a&gt;, the &lt;a href=&quot;http://www.bbc.co.uk/&quot;&gt;BBC&lt;/a&gt;
  and &lt;a href=&quot;http://www.bestbuy.com/&quot;&gt;Best Buy&lt;/a&gt; exposing machine readable information embedded
  within their existing HTML pages. Linked Process hopes to capitalise on this by exposing programs
  as machine readable data over the Web. A linked process language would use the Web as its module 
  system, and allow for orchestration and adaptation of behaviour in a decentralised fashion.
  &lt;/p&gt;
  &lt;p&gt;
  One of the first linked process languages was &lt;a href=&quot;http://ripple.fortytwo.net/&quot;&gt;Ripple&lt;/a&gt;, a 
  concatenative language using RDF as its data model. This language adopted a stack-based operational 
  semantics, based on a stream of stacks model that was both familiar and powerful. The stream model 
  allowed the language to exploit the non-determinism inherent in an open system like the Web. 
  &lt;/p&gt;
  &lt;p&gt;
  Ripple, however, was not the first language to attempt to provide an RDF expressed ‘bytecode’. The
  &lt;a href=&quot;http://groups.csail.mit.edu/haystack/&quot;&gt;Haystack project&lt;/a&gt; developed an a language called 
  &lt;a href=&quot;http://en.wikipedia.org/wiki/Adenine_(programming_language)&quot;&gt;Adenine&lt;/a&gt;, with a loosely
  &lt;a href=&quot;http://www.python.org&quot;&gt;Python&lt;/a&gt; based syntax, for expressing operations on their 
  RDF-based internal data-model. The representation was, however, purely syntactic and did not
  leverage either the semantics of RDF or the conceptual semantics of the developers.
  &lt;/p&gt;
  &lt;p&gt;
  A couple of years ago, I wrote a &lt;a href=&quot;http://logcom.oxfordjournals.org/cgi/content/short/19/5/791&quot; title=&quot;Category-based Equational Reasoning: An Approach to Ontology&quot;&gt;paper&lt;/a&gt;
  exploring the possibility of expressing the semantics of RDF using 
  &lt;a href=&quot;http://en.wikipedia.org/wiki/Category_Theory&quot;&gt;category theory&lt;/a&gt;. This was motivated by 
  Ripple, the &lt;a href=&quot;http://www.cat-language.com/&quot;&gt;Cat programming language&lt;/a&gt; and my
  research into &lt;a href=&quot;http://sites.google.com/site/narswang/&quot; title=&quot;Non-Axiomatic Reasoning System&quot;&gt;higher-order uncertain logics&lt;/a&gt;. 
  Since that paper, I have been fascinated by the possibilities of linking research into web 
  science with general research into category theory and, in particular, 
  &lt;a href=&quot;http://cseweb.ucsd.edu/~goguen/projs/inst.html&quot;&gt;institution theory&lt;/a&gt;. This is an area 
  with a lot of potential, particularly if we can connect 
  &lt;a href=&quot;http://cseweb.ucsd.edu/~goguen/&quot;&gt;Joseph Goguen&lt;/a&gt;’s work on 
  &lt;a href=&quot;https://docs.google.com/viewer?url=http://cseweb.ucsd.edu/~goguen/pps/taspm.pdf&quot;&gt;cognitive blends in terms of institutions&lt;/a&gt; to the
  idea of &lt;a href=&quot;https://docs.google.com/viewer?url=http://events.linkeddata.org/ldow2008/papers/20-idehen-erling-linked-data-spaces.pdf&quot;&gt;linked data spaces&lt;/a&gt; and named graphs.
  &lt;/p&gt;
  &lt;p&gt;
  The remainder of this article looks at the potential for combining these ideas with those of
  literate programming to produce documents which are both human-readable specifications and
  testable realisations of those specifications. 
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-executable-specifications&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Executable Specifications&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  A specification is, essentially, a description of the problem to be solved. Specifications
  can include many sorts of constraint. Some are purely functional, containing elaborate
  detail on the executable behaviour of a solution. Others are purely non-functional, and
  simply describe the motivations behind the desire for a solution to the problem. Most
  specifications are somewhere in the middle, combining some executable behaviour with 
  business cases.
  &lt;/p&gt;
  &lt;p&gt;
  Recently, &lt;a href=&quot;http://behaviour-driven.org/&quot;&gt;Behaviour Driven Development&lt;/a&gt; (BDD) has sought 
  to formalise this balancing act. A specification is seen as a set of &lt;em&gt;features&lt;/em&gt;. Each
  feature consists of a business case, usually expressed as a user story, coupled with a set
  of &lt;em&gt;scenarios&lt;/em&gt; which turn that story into a testable narrative. There are a number
  of popular BDD frameworks such as &lt;a href=&quot;http://wiki.github.com/aslakhellesoy/cucumber&quot;&gt;Cucumber&lt;/a&gt;,
  &lt;a href=&quot;http://jbehave.org/&quot;&gt;JBehave&lt;/a&gt; and &lt;a href=&quot;http://visionmedia.github.com/jspec/&quot;&gt;jspec&lt;/a&gt;.
  &lt;/p&gt;
  &lt;p&gt;
  These tools have a weakness, however, in that the implementation of the specification is
  utterly distinct from its description. Acceptance test tools like &lt;a href=&quot;http://fitnesse.org/&quot;&gt;Fitnesse&lt;/a&gt; 
  attempt to solve this by providing a user interface that can link tests to source code files. This is
  crude; you cannot see how a particular part of the specification is realised by a particular part of
  the implementation. This reduces traceability of requirements, and requires that the specification,
  including tests, be manually kept up-to-date with the implementation. In my experience in development,
  writing code frequently alters the understanding of the problem itself; in fact, that is the most
  enjoyable part of the process. These changes of understanding need to be manually percolated through
  to the specification. This is error-prone, but necessary if the client is to be kept in the loop
  on the development process.
  &lt;/p&gt;
  &lt;p&gt;
  On the Web, we navigate through a mind-boggling complex sea of information by looking at small
  fragments at a time. These fragments, which we call pages, are connected together by hyperlinks
  which can be navigated by a user, in their own time, to create a custom narrative exploration
  of the available information. These links also express relational information, a fact exploited
  by search engines such as Google, which may be used to tie together the meaning of the documents.
  This is the key insight of linked data.
  &lt;/p&gt;
  &lt;p&gt;
  I propose viewing specifications as linked data and linked process combined. A specification is
  then not only a description of a system in a human readable form, but also its realisation. When
  necessary they can be viewed together, or separately, depending on what is needed. They exist on
  the Web and can, therefore, exploit all the features and benefits of the Web architecture such as
  decentralisation, openness and partiality of description. Since the specification and the 
  implementation are fundamentally linked, changes to the specification may automatically change
  the implementation, and vice versa. The specification is automatically and fundamentally in 
  sync with the implementation at all times, and thus serves as accurate documentation of a
  project.
  &lt;/p&gt;
  &lt;p&gt;
  Whilst many representations of a program are possible, probably the best (for this purpose) is
  &lt;a href=&quot;http://en.wikipedia.org/wiki/RDFa&quot;&gt;RDFa&lt;/a&gt; embedded in HTML. The HTML provides the 
  specification whilst the RDFa annotates this specification with an implementation. As an
  example, consider the following definition of a Fibonacci number.
  &lt;/p&gt;
  &lt;figure class=&quot;specification&quot;&gt;
    &lt;blockquote&gt;
    &lt;h3&gt;Fibonacci Numbers&lt;/h3&gt;
    &lt;p&gt;
    Given a natural number n, the n&lt;sup&gt;th&lt;/sup&gt; Fibonacci number is defined as follows:
    &lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;The 0&lt;sup&gt;th&lt;/sup&gt; Fibonacci number is 0;&lt;/li&gt;
      &lt;li&gt;The 1&lt;sup&gt;st&lt;/sup&gt; Fibonacci number is 1; and&lt;/li&gt;
      &lt;li&gt;If n &gt;= 2, the n&lt;sup&gt;th&lt;/sup&gt; Fibonacci number is the sum of the n-1&lt;sup&gt;th&lt;/sup&gt; Fibonacci
          number, and the n-2&lt;sup&gt;th&lt;/sup&gt; Fibonacci number.&lt;/li&gt;
    &lt;/ul&gt;
    &lt;/blockquote&gt;
    &lt;figcaption&gt;A specification for Fibonacci numbers.&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p&gt;
  To begin turning this specification into a linked process, we must first give it a URI by adding an
  &lt;code&gt;about&lt;/code&gt; attribute. We may then add some basic metadata, such as the sort of executable
  unit being described by the specification (in this case it is a pure predicate) and the parameters
  it takes:
  &lt;/p&gt;
  &lt;figure class=&quot;code&quot;&gt;
    &lt;blockquote&gt;
      &lt;pre&gt;&lt;code&gt;  &amp;lt;figure class=&quot;specification&quot; typeof=&quot;prog:PurePredicate&quot; id=&quot;fib&quot; about=&quot;#fib&quot; prefix=&quot;prog: http://www.example.com/hypercode/core.html#&quot;&amp;gt;
&amp;lt;blockquote&amp;gt;
&amp;lt;h3 property=&quot;dc:title&quot;&amp;gt;Fibonacci Numbers&amp;lt;/h3&amp;gt;
&amp;lt;p&amp;gt;
&amp;lt;span rel=&quot;prog:arg&quot;&amp;gt;&amp;lt;span about=&quot;#fib-n&quot; id=&quot;fib-n&quot; typeof=&quot;prog:Argument&quot;&amp;gt;Given a 
  &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core-types.html#Natural&quot;&amp;gt;natural number&amp;lt;/a&amp;gt; n&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt;, 
&amp;lt;span rel=&quot;prog:outputArg&quot;&amp;gt;&amp;lt;span about=&quot;#fib-out&quot; id=&quot;fib-out&quot; typeof=&quot;prog:OutputArgument&quot;&amp;gt;the n&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; Fibonacci number&amp;lt;/span&amp;gt;&amp;lt;/span&amp;gt; 
is defined as follows:
&amp;lt;/p&amp;gt;
...
      &lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;figcaption&gt;Basic metadata for an executable unit.&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p&gt;
  Of note in the above is the use of existing vocabularies, such as 
  &lt;a href=&quot;http://dublincore.org/&quot;&gt;Dublin Core&lt;/a&gt;. One can freely annotate the specification with 
  any desired vocabularies. For example, each executable unit could be annotated with its own
  licence in a machine readable fashion, or with its creator or with topics drawn from a thesaurus.
  The only limit here is one’s imagination.
  &lt;/p&gt;
  &lt;p&gt;
  Also worth noting is the use of two different sorts of argument; plain arguments and output 
  arguments. One of the ideas behind this programming language is that predicates may be used in 
  both a &lt;em&gt;logical&lt;/em&gt; and a &lt;em&gt;functional&lt;/em&gt; fashion. If an argument is an output argument,
  and there may be at most one of these for an executable unit, then the result of this, when used
  functionally, is the value of the expression.
  &lt;/p&gt;
  &lt;p&gt;
  The body of the specification consists of a number of cases describing the behaviour of this
  executable unit depending on a set of conditionals. Let us annotate the specification to 
  implement the first two cases:
  &lt;/p&gt;
  &lt;figure class=&quot;code&quot;&gt;
    &lt;blockquote&gt;
      &lt;pre&gt;&lt;code&gt;  &amp;lt;ul&amp;gt;
&amp;lt;li rel=&quot;prog:case&quot;&amp;gt;
&amp;lt;div typeof=&quot;prog:Case&quot;&amp;gt;
The &amp;lt;span rel=&quot;prog:condition&quot;&amp;gt;
    &amp;lt;span typeof=&quot;prog:equals&quot;&amp;gt;
      &amp;lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-n&quot;&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;span property=&quot;prog:arg&quot;&amp;gt;0&amp;lt;/span&amp;gt;&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; Fibonacci number
    &amp;lt;/span&amp;gt; 
  &amp;lt;/span&amp;gt;
&amp;lt;span rel=&quot;prog:body&quot;&amp;gt;
&amp;lt;span typeof=&quot;prog:equals&quot;&amp;gt;
  &amp;lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-out&quot;&amp;gt;&amp;lt;/span&amp;gt;
  &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&amp;gt;is&amp;lt;/a&amp;gt;
  &amp;lt;span property=&quot;prog:arg&quot;&amp;gt;0&amp;lt;/span&amp;gt;;
&amp;lt;/span&amp;gt;
&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/li&amp;gt;
&amp;lt;li rel=&quot;prog:case&quot;&amp;gt;
&amp;lt;div typeof=&quot;prog:Case&quot;&amp;gt;
The &amp;lt;span rel=&quot;prog:condition&quot;&amp;gt;
    &amp;lt;span typeof=&quot;prog:equals&quot;&amp;gt;
      &amp;lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-n&quot;&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;span property=&quot;prog:arg&quot;&amp;gt;1&amp;lt;/span&amp;gt;&amp;lt;sup&amp;gt;st&amp;lt;/sup&amp;gt; Fibonacci number
    &amp;lt;/span&amp;gt;
  &amp;lt;/span&amp;gt; 
  &amp;lt;span rel=&quot;prog:body&quot;&amp;gt;
    &amp;lt;span typeof=&quot;prog:equals&quot;&amp;gt;
      &amp;lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-out&quot;&amp;gt;&amp;lt;/span&amp;gt;
      &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&amp;gt;is&amp;lt;/a&amp;gt;
      &amp;lt;span property=&quot;prog:arg&quot;&amp;gt;1&amp;lt;/span&amp;gt;; and
    &amp;lt;/span&amp;gt;
  &amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/li&amp;gt;
...
      &lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;figcaption&gt;The first two cases in the Fibonacci specification.&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p&gt;
  Each case has a set of conditions; if &lt;em&gt;any&lt;/em&gt; of these conditions are satisfied then the 
  case may execute. Execution procedes by finding a coherent ordering of &lt;em&gt;all&lt;/em&gt; of the bodies.
  In this case, with only a single body, this is trivial.
  &lt;/p&gt;
  &lt;p&gt;
  Calls of executable units are encoded using classes; each executable unit is effectively the class
  of its executions. This allows execution traces to be represented as linked data, and thus we
  can bring to bear all the same tools.
  &lt;/p&gt;
  &lt;p&gt;
  It should be noted that, where possible, normal HTML hyperlinks are used to connect (for example)
  arguments with their definitions, and executable units with their specifications. This allows for
  normal hypertext usage, as discussed earlier.
  &lt;/p&gt;
  &lt;p&gt;
  Turning to the third case, we shall see an example of functional calling easing the specification:
  &lt;/p&gt;
  &lt;figure class=&quot;code&quot;&gt;
    &lt;blockquote&gt;
      &lt;pre&gt;&lt;code&gt;  &amp;lt;li rel=&quot;prog:case&quot;&amp;gt;
&amp;lt;div typeof=&quot;prog:Case&quot;&amp;gt; 
&amp;lt;span rel=&quot;prog:condition&quot;&amp;gt;
If
&amp;lt;span typeof=&quot;prog:Predicate&quot;&amp;gt;
  &amp;lt;a rel=&quot;prog:arg&quot; href=&quot;#fib-n&quot;&amp;gt;n&amp;lt;/a&amp;gt; 
  &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#gte&quot;&amp;gt;is greater than or equal to&amp;lt;/a&amp;gt; 
  &amp;lt;span property=&quot;prog:arg&quot;&amp;gt;2&amp;lt;/span&amp;gt;
&amp;lt;/span&amp;gt;
&amp;lt;/span&amp;gt; 
&amp;lt;span rel=&quot;prog:body&quot;&amp;gt; 
then
&amp;lt;span typeof=&quot;prog:Predicate&quot;&amp;gt;
  &amp;lt;a rel=&quot;prog:arg&quot; href=&quot;#fib-out&quot;&amp;gt;the n&amp;lt;sup&amp;gt;th&amp;lt;/sup&amp;gt; Fibonacci number&amp;lt;/a&amp;gt; 
  &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&amp;gt;is&amp;lt;/a&amp;gt; 
  &amp;lt;span rel=&quot;prog:arg&quot;&amp;gt;the 
    &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#add&quot;&amp;gt;sum&amp;lt;/a&amp;gt; of 
    &amp;lt;span rel=&quot;prog:arg&quot;&amp;gt;the 
      &amp;lt;span rel=&quot;#fib-n&quot;&amp;gt;
        &amp;lt;a rel=&quot;prog:subtractand&quot; href=&quot;#fib-n&quot;&amp;gt;n&amp;lt;/a&amp;gt; 
        &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#subtract&quot;&amp;gt;-&amp;lt;/a&amp;gt; 
        &amp;lt;span property=&quot;prog:subtractor&quot;&amp;gt;1&amp;lt;/span&amp;gt;th 
      &amp;lt;/span&amp;gt;
      &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;#fib&quot;&amp;gt;Fibonacci number&amp;lt;/a&amp;gt;
    &amp;lt;/span&amp;gt; and 
    &amp;lt;span rel=&quot;prog:arg&quot;&amp;gt;the 
      &amp;lt;span rel=&quot;#fib-n&quot;&amp;gt;
        &amp;lt;a rel=&quot;prog:subtractand&quot; href=&quot;#fib-n&quot;&amp;gt;n&amp;lt;/a&amp;gt; 
        &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#subtract&quot;&amp;gt;-&amp;lt;/a&amp;gt; 
        &amp;lt;span property=&quot;prog:subtractor&quot;&amp;gt;2&amp;lt;/span&amp;gt;th 
      &amp;lt;/span&amp;gt;
      &amp;lt;a rel=&quot;rdf:type&quot; href=&quot;#fib&quot;&amp;gt;Fibonacci number&amp;lt;/a&amp;gt;
    &amp;lt;/span&amp;gt;.
  &amp;lt;/span&amp;gt;
&amp;lt;/span&amp;gt;
&amp;lt;/span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
      &lt;/code&gt;&lt;/pre&gt;
    &lt;/blockquote&gt;
    &lt;figcaption&gt;The third case in the Fibonacci specification.&lt;/figcaption&gt;
  &lt;/figure&gt;
  &lt;p&gt;
  Other than its greater complexity, there is little new in this case apart from the use of
  a functional calling style. This allows the implementation to adhere to the structure of
  the specification more closely. I anticipate that in real specifications, a mixture of
  a relational style and a functional style would be used to match the way the specification 
  was written.
  &lt;/p&gt;
  &lt;p&gt;
  I will finish this section by providing the fully annotated specification. If you look 
  at the source code for this page, or run it through an &lt;a href=&quot;http://www.w3.org/2007/08/pyRdfa/shadowextract?uri=http%3A%2F%2Fjgeldart.github.com%2Fessays%2Fhypercode-linked-process.html&amp;format=turtle&quot;&gt;RDFa extractor&lt;/a&gt;, you will find 
  the executable definition.
  &lt;/p&gt;
  &lt;figure class=&quot;specification&quot; typeof=&quot;prog:PurePredicate&quot; id=&quot;fib&quot; about=&quot;#fib&quot; prefix=&quot;prog: http://www.example.com/hypercode/core.html#&quot;&gt;
    &lt;blockquote&gt;
      &lt;h3 property=&quot;dc:title&quot;&gt;Fibonacci Numbers&lt;/h3&gt;
      &lt;p&gt;
        &lt;span rel=&quot;prog:arg&quot;&gt;&lt;span about=&quot;#fib-n&quot; id=&quot;fib-n&quot; typeof=&quot;prog:Argument&quot;&gt;Given a 
          &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core-types.html#Natural&quot;&gt;natural number&lt;/a&gt; n&lt;/span&gt;&lt;/span&gt;, 
        &lt;span rel=&quot;prog:outputArg&quot;&gt;&lt;span about=&quot;#fib-out&quot; id=&quot;fib-out&quot; typeof=&quot;prog:OutputArgument&quot;&gt;the n&lt;sup&gt;th&lt;/sup&gt; Fibonacci number&lt;/span&gt;&lt;/span&gt; 
        is defined as follows:
      &lt;/p&gt;

      &lt;ul&gt;
        &lt;li rel=&quot;prog:case&quot;&gt;
        &lt;div typeof=&quot;prog:Case&quot;&gt;
          The &lt;span rel=&quot;prog:condition&quot;&gt;
                &lt;span typeof=&quot;prog:equals&quot;&gt;
                  &lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-n&quot;&gt;&lt;/span&gt;
                  &lt;span property=&quot;prog:arg&quot;&gt;0&lt;/span&gt;&lt;sup&gt;th&lt;/sup&gt; Fibonacci number
                &lt;/span&gt; 
              &lt;/span&gt;
          &lt;span rel=&quot;prog:body&quot;&gt;
            &lt;span typeof=&quot;prog:equals&quot;&gt;
              &lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-out&quot;&gt;&lt;/span&gt;
              &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&gt;is&lt;/a&gt;
              &lt;span property=&quot;prog:arg&quot;&gt;0&lt;/span&gt;;
            &lt;/span&gt;
          &lt;/span&gt;
        &lt;/div&gt;
        &lt;/li&gt;
        &lt;li rel=&quot;prog:case&quot;&gt;
        &lt;div typeof=&quot;prog:Case&quot;&gt;
          The &lt;span rel=&quot;prog:condition&quot;&gt;
                &lt;span typeof=&quot;prog:equals&quot;&gt;
                  &lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-n&quot;&gt;&lt;/span&gt;
                  &lt;span property=&quot;prog:arg&quot;&gt;1&lt;/span&gt;&lt;sup&gt;st&lt;/sup&gt; Fibonacci number
                &lt;/span&gt;
              &lt;/span&gt; 
              &lt;span rel=&quot;prog:body&quot;&gt;
                &lt;span typeof=&quot;prog:equals&quot;&gt;
                  &lt;span rel=&quot;prog:arg&quot; resource=&quot;#fib-out&quot;&gt;&lt;/span&gt;
                  &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&gt;is&lt;/a&gt;
                  &lt;span property=&quot;prog:arg&quot;&gt;1&lt;/span&gt;; and
                &lt;/span&gt;
              &lt;/span&gt;
        &lt;/div&gt;
        &lt;/li&gt;
        &lt;li rel=&quot;prog:case&quot;&gt;
        &lt;div typeof=&quot;prog:Case&quot;&gt; 
          &lt;span rel=&quot;prog:condition&quot;&gt;
            If
            &lt;span typeof=&quot;prog:Predicate&quot;&gt;
              &lt;a rel=&quot;prog:arg&quot; href=&quot;#fib-n&quot;&gt;n&lt;/a&gt; 
              &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#gte&quot;&gt;is greater than or equal to&lt;/a&gt; 
              &lt;span property=&quot;prog:arg&quot;&gt;2&lt;/span&gt;
            &lt;/span&gt;
          &lt;/span&gt; 
          &lt;span rel=&quot;prog:body&quot;&gt; 
            then
            &lt;span typeof=&quot;prog:Predicate&quot;&gt;
              &lt;a rel=&quot;prog:arg&quot; href=&quot;#fib-out&quot;&gt;the n&lt;sup&gt;th&lt;/sup&gt; Fibonacci number&lt;/a&gt; 
              &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#equals&quot;&gt;is&lt;/a&gt; 
              &lt;span rel=&quot;prog:arg&quot;&gt;the 
                &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#add&quot;&gt;sum&lt;/a&gt; of 
                &lt;span rel=&quot;prog:arg&quot;&gt;the 
                  &lt;span rel=&quot;#fib-n&quot;&gt;
                    &lt;a rel=&quot;prog:subtractand&quot; href=&quot;#fib-n&quot;&gt;n&lt;/a&gt; 
                    &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#subtract&quot;&gt;-&lt;/a&gt; 
                    &lt;span property=&quot;prog:subtractor&quot;&gt;1&lt;/span&gt;th 
                  &lt;/span&gt;
                  &lt;a rel=&quot;rdf:type&quot; href=&quot;#fib&quot;&gt;Fibonacci number&lt;/a&gt;
                &lt;/span&gt; and 
                &lt;span rel=&quot;prog:arg&quot;&gt;the 
                  &lt;span rel=&quot;#fib-n&quot;&gt;
                    &lt;a rel=&quot;prog:subtractand&quot; href=&quot;#fib-n&quot;&gt;n&lt;/a&gt; 
                    &lt;a rel=&quot;rdf:type&quot; href=&quot;http://www.example.com/hypercode/core.html#subtract&quot;&gt;-&lt;/a&gt; 
                    &lt;span property=&quot;prog:subtractor&quot;&gt;2&lt;/span&gt;th 
                  &lt;/span&gt;
                  &lt;a rel=&quot;rdf:type&quot; href=&quot;#fib&quot;&gt;Fibonacci number&lt;/a&gt;
                &lt;/span&gt;.
              &lt;/span&gt;
            &lt;/span&gt;
          &lt;/span&gt;
        &lt;/div&gt;
        &lt;/li&gt;
      &lt;/ul&gt;
    &lt;/blockquote&gt;
    &lt;figcaption&gt;The completed specification for Fibonacci numbers.&lt;/figcaption&gt;
  &lt;/figure&gt;

  &lt;p&gt;
  Of course, we are not limited to just HTML. We could annotate equations written in MathML, for
  example, or a state-machine diagram in SVG. Rather than translating whatever is the best notation
  for our problem into some programming language in a separate file, we simply add enough information
  to our specification to make it run. I believe this will eliminate a lot of the disconnect between
  conception and realisation, and reduce the number of bugs resulting from the mental conversion of
  concepts.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-tooling&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Tooling&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  Whilst I feel this way of writing programs as linked data annotations on specifications has a certain
  elegance, I believe this idea will really shine with good tool support. IDEs have become a common way
  to navigate code, but with this your browser can be your IDE working on your specification.
  &lt;/p&gt;
  &lt;p&gt;
  Imagine taking the above specification, before the annotations were added, and selecting the whole
  block. With a single command, the block becomes an executable unit, perhaps automatically setting
  the &lt;code&gt;dc:title&lt;/code&gt; property on the heading. Select the text ‘Fibonacci number’ in the third
  case and another command could search through all linked processes to find those which look similar,
  in this case the very predicate we're defining. We can use the browser to incrementally mark-up our
  specification with behaviour.
  &lt;/p&gt;
  &lt;aside&gt;
    &lt;blockquote class=&quot;quote&quot;&gt;
      ... since the behaviour is described using linked data, this is trivial.
    &lt;/blockquote&gt;
  &lt;/aside&gt;
  &lt;p&gt;
  Should we want a different view, say as a &lt;a href=&quot;http://www.subtextual.org/&quot;&gt;schematic table&lt;/a&gt;, then since the behaviour is described in 
  linked data, this is trivial. In fact, people could write web applications that simply provide a 
  different visualisation on the executable units in different web pages. Programs become data for
  mash-ups. An entrepreneurial developer could produce a service that turns a program into an 
  execution diagram, or a dependency diagram, or anything for which there is a need.
  &lt;/p&gt;
  &lt;p&gt;
  With the wealth of data that is exposed by providing executable specifications in the form of
  linked data, search engines can be used to find routines others have written and published. Using
  them in your code is as simple as using their URI. If the routines are annotated with licencing
  information, then an IDE would be able to automatically work out whether or not there is a
  conflict. Search engines could also filter their results by compatible licences.
  &lt;/p&gt;
  &lt;p&gt;
  I believe that there are many opportunities afforded by this method, and by having the structure
  of the code available explicitly rather than serialised into a linear form. Rich comments can
  be defined, shown, hidden, linked and thrown away without touching the code itself. A web
  application could host collaborative comments for a team, without needing to touch the code just
  by using linked data principles. I am sure there are many more ideas that I haven’t thought of 
  just waiting for someone out there to develop them.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-living-code&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Living Code&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  By making specifications executable, we can allow for live specifications. By embedding a
  Javascript interpreter in the page, we could run our implementation, test it and also test the 
  assumptions in the requirements. This allows for a much tighter feedback cycle than current 
  tools. By providing a link to the specification to a client, we can push that through to the 
  full development cycle, allowing our customers to see how the specification works just by
  playing with it.
  &lt;/p&gt;
  &lt;p&gt;
  Test suites can be added to the specification as annotations, and previous executions (remember,
  they're instances of the specification) can be trivially turned into tests. Through the 
  same distributed extensibility mechanisms as I have already mentioned, others can easily extend
  the testing mechanisms. Want to add something like &lt;a href=&quot;http://www.cs.chalmers.se/~rjmh/QuickCheck/&quot;&gt;QuickCheck&lt;/a&gt;? No problem. Just define the 
  propositions in RDF and write a web application, or a piece of Javascript, to test them. At any 
  point, one may navigate through an execution trace as if it were a piece of the Web, because it is.
  &lt;/p&gt;
  &lt;p&gt;
  We could also use this method to allow for linked process web-services over simple HTTP. A suitable
  server extension could react to &lt;code&gt;POST&lt;/code&gt; requests on the document by running the
  appropriate code. Clients could find new services simply by using a semantic web search engine.
  A &lt;code&gt;GET&lt;/code&gt; request on the document would yield a precise description of its parameters 
  and behaviour, which could be used in the matchmaking and orchestration process.
  &lt;/p&gt;
&lt;/section&gt;
&lt;section id=&quot;sec-further-work&quot;&gt;
  &lt;header&gt;
    &lt;h2&gt;Further Work&lt;/h2&gt;
  &lt;/header&gt;
  &lt;p&gt;
  At the time of writing, this idea is less than 24 hours old so there is plenty of work to do. I need
  to define a vocabulary for expressing the executable behaviours. I need to define a formal semantics
  for the execution model. I need to write a Javascript interpreter and maybe a command-line one too.
  There needs to be a good IDE.
  &lt;/p&gt;
  &lt;p&gt;
  Please bear with me as I explore these thoughts further. I was excited to feel so many pieces of 
  what I have worked on over the past ten years come together so nicely so I would like to thank 
  Sean for his provocative essay. If you are interested in the ideas here, please &lt;a href=&quot;http://www.joegeldart.com/&quot;&gt;contact me&lt;/a&gt;.
  &lt;/p&gt;
&lt;/section&gt;
</content>
 </entry>
 
 
 
</feed>
