Re: finite state machine with enum
This message is in MIME format. The first part should be readable text,
while the remaining parts are likely unreadable without MIME-aware tools.
---910079544-140430949-1265843139=:21102
Content-Type: TEXT/PLAIN; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8BIT
On Wed, 10 Feb 2010, andijcr wrote:
On 10 Feb, 20:02, Tom Anderson <t...@urchin.earth.li> wrote:
On Wed, 10 Feb 2010, andijcr wrote:
the machine is activated through getRawData, which makes it perform a
complete cycle to produce a single packet of formatted data
the initial idea to use a state machine implemented as an inner class
was to:
- bring order in the code
Seriously? You think that's more ordered than:
DataInputStream in;
while (true) {
? ? ? ? pushTime(in.readByte());
? ? ? ? pushValue(in.readByte());
? ? ? ? byte stop = in.readByte();
? ? ? ? if (stop == stopByte) {
? ? ? ? ? ? ? ? commit();
? ? ? ? }
? ? ? ? else {
? ? ? ? ? ? ? ? while ((stop = in.readByte()) != stopByte);
? ? ? ? }
}
?
If what you've posted is really what you're doing, and not a huge
simplification of what you're actually doing, then you've massively
overcomplicated this.
- to take advantage of some time-dependent data (millis) managed by the
outer class RawProtocol (most important)
I don't see why you couldn't do that with the above loop.
the snippet is a simplification of the real code, tough it is not so
much more complicated. Here i made the decision to use a simple
implementation of a state machine, instead of a sequence of methods, for
the elasticity i can obtain in the interpretation of the not-so- stable
underlying protocol.
Do you configure the state machine from a file or similar? If not, it's no
more plastic than code.
People have this idea that once code is written, it's hard to change. This
is wrong.
tom
--
Big Bang. No god. Fadeout. End. -- Stephen Baxter
---910079544-140430949-1265843139=:21102--