Questions tagged [finite-state-machine]
127 questions
200
votes
10 answers
Are exceptions as control flow considered a serious antipattern? If so, Why?
Back in the late 90's I worked quite a bit with a code base that used exceptions as flow control. It implemented a finite state machine to drive telephony applications. Lately I am reminded of those days because I've been doing MVC web apps.
They…

Aaron Anodide
- 5,463
- 5
- 28
- 37
28
votes
10 answers
State machines vs threads
Alan Cox once said "A Computer is a state machine. Threads are for people who can't program state machines".
Since asking Alan directly is not an option for humble me, I'd rather ask here: how does one achieve multi-threading functionality in…

Victor Sorokin
- 484
- 1
- 4
- 8
27
votes
10 answers
Examples of Finite State Machines
I'm looking for good examples of finite state machines; language isn't particularly important, just good examples.
Code implementations are useful (generalized pseudo-code), but it's also very useful to gather the various uses of FSM's.
Examples…

ocodo
- 2,948
- 3
- 23
- 31
17
votes
4 answers
Definition of "state"
What is a good way to define "state", as in state variable or state machine, to a new (previously non) programmer? What are some good ways to explain why this concept is useful for writing software? Is the concept of state explicitly taught in…

hotpaw2
- 7,938
- 4
- 21
- 47
16
votes
4 answers
Conceptually, how does one make a rules/constraints (not graphics/physics) engine for a game
I want to make a simple game similar to the choose-your-own-adventure books. The player is presented with a narrative text and gets to choose his action from a list of possibilities. This, in turn, leads to a new narrative text, ad infinitum. The…

kaqqao
- 363
- 2
- 9
14
votes
5 answers
Can an object oriented program be seen as a Finite State Machine?
This might be a philosophical/fundamental question, but I just want to clarify it.
In my understanding a Finite State Machine is a way of modeling a system in which the system's output will not only depend on the current inputs, but also the current…

Peretz
- 337
- 2
- 7
14
votes
6 answers
How to recover from finite-state-machine breakdown?
My question may seems very scientific but I think it's a common problem and seasoned developers and programmers hopefully will have some advice to avoid the problem I mention in title. Btw., what I describe bellow is a real problem I am trying to…

Earl Grey
- 628
- 6
- 14
10
votes
4 answers
How is a state machine different from any other computer program?
I have seen several implementations of "State Machines" on github. As far as I understand, a state machine takes input that may or may not transform its state into one of a finite set of other states. How is that different from any other computer…

ConditionRacer
- 5,682
- 6
- 38
- 56
10
votes
4 answers
How can a child state machine relinquish control back to the parent state machine?
My top level state machine has some states and edges. I will call this the parent state machine.
A ----> B ----> C
Any state within the parent state machine can be a state machine too. I will call these children state machines.
…

JoJo
- 1,475
- 2
- 14
- 21
9
votes
1 answer
How to design a good generic tiled image downloader?
Tiled images
Tiled images are large images that have been split in smaller square tiles.
There are several tiled image formats, with different ways of organizing
the tile files.
A tiled image on the web can be downloaded only by finding all the…

lovasoa
- 199
- 4
7
votes
2 answers
How to store and validate data between state transitions?
I'm developing a largeish application that will have custom finite state machines. That is, the admin users of the application will be able to create their own state machines, limited by little pieces of code that are pré built, lets call those…

George Silva
- 371
- 1
- 9
7
votes
3 answers
Can a generic piece of C code be converted to an FSM?
I understand that any language worth its salt can encode a Finite state machine. My question is the opposite, is it possible to convert an arbitrary piece of code ( say in C ) to a functionally equivalent Finite State Machine ?
for example if I…

Jehandad
- 181
- 5
7
votes
1 answer
Finite state machine menu design
I'm creating an FSM in python (it's a step sequencer and sample pad based on a Raspberry Pi 2).
Right now there are two states and the third is the Menu. This is handled by a class System which handles all the states. The Menu state has to edit the…

user3466127
- 71
- 2
7
votes
4 answers
Is a finite state machine an appropriate solution for this situation?
I was writing some test code as an example where I had a washing machine class. It has a door state that should be open or closed, and also a running state, either on or off. I want to prevent the running state from changing from 'off' to 'on' when…

user1936
- 662
- 5
- 17
7
votes
1 answer
Passing data between concrete states?
I have a state machine pattern implementation that's pretty straightforward, but I've got a design problem I don't know an elegant solution to.
Here's some partly pseudo code to illustrate.
class MainRoomState:State
public override void…

Kal_Torak
- 173
- 1
- 6