Updated: 11/5/2005; 6:05:09 PM.
Chris Double's Radio Weblog
        

Wednesday, October 08, 2003

Daniel Von Fange writes about continuation based web servers saying that "but to me treating a 'page' as a method of an object makes more sense to me for 97% of things I do.". I wrote a comment (copied below) which outlines how the control flow of a web application in a continuation based server can be easier to follow.

Continuation based web servers allow you to write application logic in web applications easier than a page by page approach. Imagine a simple web application that asks you to enter a rate and then an amount and presents a final page displaying the rate * amount. You want some logic to make sure that (server side) correct data is entered. Coding the web app in a continuation based server looks like normal procedural code:

define method rate-app()
  let rate = get-rate();
  if(rate <= 0)
    show-error("Rate must be > 0");
  else
    let amount = get-amount();
    if(amount <= 0)
      show-error("Amount must be > 0");
    else
      show-result(rate, amount);
    end if;
  end if;
  /* Redisplay from the beginning */
  rate-app();
end method;

A request to an URL by the client causes the rate-app method to run. When it hits get-rate() it returns HTML to the client to display a page with an input form request entry of a rate and 'suspends'. The 'Action' of this form is to call to an URL which, when requested, calls the continuation which represents the rest of the computation. What this means is processing occurs after form submission at the point that the function was previously suspended. It checks the rate entered and performs actions based on that.

Similarly, The calls to show-result, show-error and get-amount send HTML to the client and suspend, providing a means on the page to request an URL which will resume computation.

At the end a tail call occurs, restarting everything. In 90% of the web applications I write, this type of thing makes development significantly easier to write and debug (You can step through the code in the debugger for example). Note that I said 'Web applications'. For standard serving of static pages there's not much point.


11:16:56 PM      

© Copyright 2005 Chris Double.
 
October 2003
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Sep   Dec



Click here to visit the Radio UserLand website.

Listed on BlogShares

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.