More thoughts on continuations
Avi Bryant replied with a few questions to my last post about continuations. I'll pop back some answers in a minute. My biggest issue with continuation based programing is not the details of how it works. Programming with web sites using continuations seems to put the application in the drivers seat. Letting the application drive is easier to program for (See, I admitted it.
def personDetailsApp
person = get-person()
showPersonDetails(person)
end
h4. "Stateless" style:
- personPicker.rb
#passing in where the picker should go to
showPersonPicker("personDetails.rb")
- personDetails.rb
#person coming from request vars showPersonDetails(person)The HR user pops in, picks a person, and gets their details. In both sets of code all is easy and well. This is a really trivial example, maybe too trivial. But in real life on this project, that simple continuation style code would not have worked for me. First, HR guys need to email around links to a persons info. Also there was another, non web based, HR app that we quickly modified so that from a person's details in the app, you could push a button and their web browser would launch pointing at that person's questionnaire. Because of the stateless way the site was programmed (except for authentication), both of these required no modifications to the sites code at all. Heck, someone could spend five minutes and make a javascript bookmarklet that would let an HR guy highlight someone's name on the internet and pull up their info. Logically, there is no reason why picking a person on a web based form _must_ proceed viewing their details. By using the stateless style, any program, web based or not, my code or not, that can generate a url with the users name in the query string can direct an authorized user to the person's details. It is this disconnect between individual "pieces" on the web that allows so much rich intertwinglyness. With continuations, at least as far as I can see, this is lost and has to be explicitly added? And explicitly adding "statelessness" would defeat the purpose of continuations? Now you guys are smart people, and you use and love continuations, therefore there is probably still perhaps something I'm missing. Any pointers on where to look for it? ---- In Avi's comments on his post, he says "managing flow (continuations vs. state machines)". Rather than a state machine, what I am usually trying to build is an application with very little required flow - almost stateless. (Yes, you have to register to use the system. And if you visit a page without logging in, it lets you log in, and then puts you back to the page you first requested.) I do agree that continuations would be better than stateless for multipage forms, but I don't usually use multipage forms.
$amount = $_REQUEST['amount'];
$rate = $_REQUEST['rate'];
$action = $_REQUEST['action'];
if($action == "calc"){
$calc = new interestCalculator();
$calc->setData($amount, $rate);
if($calc->validData()){
showResult($calc->answer());
}else{
//Passing in an array of errors to be displayed
showForm($calc->getErrors());
}
}else{
showForm();
}
But of course, I am still comparing using one form to Chris' code using multiple ones.
(Remember, the second half of this post is minor. First part is the meat of the matter.)
Posted by on 10/10 at 04:11 PM