Smalltalk Coding Contest Submission
May 19, 2005, 8:04:39 pm

The Smalltalk Industry Council's Coding Contest was very interesting. I participated in it. We had 48 hours to build a Survey web application that took survey answers from participants and then reported on those answers.

The idea was to build the application in Smalltalk, throw in as many bells and whistles as you could and see how you went against the other competitors. We'll find out who's in the top three at the start of next month - two weeks time.

I wrote my application in VisualWorks 7.3 using VisualWave as the Http Server base - then on top of that I used SimpleWeb.

SimpleWeb? I hear you say. Yes, SimpleWeb. SimpleWeb is basically a re-write of a framework I have at Wizard Information Services. At Wizard we use VisualAge. Because we use VisualAge we cannot use Seaside - it requires continuations.

What we wanted was something as simple to use to build web applications as seaside, yet without continuations. Thus was born our Web Canvas framework which uses Server Smalltalk underneath for it's Http Server. The API to build web applications is very simple, inspired by Seaside.

I so liked our answer that we had, I decided to re-write it for this competition during the 48-hours of the competition to use instead of Seaside. Why would I do such a thing? - mostly because of debugging. With Seaside, you have continuations. With continuations you have the worst debugging experience you could ever possibly imagine. The VisualWorks debugger does not like processes to suddenly disappear and be replaced with an entire new continuation stack.

SimpleWeb uses callback's which hold on to BlockClosure's. Each time a page request comes in, the document ree with it's BlockClosure's is duplicated so that you have a new unique instance for the BlockClosure's callbacks to run on. In this way you get the same sorts of behaviour you have in Seaside, yet without continuations.

On top of this I built my submission. I also used Prevayler - the one I made, not the Java one - as the persistence mechanism. Hey Janko Mivsek! It works! - Just like we designed it too. Unlike regular Prevayler, this Prevayler is completely transparent to the developer - you don't explicitly write and read things from a log. In fact, it doesn't use one log, it uses lots of little BOSS files for persistence.

So, combining a nice persistence mechanism with a nice web framework, I was able to rapidly knock together my submission for the competition. I'm pretty pleased with my domain model and I had lots of tests to go with it - 90 of them. I didn't do any view tests, that's always really hard and I knew it would be too big a distraction at this point.

Some of the things that distinguish my Survey application from the requirements of the competition: You can have multiple survey's in the system, you never 'drop' them and start a new one. Only one Survey is active at a time. You can view past survey results, there's an RSS feed for them and there's an XML link at the bottom of each Survey results page to get an export.

So because Blaine Buxton has put up his code, I thought I might do the same so that we can see how each other has gone. I found his approach to the problem interesting and I'm now more convinced than ever that Smalltalk is a brilliant platform for making Web Applications -of any kind-.

Here's the link to my submission. Simply load up the Survey.pcl in to your copy of VisualWorks 7.3 and read the workspace that pops up. It tells you how to start it and use it.

One thing that Blaine got to do that I didn't end up doing was an editor for survey's. That's a neat idea and it turns out to be fairly simple to implement. I just gave admin's a text area to paste in that weird format that the competition requires.

By Avi Bryant on May 20, 2005, 7:40:41 am

Hi Michael,

I'd like to hear more about SimpleWeb. It sounds like you're actually moving in a direction I wanted to go with Seaside anyway: first, to be able to use the bulk of the framework without requiring continuations (probably in much the same style as SimpleWeb). Second, I really like the idea of copying the document tree on each request, but when I was playing around with that a couple of weeks ago, the performance just didn't seem to be there: with a complicated page with a few hundred callbacks the copying was adding a huge amount of overhead to each request. Do you have some clever way around this, or is copying a large tree of objects and fixing up all the internal references much faster to do in VW and VA than in Squeak?

It's too bad about the debugger in VW, by the way - sounds like Squeak's handles it much better.

By Michael Lucas-Smith on May 20, 2005, 9:16:29 am

Comment by Michael Lucas-Smith

Hey Avi,

SimpleWeb works as a basic tree structure - very close to XML in fact. It has parent, children and attributes. Attributes only exists on an WebElement though. What was really important in making SimpleWeb useful was how the end developer used it - which is the nice API's that closely tie what it is you want to output to what the thing will do with its callbacks. That's what Seaside really got right.

Because it's an XML tree, I don't need to do much more than traverse over it. It's a simple deepCopy with a dictionary to avoid recursion. Even with hundreds of things on the page (as we have at work) it is fast. I honestly can't imagine it ever being slow? - if you think about it, any kind of marshaling system in Smalltalk is doing -more- than this.

I'd like to know if the performance of SimpleWeb is better or as bad as your Seaside experiments? I'd be happy to talk to you about licensing of SimpleWeb and of further development that could be done with it. As it stands, I'm quite proud of its simplicity of design and very few classes that allow it to do all it does.

Perhaps your issue with duplication is to do with the scope of the duplication. Any thing that is not a SimpleWeb widget or a block is not duplicated.

Avi: you can play around with SimpleWeb by downloading the Survey.zip and loading up the parcel in to a VisualWorks 7.3 image.