TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Statecharts: A Visual Formalism for Complex Systems (1987) [pdf]

142 pointsby Cieplakover 4 years ago

20 comments

adamklover 4 years ago
This approach is a big boon to the development of complex UIs.<p>If you are tired of littering your React&#x2F;Angular&#x2F;Vue&#x2F;etc code with a litany of state flags (“isLoading”, “isError”, etc)[0] take a look at the de facto canonical state chart implementation for JavaScript, XState: <a href="https:&#x2F;&#x2F;xstate.js.org&#x2F;docs&#x2F;" rel="nofollow">https:&#x2F;&#x2F;xstate.js.org&#x2F;docs&#x2F;</a><p>It’s been a joy to work with and can replace other methods of managing state (i.e. redux) while constraining the behaviour of your UI to predictable states and interactions.<p>[0] <a href="https:&#x2F;&#x2F;dev.to&#x2F;davidkpiano&#x2F;no-disabling-a-button-is-not-app-logic-598i" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;davidkpiano&#x2F;no-disabling-a-button-is-not-app-...</a>
评论 #25470642 未加载
评论 #25474444 未加载
评论 #25473630 未加载
vbtempover 4 years ago
People who gloss over this do so at your own risk. This technique is applicable for so, so many applications - even when it doesn&#x27;t appear obvious at first.<p>Factoring out complex control system logic into these (and related) formalisms dramatically enhances testability, substantially reduces code volume, and eliminates huge swaths of possible defects (not to mention seriously enhances formal verification and model checking). The &quot;code&quot; part for applications should basically be for data plumbing, and all decision-making and control logic should be factored into these.<p>Thanks for posting this!!
评论 #25469672 未加载
bmitcover 4 years ago
There is an edX course by David Harel (the author of this paper) and Michal Gordon called <i>Programming for Everyone – An Introduction to Visual Programming Languages</i>. I highly recommend it for anyone dealing with state, whether you’re a programmer, designer, engineer, or manager.<p><a href="https:&#x2F;&#x2F;www.edx.org&#x2F;course&#x2F;programming-for-everyone-an-introduction-to-visual" rel="nofollow">https:&#x2F;&#x2F;www.edx.org&#x2F;course&#x2F;programming-for-everyone-an-intro...</a>
sktrdieover 4 years ago
Harel&#x27;s recent work (which evolve from Statecharts) is so called Scenario-based programming. If interested I follow his work very closely and showcase his techniques in this article about bthreads: <a href="https:&#x2F;&#x2F;lmatteis.github.io&#x2F;react-behavioral&#x2F;" rel="nofollow">https:&#x2F;&#x2F;lmatteis.github.io&#x2F;react-behavioral&#x2F;</a>
评论 #25468246 未加载
评论 #25469986 未加载
emmanueloga_over 4 years ago
When I first saw Statecharts I failed to realize that Statecharts are _NOT_ state machines, state machines are the building block.<p>Quote from the paper:<p>&quot;... a complex system cannot be beneficially described in this naive fashion [state machines], because of the unmanageable, exponentially growing multitude of states, all of which have to be arranged in a ‘flat’ unstratified fashion, resulting in an unstructured, unrealistic, and chaotic state diagram. To be useful, a state&#x2F;event approach must be modular, hierarchical and well-structured. It must also solve the exponential blow-up problem by somehow relaxing the requirement that all combinations of states have to be represented explicitly.&quot;<p>So regular state machines are usable up to only a few states and transitions. Implementing the whole set of Statecharts features is far from the quick exercise of building an ad-hoc, implicit state machine. Fully using Statecharts introduces some overhead. But the true power of Statecharts shows when using hierarchy, parallel states, history and so on, things that build on top of state machines and take a bit more investment to learn how to use.<p>--<p>Another interesting aspect is the &quot;formal semantics&quot;. Quote:<p>&quot;The statechart formalism turns out to be quite a challenge when it comes to providing formal semantics ... The main difficulty is not in the depth of states or the orthogonality constructs themselves; ... The more difficult problems arise with the introduction of events and conditions that are generated within the statechart itself, and are sensed in orthogonal components.&quot;<p>So the idea is that given the same Statechart diagrams, two different implementations should end up in the same states when subjected with the very same sequence of events.<p>Perhaps this is less of a problem to build GUIs and other applications that don&#x27;t have super stringent requirements on safety and verifiability.
评论 #25471619 未加载
评论 #25471090 未加载
spinningslateover 4 years ago
I have mixed feeling about the hierarchical facility in statecharts. I&#x27;ve certainly found it helpful in some cases; for example, handling &quot;cancel&quot; events that apply to a group of states.<p>I&#x27;ve also seen huge, multi-level, multiple-parallel-region monsters that were impenetrable.<p>Now, no formalism is immune to abuse: &quot;just because you can, doesn&#x27;t mean you should&quot;. But I&#x27;ve often found that the simpler state model formalism - without hierarchy - has led to cleaner design and better separation of logic.<p>More generally though I do think state machines are somewhat underrated tools in the programmer&#x27;s toolbox.
评论 #25469772 未加载
评论 #25472594 未加载
john-tells-allover 4 years ago
A modern elaboration is <a href="https:&#x2F;&#x2F;statecharts.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;statecharts.github.io&#x2F;</a><p>- very clear explanation of statecharts, and why you&#x27;d want to use them (they&#x27;re an elaboration of state machines)<p>- and why you <i>wouldn&#x27;t</i> want to use them<p>very interesting, thanks to OP!
评论 #25470148 未加载
maxbendickover 4 years ago
I&#x27;ve found xstate invaluable for multi-step flows on the front end.<p>Redux and similar libraries are a bit hard to read when making these because representing sequential distinct states is implicit. I.e., have an enum for the &quot;page&quot; and some reducer cases to update the page.<p>With xstate, the order of things is often visually apparent. Not only are distinct states bread-and-butter for statecharts, the machine definition in the code visually jumps out at the reader and screams &quot;these are my states, and here&#x27;s how to move between them!&quot;
_aleph2c_over 4 years ago
Python statecharts: <a href="https:&#x2F;&#x2F;aleph2c.github.io&#x2F;miros&#x2F;html&#x2F;index.html" rel="nofollow">https:&#x2F;&#x2F;aleph2c.github.io&#x2F;miros&#x2F;html&#x2F;index.html</a>
sam_bristowover 4 years ago
I quite like <a href="https:&#x2F;&#x2F;sketch.systems&#x2F;" rel="nofollow">https:&#x2F;&#x2F;sketch.systems&#x2F;</a> as a tool for quickly getting up and running with Statecharts.<p>There&#x27;s also a good article by Hillel Wayne about using Statecharts and Alloy to formally specify UIs.<p><a href="https:&#x2F;&#x2F;www.hillelwayne.com&#x2F;post&#x2F;formally-specifying-uis&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.hillelwayne.com&#x2F;post&#x2F;formally-specifying-uis&#x2F;</a>
zitterbewegungover 4 years ago
I have no idea why in university we covered state machines so very little when they solve a host of problems and can replace fundamental ways in designing software. Not only that but it&#x27;s also compatible with them all.<p>I finally tried using state machines in a hobby project and its much better than just writing a bunch of if then statements in a event loop.
jarirajariover 4 years ago
Was also inspired by the Statecharts long time ago, and then saw an opportunity to go deeper into how server-side web applications could be implemented as state machines, and how it would ultimately lead into easier&#x2F;faster programming where correct&#x2F;complex patterns emerge from events, conditions, and actions. Wrote about it here: <a href="https:&#x2F;&#x2F;jarirajari.wordpress.com&#x2F;2014&#x2F;01&#x2F;03&#x2F;ecas-hierarchical-aspect-state-machine-aka-ecas-hasm&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jarirajari.wordpress.com&#x2F;2014&#x2F;01&#x2F;03&#x2F;ecas-hierarchica...</a>
neilvover 4 years ago
In the SwiftUI app I wrote recently, in an act of desperation, I dusted off my Harel statecharts skills (I used to develop tools like this), and ended up with a huge comment block with an ASCII-art hierarchical state model. Then the code structurese were based on that, and the names generally matched up between code and diagram. The app UI has been solid, even though some of the states are in the canned NFC UI mode, and less in my control.
kejaedover 4 years ago
I&#x27;ve worked in the past with code bases that have what were called &#x27;state machines&#x27; implemented with at best switch statements and at worse a lot of if&#x27;s and else&#x27;s and some state variables.<p>I&#x27;ve also worked with code bases with a formally defined state machine object&#x2F;concept, with pre-defined states, events, and state transitions driven by events.<p>Question for the crowd: what would you call the non-state machine state machine in the first case?
评论 #25468773 未加载
评论 #25467998 未加载
评论 #25468615 未加载
评论 #25469156 未加载
jonaiasover 4 years ago
Back in university, I had a course on reactive systems, a whole semester of state machines and statecharts. I can&#x27;t stress enough how useful it was in my career.<p>I&#x27;ve retrofitted some near unmaintainable embedded systems, and one of the easiest ways to improve spaghetti code is refactoring some of the vars into state machines&#x2F;statecharts.<p>Btw, state machines play well with event sourcing and clustering.
fokinseanover 4 years ago
I&#x27;m getting a flashback from Sproutcore JS statecharts, wish I could say they were good times but I&#x27;m so glad I&#x27;m not developing with them anymore.<p><a href="https:&#x2F;&#x2F;guides.sproutcore.com&#x2F;getting_started_2.html" rel="nofollow">https:&#x2F;&#x2F;guides.sproutcore.com&#x2F;getting_started_2.html</a>
kazinatorover 4 years ago
Relevant: <a href="https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UML_state_machine" rel="nofollow">https:&#x2F;&#x2F;en.wikipedia.org&#x2F;wiki&#x2F;UML_state_machine</a><p>(Article references the above paper as citation #2).
breckover 4 years ago
Every graph can be represented by a 2-dimensional tree.<p>Hence, every chart in this paper has a 2-D tree representation.<p>You can write that 2-D representation, and then without any type of transforming (keeping the shape of the graph in tree form untouched), you can turn it into a 3-D statechart, via the use of a Tree Language (<a href="https:&#x2F;&#x2F;jtree.treenotation.org&#x2F;designer&#x2F;" rel="nofollow">https:&#x2F;&#x2F;jtree.treenotation.org&#x2F;designer&#x2F;</a>)<p>So you get a 2-D text encoding of the statechart, editable in any dumb text editor or spreadsheet, isomorphic to the visual circles and lines diagrams they have, just as a 3-D rendering.<p>You could probably put that in a paper.
评论 #25470154 未加载
_pmf_over 4 years ago
Hands down the best paper in software development.
elviejoover 4 years ago
Any book recommendations to learn more about state machines, state charts and languages that implement them natively??