24 November 2009

An open platform for publishing applications

HTTP, HTML and CSS are inadequate for developing complex end user applications that have hard latency requirements, depend on more sophisticated input-output facilities or need to integrate closely with the clients computing environment. Examples include games, multimedia or attempts to reproduce modern desktop applications on the web.

The failure to deliver browser-based applications in those domains is in my opinion caused by:

  • the weakness of the request-response scheme of HTTP as a basis for a programming model - it works well for the operations on hypertext documents it was designed for, but it is a poor basis in almost all domains that do not naturally deal with documents, especially those requiring sending excessive amounts of information back and forth
  • poor capabilities of the browser itself - what is being made available to the programmer is insufficient for any kind of more sophisticated development, as no access at all is given to important parts of the user environment - neither to the hardware (graphic cards, sound cards, video cameras, gaming devices) nor to the software resources (files on the client computer)

Many technologies were created to deal with the two problems. AJAX, continuations-based web servers or Comet were attempts to workaround the first issue, but they all have been built on top of the flawed model, while also suffering problems with the web browsers, without trying to directly fix them. The second problem was meant to be solved by the likes of Flash or Silverlight, which do not integrate well with the rest of the web (for example search engines), making it questionable why do they at all run inside the web browser, experiencing efficiency and stability issues. Java the platform was the closest to what I want to propose, but even through it had the necessary pieces, it wasn’t clearly steered in this direction and suffered from slow start-up times, slow and ugly GUI tool-kits and weaknesses of Java the programming language.

The author is seeing much potential in an integrated attempt to solve both of those problems with a new set of standardized technologies. We already have excellent protocols for hypertext, efficient file transfer or sending messages, why shouldn’t a protocol for sharing applications exist? Links could be put to apps://musicplayer.com/ on traditional web pages in the same way as links to e-mail addresses or file servers, leaving the browsers with what they do best - processing documents.

The proposed solution that will be described here is called OAPP, standing for Open Application Publishing Platform. The following things should be specified as a part of OAPP:

  1. A virtual machine of predefined capabilities running on the client computer
  2. A way of sending executable computer programs to the virtual machine from the server
  3. A way of singalizing events on the virtual machine to the server
  4. A programming model based on points 1, 2 and 3

10 June 2007

Html generation in JavaScript

I started playing a little bit more with JavaScript recently, and one thing that bothered me was generating HTML. For example, if you have a AJAX application of any reasonable size, it probably has to change a lot of stuff inside of the various divs or other elements as it runs. For that, you need to write a lot of ugly-looking, long-running string concatenations. So, I took an idea used by the Lisp folks or in the Ruby Markaby library and I created a library to write HTML in JavaScript. I’m not sure if I’m the first one to come up with this, but my Google-fu failed in this case, so maybe… Anyway, with my JsTemple you write something like this:

$table({cellpadding: 10},
  $tr(
    $td(
      $div({klass: 'container', id: 'main'},
        $h1('Foobar'),
        $h2('Foobar2'),
        $h3('Foobar3'),
        $h4('Foobar4'),
        $h5('Foobar5'),
        $div({id: 'layer', style: 'border: solid 3px #f00; padding: 10px;'},
          $p({klass: 'foo'},
            'foo', $strong('bar')),
          $p({klass: 'shmoo'},
            'shmoo'))))));

And you get this:

<table cellpadding="30">
  <tr>
    <td>
      <div class="container" id="main">
        <h1>Foobarh1>
        <h2>Foobar2h2>
        <h3>Foobar3h3>
        <h4>Foobar4h4>
        <h5>Foobar5h5>
        <div id="layer" style="border: 3px solid #f00; padding: 10px;">
          <p class="foo">foo<strong>barstrong>p>
          <p class="shmoo">shmoop>
        div>
      div>
    td>
  tr>
table>

I generated the necessary data about tags / possible properties from HTML 4.01 W3C specification, so all the tags should work and invalid properties should be ignored. “Should”, because the generating was a little bit tricky and I’m not 100% sure if everything is the way it should be. The dollar sign is a bit annoying, too, but my goal was to avoid cluttering of the global namespace, especially a variable name like “i” may be quite popular… I don’t know how it works performance-wise or memory-wise either (certainly some optimizations are possible), but it seems to work under Firefox, Opera, Konqueror (Safari?) and MSIE 6/7 and it even doesn’t crash any of them in a short time, what I consider a big success. I don’t really know if this is useful at all (most people don’t seem to like balancing parenthesis or don’t know a decent editor which highlight pairs of matching parenthesis, judging by Lisp popularity), but you can grab it here. To start using it simply include the js file using

One more tip: keep in mind that jsTemple just returns a string, so you can for example use it with Prototype’s Template class.