Keep Working, Worker Bee!

8.11.2005

I had a pretty abbreviated day today for various reasons, but I managed to get another new feature into PLaneT -- now it's possible to use the command-line tool to download PLaneT packages without installing them, so people with only intermittent Internet access can use PLaneT more easily. I've resisted features like this in the past on the assumption that people would tend to forget about the fact that PLaneT will do everything automatically for you if you let it, but I've come around lately to the opinion that I shouldn't remove features just because they can be misused.

I also had an epiphany about how to structure web servlets to implement save points in a web application that ought to be associated with a user rather than with a session. The answer is pretty simple in retrospect - use a table that maps users to continuations, capture a new continuation just before sending off any web page and bang the table to point to that continuation (removing any old ones), and throw to that continuation whenever the user logs in - but I actually implemented this feature a much harder way for the speed-dating project without ever realizing I could get the same effect for the cost of about ten lines of code if I just used the power of first-class continuations.

The fact that this was done in the context of a continuation-based web server makes the whole thing a little more ironic, but actually it sort of makes sense: the continuation-based web-server makes you think of continuations as the same thing as URLs, so when you have a problem that involves continuation-manipulation the natural thing to think of is rephrasing it as an HTTP redirect of some sort - perhaps saving URLs as they went by and doing an HTTP redirect to the last one of those a user had seen. I scratched my head over that for a long time and realized it didn't quite work, but didn't quite understand the essence of the problem and its solution. Like I said, I actually went off and implemented the whole thing a different, awful way that was a complete beast to maintain and never really worked exactly right.

But today I found myself saying, in trying to explain the issue to someone else, that the continuation you associate with a URL is taken one step too late: it will return _after_ the web page gets shipped off, not beforehand as it should. From that perspective the answer is obvious - if the continuations the web server provides don't work out, grab your own! Scheme has no problem with that, and the fact that the continuations aren't connected to URLs is completely inconsequential. The same solution would apply to any situation where a user wants to save and resume their session, on the web or off. You've got to love the fact that Scheme gives you power tools like call/cc -- very rarely used, but indespensable when they are.

1 Comments:

  • "now it's possible to use the command-line tool to download PLaneT packages without installing them"

    Sweet, thanks.

    "but I've come around lately to the opinion that I shouldn't remove features just because they can be misused"

    No, save this mentality for Topsl ;)

    "I also had an epiphany about how to structure web servlets to implement save points in a web application that ought to be associated with a user rather than with a session"

    Pretty awesome idea too. I've got user support now and I'm going to throw your code in tonight. After that Topsl should be good to go.

    By Blogger Mike Machenry, at 08:27  

Post a Comment

<< Home