Continuations

Everybody who started in a language other than a web scripting one has written programs like this:

WriteLn('What''s your name?');
ReadLn(name);
WriteLn('What''s your age?');
ReadLn(age);
WriteLn('Hello ' + name + ', you are ' + age + ' years old.');

(Yeah sorry, I started in Turbo Pascal.)

All was nice and dandy until you start writing web applications. All of the sudden you can't write applications like that anymore. You have to do stuff like this:

switch($_GET['step']) {
   '0':
      echo '<form action="?step=1>';
      echo 'What's your name?';
      echo '<input name="name"/><input type="submit"/>';
      echo '</form>';
      break;
   '1':
      $_SESSION['name'] = $_GET['name'];
      echo '<form action="?step=2>
      echo 'What's your age?';
      echo '<input name="age"/><input type="submit"/>';
      echo '</form>';
      break;
   '2':
      $name = $_SESSION['name'];
      $age = $_GET['age'];
      echo "Hello $name, you are $age years old.";
      break;
}

The general pattern is here is that you have to store your state and restore the state of your application on every page view. This makes writing web applications very inconvenient.

Continuations allow you to write applications almost the nice old-fashioned way. Continuations are a standard feature of Ruby, in other languages it is a harder to accomplish. Continuations all of sudden became a hot issue in the past weeks. Some articles that explain how continuations work and how to implement them:

* "Sam Ruby: Continuations for Curmudgeons":http://www.intertwingly.net/blog/2005/04/13/Continuations-for-Curmudgeons * "Dynis Ducher: Continuations Made Simple and Illustrated":http://www.ps.uni-sb.de/~duchier/python/continuations.html * "Continuations on the Web":http://www.phubuh.org/Media/Writing/Continuations/ * "IBM developerWorks: Use continuations to develop complex Web applications":http://www-106.ibm.com/developerworks/library/j-contin.html#IDAO0GMB * "Borges":http://borges.rubyforge.org a Ruby web application framework that is based on continuations * "Continuations in Python":http://pyds.muensterland.org/wiki/continuationbasedserver.html * "Don Box: Continuing Continuations":http://pluralsight.com/blogs/dbox/archive/2005/04/23/7682.aspx