25
votes
Are exceptions as control flow considered a serious antipattern? If so, Why?
As others have mentioned numerously, (e.g. in this Stack Overflow question), the principle of least astonishment will forbid that you use exceptions excessively for control flow only purposes. On the ...
16
votes
Are exceptions as control flow considered a serious antipattern? If so, Why?
Using exceptions for control flow is generally considered an anti-pattern, but there are exceptions (no pun intended).
It has been said a thousand times, that exceptions are meant for exceptional ...
13
votes
Can a generic piece of C code be converted to an FSM?
The Finite State Machine has less computational power than a Turing machine. That is, the Turing Machine can do things that the FSM cannot. This is true because the FSM is limited in memory by the ...
12
votes
Are exceptions as control flow considered a serious antipattern? If so, Why?
Programming is about work
I think the easiest way to answer this is to understand the progress OOP has made over the years. Everything done in OOP (and most programming paradigms, for that matter) is ...
11
votes
How is a state machine different from any other computer program?
If you want to be really pedantic, every computer program is a Finite State Machine, because even if you convert all matter in the entire universe into a computer, it will still only have finite ...
9
votes
Accepted
UML "direct substate" vs "transitively nested substate"
Direct substate is a one level substate of a state
Transitively nested substate is a substate of a substate (any levels down)
Consider this diagram:
For active state direct substates are
filing
...
9
votes
Can a state machine transition depend on the previous state?
If you want to hold onto "classical" state machines whose transition functions only depend on the current state and incoming inputs you have to rethink how you want to model the application's state.
...
8
votes
Accepted
Can a generic piece of C code be converted to an FSM?
Yes, of course it can.
See Bohm & Jacopini's 1966 paper (Yes, fifty years ago), "Flow diagrams, turing machines and languages with only two formation rules" for the gory details.
They showed ...
8
votes
Is a finite state machine an appropriate solution for this situation?
You could implement your washing machine as a state machine, but there's just as much potential for state proliferation as there is for if statements if you don't do things carefully.
Working in ...
8
votes
How should state machines handle exceptions in actions?
State machines don't have exceptions, though they may have transitions to an error state.
There's no “one size fits all” answer for how you should handle errors. This depends a lot on the problem ...
8
votes
Accepted
So what exactly is a final state of a finite state machine?
There are several variations of the definition of a finite state machine. The one you give is common in CS classes, particularly in regards to formal languages and the theory of parsing. In this ...
7
votes
How is a state machine different from any other computer program?
From a theoretical point of view, it's not different at all. Of course, from a theoretical point of view you can write any program in assembly language and it'll work just as well.
While the computer ...
7
votes
Accepted
State machine with additional variable
The computer science answer is that you do indeed have up to 18*3*2 distinct states to deal with. How these states should be encoded into your program depends on your goals.
By writing down all ...
7
votes
Why do I need a game loop with states, instead of init the next state in current state directly?
Lets focus on the obvious advantage first: in the first example, the controllers are mostly independent from each other. PlayerSelectCharacterController does not need to know about the class ...
7
votes
Accepted
Is rebooting a server idempotent or not?
The problem here is that Tim Bray doesn't explain why he thinks it's not idempotent. The concept of idempotency is somewhat subjective. When we call a PUT twice there are a number of things that ...
6
votes
Are exceptions as control flow considered a serious antipattern? If so, Why?
Let's sketch such an Exception usage:
The algorithm searches recursively till something is found. So comming back from recursion one has to check the result for being found, and return then, ...
6
votes
Accepted
Do state machine based programs have a processing loop - or even exist?
It depends on where you draw the line. (Von Neumann) Computers are by definition finite state machines in an infinite loop. Most programs aren’t modeled this way because, well, it’s hella tedious and ...
5
votes
How is a state machine different from any other computer program?
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 program?
Some answers here emphasise that ...
5
votes
Accepted
Model of simple traffic simulation
Just some thoughts.
(Mandatory disclaimer: use of the information for purposes other than strictly personal use or entertainment, or use for purposes that may harm safety or cause loss of assets or ...
5
votes
Accepted
Why are next-state function and output functions of an FSM combinational functions?
Combinational logic can (and frequently does) receive the output of memory on its inputs, or have its outputs stored in memory. It just doesn't have memory within itself.
5
votes
Will FSM be a good solution?
Splitting the state management across the business logic and UI layers is a bad idea.
You keep going on about Finite State Machine (FSM) in a way that is fairly off putting. I think I know what you ...
5
votes
Accepted
Repeating a state in a state machine
Your first statemachine does not accurately reflect the desired behaviour you described. In the first statemachine, you keep retrying to restart the "thing" until either the tests pass or stopping ...
5
votes
Accepted
How can I unit test state machines in C
This particular problem isn't necessarily due to C as a language, but to how you structured the program. In order to make something testable, you need two things:
The ability to set state
The ...
4
votes
Accepted
Should I use multiple state machines for a layered protocol?
You say you have little real-world experience in this area. Learn from experts to become one. Look around at what professionals of this field are doing to solve your problem. Open source PMBus ...
4
votes
Language to describe Finite State Machine
Most of what has been standardised goes beyond simple finite state machines.
If you like XML, there's State Chart XML and UML's XMI for UML state charts, both of which are a superset of finite state ...
4
votes
Language to describe Finite State Machine
Since finite state machines are a basically subset of (labelled) directed graphs, what about something like DOT. It was just the first thing that popped up on a Google "directed graph language". I'...
4
votes
Accepted
Trouble with circular dependency in state machine design
... my question is more around how I should change the design to avoid needing this circular dependency. – Jordan
One method I've seen is to have each state construct the next state. That works but ...
4
votes
Accepted
In OOP which object is common to update the state of an object when working with State Machines?
This seems self-evident to me. While the Object Entity is responsible for storing the state, the State Machine itself is responsible for managing the state.
It's not about "what is the most common," ...
4
votes
Accepted
How does one combine the state pattern and the component pattern?
Be wary of YAGNI and consider this answer to a similar question which asserts that Patterns are not building blocks.
The GoF State Pattern solves a problem of selection of a single behavioural object ...
4
votes
Accepted
State machine with database records
Well, for starters, let's take aside discussions about whether it's a good or a bad practice saving different states on a single record, because that would be off topic.
That being said, consider ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
finite-state-machine × 113design-patterns × 26
state × 14
design × 13
uml × 12
architecture × 9
c# × 7
object-oriented × 7
object-oriented-design × 7
c × 4
event-programming × 4
diagrams × 4
java × 3
workflows × 3
computer-science × 3
theory × 3
transition × 3
programming-practices × 2
testing × 2
.net × 2
programming-languages × 2
api-design × 2
dependency-injection × 2
exceptions × 2
game-development × 2