<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Elegant Invariant Checking with C# 3</title>
	<atom:link href="http://andrewpeters.net/2008/07/30/invariant-checking/feed/" rel="self" type="application/rss+xml" />
	<link>http://andrewpeters.net/2008/07/30/invariant-checking/</link>
	<description>C# &#38; .NET Development, NHaml, PowerShell Gadget, Inflector.NET...</description>
	<pubDate>Fri, 21 Nov 2008 09:09:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.3</generator>
		<item>
		<title>By: Andrew</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-988</link>
		<dc:creator>Andrew</dc:creator>
		<pubDate>Fri, 01 Aug 2008 03:01:02 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-988</guid>
		<description>Stuart,

This is done by picking apart and inspecting the expression tree resulting from the lambda.

Cheers,

Andrew.</description>
		<content:encoded><![CDATA[<p>Stuart,</p>
<p>This is done by picking apart and inspecting the expression tree resulting from the lambda.</p>
<p>Cheers,</p>
<p>Andrew.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stuart Clark</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-987</link>
		<dc:creator>Stuart Clark</dc:creator>
		<pubDate>Fri, 01 Aug 2008 02:20:00 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-987</guid>
		<description>I like the idea its got me thinking. The question I have is:

Check.Argument(() =&#62; arg1.IsNotNull); // throws ArgumentNullException

How would you determine the argument name when constructing your ArgumentNullException. 

Without that its the equivalent of your original code minus the string argument name.

Invariant.ArgumentNotNull(arg1);</description>
		<content:encoded><![CDATA[<p>I like the idea its got me thinking. The question I have is:</p>
<p>Check.Argument(() =&gt; arg1.IsNotNull); // throws ArgumentNullException</p>
<p>How would you determine the argument name when constructing your ArgumentNullException. </p>
<p>Without that its the equivalent of your original code minus the string argument name.</p>
<p>Invariant.ArgumentNotNull(arg1);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Judah Himango</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-985</link>
		<dc:creator>Judah Himango</dc:creator>
		<pubDate>Thu, 31 Jul 2008 16:53:07 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-985</guid>
		<description>Regarding your use of C# 3 syntax to get around the redundancy, I suggested something similar to the CuttingEdge.Conditions library:

http://www.codeproject.com/script/Forums/View.aspx?fid=1498290&#38;msg=2640907

But the author said:

&lt;i&gt;I'm sorry Judah,

but it's even worse than you would expect. I just did some performance testing. I compared the following two lines:

a.Requires("a").IsNotNull();

compared to:

a.Requires(() =&#62; a).IsNotNull();

What's the difference? Well, the first line actually doesn't even allocate a string. It just uses a reference (a 32 bit number) to reference a string that is already allocated (and as long as that string isn't used, there only the cost of copying an Int32 on the stack).

The second isn't a simple delegate allocation. It actually allocates 7 new objects on the heap, makes at least 9 (non-inlinable) method calls and does some heavy reflection to build up the Expression (see for yourself with Reflector). And the worst part is that it doesn't do this only once during initialization. No, it does this every time a call to Requires(() =&#62; a) is made.

I found that the second statement is actually over 200 times slower than the first. here
you can take a look at my test code.&lt;/i&gt;</description>
		<content:encoded><![CDATA[<p>Regarding your use of C# 3 syntax to get around the redundancy, I suggested something similar to the CuttingEdge.Conditions library:</p>
<p><a href="http://www.codeproject.com/script/Forums/View.aspx?fid=1498290&amp;msg=2640907" rel="nofollow">http://www.codeproject.com/script/Forums/View.aspx?fid=1498290&amp;msg=2640907</a></p>
<p>But the author said:</p>
<p><i>I&#8217;m sorry Judah,</p>
<p>but it&#8217;s even worse than you would expect. I just did some performance testing. I compared the following two lines:</p>
<p>a.Requires(&#8221;a&#8221;).IsNotNull();</p>
<p>compared to:</p>
<p>a.Requires(() =&gt; a).IsNotNull();</p>
<p>What&#8217;s the difference? Well, the first line actually doesn&#8217;t even allocate a string. It just uses a reference (a 32 bit number) to reference a string that is already allocated (and as long as that string isn&#8217;t used, there only the cost of copying an Int32 on the stack).</p>
<p>The second isn&#8217;t a simple delegate allocation. It actually allocates 7 new objects on the heap, makes at least 9 (non-inlinable) method calls and does some heavy reflection to build up the Expression (see for yourself with Reflector). And the worst part is that it doesn&#8217;t do this only once during initialization. No, it does this every time a call to Requires(() =&gt; a) is made.</p>
<p>I found that the second statement is actually over 200 times slower than the first. here<br />
you can take a look at my test code.</i></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jason Bock</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-984</link>
		<dc:creator>Jason Bock</dc:creator>
		<pubDate>Thu, 31 Jul 2008 16:04:58 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-984</guid>
		<description>Have you seen this?

http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=38#body</description>
		<content:encoded><![CDATA[<p>Have you seen this?</p>
<p><a href="http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=38#body" rel="nofollow">http://www.cuttingedge.it/blogs/steven/pivot/entry.php?id=38#body</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raimon</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-982</link>
		<dc:creator>Raimon</dc:creator>
		<pubDate>Thu, 31 Jul 2008 15:19:26 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-982</guid>
		<description>this code can be used in generating documentation. 

Invariant.ArgumentNotNull(arg1, "arg1"); // throws ArgumentNullException
Invariant.ArgumentNotEmpty(arg2, "arg2"); // throws ArgumentOutOfRangeException

it's cool</description>
		<content:encoded><![CDATA[<p>this code can be used in generating documentation. </p>
<p>Invariant.ArgumentNotNull(arg1, &#8220;arg1&#8243;); // throws ArgumentNullException<br />
Invariant.ArgumentNotEmpty(arg2, &#8220;arg2&#8243;); // throws ArgumentOutOfRangeException</p>
<p>it&#8217;s cool</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dan Goldstein</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-980</link>
		<dc:creator>Dan Goldstein</dc:creator>
		<pubDate>Thu, 31 Jul 2008 14:07:33 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-980</guid>
		<description>I'm not so sure I see a big improvement. Invariant.ArgumentIsNotNull has the advantage of having the requirement at the beginning, not polluting intellisense and not having an ugly parameterless lambda function. Your new method only saves the need to specify the name of the argument in addition to its value.</description>
		<content:encoded><![CDATA[<p>I&#8217;m not so sure I see a big improvement. Invariant.ArgumentIsNotNull has the advantage of having the requirement at the beginning, not polluting intellisense and not having an ugly parameterless lambda function. Your new method only saves the need to specify the name of the argument in addition to its value.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Poul Foged</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-979</link>
		<dc:creator>Poul Foged</dc:creator>
		<pubDate>Thu, 31 Jul 2008 12:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-979</guid>
		<description>Whats wrong with:

Invariant.ArgumentNotNull(arg1);  

or

Invariant.Argument(arg1).IsNotNull();

- reflection should help us reveal the parameters real name....</description>
		<content:encoded><![CDATA[<p>Whats wrong with:</p>
<p>Invariant.ArgumentNotNull(arg1);  </p>
<p>or</p>
<p>Invariant.Argument(arg1).IsNotNull();</p>
<p>- reflection should help us reveal the parameters real name&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Rusk</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-974</link>
		<dc:creator>John Rusk</dc:creator>
		<pubDate>Thu, 31 Jul 2008 09:55:36 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-974</guid>
		<description>What about putting the magic method later in the fluent API, outside the expression, something like:

Check.That(()=&#62; arg1).IsNotNull();

In that case there'd be no extension methods, but would be too many parentheses for my liking... 

What about

Require.Value( () =&#62; arg1);</description>
		<content:encoded><![CDATA[<p>What about putting the magic method later in the fluent API, outside the expression, something like:</p>
<p>Check.That(()=&gt; arg1).IsNotNull();</p>
<p>In that case there&#8217;d be no extension methods, but would be too many parentheses for my liking&#8230; </p>
<p>What about</p>
<p>Require.Value( () =&gt; arg1);</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sergey</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-964</link>
		<dc:creator>Sergey</dc:creator>
		<pubDate>Thu, 31 Jul 2008 05:28:11 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-964</guid>
		<description>Cool!

Tought in boo it is much more simple :)

def DbC[[Required(extendee != null, "extendee must be not null")]extendee as object]:

PS
What about ensures?</description>
		<content:encoded><![CDATA[<p>Cool!</p>
<p>Tought in boo it is much more simple :)</p>
<p>def DbC[[Required(extendee != null, "extendee must be not null")]extendee as object]:</p>
<p>PS<br />
What about ensures?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Johnny Hall</title>
		<link>http://andrewpeters.net/2008/07/30/invariant-checking/#comment-951</link>
		<dc:creator>Johnny Hall</dc:creator>
		<pubDate>Wed, 30 Jul 2008 12:35:48 +0000</pubDate>
		<guid isPermaLink="false">http://andrewpeters.net/?p=104#comment-951</guid>
		<description>I'm liking the look of this, although I haven't been so concerned with the issue to evaluate it properly yet.

http://research.microsoft.com/SpecSharp/</description>
		<content:encoded><![CDATA[<p>I&#8217;m liking the look of this, although I haven&#8217;t been so concerned with the issue to evaluate it properly yet.</p>
<p><a href="http://research.microsoft.com/SpecSharp/" rel="nofollow">http://research.microsoft.com/SpecSharp/</a></p>
]]></content:encoded>
	</item>
</channel>
</rss>
