Chapter 16

Keeping Data from Changing

WHAT’S IN THIS CHAPTER?

  • Why change is not always good
  • Simple immutable data types
  • Cloning with modifications
  • Immutable container data structures
  • Alternatives to immutable data types

That data is changeable, that it actually changes all the time in real life, is usually taken as fact in mainstream imperative programming. But the changeability of data creates many problems, so programmers are questioning that idea. In the world of functional programming, data is traditionally immutable, and data structures tend to be persistent. The term persistent is easily misunderstood because it seems to point at persistence in the sense of storing data in file systems, databases, or similar storage units. It’s actually used as an opposite of ephemeral, meaning short-lived or volatile, and should not be understood to imply any storage mechanism for the data.

Get Functional Programming in C#: Classic Programming Techniques for Modern Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.