Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <blockquote> <p>What is a finite state machine?</p> </blockquote> <p>It is a way of declaring events and side effects of transitioning between them.</p> <blockquote> <p>What are some practical uses of finite state machines?</p> </blockquote> <p>Instead of code like this:</p> <pre><code>function decide() { if(mouseButtonIsDown &amp;&amp; mouseIsMoving &amp;&amp; mouseCoordinatesAreWithin(0, 0, 100, 100) &amp;&amp; thePixelIsRed) { clearBuffers(); startPlaying(); cursorBecomeHand(); } else if(!mouseButtonIsDown &amp;&amp; !mouseIsMoving &amp;&amp; mouseCoordinatesAreWithin(0, 0, 100, 100) &amp;&amp; thePixelIsRed) { } // more ifs } </code></pre> <p>You keep only a few states and break your events into functions, defining what happens in which state.</p> <pre><code>function drag_started() { switch(your_state) { case "within_box": clearBuffers(); cursorBecomeHand(); your_state= "playing"; startPlaying(); break; } </code></pre> <p>} </p> <p>Which leads to the separation of states and events, which means less regressions and more maintainability.</p> <blockquote> <p>When would I not want to use an finite state machine?</p> </blockquote> <p>Answers itself at this point. If you just have one state, don't bother with a state machine.</p> <blockquote> <p>What books, articles, tutorials, etc., offer a more in-depth look at finite state machines (in JavaScript)?</p> </blockquote> <p>Against the academia, I recommend reading the source for jquery plugins. For example look under _mouseMove and _mouseUp in <a href="http://code.jquery.com/ui/1.10.0/jquery-ui.js">the jquery ui source</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload