SlideShare a Scribd company logo
FSM.NET
A simple "stateless" finite-state
machine library for .NET.
Bill Sorensen
@BillSorensen
bill@truewill.net http://www.truewill.net/
Integrated DNA Technologies
1
What is it?
 Open-source .NET library
 “A finite-state machine (FSM) … is a mathematical model of
computation used to design both computer programs and
sequential logic circuits. It is conceived as an abstract machine that
can be in one of a finite number of states. The machine is in only
one state at a time; the state it is in at any given time is called the
current state. It can change from one state to another when
initiated by a triggering event or condition; this is called a transition.
A particular FSM is defined by a list of its states, and the triggering
condition for each transition.” – Wikipedia
2
What is it? (continued)
 Domain-specific language (DSL)
 Text tables can be provided by callers, loaded from a data store, stored in
configuration – whatever works for you
 Purely functional
 Given the same arguments, every function always returns the same values
 No side effects
 Great for web services (inherently stateless)
 Thread safe (unless I goofed)
# Turnstile
Locked | coin | Unlocked
Unlocked | coin | Unlocked
Unlocked | pass | Locked
Initial state (first line)
CurrentState|triggeringEvent|NewState
3
Why would I need it?
 You’re trying to solve a problem that looks like a state machine.
“I have that horrible feeling when I know that almost the only thing I can say is
that you should use a State Machine when the behavior you’re specifying
feels like a State Machine – that is, when you have a sense of movement,
triggered by events, from state to state. In many ways, the best way to see if a
State Machine is appropriate is to try sketching one on paper and, if it fits
well, to try it in action.” – Martin Fowler, Domain-Specific Languages
4
Why would I not need it?
 You want to associate actions or guards (behavior/code) with
transitions or with entering/exiting states.
 FSM.NET machines are designed to be self-contained, without requiring binary
references to custom code.
 FSM.NET machines are designed to be deserialized from text.
 Custom code actions could be added through a wrapper (web service, etc.).
 You want to embed a state machine in a non-.NET application.
 FSM.NET can be used through a web service, though.
5
Demo time!
https://github.com/TrueWill/FSM.NET
https://github.com/TrueWill/FSM.NET/tree/master/Samples
6
Why is FSM.NET written in F#?
 Fewer bugs
 Easier to verify correctness
 Immutable by default
 Less code – let’s see!
 Easier to write thread-safe code
 Interop with other .NET libraries
 Fun! 
7
Other options (in no particular order)
 http://smc.sourceforge.net/
 https://github.com/phatboyg/Automatonymous
 http://code.google.com/p/bbvcommon/wiki/StateMachine
 https://code.google.com/p/stateless/
 … and many more
Don’t reinvent the wheel! (Like I did…)
(Caveat: I have not evaluated all of the above options.)
// Stateless example using enums
var turnstile = new StateMachine<States, Events>(States.Locked);
turnstile.Configure(States.Locked).Permit(Events.Coin, States.Unlocked);
turnstile.Configure(States.Unlocked).Permit(Events.Pass, States.Locked);
turnstile.OnTransitioned(x => Console.WriteLine(x.Trigger));
turnstile.Fire(Events.Coin); // mutates
Console.WriteLine(turnstile.State);
8
How can I get it?
https://www.nuget.org/packages/FSM.NET/
https://github.com/TrueWill/FSM.NET
GitHub

More Related Content

PDF
Rubyslava #70
PPTX
Functional programmning
PPTX
Основы функционального JS
PPTX
PPTX
MongoDB presentation
PPTX
Programming models for event controlled programs
PDF
Introduction to Finite State Machines in Embedded Systems
PPTX
Mgd finite statemachine
Rubyslava #70
Functional programmning
Основы функционального JS
MongoDB presentation
Programming models for event controlled programs
Introduction to Finite State Machines in Embedded Systems
Mgd finite statemachine

Similar to FSM.NET presentation (20)

PPTX
Finite State Machines Digital Logic Design .pptx
PPTX
Finite state machines : why using them and how they can save devs and designe...
PPTX
Unit 4- State Machine in mobile programming
PPTX
Finite State Machine.ppt.pptx
PPTX
"Final fsFighting Complex Application State Management with Finite-State Mach...
PDF
Behavior Tree in Unreal engine 4
PDF
The State Machine Compiler
PPT
Ver6.ppt
PPT
PPTX
FSM and ASM
PPT
lec4-FSM.ppt
PPTX
High Performance Relaying of C++11 Objects Across Processes and Logic-Labeled...
PDF
Synchronous sequential Circuits
PPTX
Approaches to game AI overview
PPTX
F# in social gaming
PPTX
ASIC Design Laboratory Finite State Machines State Diagrams vs. Algorithmic S...
PDF
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
PDF
Ia+ threading
PDF
State Machine Workflow: Esoteric Techniques & Patterns Everyone Should Buy pr...
PPT
Bay NET Aug 19 2009 presentation ppt
Finite State Machines Digital Logic Design .pptx
Finite state machines : why using them and how they can save devs and designe...
Unit 4- State Machine in mobile programming
Finite State Machine.ppt.pptx
"Final fsFighting Complex Application State Management with Finite-State Mach...
Behavior Tree in Unreal engine 4
The State Machine Compiler
Ver6.ppt
FSM and ASM
lec4-FSM.ppt
High Performance Relaying of C++11 Objects Across Processes and Logic-Labeled...
Synchronous sequential Circuits
Approaches to game AI overview
F# in social gaming
ASIC Design Laboratory Finite State Machines State Diagrams vs. Algorithmic S...
"Mastering UI Complexity: State Machines and Reactive Patterns at Grammarly",...
Ia+ threading
State Machine Workflow: Esoteric Techniques & Patterns Everyone Should Buy pr...
Bay NET Aug 19 2009 presentation ppt
Ad

Recently uploaded (20)

PPTX
1. Introduction to Computer Programming.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Tartificialntelligence_presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
August Patch Tuesday
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
A Presentation on Touch Screen Technology
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
Web App vs Mobile App What Should You Build First.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
cloud_computing_Infrastucture_as_cloud_p
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Heart disease approach using modified random forest and particle swarm optimi...
1. Introduction to Computer Programming.pptx
A comparative analysis of optical character recognition models for extracting...
Tartificialntelligence_presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Digital-Transformation-Roadmap-for-Companies.pptx
August Patch Tuesday
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
A Presentation on Touch Screen Technology
Assigned Numbers - 2025 - Bluetooth® Document
Web App vs Mobile App What Should You Build First.pdf
Zenith AI: Advanced Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools
Unlocking AI with Model Context Protocol (MCP)
A novel scalable deep ensemble learning framework for big data classification...
cloud_computing_Infrastucture_as_cloud_p
SOPHOS-XG Firewall Administrator PPT.pptx
NewMind AI Weekly Chronicles - August'25-Week II
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
OMC Textile Division Presentation 2021.pptx
Heart disease approach using modified random forest and particle swarm optimi...
Ad

FSM.NET presentation

  • 1. FSM.NET A simple "stateless" finite-state machine library for .NET. Bill Sorensen @BillSorensen bill@truewill.net http://www.truewill.net/ Integrated DNA Technologies
  • 2. 1 What is it?  Open-source .NET library  “A finite-state machine (FSM) … is a mathematical model of computation used to design both computer programs and sequential logic circuits. It is conceived as an abstract machine that can be in one of a finite number of states. The machine is in only one state at a time; the state it is in at any given time is called the current state. It can change from one state to another when initiated by a triggering event or condition; this is called a transition. A particular FSM is defined by a list of its states, and the triggering condition for each transition.” – Wikipedia
  • 3. 2 What is it? (continued)  Domain-specific language (DSL)  Text tables can be provided by callers, loaded from a data store, stored in configuration – whatever works for you  Purely functional  Given the same arguments, every function always returns the same values  No side effects  Great for web services (inherently stateless)  Thread safe (unless I goofed) # Turnstile Locked | coin | Unlocked Unlocked | coin | Unlocked Unlocked | pass | Locked Initial state (first line) CurrentState|triggeringEvent|NewState
  • 4. 3 Why would I need it?  You’re trying to solve a problem that looks like a state machine. “I have that horrible feeling when I know that almost the only thing I can say is that you should use a State Machine when the behavior you’re specifying feels like a State Machine – that is, when you have a sense of movement, triggered by events, from state to state. In many ways, the best way to see if a State Machine is appropriate is to try sketching one on paper and, if it fits well, to try it in action.” – Martin Fowler, Domain-Specific Languages
  • 5. 4 Why would I not need it?  You want to associate actions or guards (behavior/code) with transitions or with entering/exiting states.  FSM.NET machines are designed to be self-contained, without requiring binary references to custom code.  FSM.NET machines are designed to be deserialized from text.  Custom code actions could be added through a wrapper (web service, etc.).  You want to embed a state machine in a non-.NET application.  FSM.NET can be used through a web service, though.
  • 7. 6 Why is FSM.NET written in F#?  Fewer bugs  Easier to verify correctness  Immutable by default  Less code – let’s see!  Easier to write thread-safe code  Interop with other .NET libraries  Fun! 
  • 8. 7 Other options (in no particular order)  http://smc.sourceforge.net/  https://github.com/phatboyg/Automatonymous  http://code.google.com/p/bbvcommon/wiki/StateMachine  https://code.google.com/p/stateless/  … and many more Don’t reinvent the wheel! (Like I did…) (Caveat: I have not evaluated all of the above options.) // Stateless example using enums var turnstile = new StateMachine<States, Events>(States.Locked); turnstile.Configure(States.Locked).Permit(Events.Coin, States.Unlocked); turnstile.Configure(States.Unlocked).Permit(Events.Pass, States.Locked); turnstile.OnTransitioned(x => Console.WriteLine(x.Trigger)); turnstile.Fire(Events.Coin); // mutates Console.WriteLine(turnstile.State);
  • 9. 8 How can I get it? https://www.nuget.org/packages/FSM.NET/ https://github.com/TrueWill/FSM.NET GitHub