The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Do we really want to use state machines to model application flow?

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Do we really want to use state machines to model application flow? Posted: Oct 9, 2003 5:11 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Do we really want to use state machines to model application flow?
Feed Title: Avi Bryant
Feed URL: http://smallthought.com/avi/?feed=rss2
Feed Description: HREF Considered Harmful
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Avi Bryant

Advertisement
Daniel von Fange replies to my post on Ptth! with this snippet of PHP code:

$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.

Read: Do we really want to use state machines to model application flow?

Topic: BloggerCon - interesting mix Previous Topic   Next Topic Topic: odd behavior of the blogs

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use