$amount = $_REQUEST['amount'];
$rate = $_REQUEST['rate'];
if( $amount != "" && $rate !=""){
if(! $amount > 0){
$t->assign("message", "Amount must be greater than zero");
$t->display("interestForm.html");
}else if(! $rate > 0){
$t->assign("message", "Rate must be greater than zero");
$t->display("interestForm.html");
}else{
$result = $amount * rate;
$t->assign("result", $result);
$t->display("interestResult.html");
}
}else{
$t->display("interestForm.html")
}
At least with an example this simple, he says, continuations don't have much of an advantage.
Not surprisingly, I disagree. Looking at that piece of code, can anybody tell me:
What's the first page the user sees? How obvious is this?
What's the order of pages the user sees after that? If this isn't fixed, what determines the order?
How would I change the order if I wanted to? If say, I decided I wanted to ask for amount first, and then rate, how many different pieces of code (and templates!) would I have to change?
Say I had to ask for 10 different variables instead of 2. How would I abstract the validation code so that I could reuse it easily?
These questions all have trivial answers when you're using a continuation-based system. They're a lot more difficult (especially the last two) when you're designing your program as a state machine - which is effectively what Daniel's code, and much code like it, does. With all due respect: this is spaghetti code, and in any context but web development you wouldn't stand for it either.