Skip to content

Instantly share code, notes, and snippets.

@laughinghan
Last active June 25, 2021 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laughinghan/f81edf30b66b95a7200ad8ac3101384d to your computer and use it in GitHub Desktop.
Save laughinghan/f81edf30b66b95a7200ad8ac3101384d to your computer and use it in GitHub Desktop.

State and Side-Effects in Mechanical

I don't like:

  • control flow
    • it confuses perceptible time ("the user clicked on something and then the thing finished downloading") and control flow "time" ("this function is called and then this function is called"). This is confusing for end-user programmers because control flow "time" is perceived as instantaneous to end-users (until you hit a blocking or asynchronous function call)
  • RxObservables/cycle.js-style stream-based functional-reactive programming (aka denotative continuous-time programming)
    • I don't think it's natural to think of like, a textbox, as its initial value and then every keypress or toolbar button click that will change its contents. I think it's much more natural to think, okay when this toolbar button gets clicked, what changes
      • the very example that Steve Krouse uses to illustrate DCTP/FRP is described as: "When either input box is modified, and it’s value is a valid number, the other input box is updated to reflect the corresponding temperature in the other units." That's simply the naturally way to describe and think about it

I do like:

  • Elm-style event-driven state machine
  • small core runtime semantics of imperative programming
    • typically has predictable and useful performance and memory characteristics
    • the rest of the language is defined in terms of them
    • data structures and other abstractions can be built on top of them (e.g. JavaScript FRP libraries like cycle.js, Turbine etc, or building OOP on top of closures in Scheme, etc)
  • abstracting over incoming or outgoing event streams, like throttle
  • defining dependent state in terms of mutation
    • this is a weird thing, but React, Elm, and Vue all work this way. We might want to find a better way to structure this, though, like if a downstream state machine listens on an event stream plus a state stream, and they trigger one state-update as a pair, or something?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment