State Machines, The Ultimate Goto

Richard Harter g-rh at cca.CCA.COM
Sun May 1 10:15:05 AEST 1988


In article <760 at dlhpedg.co.uk> cl at datlog.co.uk (Charles Lambert) writes:
>In article <27310 at cca.CCA.COM> g-rh at CCA.CCA.COM.UUCP (Richard Harter) writes:

>>f)	Put the test condition in a while statement and step through the
>>	actions [somehow].  Unfortunately, I don't see a nice way to do
>>	this in C.  The thought that first occurs to one is something like

	... sample code deleted

>This is almost a finite-state machine, and state machine programming is an
>accepted idiom. Generalise it as follows:

	... sample code deleted

Strange throat noises resembling the mating call of a frog.  [That there
is a comment.]

State machines are all very well in their way -- I use them myself --
but state machine logic is quintessential goto logic.  The essence of
state machine logic is that it doesn't matter where you came from;  all
that matters are the appropriate actions for this state and the appropriate
state to transfer to next.

>From a flow control viewpoint, entering a state machine is like falling into
a pin ball machine.  You bang around here and there and (if there is a 
guaranteed halting condition) you eventually get out.

Goto logic says leave and don't come back.  Heirarchical logic says leave
and come back.  The prescription against goto's really means -- don't mix
the two types of structure.

-- 

In the fields of Hell where the grass grows high
Are the graves of dreams allowed to die.
	Richard Harter, SMDS  Inc.



More information about the Comp.lang.c mailing list