Skip to content

EssentialStateWantsToBeGlobal

Ben Christel edited this page Jul 15, 2023 · 3 revisions

There are two kinds of State in software: EssentialState (what your users care about) and AccidentalState (state your users don't care about, that exists for technical reasons like performance optimization). These terms come from OutOfTheTarPit.

Essential state wants to be global.

Users (and by extension, product managers) don't know or care about encapsulation. They expect all the information they've put into your software to be sort of ambiently available to every part of it. When useful information isn't available, they get grumpy.

If they're technically inclined, it's even worse: they'll say things like "why can't you just put that in a variable?"

My conclusion from this is: do not encapsulate state your users care about. Make it global to your application. Model EssentialState with AlgebraicTyped immutable data and transform it with Functions. Immutability, atomic updates, and normalized data keep the globality of the state from causing problems.

On the other hand, you should definitely encapsulate AccidentalState like caches, stateful parsing algorithms, etc. Your users will never ask you to make your accidental state globally available, since they aren't aware it exists.

In summary: use FunctionalProgramming for domain and application logic, and ObjectOrientedProgramming for infrastructure.

Clone this wiki locally