Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      The Value-Driven AI Roadmap

      September 9, 2025

      This week in AI updates: Mistral’s new Le Chat features, ChatGPT updates, and more (September 5, 2025)

      September 6, 2025

      Designing For TV: Principles, Patterns And Practical Guidance (Part 2)

      September 5, 2025

      Neo4j introduces new graph architecture that allows operational and analytics workloads to be run together

      September 5, 2025

      ‘Job Hugging’ Trend Emerges as Workers Confront AI Uncertainty

      September 8, 2025

      Distribution Release: MocaccinoOS 25.09

      September 8, 2025

      Composition in CSS

      September 8, 2025

      DataCrunch raises €55M to boost EU AI sovereignty with green cloud infrastructure

      September 8, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Finally, safe array methods in JavaScript

      September 9, 2025
      Recent

      Finally, safe array methods in JavaScript

      September 9, 2025

      Perficient Interviewed for Forrester Report on AI’s Transformative Role in DXPs

      September 9, 2025

      Perficient’s “What If? So What?” Podcast Wins Gold Stevie® Award for Technology Podcast

      September 9, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Distribution Release: MocaccinoOS 25.09

      September 8, 2025
      Recent

      Distribution Release: MocaccinoOS 25.09

      September 8, 2025

      Speed Isn’t Everything When Buying SSDs – Here’s What Really Matters!

      September 8, 2025

      14 Themes for Beautifying Your Ghostty Terminal

      September 8, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: Pretty Little State Machine

    CodeSOD: Pretty Little State Machine

    September 8, 2025

    State machines are a powerful way to organize code. They are, after all, one of the fundamental models of computation. That’s pretty good. A well designed state machine can make a complicated problem clear, and easy to understand.

    Chris, on the other hand, found this one.

      <span class="hljs-keyword">static</span> {
        sM.put(tk(NONE, NONE, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t1</span>
        sM.put(tk(REJECTED, REJECTED, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t2</span>
        sM.put(tk(PENDING, IGNORED, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t3</span>
        sM.put(tk(PENDING, INVITED, cancel), sp(NONE, NONE)); <span class="hljs-comment">// t4</span>
        sM.put(tk(PENDING, IGNORED, cancel), sp(NONE, NONE)); <span class="hljs-comment">// t5</span>
        sM.put(tk(PENDING, BLOCKED, cancel), sp(NONE, BLOCKED)); <span class="hljs-comment">// t6</span>
        sM.put(tk(INVITED, PENDING, accept), sp(ACCEPTED, ACCEPTED)); <span class="hljs-comment">// t7</span>
        sM.put(tk(INVITED, PENDING, reject), sp(REJECTED, REJECTED)); <span class="hljs-comment">// t8</span>
        sM.put(tk(INVITED, PENDING, ignore), sp(IGNORED, PENDING)); <span class="hljs-comment">// t9</span>
        sM.put(tk(INVITED, PENDING, block), sp(BLOCKED, PENDING)); <span class="hljs-comment">// t10</span>
        sM.put(tk(ACCEPTED, ACCEPTED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t11</span>
        sM.put(tk(REJECTED, REJECTED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t12</span>
        sM.put(tk(IGNORED, PENDING, remove), sp(NONE, NONE)); <span class="hljs-comment">// t13</span>
        sM.put(tk(PENDING, IGNORED, remove), sp(NONE, NONE)); <span class="hljs-comment">// t14</span>
        sM.put(tk(BLOCKED, PENDING, remove), sp(NONE, NONE)); <span class="hljs-comment">// t15</span>
        sM.put(tk(PENDING, BLOCKED, remove), sp(NONE, BLOCKED)); <span class="hljs-comment">// t16</span>
        sM.put(tk(NONE, BLOCKED, invite), sp(PENDING, BLOCKED)); <span class="hljs-comment">// t17</span>
        sM.put(tk(IGNORED, PENDING, invite), sp(PENDING, INVITED)); <span class="hljs-comment">// t19</span>
        sM.put(tk(INVITED, PENDING, invite), sp(ACCEPTED, ACCEPTED)); <span class="hljs-comment">// t20</span>
        sM.put(tk(NONE, NONE, remove), sp(NONE, NONE)); <span class="hljs-comment">// t21</span>
        sM.put(tk(NONE, BLOCKED, remove), sp(NONE, BLOCKED)); <span class="hljs-comment">// t22</span>
        sM.put(tk(BLOCKED, NONE, remove), sp(NONE, NONE)); <span class="hljs-comment">// t23</span>
      }
    

    Honestly, I only know this is a state machine because Chris told me. I could hazard a guess base on the variable name sM. The comments certainly don’t help. Numbering lines isn’t exactly what I want comments for. I don’t know what tk or sp are actually doing.

    So yes, this is an unreadable blob that I don’t understand, which is always bad. But do you know what elevates this one step above that? If you note the third parameter to the tk function- invite, cancel, accept, etc? Those are constants. So are INVITED, PENDING, ACCEPTED.

    While I am not fond of using the structure of a variable name to denote its role, “caps means const” is a very well accepted standard. A standard that they’re using sometimes, but not all the time, and just looking at this makes me grind my teeth.

    [Advertisement]
    BuildMaster allows you to create a self-service release management platform that allows different teams to manage their applications. Explore how!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleSpeed Isn’t Everything When Buying SSDs – Here’s What Really Matters!
    Next Article Design Has Never Been More Important: Inside Shopify’s Acquisition of Molly

    Related Posts

    News & Updates

    ‘Job Hugging’ Trend Emerges as Workers Confront AI Uncertainty

    September 8, 2025
    News & Updates

    Distribution Release: MocaccinoOS 25.09

    September 8, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    User calls Windows 11 “pure horror,” Microsoft says it’s listening to feedback

    Operating Systems

    CVE-2025-52876 – JetBrains TeamCity Reflected Cross-Site Scripting Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    PS6 Tipped to Offer Major Ray Tracing Upgrade Over Base PS5

    Operating Systems

    CVE-2025-22859 – FortiClientEMS Relative Path Traversal File Write Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    Zyxel Firewalls Under Attack via Critical CVE-2023-28771

    June 16, 2025

    Zyxel Firewalls Under Attack via Critical CVE-2023-28771

    A sudden and coordinated wave of exploit attempts targeting a critical vulnerability in Zyxel firewalls has been detected. The attack centers around CVE-2023-28771, a high-severity remote code executi …
    Read more

    Published Date:
    Jun 17, 2025 (2 hours, 16 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2023-33010

    CVE-2023-33009

    CVE-2023-28771

    Managed Service Offering (MSO) Support Ticketing System

    Managed Service Offering (MSO) Support Ticketing System

    April 10, 2025

    The 5 Linux AppImages I depend on daily – and how to add them to your desktop menu

    April 21, 2025

    Why I no longer recommend pre-built SSDs for Windows PCs – buy this instead

    July 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.