<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>jaredpar's WebLog : RantPack</title><link>http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx</link><description>Tags: RantPack</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>BclExtras Library</title><link>http://blogs.msdn.com/jaredpar/archive/2009/01/23/bclextras-library.aspx</link><pubDate>Fri, 23 Jan 2009 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9372192</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9372192.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9372192</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9372192</wfw:comment><description>&lt;p&gt;I published a .Net utility library on &lt;a href="http://code.msdn.microsoft.com"&gt;Code Gallery&lt;/a&gt; today called &lt;a href="http://code.msdn.microsoft.com/BclExtras"&gt;BclExtras&lt;/a&gt;.&amp;#160; It’s a set of classes meant to be used in addition to the standard .Net base class libraries (BCL).&amp;#160; The main focuses of the library are functional programming, multi-threading, LINQ extensions, unit testing and API’s designed to support type inference.&lt;/p&gt;  &lt;p&gt;This project evolved from various classes and constructs I was using in personal projects.&amp;#160; For the last year or so I’ve kept as a separate tested library.&amp;#160; It started out with a lot of multi-threaded code constructs but lately is leaning to a lot of functional style API’s and collections.&amp;#160; &lt;/p&gt;  &lt;p&gt;The library includes source and binaries for .Net 2.0 and .Net 3.5.&amp;#160; The .Net 2.0 version of the library includes many constructs added in 3.5 that don’t rely on any 2.0SP1 CLR features.&amp;#160; Examples are Func&amp;lt;T&amp;gt;, Action&amp;lt;T&amp;gt;, the Extension attribute and a subset of the LINQ Enumerable class.&amp;#160; It allows for most LINQ expressions in a 2.0 targeted application. These types are removed in the 3.5 version to avoid conflicts with types in System.Core.&amp;#160; &lt;/p&gt;  &lt;p&gt;I’ve previously released this library under the name &lt;a href="http://code.msdn.microsoft.com/RantPack"&gt;RantPack&lt;/a&gt;.&amp;#160; It originally started out as personal utility library of mine and hence ended up with the somewhat obscure name.&amp;#160; But, besides to me, RantPack doesn’t really convey a useful meaning.&amp;#160; So I decided to give it a more meaningful name for the general population.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9372192" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/DotNet/default.aspx">DotNet</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/BclExtras/default.aspx">BclExtras</category></item><item><title>Immutable Collections and Compatibility with Existing Frameworks</title><link>http://blogs.msdn.com/jaredpar/archive/2008/12/10/immutable-collections-and-backwards-compatibility.aspx</link><pubDate>Wed, 10 Dec 2008 16:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9187707</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/9187707.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=9187707</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=9187707</wfw:comment><description>&lt;P&gt;When developing my &lt;A href="http://code.msdn.microsoft.com/RantPack" mce_href="http://code.msdn.microsoft.com/RantPack"&gt;immutable collections library&lt;/A&gt;, I spent a lot of time on usability.&amp;nbsp; After all, if a library is not useful then what’s the point?&lt;/P&gt;
&lt;P&gt;A big portion of usability is being able to work with existing frameworks and technologies.&amp;nbsp; For .Net and collections that means items like Data binding, LINQ etc …&amp;nbsp; Without integrating into popular technologies the usefulness of a particular library is severely impacted and hence usability decreases.&lt;/P&gt;
&lt;P&gt;Most of the existing collection based infrastructures use the .Net collection interfaces as their form of abstraction.&amp;nbsp; The most straight forward way to ensure compatibility is to implement these interfaces on the collections in question.&amp;nbsp; In particular &lt;A href="http://msdn.microsoft.com/en-us/library/92t2ye13.aspx" mce_href="http://msdn.microsoft.com/en-us/library/92t2ye13.aspx"&gt;ICollection&amp;lt;T&amp;gt;&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx" mce_href="http://msdn.microsoft.com/en-us/library/5y536ey6.aspx"&gt;IList&amp;lt;T&amp;gt;&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx" mce_href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx"&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/A&gt; are the main abstractions.&amp;nbsp; Lets investigate which ones an Immutable collection should be implementing in order to effectively integrate into existing collection based infrastructures.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This is the easiest decision.&amp;nbsp; IEnumerable&amp;lt;T&amp;gt; represents a read only, one element at time view on a sequence of objects.&amp;nbsp; Immutable collections can easily and reliably implement a IEnumerable&amp;lt;T&amp;gt;.&amp;nbsp; This is a no brainer.&amp;nbsp; Implement.&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;ICollection&amp;lt;T&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;This interfaces represents a general collection class.&amp;nbsp; Unfortunately this interface is meant to represent a mutable collection class and implements such methods as Add, Clear and Remove.&amp;nbsp; These methods cannot be implemented on an Immutable collection given the current design.&amp;nbsp; All three of these methods are void returning methods because the collection is meant to be changed in place.&amp;nbsp; Immutable collections can support these operations but it involves returning a new instance of the collection.&amp;nbsp; &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public sealed class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ImmutableCollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; : &lt;SPAN style="COLOR: #2b91af"&gt;ICollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; {
    &lt;SPAN style="COLOR: blue"&gt;public &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ImmutableCollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; Add(T item) {
        &lt;SPAN style="COLOR: green"&gt;// Actually add 
        // ...
    &lt;/SPAN&gt;}

    &lt;SPAN style="COLOR: blue"&gt;#region &lt;/SPAN&gt;ICollection&amp;lt;T&amp;gt; Members

    &lt;SPAN style="COLOR: blue"&gt;void &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICollection&lt;/SPAN&gt;&amp;lt;T&amp;gt;.Add(T item) {
        &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;created = &lt;SPAN style="COLOR: blue"&gt;this&lt;/SPAN&gt;.Add(item);
        &lt;SPAN style="COLOR: green"&gt;// What to do with created???
    &lt;/SPAN&gt;}

    ...
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;But wait!&amp;nbsp; The interface does support a property named &lt;A href="http://msdn.microsoft.com/en-us/library/0cfatk9t.aspx" mce_href="http://msdn.microsoft.com/en-us/library/0cfatk9t.aspx"&gt;IsReadOnly&lt;/A&gt;.&amp;nbsp; The intention of this property is to allow an interface to programmatically declare they do not support modifications.&amp;nbsp; A read only collection can just implement this interface, throw a&amp;nbsp;&lt;A class="" title=NotSupportedException href="http://msdn.microsoft.com/en-us/library/system.notsupportedexception.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.notsupportedexception.aspx"&gt;NotSupportedException&lt;/A&gt; for all of the mutable methods and return true for IsReadOnly and presto we have a suitable interface for an immutable collection.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Or do we?&amp;nbsp; &lt;/P&gt;
&lt;P&gt;The design for ICollection&amp;lt;T&amp;gt; with respect to read only or immutable collections is not optimal.&amp;nbsp; It attempts to combine to separate behaviors into a single interface: mutable and readonly view of a collection.&amp;nbsp; Dual purpose interfaces run into problems because it’s impossible to separate out the behaviors at compile time.&amp;nbsp; This is especially problematic when the behaviors are conflicting.&amp;nbsp; There is no way a read only collection can prevent itself from being passed to a function that expects a mutable collection at compile time.&amp;nbsp; Nor can a consumer who intends to mutate a collection prevent a read-only collection from being passed. &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;DisplayForEdit&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;ICollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; col) {
    &lt;SPAN style="COLOR: green"&gt;// ...
    &lt;/SPAN&gt;m_clearButton.Click += (x, y) =&amp;gt; col.Clear(); 
}

&lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Example1() {
    &lt;SPAN style="COLOR: #2b91af"&gt;ImmutableCollection&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&amp;gt; col = &lt;SPAN style="COLOR: #2b91af"&gt;ImmutableCollection&lt;/SPAN&gt;.Create(&lt;SPAN style="COLOR: blue"&gt;new int&lt;/SPAN&gt;[] { 1, 2, 3, 4 });
    DisplayForEdit(col);    &lt;SPAN style="COLOR: green"&gt;// Will fail as soon as Clear is clicked
&lt;/SPAN&gt;}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;But isn’t it the responsibility of the user of ICollection&amp;lt;T&amp;gt; to verify that IsReadOnly is false before mutating a instance?&amp;nbsp; Given the current design of ICollection&amp;lt;T&amp;gt; it is indeed both the responsibility of the consumer to verify this and the implementer to ensure they are not called incorrectly.&amp;nbsp; The problem with putting responsibility on the consumer though is they have to 1) know about read only uses of ICollection&amp;lt;T&amp;gt; and 2) actually care about it.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;A quick search of the BCL with reflector can give us evidence of how much consumers actually check for the read only scenario.&amp;nbsp; For the search I used mscorlib, System, System.Xml, System.Data, System.Drawing and System.Core and System.Windows.Forms.&amp;nbsp; And the number of classes which actually take into account ICollection&amp;lt;T&amp;gt;.IsReadOnly is … 1.&amp;nbsp; System.Collections.ObjectModel.Collection&amp;lt;T&amp;gt;.&amp;nbsp; That’s it.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;So even if an immutable collection implements this interface in a read-only fashion there’s little chance anyone will be checking for it.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;IList&amp;lt;T&amp;gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;IList&amp;lt;T&amp;gt; inherits from ICollection&amp;lt;T&amp;gt; and hence suffers from all of the same problems&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Decision Time&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;In order to facilitate usability with existing frameworks immutable collections are forced to implement interfaces for which they have no possible way of implementing properly.&amp;nbsp; If collections implement these interfaces they will be trading usability for compile time validation.&amp;nbsp; Even worse is the conversion is implicit which prevents even basic searches for places this conversion occurs.&amp;nbsp; This is a heavy price to pay for compatibility. &lt;/P&gt;
&lt;P&gt;After debating this for awhile I decided that loss of compile time validation was a too heavy of a price to pay for the default scenario.&amp;nbsp; But trading away usability was also unacceptable.&amp;nbsp; As a compromise I opted for adding a compatibility layer to the collections.&amp;nbsp; Instead of implementing the ICollection&amp;lt;T&amp;gt; and IList&amp;lt;T&amp;gt; collections directly I created a set of proxy objects that implement the interfaces on behalf of the immutable collections.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;In order to centralize this effort I created a factory class, CollectionUtility, which contains appropriate overloads for all of my immutable collection classes [1].&amp;nbsp; &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;public static class &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CollectionUtility &lt;/SPAN&gt;{
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;T&amp;gt; CreateEmptyEnumerable&amp;lt;T&amp;gt;();
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;T&amp;gt; CreateEnumerable&amp;lt;T&amp;gt;(T value);
&lt;SPAN style="COLOR: green"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; CreateICollection&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyCollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; col);
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IDictionary&lt;/SPAN&gt;&amp;lt;TKey, TValue&amp;gt; CreateIDictionary&amp;lt;TKey, TValue&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyMap&lt;/SPAN&gt;&amp;lt;TKey, TValue&amp;gt; map);
&lt;SPAN style="COLOR: green"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IList&lt;/SPAN&gt;&amp;lt;T&amp;gt; CreateIList&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyList&lt;/SPAN&gt;&amp;lt;T&amp;gt; list);
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ICollection &lt;/SPAN&gt;CreateObjectICollection&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyCollection&lt;/SPAN&gt;&amp;lt;T&amp;gt; col);
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IDictionary &lt;/SPAN&gt;CreateObjectIDictionary&amp;lt;TKey, TValue&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyMap&lt;/SPAN&gt;&amp;lt;TKey, TValue&amp;gt; map);
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IList &lt;/SPAN&gt;CreateObjectIList&amp;lt;T&amp;gt;(&lt;SPAN style="COLOR: #2b91af"&gt;IReadOnlyList&lt;/SPAN&gt;&amp;lt;T&amp;gt; list);
    &lt;SPAN style="COLOR: blue"&gt;public static &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IEnumerable&lt;/SPAN&gt;&amp;lt;&lt;SPAN style="COLOR: blue"&gt;int&lt;/SPAN&gt;&amp;gt; GetRangeCount(&lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;start, &lt;SPAN style="COLOR: blue"&gt;int &lt;/SPAN&gt;count);
}&lt;/PRE&gt;&lt;A href="http://11011.net/software/vspaste" mce_href="http://11011.net/software/vspaste"&gt;&lt;/A&gt;
&lt;P&gt;The proxy objects live as private inner classes inside CollectionUtility.&amp;nbsp; They implement the collection interfaces in the most read-only way possible.&amp;nbsp; When confronted with mutating calls, the proxies throw &lt;A class="" title=NotSupportedException href="http://msdn.microsoft.com/en-us/library/system.notsupportedexception.aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.notsupportedexception.aspx"&gt;NotSupportedException&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;So at the end of the day I have compile time validation for immutable collections.&amp;nbsp; If a developer wants to use them in a less than safe scenario it requires an explicit conversion.&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;PRE class=code&gt;&lt;SPAN style="COLOR: blue"&gt;static void &lt;/SPAN&gt;Example2() { 
  &lt;SPAN style="COLOR: blue"&gt;var &lt;/SPAN&gt;col = &lt;SPAN style="COLOR: #2b91af"&gt;ImmutableCollection&lt;/SPAN&gt;.Create(&lt;SPAN style="COLOR: blue"&gt;new int&lt;/SPAN&gt;[] { 1, 2, 3, 4 }); 
  &lt;SPAN style="COLOR: green"&gt;// Still fails, but explicit conversion required 
  &lt;/SPAN&gt;DisplayForEdit(&lt;SPAN style="COLOR: #2b91af"&gt;CollectionUtility&lt;/SPAN&gt;.CreateICollection(col)); 
  }&lt;/PRE&gt;
&lt;P&gt;I feel like this as an appropriate tradeoff.&amp;nbsp;&amp;nbsp; In the worst case scenario, a developer can search for all accesses of the CollectionUtility class and find places where a proxy is being created.&lt;/P&gt;
&lt;P&gt;Next time, lets take a look at a different way of approaching an interface hierarchy for a set of collections.&amp;nbsp; One that will allow us to avoid this problem altogether going forward.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;[1] It actually contains overloads for a set of truly read only collection interfaces that I wrote for my library but we’ll get to that another time.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Edit: Updated the exception to be NotSupportedException&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9187707" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/C_2300_/default.aspx">C#</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Generics/default.aspx">Generics</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Immutable/default.aspx">Immutable</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/API+Design/default.aspx">API Design</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category></item><item><title>RantPack Update 2.0.0.2</title><link>http://blogs.msdn.com/jaredpar/archive/2008/07/23/rantpack-update-2-0-0-2.aspx</link><pubDate>Wed, 23 Jul 2008 15:00:13 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8765442</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8765442.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8765442</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8765442</wfw:comment><description>&lt;p&gt;Version 2.0.0.2 released.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Summary: RantPack is a utility library I maintain and actively use.&amp;nbsp; The main themes of this library are functional programming, patterns, immutable/pressitent collections, future and other threading primitives.&amp;nbsp; I've placed the code and binaries on &lt;a href="http://code.msdn.microsoft.com/RantPack"&gt;http://code.msdn.microsoft.com/RantPack&lt;/a&gt; for educational and sharing purposes.&lt;/p&gt; &lt;p&gt;Release Link: &lt;a title="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1306" href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1306"&gt;https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1306&lt;/a&gt;&lt;/p&gt; &lt;p&gt;Release Notes:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Renamed Tuple properties to be more consistent&lt;/li&gt; &lt;ul&gt; &lt;li&gt;Item0, Item1 instead of A,B&lt;/li&gt;&lt;/ul&gt; &lt;li&gt;Added a Match operator&lt;/li&gt; &lt;li&gt;Made Enumerable more compatible&lt;/li&gt; &lt;li&gt;Bug fixes&lt;/li&gt;&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8765442" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category></item><item><title>To name a tuple value: A or Item0?</title><link>http://blogs.msdn.com/jaredpar/archive/2008/06/23/to-name-a-tuple-value-a-or-item0.aspx</link><pubDate>Mon, 23 Jun 2008 15:00:17 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8599391</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8599391.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8599391</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8599391</wfw:comment><description>&lt;p&gt;One of the parts of a Tuple implementation for &lt;a href="http://code.msdn.microsoft.com/RantPack"&gt;RantPack&lt;/a&gt; I struggled the most with was naming.&amp;#160; I tend to struggle with names quite a bit and there's really no reason for it.&amp;#160; It's a combination of pickiness and ... well there's really no good reason.&amp;#160; Pieces which can bother me range from &lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Don't like the way it types.&amp;#160; If I can't type something easily it drives me nuts and I secretly desire to change it to a word that is easier to type.&amp;#160; I have sadly spent a large amount of time on &lt;a href="http://www.thesaurus.com"&gt;www.thesaurus.com&lt;/a&gt; looking for better words to type.&lt;/li&gt;    &lt;li&gt;Looks funny.&amp;#160; No real solid criteria here, just what I don't like.&amp;#160; Words sometimes look good the first time you type them but over time lose their appeal&lt;/li&gt;    &lt;li&gt;Doesn't match conventions.&amp;#160; Ah, now we're onto solid reasons.&amp;#160; Names should match conventions.&lt;/li&gt;    &lt;li&gt;Name is ambiguous.&amp;#160; If the name doesn't give a clear intention of the operation I do my best to change it.&amp;#160; &lt;/li&gt;    &lt;li&gt;FxCop violation.&amp;#160; This bothers me less than others but if FxCop doesn't like it I think a bit harder about naming it. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Now comes Tuples.&amp;#160; Many implementations of tuples don't even have names but instead rely on language constructs such as pattern matching to access the values.&amp;#160; That's not really the DotNet way of doing things though so I chose to give Tuple values names.&amp;#160; &lt;/p&gt;  &lt;p&gt;Originally I chose A for item 0, B for item 1, etc ...&amp;#160; This made sense at the time because it kept the syntax short.&amp;#160; However I've grown to dislike this naming convention.&amp;#160; Primarily because it violates #3 and #4 above.&amp;#160; While A-E is perfectly clear for me I've talked with others who this confuses.&amp;#160; &lt;/p&gt;  &lt;p&gt;In addition, to keep the nameless syntax option I provided an indexer property.&amp;#160; So values are available with a 0 based index.&amp;#160; Since several languages expose this with the name &amp;quot;Item&amp;quot;, there are now really two names for a value.&amp;#160; For example the first value is both tuple.A and tuple.Item[0].&amp;#160; &lt;/p&gt;  &lt;p&gt;After some thought I decided to name the values Item0-&amp;gt;Item4 depending on the size of the tuple.&amp;#160; &lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8599391" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Rant/default.aspx">Rant</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category></item><item><title>RantPack Update</title><link>http://blogs.msdn.com/jaredpar/archive/2008/06/02/rantpack-update.aspx</link><pubDate>Tue, 03 Jun 2008 03:26:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8570651</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8570651.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8570651</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8570651</wfw:comment><description>&lt;p&gt;I released a new version of RantPack today.&amp;#160; Mostly this is a bug fix release with a couple of minor new features.&lt;/p&gt;  &lt;p&gt;&lt;a title="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1119" href="https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1119"&gt;https://code.msdn.microsoft.com/Release/ProjectReleases.aspx?ProjectName=RantPack&amp;amp;ReleaseId=1119&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Features&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Added a way to shim Immutable collections to non-immutable interfaces to increase the level of interoperability.&amp;#160; The collections are still immutable and throw an exception whenever one of the mutable APIs are called.&amp;#160; However if the collection is used in an immutable fashion, such as data binding, CollectionUtility.Create* can be used to quickly create a wrapper&lt;/li&gt; &lt;/ul&gt;  &lt;pre class="code"&gt;&lt;span style="color: blue"&gt;var &lt;/span&gt;q = &lt;span style="color: #2b91af"&gt;ImmutableStack&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt;.Empty;
&lt;span style="color: #2b91af"&gt;CollectionUtility&lt;/span&gt;.GetRangeCount(1, 10).ForEach(x =&amp;gt; q = q.Push(x));
&lt;span style="color: #2b91af"&gt;ICollection&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;&amp;gt; list = &lt;span style="color: #2b91af"&gt;CollectionUtility&lt;/span&gt;.CreateICollection(q);

&lt;span style="color: blue"&gt;var &lt;/span&gt;m = &lt;span style="color: #2b91af"&gt;ImmutableAvlTree&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt;.Empty;
&lt;span style="color: #2b91af"&gt;CollectionUtility&lt;/span&gt;.GetRangeCount(1, 10).ForEach(x =&amp;gt; m = m.Add(x, x.ToString()));
&lt;span style="color: #2b91af"&gt;IDictionary&lt;/span&gt;&amp;lt;&lt;span style="color: blue"&gt;int&lt;/span&gt;, &lt;span style="color: blue"&gt;string&lt;/span&gt;&amp;gt; map = &lt;span style="color: #2b91af"&gt;CollectionUtility&lt;/span&gt;.CreateIDictionary(m);&lt;/pre&gt;
&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;

&lt;ul&gt;
  &lt;li&gt;Added an immutable queue named ImmutableQueue&lt;/li&gt;

  &lt;li&gt;Added more overloads to Immutable*.Create to allow more interoperability with BCL data structures.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Bugs&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;MutableTuple.GetHashCode() violated the contract for Object.GetHashCode() by allowing updates to mutate the hash code&lt;/li&gt;
&lt;/ul&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8570651" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/Patterns/default.aspx">Patterns</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category></item><item><title>RantPack - A utility library</title><link>http://blogs.msdn.com/jaredpar/archive/2008/04/30/rantpack-a-utility-library.aspx</link><pubDate>Thu, 01 May 2008 06:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8446131</guid><dc:creator>Jared Parsons</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/jaredpar/comments/8446131.aspx</comments><wfw:commentRss>http://blogs.msdn.com/jaredpar/commentrss.aspx?PostID=8446131</wfw:commentRss><wfw:comment>http://blogs.msdn.com/jaredpar/rsscomments.aspx?PostID=8446131</wfw:comment><description>&lt;P&gt;I often post code examples, samples and snippets on this blog.&amp;nbsp; Many of these samples are a part of a utility library I've been writing and maintaining for many years now.&amp;nbsp; Essentially since I got involved in DotNet programming.&lt;/P&gt;
&lt;P&gt;I write a lot of code for&amp;nbsp;internal apps, demos&amp;nbsp;and hobby projects.&amp;nbsp; Having a utility library to tote around with me greatly increases my impact in a project because it gives me a place to put common code that I would otherwise have to repeatedly cut and paste into projects.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;Whenever I work on something I think the community at large would benefit from I try to blog about it.&amp;nbsp; Unfortunately for the more complex samples blogging is not always easy.&amp;nbsp; Complex structures don't really fit on a blog and often utilities depend on utilities and it forces users to cut and paste between multiple blog entries.&amp;nbsp; Not good. &lt;/P&gt;
&lt;P&gt;Now with &lt;A href="http://code.msdn.com/" mce_href="http://code.msdn.com"&gt;http://code.msdn.com&lt;/A&gt; I have a forum to fully share the items I've been working on.&amp;nbsp; This is the perfect place to share code for the community and helps avoid the messiness of cutting and pasting blog posts.&amp;nbsp; As such I've released my Library, &lt;A href="http://code.msdn.microsoft.com/RantPack" mce_href="http://code.msdn.microsoft.com/RantPack"&gt;RantPack&lt;/A&gt;, on Code Gallery.&amp;nbsp; This includes both binaries and sources and is covered under the &lt;A href="http://code.msdn.microsoft.com/RantPack/Project/License.aspx" mce_href="http://code.msdn.microsoft.com/RantPack/Project/License.aspx"&gt;Microsoft Public License&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;RantPack is available at &lt;A title=http://code.msdn.microsoft.com/RantPack href="http://code.msdn.microsoft.com/RantPack" mce_href="http://code.msdn.microsoft.com/RantPack"&gt;http://code.msdn.microsoft.com/RantPack&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;A couple of notes on the sample. This is mainly for education and sharing purposes.&amp;nbsp; The goal of this library is to make developing software faster and more reliable.&amp;nbsp; It includes, but is not limited to &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Functional Programming Patterns&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Tuples&lt;/LI&gt;
&lt;LI&gt;Immutable/Persistent collections&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;Threading &lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;Futures&lt;/LI&gt;
&lt;LI&gt;Active Objects&lt;/LI&gt;
&lt;LI&gt;Various other primitives&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;General Patterns&lt;/LI&gt;
&lt;LI&gt;General Utilities&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Another item you will find browsing the sources are tests.&amp;nbsp; Lots and lots of tests.&amp;nbsp; At the time of this writing there are around 400 some odd unit tests on the library.&amp;nbsp; There is nothing more frustrating than a utility library that doesn't work.&amp;nbsp; As such I rigorously test the code I write. &lt;/P&gt;
&lt;P&gt;Although I performance test much of my code and it performs great in the applications I use it for I'm sure there are a few cases I missed.&amp;nbsp; Please feel free to point this out to me and I'll look into them.&lt;/P&gt;
&lt;P&gt;Why the name RantPack?&amp;nbsp; My blog is Rantings of a programmer and it's a pack of code :)&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8446131" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/jaredpar/archive/tags/DotNet/default.aspx">DotNet</category><category domain="http://blogs.msdn.com/jaredpar/archive/tags/RantPack/default.aspx">RantPack</category></item></channel></rss>