From: Robert Klemme Date: 2006-09-09T03:35:15+09:00 Subject: Re: state machine in ruby snacktime wrote: > So I'm refactoring a very ugly piece of client code that needs to > implement some fairly complicated error correction over a line based > tcp protocol. There are about 10 different error scenarios I have to > detect and respond differently to. Think error correction over serial > lines, that's actually where this was derived from and now it's > layered over a tcp connection. Most of the scenarios involve several > back and forth messages between client and host. Most of the > scenarios are very similar, so if you think of it as a tree I might > not know what scenario I am dealing with until I've gotten 2-3 levels > deep, and at any point in the tree I need to know where I am and what > the possible branches are I can take based on the next response from > the host. > > Any suggestions on how to implement this cleanly? It seems you have answered it in the subject already, don't you? One other solution came to mind, something like a decision tree when you mentioned that you need several steps to determine what's going on. A bit like a mini expert system. Only 0.01 EUR today... Kind regards robert