Opinions wanted: is this worth making a SF project out of?
Discuss Opinions wanted: is this worth making a SF project out of? in the Python Programming forum on Dev Shed. Opinions wanted: is this worth making a SF project out of? Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
Receive the tools necessary to be the rock star of your field. Our 12-month program teaches you the evolving world of multi-channel marketing as well as the complex issues and opportunities found in the industry.
ASP Free and Iron Speed Designer are giving away $5,500+ in FREE licenses. Iron Speed's RAD CASE toolset can save up to 80% of your coding time. One free license per week, one perpetual license per month! Download and Activate to enter!
Web development can be a daunting task, even for specialists. There is a lot of information to absorb and a lot of technologies to learn in order to manage a superior website. When trying to learn the ropes, developers need a reliable source to introduce new ideas that can be easily implemented. When working on large projects, even web veterans may run into a technology or an aspect of a technology that they are unfamiliar with.
Posts: 1,713
Time spent in forums: 1 Month 2 Weeks 1 Day 33 m 13 sec
Reputation Power: 1495
Opinions wanted: is this worth making a SF project out of?
Mods: I wasn't certain if it should be in the language-specific forum or one of the discussion forums. If this would be better off in another message board, feel free to move it.
Earlier this year, I took a course an undergraduate course in compiler design, and opted to use Python as my implementation language - the class was to focus on the design aspects, not performance, so I concluded that I would rather use a language which wouldn't fight back so much as Java or C++ would when it came to string handling. While this may have been a mistake in the end - the time I saved not writing a lot of string handling code was lost again by some rather overly ambitious design approaches - in the process of it, I implemented a more or less general string-driven finite automata library.
I am now wondering if this would be something which would be of use to others, so I am considering creating a project on SourceForge for it. I would like to know if others think this would be worth the trouble to share or not, and if so, what changes or refinements should be made to make it a viable open-source library. I am concerned that it is too small and basic to be worth making a library out of. Conversely, it may be too heavyweight to be practical, since FSMs are usually implemented in much simpler manners than the one I used. Also, the design is not especially Pythonic, being rather clumsy and Java-esque in it's initialization specifically. Finally, it may not be suited to a lot of things people might want an FSM for - while the design is almost general, it is still designed primarily for tokenizing a stream of characters, which may limit its applicability.
The library consists of two classes, a State class and a StateMachine class. A State object consists of a key, a table of input/state transition pairs, a flag whether the state can be a final state, a type for the type of token it returns (if any), and a pushback number (most likely, I will replace these with some more general sort of completion value, though just how I haven't decided). The class has four class constants: three representing the common transition states (accept, error, and other), one serving a common start state key (used by the StateMachine class), and one used to indicate a default transition state for input not otherwise specified (if none is given, it assumes an error state). In addition to a constructor and a string-representation method, t has one instance method, next(), which takes an input string and returns a tuple with state to which it would transition, the final-state flag, a token, (if it is an accept state), and a pushback number (if it is at a final state that ends one or more characters back).
The StateMachine object consists of a table of state keys (right now, it only uses numbers, but I think that allowing named states may prove valuable later) and states, State object representing the current state of the FSM, and a flag indicating if the table is 'locked' or not (that is, the table has been completely populated). The StateMachine is constructed with a required start state, and new states are added to the table using the add() method, and new states can be added until lock() is called. There is a locked() method to test whtehr it is locked or not. Once the table is locked, the transition() method can be used to step through the input stream, taking one character at a time as input. It returns the accept flag, the token, and the pushback number returned by the call to current_state.next(); on a error state, it returns State.ERROR for the token.
# see if the state has finalized, reset the current state and
# determine if it accepted or rejected the input string
if final:
self.__current_state = self.__states[State.START]
if successor == State.ACCEPT: # string accepted
returnTrue, token, pb
else: # string rejected
returnTrue, State.ERROR, pb
# if the state has not finalized, see if it is a 'non-final' error
# state and return an error value if it is. This will only occur if
# the input is not valid.
elif successor == State.ERROR:
self.__current_state = self.__states[State.START]
returnTrue, State.ERROR, pb
# if the state is not final and not an error, advance to the next state
else:
self.__current_state = self.__states[successor]
returnFalse, 0, 0
def__str__(self):
"""Return a simple string representation of the FSM for debugging. """
returnstr(self.__states)
################################
if __name__ == "__main__":
pass
I have attached a copy of the actual project it had been part of for anyone who wants a reference point in how I intended it to be used.
Any and all (constructive) comments and critiques would be helpful. At the moment, I have tentatively given the projec the name 'AutonomousCollective', but any other suggestions would be appreciated (though I'd prefer something with either a MP or H2G2 theme - the latter to match th name of the original project). TIA.
FOR SALE: One ShapeSystem 2300 CMD, extensively modified for human use. Includes s/w for anthro, transgender, sex-appeal enhance, & Gillian Anderson and Jason D. Poit clone forms. Some wear. $4500 obo. tverres@et.ins.gov
Last edited by Schol-R-LEA : August 23rd, 2008 at 04:13 PM.
Posts: 841
Time spent in forums: 3 Weeks 5 Days 12 h 59 m 16 sec
Reputation Power: 1679
I think this implementation is pretty good for what its trying to do, but to be a full-fledged library you need to generalize for 3+ different use-cases. I think you'll find faults and either fix them or decide to limit the scope of the library to target a narrow nitch. Both are excellent choices, but force drastically different design choices.
As per your private message regarding my assertion that states should not perform work or provide the transition logic, let me explain why. A very common use-case is for workfow engines: travel booking, ticket tracking (support, bugs, etc), data processing, and so on. If your task knows where to go next, then this would leak across different workflows. If you specify it on a per flow basis, you're still making the execution brittle. You'll find developers making implicit data dependancies across tasks or creating bizaar flows that loop back through states to arrive at the desired final one. You'll even find workflows being used where they shouldn't be (e.g. routing of an ESB). When you make states manage the tranitioning, you put them in control of the framework. In effect, you are inverting the framework's implicit inversion of control.
I think your project works elegantly for a small, discrete set of states. But what if you have dozens? Will there be duplicate state logic but with different transitions, or the same state with many transitions (most of which are not acceptable given the flow)? Overall, it gets messier and messier the bigger the state machine grows.
Your usage makes me think of Turing machines and push-down automata. Clients of those tend not to have too many states either, and it would fit well with your usage as well. So it might be useful as a pre-rolled version to allow others to plug into. Or at least be a fun excersize to simulate different types of FSA designs. Even a package of those could be useful, given the very special-purpose nature of them.
I think the first thing to do is determine what class of problems you want to solve and then rework the design as needed.