[Second review] SE-0395: Observability

Well, I'm not entirely sure I can help you there, because I have an issue with the word “magically.” When stuff happens magically that usually means local reasoning has been lost… so I'm opposed to magic in programming. The whole point of value semantics is to retain local reasoning.

If you're willing to settle for non-magic, you could take the approach SwiftUI, Photoshop, the desktop software I developed way back in prehistory—and I'm sure countless other systems—take to this problem:

  1. Make your data structure a value
  2. Use CoW so similar values of the data structure created by small mutations share lots of storage
  3. Make it efficient to compare parts of the data structure for equality and describe the differences between one value and another (didn't Foundation add collection diffing facilities some years ago?)
  4. Take a snapshot of your data structure before making a series of changes
  5. Compare the snapshot with the new state to see what changed and do whatever you need to do in response to those changes.

(This is super convenient if you need to be able to undo changes, because your undo history can just be a series of snapshots)

This is just one way to do it. I'm sure you can think of others.

Notice that steps 3 and 5 involve first-class algorithms that allow you to describe the behaviors of the system coherently rather than as a scattered set of observation actions.

And this is exactly the key. More generally, reference semantics doesn't scale because it undermines local reasoning.

6 Likes