<?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>Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx</link><description>Upon submitting that specification for review, even before seeing my code, Chris found a bug and an omission. 
 The omission is that I neglected to say what happens when the ref variable is an index into a fixed-size array buffer. As it turns out, that</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#10208600</link><pubDate>Fri, 09 Sep 2011 16:09:38 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:10208600</guid><dc:creator>Limited Atonement</dc:creator><description>&lt;p&gt;I&amp;#39;m sure you agree that &amp;quot;whitelist programming&amp;quot; (a term from a comment to some other blog that I like, although I can&amp;#39;t seem to find it anywhere else) is a bad idea when it can be avoided. &amp;nbsp;Is there any way to get at (things like) this correctly through and through? &amp;nbsp;By &amp;quot;whitelist programming&amp;quot; I mean going through and making a list of cases and programming to all those and hoping (against hope) that you&amp;#39;ll get all the cases. &amp;nbsp;This isn&amp;#39;t systematic. &amp;nbsp;Is it provable?&lt;/p&gt;
&lt;p&gt;Thanks for the post, very informative.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=10208600" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9929686</link><pubDate>Sat, 28 Nov 2009 19:11:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9929686</guid><dc:creator>Vladimir Reshetnikov</dc:creator><description>&lt;p&gt;Eric, what about this example?&lt;/p&gt;
&lt;p&gt;struct S&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;	int X;&lt;/p&gt;
&lt;p&gt;	static void Main()&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		S[][] s = { };&lt;/p&gt;
&lt;p&gt;		Foo(ref s[Bar(1)][Bar(2)].X);&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	static int Bar(int x)&lt;/p&gt;
&lt;p&gt;	{&lt;/p&gt;
&lt;p&gt;		System.Console.WriteLine(x);&lt;/p&gt;
&lt;p&gt;		return 0;&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;	static void Foo(ref int x) { }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;Will your implementation print 1 or 1 2 before throwing IndexOutOfRangeException?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9929686" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9929653</link><pubDate>Sat, 28 Nov 2009 15:43:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9929653</guid><dc:creator>Vladimir Reshetnikov</dc:creator><description>&lt;p&gt;Eric, your classification of possible ref/out arguments misses 'this' access in structures.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9929653" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9928361</link><pubDate>Wed, 25 Nov 2009 03:47:21 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9928361</guid><dc:creator>James</dc:creator><description>&lt;p&gt;&amp;quot;And anyone have any guesses as to why I needed this function implemented?&amp;quot;&lt;/p&gt;
&lt;p&gt;IntelliTrace&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928361" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9928119</link><pubDate>Tue, 24 Nov 2009 17:59:43 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9928119</guid><dc:creator>Zak Jensen</dc:creator><description>&lt;p&gt;@Pop.Catalin&lt;/p&gt;
&lt;p&gt;Whoops, that detail escaped me. For some reason, I imagined that the Display() call was the lambda. I'll read closer next time :)&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928119" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9928062</link><pubDate>Tue, 24 Nov 2009 16:31:37 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9928062</guid><dc:creator>Catalin Pop Sever</dc:creator><description>&lt;p&gt;@Zak Jensen, &lt;/p&gt;
&lt;p&gt;I think you've misread the example. &lt;/p&gt;
&lt;p&gt;There are &amp;quot;two&amp;quot; calls to Console.WriteLine in a &amp;quot;single&amp;quot; instance method of a immutable value type. The instance method is called only &amp;quot;once&amp;quot;, but the output is &amp;quot;two&amp;quot; different values, from within the same instance method that accesses a read only field of the instance.&lt;/p&gt;
&lt;p&gt;Basically the instance method reads a field of it's immutable value type instance twice and gets two different values.&lt;/p&gt;
&lt;p&gt;Besides, the example can be rewritten without lambdas, by promoting the local immutable value to a field (by using a lambda that captures the variable the compiler does the same thing basically).&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9928062" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9927964</link><pubDate>Tue, 24 Nov 2009 14:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9927964</guid><dc:creator>Zak Jensen</dc:creator><description>&lt;p&gt;Pop.Catalin said: &amp;quot;P.S. Even Immutable value types aren't thread safe, not just mutable value types&amp;quot;.&lt;/p&gt;
&lt;p&gt;The immutable value type is still thread safe, the lambda expression is not. From the C#3 specification:&lt;/p&gt;
&lt;p&gt;&amp;quot;The body has access to the outer variables (&amp;#167;7.14.4) of the anonymous function. Access of an outer variable will reference the instance of the variable that is active at the time the lambda-expression or anonymous-method-expression is evaluated (&amp;#167;7.14.5).&amp;quot;&lt;/p&gt;
&lt;p&gt;i.e. The lambda captures the variable, not it's value.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9927964" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9927893</link><pubDate>Tue, 24 Nov 2009 12:30:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9927893</guid><dc:creator>Laura T.</dc:creator><description>&lt;p&gt;My guess would go for STM, some atomic {} optimization.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9927893" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9927863</link><pubDate>Tue, 24 Nov 2009 11:26:58 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9927863</guid><dc:creator>Catalin Pop Sever</dc:creator><description>&lt;p&gt;&amp;quot;Once more, mutable value types are revealed to be pure concentrated evil&amp;quot;&lt;/p&gt;
&lt;p&gt;You didn't really mean that, did you? :P&lt;/p&gt;
&lt;p&gt;Pure evil means absolutely no good can come out of mutable value types (Yes that's and absolute statement) and only bad things.&lt;/p&gt;
&lt;p&gt;What I've found is that value types complicate the code allot in multi threading scenarios &amp;nbsp;(in place mutable state), but, I've found value types to be a invaluable tool dozens of times, when there was a performance requirement and resource requirement (memory) above all other requirements (and I mean 2 -3x more computational performance compared to classes, and less than half memory usage). &lt;/p&gt;
&lt;p&gt;I can understand why some people don't like value types, but I really and truly love them :)&lt;/p&gt;
&lt;p&gt;P.S. Even Immutable value types aren't thread safe, not just mutable value types, &lt;a rel="nofollow" target="_new" href="http://stackoverflow.com/questions/370859/why-isnan-is-a-static-method-on-the-double-class-instead-of-an-instance-property/370996#370996"&gt;http://stackoverflow.com/questions/370859/why-isnan-is-a-static-method-on-the-double-class-instead-of-an-instance-property/370996#370996&lt;/a&gt;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9927863" width="1" height="1"&gt;</description></item><item><title>re: Always write a spec, Part Two</title><link>http://blogs.msdn.com/b/ericlippert/archive/2009/11/23/always-write-a-spec-part-two.aspx#9927677</link><pubDate>Tue, 24 Nov 2009 02:16:59 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9927677</guid><dc:creator>Michael McMullen</dc:creator><description>&lt;p&gt;That was one of the other things I was thinking of, but that would also require you to ensure that the method itself does not have any side effects. &amp;nbsp;Most of the other possibilities I thought of also had this restriction, and since ref/out parameters were a major consideration in the spec, it doesn't seem likely that whatever this is for would require the method to have no side effects.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9927677" width="1" height="1"&gt;</description></item></channel></rss>