EVERYTHING ELSE CAN BE MUTABLE, NOT MY DOCUMENTS!
Updated: Nov 7
Immutability is a hard topic to breach. As a programmer used to modelling the world, you might object to immutable data structures. How do you model a changing world? Why would you choose to use immutable data structures when everything in the world is changeable?
Let’s do a little thought experiment. Let’s look at a nice mutable system: paper and pencil. You can write, erase, and write again. It’s very convenient. It lets you correct mistakes. And when you don’t need something any more, you can easily erase it.
Now answer this: would you trust a bank that used pencils to record transactions? It would be easy: whenever you would withdraw money, they would erase the old balance and write the new balance. And if you transferred money from one account to another, they’d erase two balances and write the new ones in. It may sound great, but there’s a reason banks don’t use pencils: they want to be sure nothing has changed. That sounds like immutability.
Each transaction gets its own line. Always done in pen. It’s an example of an append-only data structure. You can answer questions about the past like “How much money was in the account at the close of last Tuesday?” by going up lines until you find the last entry for Tuesday. And you can do that because you never modify existing entries. You only add new entries on blank lines.
Let's take the example of immutability in hospital documentation. Each patient gets a file that everything is added to. You never modify old records. That way, everything is recorded, even the wrong diagnoses (mistakes) of the doctor.
It turns out that traditional systems that need a high degree reliability create immutable records out of mutable paper. Even though you could in theory scratch out some data and write it again, or white it out, or find some other way to mutate the document, a mark of professionalism in the job is to discipline yourself to adhere to strict append-only behaviours.
Wouldn’t it be nice if the machine took care of the discipline for us? Even though RAM and disk are mutable like paper and pen, we can impose a discipline inside our program. We could rely on the programmer to never accidentally overwrite existing data. But that’s just shifting the burden. Instead, we can build in immutability into our data structures and make a paper that cannot be overwritten.
That’s how immutable data structures work. All new pieces of information are written to new locations in memory. Only when it is proven that a location is never going to be used again is it reused.
Reliable paper-based systems use immutable data. There was a time when computer memory was expensive when we had to reuse storage, so we couldn’t make immutable systems. But RAM is cheap now! We should be using immutable data, just as banks have done for hundreds of years. Ready to join the 13th century?
If you’re interested in a language with a very cool set of powerful immutable data structures, probably the most cutting edge immutable data structures in any language, you’re in luck! TiiQu score is algorithmically calculated from immutable and verifiable credentials continuously collected into a digital wallet. Credentials are immutable in the sense that they cannot be altered nor can be removed, but the score is constantly updated from irrefutable proofs that are continuously added with the aim to make it easy for decision-makers, to identify how much a set of claims can be trusted at a given point in time.
Check us out at: https://www.tiiqu.com/