6 ms·
A lot of the comments here are rails oriented and anti state machine. In the context of rails that may make sense, but I do a lot of non rails ruby, and non obj
by fortysixdegrees 4y ago
A lot of the comments here are rails oriented and anti state machine. In the context of rails that may make sense, but I do a lot of non rails ruby, and non object oriented Dev style, and state machines are a great way to write solid systems where the allowed state and transitions are explicit and easy to reason with.
- bowsamic 4y agoUnfortunately almost everyone treats rails and Ruby as synonymous
- Toutouxc 4y agoWould you mind sharing a little example of what you mean by non-OOP Ruby code with state machines?
- fortysixdegrees 4y agoSure. I am working on the firmware for a camera. Believe it or not it's a bunch of ruby services coordinated via redis pubsub. But at the core is the main system state which is a service in itself which is the main state machine. This pattern is something which I've evolved over the years and it's fantastic (if I do say so myself).
- craigkerstiens 4y agoA pretty big +1 to this. My team (at Crunchy Data building Crunchy Bridge[1]) and similar teams at prior Citus Data and Heroku did a lot of Ruby and a lot of state machines. In all cases it was actually less Rails, but that may be because the team really prefers sequel as the ORM to ActiveRecord, though Rails does a bunch that doesn't really apply to such a workflow. We wrote about some of how we used state machines to power our database as a service and the full control plane previously[2]. Another big piece of the approach and stack that helps today is leveraging Sorbet[3] and our approach to test coverage, we probably should blog a little more on some of this but it helps quite a bit. [1] - https://www.crunchydata.com/products/crunchy-bridge https://www.crunchydata.com/products/crunchy-bridge [2] - https://www.citusdata.com/blog/2016/08/12/state-machines-to-run-databases/ https://www.citusdata.com/blog/2016/08/12/state-machines-to-... [3] - https://brandur.org/fragments/large-scale-ruby-refactoring https://brandur.org/fragments/large-scale-ruby-refactoring
- fortysixdegrees 4y agoClearly some quite senior developers there. Makes me wonder if the people hating on state machines have been at the mercy of junior devs or people trying it out for the first time, instead of a well planned state machine by someone with experience. Full disclosure, I think I wrote my first state machine in around 1996. So yea... Grey hair etc. Also it was a big part of my computer science degree, studied formally, so perhaps that's why I'm biased in favour of them.
- Sinjo 4y agoHonestly state machines are fantastic in Rails too. My last company built Statesman (https://github.com/gocardless/statesman/ https://github.com/gocardless/statesman/) and being able to lean on it to prevent you getting into invalid states is fantastic. You also get the bonus of tracking the history of states your resources went through (which is especially useful when you're dealing with payments). At some point you'll have to think about query performance on the state transition table, but it'll go further than you think and is firmly in the realm of problems of success.
- fortysixdegrees 4y agoIn a previous life I implemented a business system in rails with a core state machine. The staff who used it could fundamentally understand the states and transitions, bringing them closer to understanding how the whole system worked. Not all benefits or costs of a technique are limited to the developer
- threatofrain 4y agoRedux is basically a state machine.