<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xml:base="http://thoughtshapes.com" xmlns:dc="http://purl.org/dc/elements/1.1/">
<channel>
 <title>ThoughtShapes - DotNet - Comments</title>
 <link>http://thoughtshapes.com/taxonomy/term/11</link>
 <description>Comments for &quot;DotNet&quot;</description>
 <language>en</language>
<item>
 <title>It&#039;s coming.</title>
 <link>http://thoughtshapes.com/node/74#comment-654</link>
 <description>&lt;p&gt;It&#039;s coming.&lt;/p&gt;
</description>
 <pubDate>Sat, 22 Nov 2008 21:16:14 -0500</pubDate>
 <dc:creator>Anonymous</dc:creator>
 <guid isPermaLink="false">comment 654 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>Sweet!  Thanks!</title>
 <link>http://thoughtshapes.com/node/69#comment-589</link>
 <description>&lt;p&gt;Sweet!  Thanks!&lt;/p&gt;
</description>
 <pubDate>Wed, 31 Oct 2007 14:34:09 -0400</pubDate>
 <dc:creator>jay</dc:creator>
 <guid isPermaLink="false">comment 589 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>You sure do get it Jay. But</title>
 <link>http://thoughtshapes.com/node/69#comment-588</link>
 <description>&lt;p&gt;You sure do get it Jay. But I kinda already knew that.&lt;/p&gt;
&lt;p&gt;I am thrilled that the post was so timely and helped.&lt;/p&gt;
</description>
 <pubDate>Wed, 31 Oct 2007 14:26:52 -0400</pubDate>
 <dc:creator>Rjae Easton</dc:creator>
 <guid isPermaLink="false">comment 588 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>I hope you don&#039;t mind, but I</title>
 <link>http://thoughtshapes.com/node/69#comment-587</link>
 <description>&lt;p&gt;I hope you don&#039;t mind, but I replaced &amp;lt;code&amp;gt; with &amp;lt;pre class=&quot;code cs&quot;&amp;gt; to retain your formatting.&lt;/p&gt;
</description>
 <pubDate>Wed, 31 Oct 2007 14:25:35 -0400</pubDate>
 <dc:creator>Rjae Easton</dc:creator>
 <guid isPermaLink="false">comment 587 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>sorry for the formatting of</title>
 <link>http://thoughtshapes.com/node/69#comment-586</link>
 <description>&lt;p&gt;sorry for the formatting of the code.&lt;br /&gt;
There were spaces there when I hit post :P&lt;/p&gt;
</description>
 <pubDate>Wed, 31 Oct 2007 13:16:00 -0400</pubDate>
 <dc:creator>jay</dc:creator>
 <guid isPermaLink="false">comment 586 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>I get it!
So I must admit</title>
 <link>http://thoughtshapes.com/node/69#comment-585</link>
 <description>&lt;p&gt;I get it!&lt;br /&gt;
So I must admit that the terms Closure and lexical context threw me off at first.  But when I replaced them with Scope and Stack (and happened to be using something like this in a unit test I was writing) it coalesced for me.&lt;/p&gt;
&lt;p&gt;My example was this:&lt;/p&gt;
&lt;pre class=&quot;code cs&quot;&gt;[Test]
public SomeWorkRelatedUnitTestIWasWorkingOnThatTestsThreadSafetyOfACertainCall()
{
      // Some Mocking initialization goes here
      //....

      List autos = new List();
      for (int i = 0; i &amp;lt; 1; i++)
      {
          autos.Add(new AutoResetEvent(false));                
            ThreadPool.QueueUserWorkItem(
                delegate
                    {
                        myWorker.InitializeProcessors(true, mySettings);
                        autos[i].Set();
                    });
       }
       WaitHandle.WaitAll(autos.ToArray());
       myMocks.VerifyAllExpectationsHaveBeenMet();
}
&lt;/pre&gt;&lt;p&gt;
When I ran my test I was getting an exception at the autos[i].Set() call.  at this point i was 1, when I expected it to be 0.  I remember reading this post this morning and hopped on back to see what I was missing.&lt;/p&gt;
&lt;p&gt;Rjae&#039;s words (once I understood them) were exactly what was happening to me.  i was continuing to increment while the work was being done, because the delegate has a view into the scope that i lives at.&lt;br /&gt;
When I switched to something like:&lt;/p&gt;
&lt;pre class=&quot;code cs&quot;&gt;[Test]
public SomeWorkRelatedUnitTestIWasWorkingOnThatTestsThreadSafetyOfACertainCall()
{
     List autos = new List();
     for (int i = 0; i &amp;lt; 1; i++)
     {
         int anotherI = i;
         autos.Add(new AutoResetEvent(false));                
           ThreadPool.QueueUserWorkItem(
              delegate
                    {
                        myWorker.InitializeProcessors(true, mySettings);
                        autos[anotherI].Set();
                    });
      }
      WaitHandle.WaitAll(autos.ToArray());
}
&lt;/pre&gt;&lt;p&gt;It really became clear to me what Rjae was saying.  It&#039;s almost like a delegate gets it&#039;s own &quot;local(ish)&quot; storage.&lt;/p&gt;
&lt;p&gt;Thanks Rjae for the timely post!&lt;/p&gt;
</description>
 <pubDate>Wed, 31 Oct 2007 13:14:00 -0400</pubDate>
 <dc:creator>jay</dc:creator>
 <guid isPermaLink="false">comment 585 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>The Monostate design pattern</title>
 <link>http://thoughtshapes.com/node/49#comment-57</link>
 <description>&lt;p&gt;The Monostate design pattern takes the general form:&lt;/p&gt;
&lt;pre class=&quot;code cs&quot;&gt;public class ClassName
{
    private static int theStaticState = 0;

    public virtual int StaticState
    {
        get { return theStaticState; }
        set { theStaticState = value; }
    }
}
&lt;/pre&gt;&lt;p&gt;The type itself is not limited to a single instance but its state is. In this way the benefits of polymorphism are protected (no pun intended ;-).&lt;/p&gt;
</description>
 <pubDate>Mon, 30 Apr 2007 10:37:26 -0400</pubDate>
 <dc:creator>Rjae Easton</dc:creator>
 <guid isPermaLink="false">comment 57 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>I should add that there is</title>
 <link>http://thoughtshapes.com/node/49#comment-56</link>
 <description>&lt;p&gt;I should add that there is another way for a MarshalByRefObject to indicate infinite lifetime. Return null from InitializeLifetimeService as in:&lt;/p&gt;
&lt;pre class=&quot;code cs&quot;&gt;public override object InitializeLifetimeService()
{
    return null;
}
&lt;/pre&gt;&lt;p&gt;Unless your object needs control over sponsor and renewal lifetime it is best to use this approach.&lt;/p&gt;
</description>
 <pubDate>Mon, 30 Apr 2007 10:19:52 -0400</pubDate>
 <dc:creator>Rjae Easton</dc:creator>
 <guid isPermaLink="false">comment 56 at http://thoughtshapes.com</guid>
</item>
<item>
 <title>I&#039;d like to point something</title>
 <link>http://thoughtshapes.com/node/49#comment-55</link>
 <description>&lt;p&gt;I&#039;d like to point something out that might not be obvious to all readers.  In Rjae&#039;s post you&#039;ll notice that he doesn&#039;t provide the code for the types he mentions (Message and MessageRepository) but instead provides the test fixtures that test these types.  This is a very important, conscious (and I believe totally correct) decision he must have made and it emphasizes what we practice: The tests are the most important thing in the code.  I say &quot;must have made&quot; in the previous sentence because I normally don&#039;t like making assumptions about another&#039;s thoughts,  but I do know the way Rjae thinks in regards to this area and I also know his thoughts totally jibe with mine.&lt;/p&gt;
&lt;p&gt;One perspective in particular to try to grab hold of is to look at the test fixture method names.  When I read the test method names I gain an instant understanding of what the behavior of the CUT (Class Under Test) is.  I therefore gain a much quicker understanding of the class than I would if I was looking at the actual code for the class.  I&#039;m not sure how obvious this is to readers, so I think it&#039;s worth mentioning.  Even if you&#039;re only developing a class library for a client, it&#039;s a good idea to ship all the tests with the code.  I know that if I hire someone to create a library for me I&#039;d be giddy if they give me all the tests.  (This is really not true, but only because I&#039;d expect all the tests in advance--since that would be part of the contract with the library writer.  If I didn&#039;t have such a contract, then I&#039;d be giddy.)&lt;/p&gt;
&lt;p&gt;And, as I&#039;ve said before and will say again, this is why the tests serve as the documentation.&lt;/p&gt;
</description>
 <pubDate>Fri, 27 Apr 2007 10:15:13 -0400</pubDate>
 <dc:creator>Steve Seymour</dc:creator>
 <guid isPermaLink="false">comment 55 at http://thoughtshapes.com</guid>
</item>
</channel>
</rss>
