front matter
Every programming principle, every design method, every architecture style, and even most language features are about organizing complexity while allowing adaptation. Two characteristics—immutable data and turning parts of the program into data inside the program itself—drew me to Clojure in 2009 and more recently to Yehonathan Sharvit’s Data-Oriented Programming.
In 2005, I worked on one of my favorite projects with some of my favorite people. It was a Java project, but we did two things that were not common practice in the Java world at that time. First, we made our core data values immutable. It wasn’t easy but it worked extraordinarily well. We hand-rolled clone and deepClone methods in many classes. The payoff was huge. Just as one example, suppose you need template documents for users to instantiate. When you can make copies of entire object trees, the objects themselves don’t need to “know” whether they are template data or instance data. That decision is up to whatever object holds the reference. Another big benefit came from comparison: when values are immutable, equality of identity indicates equality of value. This can make for very fast equality checks.