Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^4: Review: CGI::Prototype

by fizbin (Chaplain)
on Dec 29, 2004 at 18:57 UTC ( #418055=note: print w/replies, xml ) Need Help??


in reply to Re^3: Review: CGI::Prototype
in thread Review: CGI::Prototype

So let me see if I've got this. State machines basically follow this cycle, after an initial setup:
  1. Look at your state and look in a table for what to do.
  2. Do stuff, probably depending on input, and figure out what state to go to next.
  3. Transition to the next state
Now both C::A and C::P maintain state information by telling the browser "when you submit this form back to the server, come back in as state X". This is pretty much driven by the way HTTP works (the other choice is to use session ID variables and database lookups, but that tends to lead to un-web-like applications), so it's not surprising that they look alike in that respect. The difference is where in the state machine cycle the browser comes in. C::A seems from your description to put the browser into the last step; its state machine loop would be:
  1. Look at your state and look in a table for what to do.
  2. Do stuff, probably depending on input, and figure out what state to go to next.
  3. Tell the browser to come back in as the next state.
  4. Wait for the browser
Whereas C::P seems to be:
  1. Look at your state and look in a table for what to do.
  2. Do stuff, and tell the browser to come back in as the second half of this state.
  3. Wait for browser
  4. Do some more stuff, probably depending on input, and determine what the next state should be.
  5. Transition to the next state
Now, from just this description I'd expect the two application frameworks to be equivalent in the sense that an application could be switched between them by renaming some states and shuffling a bit of logic. The discussion so far would suggest that there are stronger differences. I'm not sure from this description which approach makes it easier to develop and maintain applications. The C::P approach seems more in line with what I'd want to do in typical data-entry or shopping cart web applications, but I'm wary of dismissing the C::A approach just because it doesn't immediately align with my current thinking. Lots of very useful tools don't align with my first impression of the problem domain.
-- @/=map{[/./g]}qw/.h_nJ Xapou cets krht ele_ r_ra/; map{y/X_/\n /;print}map{pop@$_}@/for@/

Replies are listed 'Best First'.
Re^5: Review: CGI::Prototype
by xdg (Monsignor) on Dec 30, 2004 at 06:44 UTC

    I don't think that's quite right. In both cases, the logic flow is

    1. Receive a request from the browser
    2. Decide what do do about it
    3. Tell the browser to enter a new state
    4. Wait for the next request from the browser

    The difference is in the nature of (1) and the details of (2). I prefer to think about it this way:

    • C::A wants to know where you want to go, and decides based on that and the data provided where you actually end up.
    • C::P wants to know where you were and decides based on the data provided where you actually go next.

    For me, apart from style preferences, C::P works well where the validity conditions for entering particular states frequently depend on the current state. C::A is useful where the validity conditions for entering a particular state depend solely on the data requirements of the target state.

    If a C::A app always required a parameter for "current state" along with the "run mode" and used that plus other submissions to determine the state entered, it would provide the same functionality as C::P. C::P just enforces that kind of thinking from the beginning.

    -xdg

    Code posted by xdg on PerlMonks is public domain. It has no warranties, express or implied. Posted code may not have been tested. Use at your own risk.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://418055]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (8)
As of 2021-06-22 14:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (105 votes). Check out past polls.

    Notices?