Immutable isn’t just for parallel code

For the last 6 months the BCL team has been hard at work shipping an out of band release of immutable collections for .Net.  Most recently delivering an efficient implementation of ImmutableArray<T> http://blogs.msdn.com/b/dotnet/archive/2013/06/24/please-welcome-immutablearray.aspx Unfortunately with every announcement around these collections I keep seeing the following going past in my twitter feed. That looks neat.  Next…

5

Immutable vs. Mutable Collection Performance

One argument I commonly hear against immutable collections is they are slow.  I’ve held the opposite belief for some time but shamefully had yet to look at actual numbers on the CLR.  Tonight I decided to change that by benchmarking one of my immutable collections against a mutable collection in the BCL.  The goal is…

6

Why are thread safe collections so hard?

Writing a collection which is mutable, thread safe and usable is an extremely difficult process.  At least that’s what you’ve likely been told all through your schooling.  But then you get out on the web and see a multitude of thread safe lists, maps and queues.  If it’s so hard, why are there so many…

52

Immutable Collections and Compatibility with Existing Frameworks

When developing my immutable collections library, I spent a lot of time on usability.  After all, if a library is not useful then what’s the point? A big portion of usability is being able to work with existing frameworks and technologies.  For .Net and collections that means items like Data binding, LINQ etc …  Without…

3

A Lesson in Serialization

A few days ago, I recklessly added a [Serialization] attribute to a few of my immutable collection types.  I needed to pass data between AppDomain’s and adding [Serialization] was the quick and dirty fix.  Compiled, ran and I didn’t think much about it.  Luckily I was updating some unit tests last night and I remembered…

2

ImmutableStack in F# Part 2

I’m a bit busier than I thought I would be after returning from vacation.  But I had a little bit of time to play around with the implementation again today.  Thanks to all the suggestions in the comments from the previous post.  This version has a couple of improvements including Removing the ambiguous constructor More…

1

Immutability and ReadOnlyCollection<T>

I am a huge fan of read only/immutable collections and data.  Hopefully the increased exposure through the blogosphere alerted users to the advantages of this type of programming for the appropriate scenarios.  I wanted to discuss ReadOnlyCollection<T> in case devs looking around in the BCL discover it and assume it’s immutable.  There are two details of this…

1

PipeSingleReaderNoLock

Previously we discussed a multi-thread safe queue like data structure using locks as an internal synchronization mechanism.  This time we’ll look at a version requiring no locks.  In the previous version, locks were used to synchronize access to an underlying queue which stored the data.  Removing the locks necessitates us moving away from Queue<T> to…

0

Tuples Part 7: Mutable Tuples

Part 6 left us with comparable tuples.  At this point, the Tuple class is functionally complete.  There will be a little more done with the debugability and overall fit into larger projects.  But otherwise it is sound.  Now the focus shifts to generating mutable tuples.  Immutability is nice for threading, memoization, etc …  However it’s…

1

Tuples Part 1

A tuple in computer science can be described as a set of name/value pairs.  In some cases it can be described as simply a set of values that are accessible via an index [1].  Previously I discussed how to create a Tuple inside of PowerShell.  This series will focus on the use of Tuples in…

6