Immutable types provide a way to build applications out of a solid foundation of reusable building blocks that are easy to understand and reason about. In some cases, immutable types can also improve memory use (by aggressive sharing) and increase performance (by eliminating time consuming copying and locks).

The design of immutable types means that their externally visible state doesn’t change over their lifetime, making them implicitly safe to share - no need to take a private copy of information to ensure it isn’t changed behind your back. (In some implementations, the internal state of an immutable object might change over time - perhaps caching the result of a time consuming calculation, for example.)

Why Immutable Types?

Saturday, March 11 2017 immutable-types

This series on immutable types has turned into something of an epic - when I began, I never expected it to become a series of this length. For now, the final question I want to address is a simple one: Why are immutable types important?

Read more »

Immutable Type Miscellany

Sunday, March 05 2017 immutable-types

As we near the end of this series on immutable types (for now, anyway), here’s a grab bag of things that didn’t seem to fit elsewhere.

Read more »

Testing Immutable Types

Saturday, February 25 2017 immutable-types

As alluded to previously, having a good suite of unit tests is critical for ensuring these immutable instances do what they should - after all, there’s no point in having a queue or stack that doesn’t behave.

Read more »

Factory Methods

Saturday, February 18 2017 immutable-types

Our stacks and queues don’t exist in isolation - they have to interoperate with standard framework classes and other domain constructs to be useful. For example, it is extremely useful to have some factory methods to make it easier to construct stacks and queues from existing lists and sequences.

Read more »

Queue Concatenation

Saturday, February 11 2017 immutable-types

If you have a whole sequence of items you want to add to an existing IImmutableQueue<T>, it’s pretty simple to write a loop to add them all. We can make this even easier by writing a simple extension method that handles the looping on our behalf.

Read more »