[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Y Store /Closures




On Thu, 27 Feb 2003, Sundar Narasimhan wrote:

>
> Mike: Actually, I'd like to know precisely how closures in a language
> or how some other features (such as continuations) help build web apps
> that cannot be done in other languages w/out such features. Note I say
> web apps -- not all apps.

I've spent the last year and a bit building web applications in a
framework that makes extensive use of both closures and continuations.  I
have a very simple criterion now for web development languages and tools:
if they don't support continuations, I'm not interested in using them.
The difference is that profound.

Let me try to give you an example.  One of the applications I worked on
about a year ago was a "point of sale" system for a theatre boxoffice.
Like many applications, it was very task based: the front page consisted
of a large list of things the user could do, each of which led the user
through a series of wizard-like screens.  For example, one task was
obviously "Sell Tickets", which consisted of, roughly,

- Pick Performance
- Pick Ticket Types (Adult, Student, etc)
- Pick Seats
- Pick Patron (possibly involving Add Patron)
- Enter Payment Information
- Show Confirmation

Of course, many of these steps were reused in other tasks - for example,
"Exchange Tickets" is almost the same sequence of actions but in a
different order.

What using continuations allowed me to do is to have each step/page
implemented, effectively, as a subroutine.  I won't go into the details of
how this is implemented, but it means that the *actual code* for these
tasks looked something like this:

performance = pickPerformance();
types = getTicketTypesForPerformance(performance);
if(performance.hasAssignedSeating())
  seats = getNSeatsForPerformance(types.size(), performance);
patron = pickPatron();
payment = getPaymentInformationForPrice(priceForTypes(types));
showConfirmationPage(performance, types, seats, patron, payment);

The kicker is that this all still works when the user goes and clicks on
the back button.  If they go back to the "Pick Seats" page and choose a
different bunch of seats, that method will rewind back to the point where
getNSeatsForPerformance is called, return a different value, and continue
from there.

The effect this all has on the maintainability of the code base is
unbelievable.  And there is simply no way to get the same results
without either having first class continuations in your language, or
doing an automated transformation on all of your code to simulate them.

Avi