lua-users home
lua-l archive

Re: Ah, those uninitiated people...

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jan 14, 2010, at 9:36 AM, David Kastrup wrote:
> Mark Hamburg <mark@grubmah.com> writes:
> 
>> On Jan 14, 2010, at 8:05 AM, David Kastrup wrote:
>> 
>>> No, the whole "state machine" is one coroutine. You just program the
>>> control flow that is to be modelled by the state machine. Yield/resume
>>> pairs are used to get new input, and the input is processed with normal
>>> conditionals and other branches. Every code path containing a yield
>>> call corresponds to a state.
>> 
>> Which maps nicely to the state machine = regular language = structured
>> programming equivalence, but I'm not sure it always maps well to the
>> cases where one wants to use a state machine.
> 
> Well, the point is that it often maps well to the cases where you don't
> want to use a state machine.
> 
> I mean, who wants to use a state machine? Seriously?
> 
> Even if you see people drawing a state machine, they tend to do it in a
> diagram, with anonymous states. States that you have to name and look
> up just are not fun.
If you have states of the form "waiting for async result" that could receive either a result or perhaps an instruction to cancel the computation, a state machine can be clearer than the straight code since it can have logic in multiple states to say "if you see a cancel message, stop what we're doing and go back to the idle state".
If you are using anonymous states, on the other hand, then I agree that conventional control flow is better and I've long argued that control flow should mirror the expected event sequence.
Mark

AltStyle によって変換されたページ (->オリジナル) /