State-Free Programs and On-Disk State

I’m having some thoughts this morning:

If we view programs as pure execution (or, as in SICP, a way to wrangle processes and make them do what we want), and if we follow Functional Programming “rules”, still there must be some way to keep and store state of a system—state in a system is inescapable, from a Systems Modelling point of view.

It occurs to me, that if one takes the idea of separating components of a program to its logical conclusion, one should be able to separate state-related computation from state itself. State-related computation should end up as a separate module of a certain given program, and state should end up in a datastore of some sort, whether volatile or not.

So in practical terms, if we subtract state from a program, we could offload it into a separate store on-disk or on-RAM, and with such fast I/O these days, it becomes trivial to use something like, for example, LevelDB, or Redis, or RocksDB for this. In even more pragmatical terms, make your program state-free, and any time you might need to save it or read it, just fire off a write/query to some fast, simple k/v datastore.

This is probably obscenely obvious and not a new idea by any means, but something just clicked and went off in my head, and I had to write it down to cement my intuition.