Daniel Von Fange

Life, Code, and Cool Stuff

Continuations? - Code Calling the User vs the User Calling the Code

Three good responses to my post on continuations. Patrick Logan explains continuation based web coding as “calling the user”, which is a clear term for the fuzzy thoughts that have been floating around in my head. Cris Double shows some simple example code. Avi Bryant demonstrates tradtional web programing in terms of a IO named Ptth.

My background on contination based web programming: I’ve used Ruby continuations in non web coding. And I’ve read the ”A Walk on the Seaside” tutorial. Along with the examples just given, I think I have good understanding on what site programming with continuations is. I see how it could be a good way of doing a tricky set of registration forms.

The concept that bugs me though is the same concept that makes continuations easier to code certain things with - that it is “calling the user from within the code”. When I’m programing, I am trying to make the site user driven, not code driven. I want someone to be able to send a URL over email, and the other person get what they were expecting.

A URL to me represents either a particular piece of data, or a particular action that could be done by submitting the form displayed. At least in the examples of continuations I have seen, the URL’s get hosed. :)

Here is the “Ptth” example coded in php - but without the ptth. :P (So maybe it’s not fair). ($t is my handy template class. Yes, it would be a clearer example if I did not use it, and yes this example is not perfect. )

$amount = $_REQUEST['amount'];
$rate = $_REQUEST['rate'];

if( $amount != "" && $rate !=""){
    if(! $amount > 0){
        $t->assign("message", "Amount must be greater than zero");
    }else if(! $rate > 0){
        $t->assign("message", "Rate must be greater than zero");
        $result = $amount * rate;
        $t->assign("result", $result);

So the effect of this is that a user goes to the url, which is of an “action” page, and gets a form. When If their data validates, the action is done. If it does not validate, they get an error, and can change their data.

At least with an example this simple, continuations don’t have much of an advantage. Is there an open source project using continuations well? Then I could look in the source and see how they are used in the real world.