Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Stovepipe Systems:
Immutability of Data
Jul 13, 2017 @ 10:51:22

On the Stovepipe Systems blog today Yannick de Lange has written up a post looking at data immutability and how using this concept can help improve your development and simplify data handling in your applications.

When dealing with enterprise software, your data is often the most valuable part. It contains all your customer information, contracts, invoices and much more. So what are you going to do to make sure the data is being dealt with correctly? A bug in your code can have a high impact on the integrity of your data. If the bug is causing unwanted changes in your data, fixing the damage might prove to be quite a big challenge.

With this post I would like to show how data immutability can help design a more robust system. One that is less susceptible to bugs that might make unwanted changes to your data.

He starts by talking about how immutability and data handling might seem like "a contradiction" but that it can, instead, be thought of as "versioning your data". He gives an example of an end date on a contract and how changing it directly leads to data loss. He then gets into an actual code example showing how to implement this data versioning. He starts by creating the basic "Contract" object but then refactors it into "versioned" types and how the changes would be tracked internally, updating with each change to the data instead of overwriting.

tagged: data immutability example tutorial version dataloss

Link: https://stovepipe.systems/post/immutability-of-data