Thursday, January 18, 2007

About .NET Collection Libraries (PowerCollections and C5)

Summary: Some positive and negative points of the PowerCollections and C5 .NET collection libraries from early experience.

It is no secret that the .NET Base Class Library (BCL) is not overly generous when it comes to collection classes. Though generics have improved life a lot, there still are considerable holes. Fairly well known examples are the lack of set implementations and read-only wrappers around collections/dictionaries.

There are various more or less open-source .NET collection library projects that try to fill the gap of which the Wintellect PowerCollections and the C5 Collections seem to be mentioned most. Of the possible other alternatives, the NCollection project at CodePlex has barely started and the NGenLib project on SourceForge has not seen any activity for two years.

The philosophy behind PowerCollections and C5 differs a lot. The PowerCollections approach is pragmatic and aims to stay as close as possible to the existing BCL collections programming model and interfaces, filling the gaps where necessary. A very appealing part of PowerCollections is the static Algorithms class, which defines tens of generic methods for algorithms such as searching and sorting any object that supports IEnumerable. This class is very useful, because the implementation of similar methods on the BCL collections is either missing or inconsistent.

Contrary to this the C5 Collection classes have been designed from scratch and show how a more academic approach has resulted in a set of very powerful and consistently implemented collections. Examples of out-of-the-box functionality are fine-grained events and read-only wrappers for all collections. To get the most from the C5 collections, it pays to have a look at the technical paper that outlines their design and also provides a full API reference.

Based on approach, I would consider PowerCollections first if I needed a patch for missing BCL functionality. However, the one thing I don't like about the PowerCollections is its non-standard license, which seems to prohibit use in applications that are distributed under GPL/LGPL-like licenses. As Wintellect (recently bought by Microsoft) invited community participation, I feel this would have deserved a more liberal license. For example, a BSD style license, such as used for the C5 collections. For me, this has tipped the balance in favour of C5.

Having said that, the C5 library needs a bit of nurturing to gain most of its power in day-to-day applications. Offering an implementation of the BCL IDictionary and IList interfaces is an important facet of this. Otherwise it can be hard to interface with other modules (NHibernate, Castle or Spring.NET for example) that work with the BCL collection interfaces.

So far, my experience in modifying the C5 code has been promising. After some refactoring of the C5 code, I have been able to implement the
BCL IDictionary interface on all C5 dictionaries. It is too early to start posting code yet, but feel free to leave a comment on this post if you're interested!

2 Comments:

Blogger Brad said...

Just started looking at C5. I would be interested in any source code changes/improvements that you make and would be happy to share any I make with you.

Cheers, Brad Jones

Fri Mar 23, 06:15:00 pm GMT  
Blogger Gerke Geurts said...

Brad, I would be happy to collaborate . Refactoring the C5 collections currently does not have my top priority due to other work commitments, but I still believe strongly in its potential.

Thu Mar 29, 02:37:00 pm BST  

Post a Comment

<< Home