State Machines in Ruby: An Introduction
blog.appsignal.com
State Machines in Ruby: An Introduction
1–10 of 42 posts
Re: State Machines in Ruby: An Introduction
#2Re: State Machines in Ruby: An Introduction
#3The article starts with examples that just define the state machine by hand. This is a much better approach and scales to larger code much better. You can grep "def start!" and just read what the method does. A state machine DSL is really not providing much value and eventually just gets in the way.
Re: State Machines in Ruby: An Introduction
#4Here are somebody's notes from a Railsconf talk that made this point, plus a link to the video:
https://gist.github.com/benoittgt/05521e272e13c7b7c9c89eb4a9...
But the short version is the takeaway quote:
> State machines are magnetic : they attract more states, transitions, events, callbacks and they accumulate callback logic where our bugs hide
Re: State Machines in Ruby: An Introduction
#5Nice article. Are state machines used widely in Rails apps?
Re: State Machines in Ruby: An Introduction
#6After playing around different JS frameworks I'm back to Rails and I've been able to iterate quickly. That gem solves a few pain points.
Re: State Machines in Ruby: An Introduction
#7I've seen a few large Rails codebases that included a state machine library like mentioned in the article. Every single one was worse because of it. It pushes the code down a path where hidden hooks run when magic methods are called. At this point in my career I'm just done with that type of "clever" code. The article starts with examples that just define the state machine by hand. This is a much better approach and…
Re: State Machines in Ruby: An Introduction
#8It got to the point where this state machine approach was a real bottleneck and though I left before it was resolved last I heard they had to put real engineering time in to move off of it.
Be very careful when deciding to go this route.
Re: State Machines in Ruby: An Introduction
#9Nice article. Are state machines used widely in Rails apps?