[plt-scheme] web programming, continuation, CPS transform, etc.

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue May 1 11:20:17 EDT 2007

On May 1, 2007, at 10:59 AM, Grant Rettke wrote:

>> > My take is that continuations are more about capturing state and
>> > making the program easier to understand. AJAX achieves neither of
>> > these goals, in fact, quite the opposite!
>>
>> AJAX programming is two-tier programming. The client tier is about  
>> re-
>> actions to external events. The server tier supports persistency and
>> outside pages. Continuations -- which capture control and NO state at
>> all (see the research lit) -- are about facilitating the server
>> switching pages. The client tier makes it less necessary to switch
>> pages; instead local updates to pages are computed. -- Matthias
>
> I had read that continuations allow you to maintain state so you can
> do things like write web based tasks as flows where you can easily use
> the back button to go back to a previous state.  This is what nearly
> every article on continuation based web servers that I have read have
> reflected, but then again, I've never done it myself, so I couldn't
> make an authoritative statement on this one.


If you have found the word state in conjunction with continuation in  
one of our publications, please let us know. It would be a major and  
grave mistake.

In your words, a continuation is a function from an intermediate  
state to a final answer. In other words, it's explicitly NOT closed  
over the intermediate state.

The back-button problem is related but it is NOT solved with  
continuations. The true problem is that every program has at least  
three attributes (things to manage) and there are different ways to  
manage them:

  -- binding (e.g., a procedure parameter)
  -- state (e.g., a locally declared variable or specifically the  
association between its location and the content of the location)
  -- control (e.g., the "back" or "clone" action on browsers)

The problem with back-button and other Web navigation is two-fold:

1. The actual flow of control is best mapped to the mechanism of  
continuations in PLs (if they exist).

2. The control flow of Web programs forces programmers to make  
decisions of how to map bindings to linguistic mechanisms in a way  
that they have never seen before. Worse, binding is a concept that in  
normal forms of programming is considered shallow and trivial. Now in  
web programming, it must be put somewhere and especially somewhere  
between different web pages, which corresponds to different programs  
EVEN IF THEY LOOK LIKE ONE PROGRAM.

This transmission of information from one program to another that is  
usually in bindings is often mapped to state by naive, uneducated web  
programmers. (After all, 21 days is all you need. Right?) And you  
know what: most web programming frameworks force programmers (or  
naturally guide programmers) to mapping information that belongs into  
bindings into state.

When you know how to use continuations properly, then binding natural  
stays binding (the parameter of the continuation 'function') and  
state stays state. BUT it is possible to make the very same mistakes  
with continuation-based languages.


> Your take on AJAX programming is interesting. Would you say that AJAX
> makes web development easier, then?

To some extent. It is a benefit-vs-cost balance and the overall  
answer is a yes.

Check out flapjax. -- Matthias





Posted on the users mailing list.