Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 04 Oct 1999 07:12:24 +0100
From:      Brian Somers <brian@Awfulhak.org>
To:        Dennis <dennis@etinc.com>
Cc:        W Gerald Hicks <wghicks@bellsouth.net>, freebsd-hackers@FreeBSD.org
Subject:   Re: A bug in the sppp driver? 
Message-ID:  <199910040612.HAA00448@hak.lan.Awfulhak.org>
In-Reply-To: Your message of "Thu, 30 Sep 1999 11:46:30 EDT." <199909301648.MAA12186@etinc.com> 

next in thread | previous in thread | raw e-mail | index | archive | help
> 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 <brian@Awfulhak.org>                        <brian@FreeBSD.org>
      <http://www.Awfulhak.org>;                   <brian@OpenBSD.org>
Don't _EVER_ lose your sense of humour !          <brian@FreeBSD.org.uk>




To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199910040612.HAA00448>