Dendarii
  • Communities
  • Create Post
  • Create Community
  • heart
    Support Lemmy
  • search
    Search
  • Login
  • Sign Up
☆ Yσɠƚԋσʂ ☆@lemmy.ml to General Programming Discussion@lemmy.mlEnglish ·
edit-2
6 months ago

Why developers should be force-fed state machines

shopify.engineering

external-link
message-square
6
fedilink
  • cross-posted to:
  • [email protected]
15
external-link

Why developers should be force-fed state machines

shopify.engineering

☆ Yσɠƚԋσʂ ☆@lemmy.ml to General Programming Discussion@lemmy.mlEnglish ·
edit-2
6 months ago
message-square
6
fedilink
  • cross-posted to:
  • [email protected]
Why developers should be force-fed state machines - Shopify
shopify.engineering
external-link
This post is meant to create more awareness about state machines in the web application developer crowd. If you don’t know what state machines are, please read up on them first. Wikipedia is a good place to start, as always. State machines are awesome The main reason for using state machines is to help the design process. It is much easier to figure out all the possible edge conditions by drawing out the state machine on paper. This will make sure that your application will have less bugs and less undefined behavior. Also, it clearly defines which parts of the internal state of your object are exposed as external API. Moreover, state machines have decades of math and CS research behind them about analyzing them, simplifying them, and much more. Once you realize that in management state machines are called business processes, you'll find a wealth of information and tools at your disposal. Recognizing the state machine pattern Most web applications contain several examples of state machines, including accounts and subscriptions, invoices, orders, blog posts, and many more. The problem is that you might not necessarily think of them as state machines while designing your application. Therefore, it is good to have some indicators to recognize them early on. The easiest way is to look at your data model: Adding a state or status field to your model is the most obvious sign of a state machine. Boolean fields are usually also a good indication, like published, or paid. Also timestamps that can have a NULL value like published_at and paid_at are a usable sign. Finally, having records that are only valid for a given period in time, like subscriptions with a start and end date. When you decide that a state machine is the way to go for your problem at hand, there are many tools available to help you implement it. For Ruby on Rails, we have the excellent gem state_machine which should cover virtually all of your state machine needs. Keeping the transition history Now that you are using state machines for modelling, the next thing
  • davel [he/him]@lemmy.ml
    link
    fedilink
    English
    arrow-up
    6
    arrow-down
    1
    ·
    6 months ago

    Nobody needs to force state machines on me. I’ve been addicted to them ever since my CS classes covering language theory.

    • ☆ Yσɠƚԋσʂ ☆@lemmy.mlOP
      link
      fedilink
      arrow-up
      2
      ·
      6 months ago

      :)

General Programming Discussion@lemmy.ml

programming@lemmy.ml

Subscribe from Remote Instance

Create a post
You are not logged in. However you can subscribe from another Fediverse account, for example Lemmy or Mastodon. To do this, paste the following into the search field of your instance: [email protected]

A general programming discussion community.

Rules:

  1. Be civil.
  2. Please start discussions that spark conversation

Other communities

  • [email protected]
  • [email protected]
  • [email protected]
  • [email protected]

Systems

  • [email protected]
  • [email protected]
  • [email protected]

Functional Programming

  • [email protected]
  • [email protected]

Also related

  • [email protected]
Visibility: Public
globe

This community can be federated to other instances and be posted/commented in by their users.

  • 7 users / day
  • 17 users / week
  • 89 users / month
  • 432 users / 6 months
  • 1 local subscriber
  • 8.33K subscribers
  • 393 Posts
  • 595 Comments
  • Modlog
  • mods:
  • Evan@lemmy.ml
  • Restioson@lemmy.ml
  • BE: 0.19.9
  • Modlog
  • Instances
  • Docs
  • Code
  • join-lemmy.org