> At 05:54 AM 9/30/99 -0400, W Gerald Hicks wrote:
> >
> >> doing state machines with switch statements is a big mess.
> >
> >Still, you'll find a lot of them around.  Do you have a favored
> >technique for coding complex state machines?  (I'm a collector :)
> 
> 
> yes, state tables. Clean and easy to modify.

IMHO state tables are fine in theory.  The problem is that the ``do 
this'' bit sometimes needs to be split into two - one before the 
state change and one after, and that same bit is frequently ``almost 
the same'' as the ``do this'' bit for another transition.

Once you start coding it, you start to bring the common bits of code 
into common routines, and eventually end up actually passing the 
from/to states into those functions.

I found that redesigning the ppp(8) state machine eventually ended up 
with lots of switch statements and a result that was nothing like I 
had in mind when I started writing it !  It registers state 
transition handlers to a certain extent, but there are too few 
handlers and lots of ``if I'm in this state'' code.
-- 
Brian <[EMAIL PROTECTED]>                        <[EMAIL PROTECTED]>
      <http://www.Awfulhak.org>                   <[EMAIL PROTECTED]>
Don't _EVER_ lose your sense of humour !          <[EMAIL PROTECTED]>




To Unsubscribe: send mail to [EMAIL PROTECTED]
with "unsubscribe freebsd-hackers" in the body of the message

Reply via email to