From owner-freebsd-hackers Sun Oct 3 23:41:24 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from storm.FreeBSD.org.uk (storm.freebsd.org.uk [194.242.128.198]) by hub.freebsd.org (Postfix) with ESMTP id D5DB315068 for ; Sun, 3 Oct 1999 23:41:06 -0700 (PDT) (envelope-from brian@Awfulhak.org) Received: from hak.lan.Awfulhak.org (root@localhost [127.0.0.1]) by storm.FreeBSD.org.uk (8.9.3/8.9.3) with ESMTP id HAA22253; Mon, 4 Oct 1999 07:41:05 +0100 (BST) (envelope-from brian@Awfulhak.org) Received: from hak.lan.Awfulhak.org (brian@localhost.lan.Awfulhak.org [127.0.0.1]) by hak.lan.Awfulhak.org (8.9.3/8.9.3) with ESMTP id HAA00448; Mon, 4 Oct 1999 07:12:24 +0100 (BST) (envelope-from brian@hak.lan.Awfulhak.org) Message-Id: <199910040612.HAA00448@hak.lan.Awfulhak.org> X-Mailer: exmh version 2.0.2 2/24/98 To: Dennis Cc: W Gerald Hicks , freebsd-hackers@FreeBSD.org Subject: Re: A bug in the sppp driver? In-reply-to: Your message of "Thu, 30 Sep 1999 11:46:30 EDT." <199909301648.MAA12186@etinc.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Mon, 04 Oct 1999 07:12:24 +0100 From: Brian Somers Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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 Don't _EVER_ lose your sense of humour ! To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message