<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>GrinGod [dot] Com &#187; .Net</title>
	<atom:link href="http://www.gringod.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.gringod.com</link>
	<description>Randomised nonsense.</description>
	<lastBuildDate>Fri, 16 Jul 2010 18:42:32 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>The SharePoint Adrenalin Moment</title>
		<link>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/</link>
		<comments>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 20:20:31 +0000</pubDate>
		<dc:creator>gringod</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[moss]]></category>
		<category><![CDATA[sharepoint]]></category>
		<category><![CDATA[twitter]]></category>

		<guid isPermaLink="false">http://www.gringod.com/?p=719</guid>
		<description><![CDATA[I&#8217;ve been developing with SharePoint for about 9 month now, and by developing I don&#8217;t mean airy-fairy SharePoint Designer drag-and-drop, I mean proper getting your hands dirty in code because SharePoint doesn&#8217;t have an *cough* out of the box *cough* feature that does what you want.
Mostly, deployment is done in two stages, firstly to a [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been developing with SharePoint for about 9 month now, and by developing I don&#8217;t mean airy-fairy SharePoint Designer drag-and-drop, I mean proper getting your hands dirty in code because SharePoint doesn&#8217;t have an <em>*cough*</em> out of the box <em>*cough*</em> feature that does what you want.</p>
<p>Mostly, deployment is done in two stages, firstly to a UAT box and then to a Live box.  Obviously the most efficient way to do this is to bundle your features into a solution which can easily be deployed onto any number of machines.  But, it does mean you have to make sure you&#8217;ve got everything right.  Untangling mistakes in your code can be a right royal pain in the arse.</p>
<p>By the time you&#8217;ve developed your solution, tested it out, deployed it to UAT and tested it again you should be fairly confident that when you come to deploy it on the Live server things should go pretty smoothly.  And, touch wood, to date things have gone smoothly.</p>
<p>But I still can&#8217;t get over that rush of adrenaline that comes with clicking &#8220;Activate Feature&#8221; after deploying the solution on Live.  In the second or two whilst the page waits to reload my mind runs through all the possible things that could go wrong and how long it would take me to unpick the changes my code might have got half way though.  Then the page finally loads&#8230;..</p>
<p>&#8230;.. &#8220;Feature Activated&#8221;, phew!  Time for a lie down to clam my nerves.</p>
 <img src="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=719" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2009/03/10/the-sharepoint-adrenalin-moment/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Try&#8230;Catch For No Reason</title>
		<link>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/</link>
		<comments>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/#comments</comments>
		<pubDate>Mon, 11 Aug 2008 13:49:24 +0000</pubDate>
		<dc:creator>gringod</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[best practice]]></category>
		<category><![CDATA[Exceptions]]></category>

		<guid isPermaLink="false">http://www.gringod.com/2008/08/11/trycatch-for-no-reason/</guid>
		<description><![CDATA[I’ve seen this time and time again and I’m sure just about every developer out there has seem the same sort of thing:
try {
    //many lines of code
catch (Exception ex) {
    throw new Exception(&#34;Something went wrong dude!&#34;);
}


.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre [...]]]></description>
			<content:encoded><![CDATA[<p>I’ve seen this time and time again and I’m sure just about every developer out there has seem the same sort of thing:</p>
<blockquote><pre class="csharpcode"><span class="kwrd">try</span> {
    <span class="rem">//many lines of code</span>
<span class="kwrd">catch</span> (Exception ex) {
    <span class="kwrd">throw</span> <span class="kwrd">new</span> Exception(<span class="str">&quot;Something went wrong dude!&quot;</span>);
}</pre>
</blockquote>
<style type="text/css">
<p>.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>This is probably the single most un-helpful piece of code a developer can write.&#160; All you are doing is making you life and future developers lives harder when it comes to debugging.&#160; The whole point of the try…catch block is for times when you know an exception may happen and it allows you to gracefully handle it without the whole system crashing to the ground.</p>
<p>So lets have a closer look at what’s wrong with this code:</p>
<p><span id="more-679"></span></p>
<h1>Too many lines wrapped</h1>
<p>You wrap code in a try…catch block the idea is to only wrap the code that is likely to throw an exception.&#160; Whilst it isn’t impossible, it does make identifying the offending line of code harder to find.&#160; This may sound like a trivial reason to complain but when you have to deal with this day after day it does get a little tedious.</p>
<h1>Indiscriminate exception handling</h1>
<p>By catching exceptions of type Exception you’re really saying to developers that come after you “I don’t care enough about this code to know what exceptions might happen.”&#160; In many instances different exception types can be handled in different ways.&#160; I’m betting that the default response of most developers that catch Exception will be to throw a cryptic message at the user and drop out of whatever the method was – probably without clean up resources either.</p>
<p>It is possible to have multiple catch blocks that catch different exception types if you think that there are multiple types of exceptions that might be thrown:</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">try</span> {
    File.WriteAllText<span class="str">&quot;(@&quot;</span>c:\test.txt<span class="str">&quot;, &quot;</span>Hello world!&quot;);
}
<span class="kwrd">catch</span> (FileNotFoundException ex) {
    <span class="rem">// do something</span>
}
<span class="kwrd">catch</span> (SecurityException ex) {
    <span class="rem">// do something else</span>
}</pre>
</blockquote>
<p>This means that you can handle different exceptions in different ways.&#160; Also, any type of Exception that you don’t handle gets passed up the call stack.</p>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<h1>The exception isn’t handled</h1>
<p>In this particular instance the exception isn’t handled, so why on earth put the try…catch block there in the first place?!&#160; If all you’re going to do is throw a new exception or re-throw the old exception without doing anything you’re better off leaving out the try…catch block.&#160; It just adds overhead to instances when it runs through without exception.</p>
<h1>Original exception is masked</h1>
<p>Again, in this example a new exception is thrown.&#160; If you must do this then at least include the original exception as the inner exception (the exception that cause the new exception to be thrown).&#160; The Exception class even has a constructor to help with this:</p>
<blockquote>
<pre class="csharpcode"><span class="kwrd">public</span> Exception( <span class="kwrd">string</span> message, Exception inner )</pre>
</blockquote>
<p>Alternatively, you can throw the original exception.</p>
<h1>New exception is generalised</h1>
<p>By throwing the base Exception class you are forcing developers that use your code to have to catch exceptions of type Exception – see above for why this can be bad.&#160; If you can’t find a built-in exception class to use, and there are many, create your own.&#160; Visual Studio 2008 has a code snippet for creating an exception class, all you have to do is fill-in the blanks.</p>
<h1>In an ideal world…</h1>
</p>
<p>… I’d like .Net to have a similar method to java of having to specify (use attributes) what exceptions a method throws or catches.&#160; This allows you to easily find out what exceptions may originate in a method your code calls, and let other developers know what exceptions your code doesn’t handle.&#160; It also allows for pretty good compile time exception checking.&#160; It means extra code has to be written but I think it results in better code.</p>
 <img src="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=679" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2008/08/11/trycatch-for-no-reason/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Test Driven Porting</title>
		<link>http://www.gringod.com/2007/11/20/test-driven-porting/</link>
		<comments>http://www.gringod.com/2007/11/20/test-driven-porting/#comments</comments>
		<pubDate>Tue, 20 Nov 2007 15:34:33 +0000</pubDate>
		<dc:creator>gringod</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Bell Ringing]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[.Net]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Test-Driven-Development]]></category>
		<category><![CDATA[Test-Driven-Porting]]></category>

		<guid isPermaLink="false">http://www.gringod.com/2007/11/20/test-driven-porting/</guid>
		<description><![CDATA[Technorati Tags:  		Test-Driven-Development 		,  		Test-Driven-Porting 		,  		.Net 		,  		C# 		,  		C++ 		,  		Programming 		
Recently I&#8217;ve had reason to take an code library written in C++ and port it to C#.&#xA0; Whilst I dabbled in C++ on a compilers course at university, I hated it then and I still hate [...]]]></description>
			<content:encoded><![CDATA[<div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:00c73987-59b1-4d1a-a2cb-32b32ed5f479" style="padding-right: 0px; display: inline; padding-left: 0px; float: none; padding-bottom: 0px; margin: 0px; padding-top: 0px">Technorati Tags:  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvVGVzdC1Ecml2ZW4tRGV2ZWxvcG1lbnQv" rel=\"tag\">Test-Driven-Development</a> 		,  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvVGVzdC1Ecml2ZW4tUG9ydGluZy8=" rel=\"tag\">Test-Driven-Porting</a> 		,  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvLk5ldC8=" rel=\"tag\">.Net</a> 		,  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvQyMv" rel=\"tag\">C#</a> 		,  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvQysrLw==" rel=\"tag\">C++</a> 		,  		<a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2hub3JhdGkuY29tL3RhZ3MvUHJvZ3JhbW1pbmcv" rel=\"tag\">Programming</a> 		</div>
<p>Recently I&#8217;ve had reason to take an code library written in C++ and port it to C#.&#xA0; Whilst I dabbled in C++ on a compilers course at university, I hated it then and I still hate it now.&#xA0; I personally think it&#8217;s an abomination and should be consigned to the great garbage collector in the sky.&#xA0;&#xA0; Whilst I can just about read the C++ syntax there is a lot that I don&#8217;t understand about it.</p>
<p>The library I was porting had semi reasonable documentation outlining what classes exist and their methods and a brief description of the overall usage.&#xA0; This gave me a good starting point, however the documentation didn&#8217;t include example usages and expected results, for this I was forced to delve into the code.</p>
<p>One development paradigm I have been interested in but have been unable to find a decent project to test it on is Test-Driven-Development and this seemed like the perfect project to try it on.&#xA0; So I set to work on the first iteration getting the test set up.&#xA0;&#xA0; Without knowing exactly what results I should be expecting I was finding it hard going, so once again I dived back into the old code.</p>
<p>Thankfully, the developers of the C++ library had create a fairly comprehensive set of unit tests and with my limited C++ knowledge and a text editor with RegEx Find &amp; Replace I was quickly able to convert their unit tests into NUnit based unit tests.</p>
<p>For example, what started out life as:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span><span class="kwrd">void</span> test_row_multiply_change(<span class="kwrd">void</span>)</pre>
<pre><span class="lnum"> 2: </span>{</pre>
<pre class="alt"><span class="lnum"> 3: </span> row r;</pre>
<pre><span class="lnum"> 4: </span> RINGING_TEST( ( r *= change( 6, <span class="str">&quot;X&quot;</span> ) ) == <span class="str">&quot;214365&quot;</span> );</pre>
<pre class="alt"><span class="lnum"> 5: </span> RINGING_TEST( ( r *= change( 6, <span class="str">&quot;1&quot;</span> ) ) == <span class="str">&quot;241635&quot;</span> );</pre>
<pre><span class="lnum"> 6: </span> RINGING_TEST( ( r *= change( 8, <span class="str">&quot;X&quot;</span> ) ) == <span class="str">&quot;42615387&quot;</span> );</pre>
<pre class="alt"><span class="lnum"> 7: </span> RINGING_TEST( ( r *= change( 5, <span class="str">&quot;3&quot;</span> ) ) == <span class="str">&quot;24651387&quot;</span> );</pre>
<pre><span class="lnum"> 8: </span>&#xA0;</pre>
<pre class="alt"><span class="lnum"> 9: </span> RINGING_TEST( row( <span class="str">&quot;214365&quot;</span> ) * change( 7, <span class="str">&quot;5&quot;</span> ) == row( <span class="str">&quot;1234675&quot;</span> ) );</pre>
<pre><span class="lnum"> 10: </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Quickly became:</p>
<div class="csharpcode">
<pre class="alt"><span class="lnum"> 1: </span>[Test]</pre>
<pre><span class="lnum"> 2: </span><span class="kwrd">public</span> <span class="kwrd">void</span> TestMultiplicationByChange()</pre>
<pre class="alt"><span class="lnum"> 3: </span>{</pre>
<pre><span class="lnum"> 4: </span> Row r = <span class="kwrd">new</span> Row();</pre>
<pre class="alt"><span class="lnum"> 5: </span> Assert.AreEqual((Row)<span class="str">&quot;214365&quot;</span>, r *= <span class="kwrd">new</span> Change(6, <span class="str">&quot;X&quot;</span>) );</pre>
<pre><span class="lnum"> 6: </span> Assert.AreEqual((Row)<span class="str">&quot;241635&quot;</span>, r *= <span class="kwrd">new</span> Change(6, <span class="str">&quot;1&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 7: </span> Assert.AreEqual((Row)<span class="str">&quot;42615387&quot;</span>, r *= <span class="kwrd">new</span> Change(8, <span class="str">&quot;X&quot;</span> ));</pre>
<pre><span class="lnum"> 8: </span> Assert.AreEqual((Row)<span class="str">&quot;24651387&quot;</span>, r *= <span class="kwrd">new</span> Change(5, <span class="str">&quot;3&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 9: </span>&#xA0;</pre>
<pre><span class="lnum"> 10: </span> Assert.AreEqual((Row)<span class="str">&quot;1234675&quot;</span>, <span class="kwrd">new</span> Row(<span class="str">&quot;214365&quot;</span>) * <span class="kwrd">new</span> Change(7, <span class="str">&quot;5&quot;</span>));</pre>
<pre class="alt"><span class="lnum"> 11: </span>}</pre>
</div>
<style type="text/css">
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }</style>
<p>Now, with a full set of unit tests at my disposal I was quickly able to bash away at the library and very quickly got working code without the need to trawl through ghastly C++ code.</p>
<p>Hooray for Test-Driven-Development and three cheers for Test-Driven-Porting.</p>
<p><font size="1">ps. The library I&#8217;m porting is an open source library for Bell Ringing &#8211; yes I know I&#8217;m a geek but anyone that has followed everything else in this post must also be a geek <img src='http://www.gringod.com/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' /> .&#xA0; Once I&#8217;m finished I will be releasing my code under an open source license as well, I just need to pick the right one.</font></p>
<p><font size="1">pps. I may have exaggerated my hate of C++ a little.&#xA0; I believe all languages have their place, even the </font><a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Vzb3RlcmljLnZveGVscGVyZmVjdC5uZXQvd2lraS9MYW5ndWFnZV9saXN0"><font size="1">esoteric languages</font></a><font size="1"> like </font><a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2xvbGNvZGUuY29tLw=="><font size="1">LOLCode</font></a><font size="1">.</font></p>
<div class="wlWriterSmartContent" id="scid:C16BAC14-9A3D-4c50-9394-FBFEF7A93539:cf502d0c-443d-4be4-88e5-3d2832bfad62" style="padding-right: 0px; display: inline; padding-left: 0px; padding-bottom: 0px; margin: 0px; padding-top: 0px"><a href="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5kb3RuZXRraWNrcy5jb20va2ljay8/dXJsPWh0dHA6Ly93d3cuZ3JpbmdvZC5jb20vMjAwNy8xMS8yMC90ZXN0LWRyaXZlbi1wb3J0aW5nLw=="><img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://www.gringod.com/2007/11/20/test-driven-porting/" border="0" alt="kick it on DotNetKicks.com" /></a></div>
 <img src="http://www.gringod.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=605" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://www.gringod.com/2007/11/20/test-driven-porting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
