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 ...
user avatar
  • 1,110
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 ...
user avatar
  • 8,706
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 697
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. ...
user avatar
  • 1,067
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 ...
user avatar
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 ...
user avatar
  • 19.9k
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 ...
user avatar
  • 124k
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 ...
user avatar
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 ...
user avatar
  • 27.2k
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 ...
user avatar
  • 124k
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 ...
user avatar
  • 185k
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 ...
user avatar
  • 22.1k
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, ...
user avatar
  • 1,670
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 ...
user avatar
  • 107k
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 ...
user avatar
  • 1,032
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 ...
user avatar
  • 16.5k
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.
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
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 ...
user avatar
  • 254
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 ...
user avatar
  • 1,779
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'...
user avatar
  • 22.1k
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 ...
user avatar
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," ...
user avatar
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 ...
user avatar
  • 9,703
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 ...
user avatar
  • 4,000

Only top scored, non community-wiki answers of a minimum length are eligible