Read on and leave a comment
or return to our portfolio.

2 Aug 2007

by Noel

A Scheme Case Study

If you’ve looked at the ICFP 2007 preliminary program you’ll have noticed we’re presenting “Experience Report: Scheme in Commercial Web Application Development”. We submitted the final version of the paper a couple of weeks ago, and I’ve finally got around to putting itonline for your reading pleasure. The contents shouldn’t come as a surprise: a summary of our experiences developing commercial web applications in PLT Scheme over the last year. We’ve tried to be honest, including the good and bad. Hopefully the points you’ll take away are that we’ve been able to overcome initial problems with stability, and in a fairly short time we’ve developed a framework that compares well to popular alternatives such as Ruby on Rails.

The four page limit on experience reports is very tight, and unfortunately our experiences with Flapjax were cut from the final version. So let me say here that if you write Javascript code you need to check out Flapjax! Our Flapjax code is about half the size of the equivalent Javascript, and this is without using the Flapjax compiler. The only problem with Flapjax is performance in large networks. This is more a property of the poor quality of Javascript interpreters: Wolfenstein 3D on my 286 back in 1990-something was smoother than Javascript raycaster running today on my Powerbook. Luckily the new developments taking place at Mozilla will alleviate this problem in the next few years.

Posted in Web development | Comments Off on A Scheme Case Study

26 Jul 2007

by Noel

Visual Manipulation

This post is about two different forms of visual manipulation for artistic effect. Start by looking at these
pseudo-3D chalk drawings. The monocular vision of the camera enhances the effect but I believe they would work in life if seen from the right angle. There was an exhibition of pseudo-3D paintings at the Birmingham Museum and Art Gallery and they worked very well — arguably better than in photographs are you could actually walk around the works and the effect was maintained for quite a wide viewing angle.

Now you’re warmed up, we’re going to go into a time machine hereand here. I find the lack of colour in early photographs presents a barrier that makes it difficult to imagine myself in the scene. These colour photographs from the period 1909-1915 (reconstructed from red, green, and blue images using an ingenious process) remove that barrier and the results are striking. Some of the scenes — railways, forests, grand buildings — could be contemporary, but note how few roads there are, how few possessions are visible. I can relate to the pictures and yet they still feel like another world. Fantastic stuff.

Posted in Design | Comments Off on Visual Manipulation

18 Jul 2007

by Noel

Power to the People!

Waitrose has opened up near to Untyped Central and obviously Dave and I are agog with excitement. Only just less exciting than the thought of the great lunches we’re going to have is the chance to see the John Lewis Partnership in action. They have a fairly unique corporate form, and talk a good game, but do they deliver? I did my first test today when I asked the checkout operator what is was like to work for the Partnership. To my great surprise she responded very positively and could give me specific examples of the benefits. I don’t think many people could answer half as well if quizzed about their government, for example.

Posted in Business | Comments Off on Power to the People!

5 Jul 2007

by Noel

Of Interest 05/07/2007

There’s been a bit of a backlog building up for Untyping while I work hard on other stuff. Here’s so the of the stuff that has recently caught my eye:

  • “Show, don’t tell” is an old mantra in creative writing.
    Announcing the Business of Software Wiki is a great example of this principle in action. Note how Joel doesn’t tell you what a wiki is, which would be boring, but shows you with a brief demonstration. In addition to making more engaging prose showing conveys information on how to use the wiki, which helps bootstrap new users. Neat.
  • Facebook opened up an API recently. While Facebook could make an engaging platform for many things Jason Kottke gives a well-reasoned argument on why it probably isn’t a big deal
  • Watching without being. Just read this. Its only a short blog post but there’s too much in it to summarise here.

Posted in General | Comments Off on Of Interest 05/07/2007

20 Jun 2007

by Noel

Selenium Code Released

The Selenium code I talked about in an earlier post has beenreleased to PLaneT

Posted in Web development | Comments Off on Selenium Code Released

19 Jun 2007

by Noel

Font Rendering Fun

I’ve always wondered why fonts looked different on OS X and Windows and thanks to this blog post I now know why. The summary is that Windows favours aligning the fonts with the pixel grid, which leads to clearer type but thinner blockier text. Follow the link to see examples of the difference.

More interesting are the various font rendering techniques in use. Microsoft’s ClearType takes advantage of the known arrangement of pixels in LCD monitors which effectively triples horizontal resolution at the expensive of distorting colour. FontFocus takes a different approach to get a better result. It again focuses on aligning fonts with the pixel grid. Here’s an explanation from the white paper linked above:

Previous grid-fitting techniques … improve contrast by aligning stems to pixel boundaries, but in doing so distort individual letterforms. FontFocus leaves the shapes of the glyphs completely unchanged. Instead, it shifts each character left or right by a tiny subpixel amount, and also subtly expands or condenses individual glyphs to align all stems, if there are more than one. …

While the idea of subtly shifting and stretching glyphs to enhance contrast is simple, the core of the of FontFocus technology is how it chooses these tweaks. Most existing font rendering techniques work with a single glyph at a time. FontFocus optimizes the entire word at a time. The results are similar to what you’d get from trying each combination of subpixel offset and width stretch for each glyph in the word, and picking the combination with the best overall score. FontFocus uses an intelligent divide-and-conquer algorithm to avoid the combinatorial explosion of this brute-force method.

This immediately suggests a further improvement: try to align a whole line of text optimally. Of course the search space gets much larger so a better search method is needed. If anyone is looking for a PhD this could be fun.

Posted in Design | Comments Off on Font Rendering Fun

8 Jun 2007

by Noel

What The World Eats

What the World Eats is a moderately fascinating photo essay of the weekly food consumption of 16 families around the world. The choices and differences aren’t that unexpected, but it is interesting none-the-less. Here are some thoughts:

  • Those starving Africans really are. Of course I knew that intellectually, but didn’t feel it till I saw what they ate.
  • The Bhutan family’s food looks tasty. All those chillies and ginger. Yum. Mexico and Cairo also look good.
  • I’m surprised the Sicilians have such anaemic looking tomatoes. Perhaps the photo was taken in winter.
  • The backgrounds are fascinating. Almost the best thing in the pictures. Favourites are Bhutan, Mongolia, and Ecuador. What’s with the Western families that look like they haven’t redecorated since the 1970s? I can just feel the desert looking at the Kuwait house.

For comparison the two of us spend around £40 on food a week.

Posted in Fun | Comments Off on What The World Eats

5 Jun 2007

by Noel

Of Interest 05/06/2007

Just some quick links. It has been a busy day.

  • [T]he human race publishes a book every 30 seconds. If current trends continue, by 2052 the number of people writing and publishing a book in a given year will exceed the number of people who will read one.
  • From Design Observer

    Last night I had my first foray onto eBay. As I surveyed the hundreds of professional sellers my stuff would be competing for attention against I thought I’d missed the boat on this one. Looks like I have a few years yet to impress any book-length ideas on the world, but the window is closing.

  • Just everyone has linked to the Profit Calculator, which lightly skims over how a variety of NY businesses make money. Most interesting for me were the drug dealer, the yoga studio, and Nobu.
  • Mark Fletcher asks if distributed development leads to better communication. Interesting idea. So far I’m undecided on the basis of our efforts.

Posted in General | Comments Off on Of Interest 05/06/2007

10 May 2007

by Noel

XML Transformation in Scheme

Selenium is a tool for testing web applications, the core of which is a Javascript library that controls a web browser. With the Selenium IDE you can convert your actions in a web browser into tests, and with the Selenium Remote Control you can control a web browser from code. I’ve recently been working on adding Selenium Remote Control bindings to PLT Scheme, which has resulted in a nice and hopefully instructional demonstration of XML transformation in PLT Scheme

The Selenium Remote Control is controlled by sending simple messages over HTTP. The format of the messages isn’t important. What is, is that there are a lot of them, and the API is specified in a file called iedoc.xml that comes with Selenium. The Java/Python/Ruby bindings are generated using XSL. If I was to use XSL I’d have a processing pipeline that uses three languages (XSL, Java, Scheme) which is two more than I’d like. Hence I turned toWebIt!, an XML transformation DSL written in Scheme, to create an all Scheme pipeline. The rest of this post wshows the steps I used to transform the Selenium API into Scheme code using WebIt! I think this is interesting in its own right, but also serves as a nice demonstration of the power of macros, which WebIt! makes extensive use of.

My first step is to get an idea of the structure of the XML. The bits I’m interested in look like this:

<function name="click">
<param name="locator">an element locator</param>
<comment>Clicks on a link, button, checkbox or radio button.
If the click action causes a new page to load (like a link usually
does), call waitForPageToLoad.</comment>
</function>

Let’s read in the XML file and extract all the function elements. For this I’ll use SSAX and SXPath:

(require
(planet "ssax.ss" ("lizorkin" "ssax.plt" 1))
(only (planet "sxml.ss" ("lizorkin" "sxml.plt" 1)) sxpath))

(define api
(with-input-from-file "iedoc.xml"
(lambda () (ssax:xml->sxml (current-input-port) '()))))

(define functions
((sxpath '(// function)) api))

Ok, so we have all the functions. Now let’s parse them into a more useful datastructure. Here’s my first attempt:

(require (planet "xml.ss" ("jim" "webit.plt" 1 5)))

;; struct function : string (listof string)
(define-struct function (name params))

;; parse-function : sxml -> function
(define (parse-function fn)
(xml-match fn
[(function name: ,name
(param name: ,param-name ,desc) ...
(comment ,_ ...))
(make-function name (list param-name ...))]))

(map parse-function functions)

The xml-match macro is a pattern matcher for SXML. You specify the “shape” of the SXML, and if the input matches the pattern the following expressions are evaluated:

(xml-match value
[(pattern expression ...)]...)

The simplified form of a pattern is:

  • (element ...) matches an element with the given name.
  • name: value matches an attribute with the given name and value.
  • ,binding binds the value of binding to the given name in the scope of the following expressions.
  • ... matches zero or more of the preceeding patterns.

In our example the pattern is:

     (function name: ,name
(param name: ,param-name ,desc) ...
(comment ,_ ...))

So we’re looking for an element called function with an attribute called name the value of which is bound to name. Then follows zero or more param elements, with attribute name, the value of which is bound to param-name. Finally we expect a comment element which can contain any amount of data. The use of _ as the binding name is a common convention to indicate data we don’t care about but must still match to make our pattern complete.

I run the code in DrScheme and see the result:

xml-match: no matching clause found

Oops. So our pattern isn’t complete. We’ve also seen one flaw of WebIt!: it doesn’t give very good error messages. However we can easily fix this by adding a catch all pattern that raises an error telling us what we failed to match. The code follows. Notice that I’ve also added pretty printing to make the unmatched SXML easier to read.

(require (lib "pretty.ss"))

;; parse-function : sxml -> function
(define (parse-function fn)
(xml-match fn
[(function name: ,name
(param name: ,param-name ,desc) ...
(comment ,_ ...))
(make-function name (list param-name ...))]
[,err (let ([op (open-output-string)])
(pretty-print err op)
(error (format "Didn't match ~n~a~n" (get-output-string op))))]))

Run this code and you’ll see the error occurs as we don’t allow the description to contain more than one element. This is easily fixed by extending the pattern to ,desc .... The next error is more interesting. The function element contains a return element. The WebIt! pattern language doesn’t allows us to express optional patterns, so we have to duplicate our pattern and include the case ofreturn. This also requires we extend the defintion of the functionstructure.

;; struct function : string string (listof string)
(define-struct function (name return params))

;; parse-function : sxml -> function
(define (parse-function fn)
(xml-match fn
[(function name: ,name
(param name: ,param-name ,desc ...) ...
(comment ,_ ...))
(make-function name "void" (list param-name ...))]
[(function name: ,name
(return type: ,type ,return-desc ...)
(param name: ,param-name ,desc ...) ...
(comment ,_ ...))
(make-function name type (list param-name ...))]
[,err (let ([op (open-output-string)])
(pretty-print err op)
(error (format "Didn't match ~n~a~n" (get-output-string op))))]))

This works! This is as far as I want to go in this article. We’ve seen how we can use SSAX. SXPath, and WebIt! to create XML transforms in pure Scheme. There is a lot more to all of these packages but what we’ve used is sufficient for many uses. The rest of the code to create Scheme from the API is quite straightforward and specific to Selenium. If you’re curious read the source of the Selenium PLaneT package, which will be released soon.

This post also appears on the PLT Scheme Blog

Posted in Code | Comments Off on XML Transformation in Scheme

3 May 2007

by Noel

Get It Right (or Left)!

Next time you’re walking down the street and have to step aside to avoid a fellow pedestrian, note which way you move. The chances are you’ll step over to the side people drive on in your country. Normally this is unconscious and the two of you will smoothly avoid one another as if the process had been choreographed. Go to a country where people drive on the other side of the road and it will become immediately noticeable as you play the hilarious game of stepping-in-front-of-one-another. Why do I bring this up? The local branch of Aldihas undergone redevelopment, including a new front door. You enter on the right and leave on the left. I ambled up not really paying attention and of course went to the wrong side. So did the next three people after me. The difference between a great design and a bad design is made in the little details like this.

Posted in Design | Comments Off on Get It Right (or Left)!