<?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>Haugerns Development Escapades &#187; dotnet</title>
	<atom:link href="http://www.haugern.net/blog/category/dotnet/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.haugern.net/blog</link>
	<description>Morten Haug on development and other curiosities</description>
	<lastBuildDate>Sun, 31 May 2009 21:56:23 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Beware of the IEnumerables</title>
		<link>http://www.haugern.net/blog/beware-of-the-ienumerables/</link>
		<comments>http://www.haugern.net/blog/beware-of-the-ienumerables/#comments</comments>
		<pubDate>Fri, 17 Oct 2008 08:58:00 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/beware-of-the-ienumerables/</guid>
		<description><![CDATA[Some time ago I wrote about the difference between List and Collection, and how you should use them. Usually you want to keep the details away from the users of your class, and an even tighter way to encapsulate a list of something is to expose IEnumerable&#60;T&#62;. Note that both IList&#60;T&#62; and ICollection&#60;T&#62; inherits this [...]]]></description>
			<content:encoded><![CDATA[<p>Some time ago I wrote about <a href="http://www.haugern.net/blog/net-collectiont-vs-listt/">the difference between List and Collection</a>, and how you should use them. Usually you want to keep the details away from the users of your class, and an even tighter way to encapsulate a list of something is to expose <a href="http://msdn.microsoft.com/en-us/library/9eekhta0.aspx" target="_blank">IEnumerable&lt;T&gt;</a>. Note that both IList&lt;T&gt; and ICollection&lt;T&gt; inherits this interface, so IEnumerable&lt;T&gt; exposes even less details to the user. Another benefit is now you can use <a href="http://msdn.microsoft.com/en-us/library/9k7k7cf0.aspx" target="_blank">yield</a> behind the scenes to create your “list” on the fly.</p>
<p>But this also its pitfall. What do you think will be the output of this code?</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red255\green255\blue255;\red0\green0\blue0;\red255\green128\blue0;\red128\green128\blue64;\red43\green145\blue175;\red0\green255\blue0;}??\fs24 \cf1\cb2\highlight2   \cf3 static\cf1  \cf3 void\cf1  \cf4 Main\cf1 (\cf3 string\cf1 [] \cf4 args\cf1 )\par ??  \{\par ??      \cf3 var\cf1  \cf4 ola\cf1  = \cf3 new\cf1  \cf5 Pupil\cf1 ()\{\cf4 Name\cf1 =\cf6 "Ola"\cf1 , \cf4 IsMate\cf1  = \cf3 false\cf1 \};\par ??      \cf3 var\cf1  \cf4 trond\cf1  = \cf3 new\cf1  \cf5 Pupil\cf1 () \{\cf4 Name\cf1  = \cf6 "Trond"\cf1 , \cf4 IsMate\cf1  = \cf3 true\cf1 \};\par ??      \cf3 var\cf1  \cf4 pupils\cf1  = \cf3 new\cf1  \cf5 List\cf1 &lt;\cf5 Pupil\cf1 &gt;()\{\cf4 ola\cf1 ,\cf4 trond\cf1 \};\par ??\par ??      \cf5 IEnumerable\cf1 &lt;\cf3 string\cf1 &gt; \cf4 names\cf1  = \cf4 ClassMateNames\cf1 (\cf4 pupils\cf1 );\par ??\par ??      \cf3 foreach\cf1  (\cf3 string\cf1  \cf4 name\cf1  \cf3 in\cf1  \cf4 names\cf1 )\par ??      \{\par ??          \cf5 Console\cf1 .\cf4 WriteLine\cf1 (\cf4 name\cf1 );\par ??      \}\par ??  \}\par ??\par ??  \cf3 private\cf1  \cf3 static\cf1  \cf5 IEnumerable\cf1 &lt;\cf3 string\cf1 &gt; \cf4 ClassMateNames\cf1 (\cf5 IEnumerable\cf1 &lt;\cf5 Pupil\cf1 &gt; \cf4 pupils\cf1 )\par ??  \{\par ??      \cf3 foreach\cf1  (\cf5 Pupil\cf1  \cf4 pupil\cf1  \cf3 in\cf1  \cf4 pupils\cf1 )\par ??      \{\par ??          \cf3 if\cf1  (\cf4 pupil\cf1 .\cf4 IsMate\cf1 )\par ??              \cf3 yield\cf1  \cf3 return\cf1  \cf4 pupil\cf1 .\cf4 Name\cf1 ;\par ??      \}\par ??  \}\par ??}<br />
--></p>
<div style="font-size: 8pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 10</span>&#160;&#160; <span style="color: #ff8000">static</span> <span style="color: #ff8000">void</span> <span style="color: #808040">Main</span>(<span style="color: #ff8000">string</span>[] <span style="color: #808040">args</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 11</span>&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 12</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">var</span> <span style="color: #808040">ola</span> = <span style="color: #ff8000">new</span> <span style="color: #2b91af">Pupil</span>(){<span style="color: #808040">Name</span>=<span style="color: lime">&quot;Ola&quot;</span>, <span style="color: #808040">IsMate</span> = <span style="color: #ff8000">false</span>};</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 13</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">var</span> <span style="color: #808040">trond</span> = <span style="color: #ff8000">new</span> <span style="color: #2b91af">Pupil</span>() {<span style="color: #808040">Name</span> = <span style="color: lime">&quot;Trond&quot;</span>, <span style="color: #808040">IsMate</span> = <span style="color: #ff8000">true</span>};</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 14</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">var</span> <span style="color: #808040">pupils</span> = <span style="color: #ff8000">new</span> <span style="color: #2b91af">List</span>&lt;<span style="color: #2b91af">Pupil</span>&gt;(){<span style="color: #808040">ola</span>,<span style="color: #808040">trond</span>};</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 15</span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 16</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #ff8000">string</span>&gt; <span style="color: #808040">names</span> = <span style="color: #808040">ClassMateNames</span>(<span style="color: #808040">pupils</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 17</span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 18</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">foreach</span> (<span style="color: #ff8000">string</span> <span style="color: #808040">name</span> <span style="color: #ff8000">in</span> <span style="color: #808040">names</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 19</span>&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 20</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.<span style="color: #808040">WriteLine</span>(<span style="color: #808040">name</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 21</span>&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 22</span>&#160;&#160; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 23</span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 24</span>&#160;&#160; <span style="color: #ff8000">private</span> <span style="color: #ff8000">static</span> <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #ff8000">string</span>&gt; <span style="color: #808040">ClassMateNames</span>(<span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #2b91af">Pupil</span>&gt; <span style="color: #808040">pupils</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 25</span>&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 26</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">foreach</span> (<span style="color: #2b91af">Pupil</span> <span style="color: #808040">pupil</span> <span style="color: #ff8000">in</span> <span style="color: #808040">pupils</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 27</span>&#160;&#160;&#160;&#160;&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 28</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">if</span> (<span style="color: #808040">pupil</span>.<span style="color: #808040">IsMate</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 29</span>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">yield</span> <span style="color: #ff8000">return</span> <span style="color: #808040">pupil</span>.<span style="color: #808040">Name</span>;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 30</span>&#160;&#160;&#160;&#160;&#160;&#160; }</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 31</span>&#160;&#160; }</p>
</p></div>
<p>&#160;</p>
<p>Yes, you’re right, the output is my only friend “Trond”:</p>
<p><a href="http://www.haugern.net/blog/wp-content/image.png"><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="118" alt="image" src="http://www.haugern.net/blog/wp-content/image-thumb.png" width="244" border="0" /></a> </p>
</p>
<p>But when are we really finding out who my friends are? The most natural thing is that I find them when I call <font face="Consolas">ClassMateNames</font>, as it is called first. That’s what I’d think anyway. But what if got in a fight with “Trond” between when I sort out my friends and list them to the console? </p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red255\green255\blue255;\red0\green0\blue0;\red255\green128\blue0;\red128\green128\blue64;\red43\green145\blue175;}??\fs24 \cf1\cb2\highlight2   \cf3 private\cf1  \cf3 static\cf1  \cf3 void\cf1  \cf4 FightWith\cf1 (\cf5 Pupil\cf1  \cf4 pupil\cf1 )\par ??  \{\par ??      \cf4 pupil\cf1 .\cf4 IsMate\cf1  = \cf3 false\cf1 ;\par ??  \}\par ??}<br />
--></p>
<div style="font-size: 8pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 35</span>&#160;&#160; <span style="color: #ff8000">private</span> <span style="color: #ff8000">static</span> <span style="color: #ff8000">void</span> <span style="color: #808040">FightWith</span>(<span style="color: #2b91af">Pupil</span> <span style="color: #808040">pupil</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 36</span>&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 37</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">pupil</span>.<span style="color: #808040">IsMate</span> = <span style="color: #ff8000">false</span>;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 38</span>&#160;&#160; }</p>
</p></div>
</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof65001\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red255\green128\blue0;\red128\green128\blue64;}??\fs24 \cf1\cb2\highlight2   \cf3 IEnumerable\cf1 &lt;\cf4 string\cf1 &gt; \cf5 names\cf1  = \cf5 ClassMateNames\cf1 (\cf5 pupils\cf1 );\par ??\par ??  \cf5 FightWith\cf1 (\cf5 trond\cf1 );\par ??\par ??  \cf4 foreach\cf1  (\cf4 string\cf1  \cf5 name\cf1  \cf4 in\cf1  \cf5 names\cf1 )\par ??  \{\par ??      \cf3 Console\cf1 .\cf5 WriteLine\cf1 (\cf5 name\cf1 );\par ??  \}\par ??}<br />
--></p>
<div style="font-size: 8pt; background: black; color: white; font-family: consolas">
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 16</span>&#160;&#160; <span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: #ff8000">string</span>&gt; <span style="color: #808040">names</span> = <span style="color: #808040">ClassMateNames</span>(<span style="color: #808040">pupils</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 17</span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 18</span>&#160;&#160; <span style="color: #808040">FightWith</span>(<span style="color: #808040">trond</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 19</span>&#160;</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 20</span>&#160;&#160; <span style="color: #ff8000">foreach</span> (<span style="color: #ff8000">string</span> <span style="color: #808040">name</span> <span style="color: #ff8000">in</span> <span style="color: #808040">names</span>)</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 21</span>&#160;&#160; {</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 22</span>&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #2b91af">Console</span>.<span style="color: #808040">WriteLine</span>(<span style="color: #808040">name</span>);</p>
<p style="margin: 0px"><span style="color: #2b91af">&#160;&#160; 23</span>&#160;&#160; }</p>
</p></div>
</p>
<p>This gives me these friends:</p>
<p><a href="http://www.haugern.net/blog/wp-content/image1.png"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="126" alt="image" src="http://www.haugern.net/blog/wp-content/image-thumb1.png" width="244" border="0" /></a> </p>
</p>
<p>How about that! The information that I no longer is friends with “Trond” has changed the list I thought I retrieved with the call to <font face="Consolas">ClassMateNames</font>. What is happening is called <a href="http://www.google.no/search?hl=no&amp;q=deferred+execution&amp;meta=" target="_blank">deferred execution</a>, which delays the actual execution of the <a href="http://blogs.msdn.com/oldnewthing/archive/2008/08/12/8849519.aspx" target="_blank">internals</a> in the <font face="Consolas">ClassMateNames</font> to when I iterate it. This is exactly how LINQ to [insert TLA here] operate as well, so nothing is actually fetched until you need it.</p>
<p>In my case this was an advantage, because at the time I was listing my friends, I didn’t actually have any!</p>
<h3>And the problem is?</h3>
<p>The problem starts when you before and/or after the call to <font face="Consolas">ClassMateNames</font> set up and tear down a session, connection, or anything that the inside of the iterator rely on. Any fetching of IEnumerables <a href="http://www.haugern.net/blog/using-the-using-statement-and-pattern-in-c/" target="_blank">inside using-blocks</a> should also be considered smells in this regard. If you should clear the list of pupils right after you have sent it to <font face="Consolas">ClassMateNames</font> (you don’t need it anymore right?), you have introduced a very subtle bug as the list is empty at execution.</p>
<p>The advice are thus: IEnumerables and yield is definitively great tools, but be aware of the inherent difficulties and quirks of deferred execution and use them with caution both as producer and consumer!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/beware-of-the-ienumerables/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MSDN Live with Steve Ballmer keynote</title>
		<link>http://www.haugern.net/blog/msdn-live-with-steve-ballmer-keynote/</link>
		<comments>http://www.haugern.net/blog/msdn-live-with-steve-ballmer-keynote/#comments</comments>
		<pubDate>Thu, 02 Oct 2008 19:05:04 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[conferences]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[learning]]></category>
		<category><![CDATA[oo principles]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/msdn-live-with-steve-ballmer-keynote/</guid>
		<description><![CDATA[MSDN Live has toured Norway this fall, with a handful of presentations for .NET developers. I attended the last one in Oslo on Tuesday, where Steve Ballmer made the keynote!
Most developers have seen the developers, developers, developers talk, and we had high expectations for this keynote. He was quite enthusiastic in Oslo as well, telling [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.haugern.net/blog/wp-content/windowslivewritermsdnlivewithsteveballmerkeynote-115e2ballmer-2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="254" alt="ballmer" src="http://www.haugern.net/blog/wp-content/windowslivewritermsdnlivewithsteveballmerkeynote-115e2ballmer-thumb.jpg" width="263" align="left" border="0" /></a>MSDN Live has toured Norway this fall, with a handful of presentations for .NET developers. I attended the last one in Oslo on Tuesday, where Steve Ballmer made the keynote!</p>
<p>Most developers have seen the <a href="http://www.youtube.com/watch?v=KMU0tzLwhbE">developers, developers, developers</a> talk, and we had high expectations for this keynote. He was quite enthusiastic in Oslo as well, telling us about things he thinks will influence our industry in the foreseeable future. <a href="http://www.youtube.com/results?search_query=ballmer+oslo&amp;search_type=&amp;aq=f">This search at Youtube seems to find the whole show</a>.</p>
<p>The rest of the day I attended the main track, starting out with a Silverlight 2 presentation from <a href="http://blog.goeran.no/">G&#248;ran Hansen</a>. While Silverlight 1 was mostly about animations and media, I didn&#8217;t give much attention. But the second version looks promising, with the CLR and a subset of the .NET libraries present. What I miss though, is maybe some background about the fact that running .NET WinForms applications in IE in object-tags has been possible a long time (without the automatic deployment of the framework). Props however to MS for finally supporting more than Windows &amp; IE only! G&#248;ran did a great job presenting, I really enjoyed his presence on stage.</p>
<p>Next up was another presentation from G&#248;ran, which gave the audience an introduction to <a href="http://msdn.microsoft.com/en-us/library/cc488545.aspx">ASP.NET Dynamic Data</a>. For those of us who attended <a href="http://www.haugern.net/blog/norwegian-developer-conference-2008-review/">NDC2008</a> and <a href="http://www.hanselman.com/blog/">Scott Hanselmans</a> keynote there, it was plain repetition. The only difference might be that this was showing the final bits released with SP1 of the framework, and Scott showing us some earlier version. It seems like a great technology to get you up and running very quick, but I wonder how many pages you end up with in the CustomPage directory after a while. Even though the topic didn&#8217;t tickle my fancy, G&#248;ran did a great job on this one as well.</p>
<p>Then it was time for lunch, rather late according to my stomach. But it tasted good, and there seemed to be enough to fill up all us starving geeks. As always during the breaks, old colleagues and friends sneak up on you and says hello. Which I really do appreciate!</p>
<p>After the break, <a href="http://andersnoras.com/blogs/anoras/default.aspx">Anders Nor&#229;s</a> gave a talk about SOA. More specifically about how we should start thinking along the lines of <a href="http://en.wikipedia.org/wiki/Enterprise_Service_Bus">enterprise service buses</a> and leave our old crusty webservices in the dust. I really do concur with a lot his ideas, and I&#8217;m always happy to see code with binsor-love. I also liked his onion-architecture, which resembles my standard layered architecture (no, not the &quot;standard standard&quot;). Hmmm, looks like another blog post (again).</p>
<p>&quot;Debugging your debugging habits&quot; was up next with Rune Zakariassen from Microsoft. He showed us some tips &amp; tricks for your debugging needs in Visual Studio, and presented a step-by-step recipe on how you best can find bugs in your code. I thought it was a nice presentation, even though my only real takeaway was the tracepoint functionality in VS. I&#8217;ve been a sucker for Debug.Writeline when I don&#8217;t want to impact the run of things stepping through, but this gives me an even less intrusive way keeping track of how the program executes.</p>
<p>Finally, G&#248;ran entered the stage for the last time this day. He showed us how WPF databinding can be used with a variant of Model-View-Presenter called Presentation Model. The emphasis was really on this pattern, and how it helps attain <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">SoC</a>. He also mentioned <a href="http://en.wikipedia.org/wiki/Dependency_inversion_principle">DIP</a> with the short version &quot;Program to an interface, not an implementation&quot;. A good thing can&#8217;t be said enough so here is the original:</p>
<blockquote><p>High level modules should not depend upon low level modules. Both should depend upon abstractions.</p>
<p>Abstractions should not depend upon details. Details should depend upon abstractions.</p>
</blockquote>
<p>All things considered, yet another great talk from G&#248;ran, keep up the good work and preach on about those design patterns and OO principles!</p>
<p>Yet again, great work by <a href="http://blogs.msdn.com/grothaug/default.aspx">Rune @ Microsoft</a> arranging this event. Until next time, I&#8217;m on twitter at <a href="http://twitter.com/haugern">http://twitter.com/haugern</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/msdn-live-with-steve-ballmer-keynote/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Norwegian Developer Conference 2008 Review</title>
		<link>http://www.haugern.net/blog/norwegian-developer-conference-2008-review/</link>
		<comments>http://www.haugern.net/blog/norwegian-developer-conference-2008-review/#comments</comments>
		<pubDate>Tue, 24 Jun 2008 19:44:07 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[agile]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[conferences]]></category>
		<category><![CDATA[dotnet]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/norwegian-developer-conference-2008-review/</guid>
		<description><![CDATA[
I arrived Tuesday at NDC2008 full of anticipation and excitement; there were a lot of great talks scheduled as I could see it, and I had trouble choosing which ones to attend. I almost immediately found some old colleagues and class mates, which I hadn&#8217;t talked to in several years. That was really an added [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.haugern.net/blog/wp-content/ndc2008logo-thumb2.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="72" alt="ndc2008Logo_thumb" src="http://www.haugern.net/blog/wp-content/ndc2008logo-thumb-thumb1.jpg" width="240" align="right" border="0" /></a></p>
<p>I arrived Tuesday at <a href="http://www.ndc2008.no/en/home/" target="_blank">NDC2008</a> full of anticipation and excitement; there were a lot of great talks scheduled as I could see it, and I had trouble choosing which ones to attend. I almost immediately found some old colleagues and class mates, which I hadn&#8217;t talked to in several years. That was really an added bonus, and I really appreciated the little &quot;reunions&quot;.</p>
<h3>Day 1</h3>
<p><a href="http://www.hanselman.com/blog/" target="_blank">Scott Hanselman</a> started the show with a keynote, showing us a little LINQ and the new <a href="http://weblogs.asp.net/scottgu/archive/2007/12/14/new-asp-net-dynamic-data-support.aspx" target="_blank">Dynamic Data</a>-bits. Hanselman was witty, and was a <a href="http://www.hanselman.com/blog/11TopTipsForASuccessfulTechnicalPresentation.aspx" target="_blank">great presenter</a>. There might have been a couple of things that did go to fast if you hadn&#8217;t seen a lot of .NET 3.5 before, but I guess most got at least a glimpse of what it can do.</p>
<p>After the keynote I was considering several sessions, but I decided to attend <a href="http://www.poppendieck.com/" target="_blank">Mary Poppendiecks</a> first session titled <a href="http://en.wikipedia.org/wiki/Thrash_%28computer_science%29" target="_blank">Thrashing</a>. She went through the reasons for them, and what can be done to remedy it. As a reader of the <a href="http://en.wikipedia.org/wiki/The_Mythical_Man-Month" target="_blank">Mythical Man Month,</a> <a href="http://www.amazon.com/Slack-Getting-Burnout-Busywork-Efficiency/dp/0767907698" target="_blank">Slack</a>, <a href="http://www.amazon.com/Peopleware-Productive-Projects-Teams-Second/dp/0932633439" target="_blank">Peopleware</a>, and others, I found she conveyed a lot of the same information found there, and I really share their views. A new aspect I hadn&#8217;t thought of before was <a href="http://en.wikipedia.org/wiki/Queueing_theory" target="_blank">queuing theory</a>, which we apply consciously to hardware and related problems, but seldom to team and people dynamics. I will make a follow up post on the matter.</p>
<p>I&#8217;ve lately dabbled with some reflection, so next I attended <a href="http://weblogs.asp.net/rosherove/" target="_blank">Roy Osheroves</a> talk Deep Reflection, hoping it would be as deep as promised (level 400 session). It certainly was, and I&#8217;m glad I&#8217;ve recently been looking at both Reflection.Emit and CodeDom-programming. It also helps to extensively take advantage of the vanilla reflection utilities regularly. This was a prerequisite, but it seemed like a lot of eyes glazed over when it was presented. He ended the session with a song, and I think he did his presentation on this heavy topic in a great way.</p>
<p>Supposed to be doing a talk about agility in Typemock (the firm), I gave Roys next session a chance. But the agenda had changed and we were introduced to Designing for Testability. I had this part mostly under control, so I was a bit disappointed that the original talk was exchanged. It was an introduction to IoC, DI, and IoC-containers, as well as our options when designing for testability with mocks or subclassing. This session ended in a song as well, and the lyrics was funny as always.</p>
<p>There was unfortunately another change in the agenda, Roy had originally a Threading-talk I&#8217;d like to see, but it was changed to a Testing your data access layer session. With this change, I attended Mary Poppendiecks talk on The Role of Leadership in <a href="http://en.wikipedia.org/wiki/Lean_software_development" target="_blank">Lean Software Development</a>. Contrary to popular belief in most Agile circles, she thinks there is a place for leaders, not only self-organizing teams. I must admit that this is something I&#8217;ve personally experienced as well; when everyone is responsible, no one takes responsibility. I won&#8217;t go into more detail here, but I think it was a great talk, and she definitively hit home many points with me.</p>
<h3>Day 2</h3>
<p>I start out attending an Agile Panel discussion hosted by Scott Hanselman, featuring Mary Poppendieck, Roy Osherove, <a href="http://en.wikipedia.org/wiki/Ken_Schwaber" target="_blank">Ken Schwaber</a>, <a href="http://www.hendricksonxp.com/" target="_blank">Chet Hendrickson</a>, and <a href="http://en.wikipedia.org/wiki/Ron_Jeffries" target="_blank">Ron Jeffries</a>. An example topic was what are the first steps to become agile. It wasn&#8217;t that much of a discussion really, as all the panelists believe in the Agile values.</p>
<p>The next two sessions I followed the Agile crowd in general, and Jeffries &amp; Hendrickson in particular in their first two talks about Natural Laws of Agile Software Development. They presented the same material I saw from <a href="http://smidig.no/smidig2007/" target="_blank">Smidig (Agile) 2007</a> on the economics of releasing early. I think it shows the potential payoff of releasing early, but it misses some aspects of going to early into maintenance mode with the software. I think this has to be explored some more. After showing these teasers, they went more into how early and frequent releases can be done baking quality into the process through the means of TDD and Acceptance Tests.</p>
<p>While I was humming along with Ron &amp; Chet, it seemed like Roy got quite a following. It was almost impossible to get a seat on his Advanced Unit Testing session. It really seems my fellow Norwegians are good &amp; ready for some <a href="http://altdotnet.org/" target="_blank">ALT.NET</a> techniques &amp; practices, especially unit testing. I eventually got a seat on the session, but I must admin I personally was a little bit disappointed as I&#8217;ve already been down most of the roads before. Hopefully it was another teaser for all those who are thinking of getting into the whole unit testing business.</p>
<p>Next up, I attended <a href="http://blogs.msdn.com/madst/" target="_blank">Mads Torgersens</a> Microsoft LINQ Under the Covers: An In-Depth Look at LINQ. And under the covers it was indeed. He gave us a great peek into how a LINQ-expression was disassembled, and showed us the output through Reflector. I must admit it was hard to follow everything, but I was at least familiar with all the constructs. All in all a mindblowing experience, and Mads gets credit for his enthusiasm during the session.</p>
<p>Finally, I attended Mary Poppendiecks session on The Discipline of Going Fast. We got new insights into the <a href="http://en.wikipedia.org/wiki/The_Toyota_Way" target="_blank">Toyota Way</a>, a little bit of history, and specifically the Stop-the-Line practice. I definitively will continue this flirt the Lean methodologies.</p>
<h3>Conclusion</h3>
<p>I&#8217;m very pleased, and I was exhausted after two days packed with great content. The only thing I have a complaint about is that a couple of Roys talks should have been moved to accommodate the massive interest his topics achieved.</p>
<p>For another review from a <a href="http://www.iridescence.no/Posts/Summary-of-the-Norwegian-Developer-Conference-2008.aspx" target="_blank">fellow Norwegian blogger look at Fredriks post</a>. You may also see <a href="http://blogs.msdn.com/grothaug/archive/2008/06/20/bilder-fra-norwegian-developers-conference-2008.aspx" target="_blank">more pictures from Rune Grothaug</a>, who did an amazing job arranging this as well.</p>
<p>I must thank the hosts for a great event, and I will come back next year!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/norwegian-developer-conference-2008-review/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using the using-statement and pattern in C#</title>
		<link>http://www.haugern.net/blog/using-the-using-statement-and-pattern-in-c/</link>
		<comments>http://www.haugern.net/blog/using-the-using-statement-and-pattern-in-c/#comments</comments>
		<pubDate>Fri, 13 Jun 2008 20:31:09 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[c#]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[pattern]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/using-the-using-statement-and-pattern-in-c/</guid>
		<description><![CDATA[How often do find yourself writing code like this to do some things in batch:
 


&#160;&#160;&#160; BatchCalculator calc = new BatchCalculator();
&#160;&#160;&#160; calc.Suspend();
&#160;&#160;&#160; calc.CalculateSomething(something);
&#160;&#160;&#160; calc.CalculateSomethingElse(something);
&#160;&#160;&#160; calc.Resume();

Well, I do and I&#8217;m not really happy about sprinkling those Suspends and Resumes around everywhere I need to start and stop something. I see at least two common pitfalls with [...]]]></description>
			<content:encoded><![CDATA[<p>How often do find yourself writing code like this to do some things in batch:</p>
<p> <!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Consolas;}}{\colortbl;??\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red128\green128\blue64;\red255\green128\blue0;}??\fs24 \cf1\cb2\highlight2     \cf3 BatchCalculator\cf1  \cf4 calc\cf1  = \cf5 new\cf1  \cf3 BatchCalculator\cf1 ();\par ??    \cf4 calc\cf1 .\cf4 Suspend\cf1 ();\par ??    \cf4 calc\cf1 .\cf4 CalculateSomething\cf1 (\cf4 something\cf1 );\par ??    \cf4 calc\cf1 .\cf4 CalculateSomethingElse\cf1 (\cf4 something\cf1 );\par ??    \cf4 calc\cf1 .\cf4 Resume\cf1 ();\par ??}<br />
-->
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #2b91af">BatchCalculator</span> <span style="color: #808040">calc</span> = <span style="color: #ff8000">new</span> <span style="color: #2b91af">BatchCalculator</span>();</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">Suspend</span>();</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">CalculateSomething</span>(<span style="color: #808040">something</span>);</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">CalculateSomethingElse</span>(<span style="color: #808040">something</span>);</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">Resume</span>();</pre>
</div>
<p>Well, I do and I&#8217;m not really happy about sprinkling those Suspends and Resumes around everywhere I need to start and stop something. I see at least two common pitfalls with this<a href="http://www.haugern.net/blog/wp-content/slum.jpg"><img style="border-top-width: 0px; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="379" alt="http://www.flickr.com/photos/stuckincustoms/894698437/" src="http://www.haugern.net/blog/wp-content/slum-thumb.jpg" width="287" align="right" border="0" /></a> solution and a minor hiccup:</p>
<ol>
<li>Somewhere down the pipe I&#8217;m bound to forget the call to Resume explicitly and I&#8217;ll have a bug on my hands. </li>
<li>Somewhere in between the Suspend and Resume calls an Exception is thrown, Resume is never reached, and leaving the object in an unwanted state. </li>
<li>It could be better looking!&#160; -&gt; </li>
</ol>
<h3>The short using-introduction</h3>
<p>With the introduction of .NET and it&#8217;s managed environment and non-deterministic garbage collector, there were several figureheads in the industry that raised an eyebrow or two. There were also people raising more than their eyebrows as well, and according to legend and several <a href="http://www.dotnetrocks.com" target="_blank">.NET Rocks</a> shows, <a href="http://www.sellsbrothers.com/" target="_blank">Chris Sells</a> (now a blue badge) was one. They allegedly made MS include an IDisposable interface with a simple method Dispose() to fill their garbage collection needs. And if that wasn&#8217;t enough, they included the <a href="http://msdn.microsoft.com/en-us/library/yh598w02.aspx" target="_blank">using</a>-statement which is a <a href="http://www.codeproject.com/KB/cs/CSharp_using.aspx" target="_blank">try-finally</a> in disguise where the finally automatically calls IDisposable.Dispose()!</p>
<p>A couple of regulars in my world in that department are the <a href="http://msdn.microsoft.com/en-us/library/system.data.idbconnection.aspx" target="_blank">IDbConnection interface</a> and later (from 2.0 and onwards) the <a href="http://msdn.microsoft.com/en-us/library/ms172152.aspx" target="_blank">TransactionScope</a> class, but it has also been recommended practice for any implementers of the IDisposable interface.</p>
<h3>Yeah yeah, but what can <u>I</u> do with it?</h3>
<p>With the aforementioned background in place we can exploit it to create a better and more fluent API for our batch-oriented processes. Let us simply dive into the code, and I introduce without further ado; the changed BatchCalculator:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #ff8000">class</span> <span style="color: #2b91af">BatchCalculator</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #2b91af">IDisposable</span> <span style="color: #808040">Suspend</span>(){}</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">Resume</span>(){}</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">CalculateSomethingElse</span>(<span style="color: #ff8000">object</span> <span style="color: #808040">something</span>){}</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">CalculateSomething</span>(<span style="color: #ff8000">object</span> <span style="color: #808040">something</span>){}</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>Suspend now returns an IDisposable and we can replace our calling code to this:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #2b91af">BatchCalculator</span> <span style="color: #808040">calc</span> = <span style="color: #ff8000">new</span> <span style="color: #2b91af">BatchCalculator</span>();</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">using</span>(<span style="color: #808040">calc</span>.<span style="color: #808040">Suspend</span>())</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">CalculateSomething</span>(<span style="color: #808040">something</span>);</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">calc</span>.<span style="color: #808040">CalculateSomethingElse</span>(<span style="color: #808040">something</span>);</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
</div>
<p>Yes! That&#8217;s more like it. I definitively like to looks of that.</p>
<h3>But how.. do I ensure a call to Resume?</h3>
<p>This is where the &quot;magic&quot; happens. Let us make a class which implements IDisposable that gets returned from our Suspend method:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #ff8000">class</span> <span style="color: #2b91af">Suspender</span> : <span style="color: #2b91af">IDisposable</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">private</span> <span style="color: #ff8000">readonly</span> <span style="color: #2b91af">BatchCalculator</span> <span style="color: #808040">m_calculator</span>;</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #808040">Suspender</span>(<span style="color: #2b91af">BatchCalculator</span> <span style="color: #808040">calculator</span>)</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">m_calculator</span> = <span style="color: #808040">calculator</span>;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">Dispose</span>()</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">m_calculator</span>.<span style="color: #808040">Resume</span>();</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>And our revised Suspend method:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #2b91af">IDisposable</span> <span style="color: #808040">Suspend</span>()</pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">return</span> <span style="color: #ff8000">new</span> <span style="color: #2b91af">Suspender</span>(<span style="color: #ff8000">this</span>);</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>Now go look at the implemented Dispose-method in our Suspender-class. It just calls our Resume method on our BatchCalculator! So when the using-block is exited, the Dispose-method is called and hooray, mission accomplished.</p>
<h3>Finishing touch</h3>
<p>To increase the applicability of the Suspender-class I introduce the <a href="http://www.martinfowler.com/bliki/RoleInterface.html" target="_blank">role interface</a> IResumable:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #ff8000">interface</span> <span style="color: #2b91af">IResumable</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">void</span> <span style="color: #808040">Resume</span>();</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>And implement it in BatchCalculculator:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #ff8000">class</span> <span style="color: #2b91af">BatchCalculator</span> : <span style="color: #2b91af">IResumable</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #2b91af">IDisposable</span> <span style="color: #808040">Suspend</span>()</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #ff8000">return</span> <span style="color: #ff8000">new</span> <span style="color: #2b91af">Suspender</span>(<span style="color: #ff8000">this</span>);</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">Resume</span>(){}</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">CalculateSomethingElse</span>(<span style="color: #ff8000">object</span> <span style="color: #808040">something</span>){}</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">CalculateSomething</span>(<span style="color: #ff8000">object</span> <span style="color: #808040">something</span>){}</pre>
<pre style="margin: 0px">}</pre>
</div>
<p>Now the Suspender class can just wrap our new interface:</p>
</p>
<div style="font-size: 10pt; background: black; color: white; font-family: consolas">
<pre style="margin: 0px"><span style="color: #ff8000">public</span> <span style="color: #ff8000">class</span> <span style="color: #2b91af">Suspender</span> : <span style="color: #2b91af">IDisposable</span></pre>
<pre style="margin: 0px">{</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">private</span> <span style="color: #ff8000">readonly</span> <span style="color: #2b91af">IResumable</span> <span style="color: #808040">m_resumable</span>;</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #808040">Suspender</span>(<span style="color: #2b91af">IResumable</span> <span style="color: #808040">resumable</span>)</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">m_resumable</span> = <span style="color: #808040">resumable</span>;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">&#160;</pre>
<pre style="margin: 0px">&#160;&#160;&#160; <span style="color: #ff8000">public</span> <span style="color: #ff8000">void</span> <span style="color: #808040">Dispose</span>()</pre>
<pre style="margin: 0px">&#160;&#160;&#160; {</pre>
<pre style="margin: 0px">&#160;&#160;&#160;&#160;&#160;&#160;&#160; <span style="color: #808040">m_resumable</span>.<span style="color: #808040">Resume</span>();</pre>
<pre style="margin: 0px">&#160;&#160;&#160; }</pre>
<pre style="margin: 0px">}</pre>
</div>
<h3>Final note</h3>
<p>If we revisit our weak spots, have we solved them all? A definitive yes; using using guarantees that the Dispose()-method is called which in turn calls our wrapped method. I must also add I really like the syntactic sugar using represents.</p>
<p>This pattern is obviously at a tangent for what using and IDisposable was supposed to be used for. The MSDN library has this to say about <a href="http://msdn.microsoft.com/en-us/library/system.idisposable.aspx" target="_blank">IDisposable</a>: </p>
<blockquote>
<p>The primary use of this interface is to release unmanaged resources.</p>
</blockquote>
<p>But why not leverage what we have available. After all, coding is done once. Reading it is another matter completely.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/using-the-using-statement-and-pattern-in-c/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Remember to check out PartCover</title>
		<link>http://www.haugern.net/blog/remember-to-check-out-partcover/</link>
		<comments>http://www.haugern.net/blog/remember-to-check-out-partcover/#comments</comments>
		<pubDate>Sun, 03 Feb 2008 20:53:02 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[code coverage]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[ncover]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/remember-to-check-out-partcover/</guid>
		<description><![CDATA[Bil Simser just wrote about the lack of coverage tools for .NET in this article, and I agree with his points.
In our current project we&#8217;re using NCover and NCoverExplorer (older editions), which are working just fine as we&#8217;re still in the .NET 2.0 world. It seems there are some problems with the older versions (they [...]]]></description>
			<content:encoded><![CDATA[<p>Bil Simser just wrote about <a href="http://weblogs.asp.net/bsimser/archive/2008/01/29/lack-of-coverage-tools-for-net.aspx" target="_blank">the lack of coverage tools for .NET in this article</a>, and I agree with his points.</p>
<p>In our current project we&#8217;re using <a href="http://www.ncover.com/" target="_blank">NCover and NCoverExplorer</a> (<a href="http://www.ncover.com/download/discontinued" target="_blank">older editions</a>), which are working just fine as we&#8217;re still in the .NET 2.0 world. It seems there are some problems with the older versions (they have gone commercial on us) and the new .NET 3.5 framework.</p>
<p>This isn&#8217;t particularly good news, as we&#8217;re going to utilize VS 2008 and .NET 3.5 shortly. The choice is wether fleshing out 150 USD, or find an alternative. One of the comments on Bils post linked to another coverage utility; <a href="http://sourceforge.net/projects/partcover" target="_blank">PartCover</a>.</p>
<p>So, note to self: <a href="http://sourceforge.net/projects/partcover" target="_blank">Check out PartCover when</a> we&#8217;re going .NET 3.5.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/remember-to-check-out-partcover/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Automatic versioning with CruiseControl.Net and NAnt</title>
		<link>http://www.haugern.net/blog/automatic-versioning-with-cruisecontrolnet-and-nant/</link>
		<comments>http://www.haugern.net/blog/automatic-versioning-with-cruisecontrolnet-and-nant/#comments</comments>
		<pubDate>Fri, 11 Jan 2008 18:53:22 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[cruisecontrol.net]]></category>
		<category><![CDATA[dotnet]]></category>
		<category><![CDATA[nant]]></category>
		<category><![CDATA[source control]]></category>
		<category><![CDATA[tfs]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/automatic-versioning-with-cruisecontrolnet-and-nant/</guid>
		<description><![CDATA[I&#8217;ve created a similar setup as David Donald Belcham (a.k.a. igloocoder) mentions in this post for our current project at NOIS.
When I mean similar, we&#8217;re using the exact same tools for the job, with NAnt (asminfo task) &#38; CC.NET. But there&#8217;s a couple of differences.
New labeller for CC.NET
The first, and minor difference is the labeller. [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve created a similar setup as <strike>David</strike> Donald Belcham (a.k.a. igloocoder)<a href="http://igloocoder.com/archive/2008/01/04/versioning-applications-using-nant-and-cruisecontrol.net.aspx" target="_blank"> mentions in this post</a> for our current project at <a href="http://www.nois.no" target="_blank">NOIS</a>.</p>
<p>When I mean similar, we&#8217;re using the exact same tools for the job, with <a href="http://nant.sourceforge.net/" target="_blank">NAnt</a> (<a href="http://nant.sourceforge.net/release/0.85/help/tasks/asminfo.html" target="_blank">asminfo task</a>) &amp; <a href="http://confluence.public.thoughtworks.org/display/CCNET/Welcome+to+CruiseControl.NET" target="_blank">CC.NET</a>. But there&#8217;s a couple of differences.</p>
<h3>New labeller for CC.NET</h3>
<p>The first, and minor difference is the <a href="http://confluence.public.thoughtworks.org/display/CCNET/Labeller+Blocks" target="_blank">labeller</a>. I wanted the versions to work almost as the <a href="http://nantcontrib.sourceforge.net/release/latest/help/tasks/version.html" target="_blank">NAntContrib version task</a> with the automatic build &amp; revision based on day of year and time of day respectively. As most people were running the traditional ymmdd-format for the build, this effectively had to stop at the beginning of 07; 16 bit for the build number breaks that setup. So I settled for an algorithm which won&#8217;t break until the year 2066. The major &amp; minor numbers is set manually.</p>
<p>I couldn&#8217;t seem to find such a labeller <a href="http://www.google.com" target="_blank">out there</a>, and as I wanted the same number in the CC.NET build-number, and in the assemblies (and in the source control system as well, I&#8217;ll get back to that), CC.NET needed to be master. Not finding what I wanted, I created my own labeller for CC.NET, which gives me the build-numbering scheme I wanted.</p>
<p>With the <a href="http://confluence.public.thoughtworks.org/display/CCNET/Custom+Builder+Plug-in" target="_blank">extensibility-points in CC.NET</a> it was great fun, and real easy to deploy my own. Here&#8217;s the whole thing:</p>
<p><!--<br />
{\rtf1\ansi\ansicpg\lang1024\noproof1252\uc1 \deff0{\fonttbl{\f0\fnil\fcharset0\fprq1 Courier New;}}{\colortbl;??\red0\green0\blue255;\red255\green255\blue255;\red0\green0\blue0;\red43\green145\blue175;\red163\green21\blue21;}??\fs20 \cf1 using\cf0  System;\par ??\cf1 using\cf0  Exortech.NetReflector;\par ??\cf1 using\cf0  ThoughtWorks.CruiseControl.Core;\par ??\par ??\cf1 namespace\cf0  Haugern.Util.CCNet\par ??\{\par ??    [\cf4 ReflectorType\cf0 (\cf5 "versionLabeller"\cf0 )]\par ??    \cf1 public\cf0  \cf1 class\cf0  \cf4 VersionLabeller\cf0  : \cf4 ILabeller\par ??\cf0     \{\par ??        [\cf4 ReflectorProperty\cf0 (\cf5 "major"\cf0 , Required = \cf1 true\cf0 )] \par ??        \cf1 public\cf0  \cf1 int\cf0  Major;\par ??        [\cf4 ReflectorProperty\cf0 (\cf5 "minor"\cf0 , Required = \cf1 true\cf0 )] \par ??        \cf1 public\cf0  \cf1 int\cf0  Minor;\par ??\par ??        \cf1 public\cf0  \cf1 string\cf0  Generate(\cf4 IIntegrationResult\cf0  integrationResult)\par ??        \{\par ??            \cf1 if\cf0 (integrationResult == \cf1 null\cf0 )\par ??                \cf1 throw\cf0  \cf1 new\cf0  \cf4 ArgumentNullException\cf0 (\cf5 "integrationResult"\cf0 );\par ??\par ??            \cf4 DateTime\cf0  now = \cf4 DateTime\cf0 .Now;\par ??            \cf1 return\cf0  Major + \cf5 "."\cf0  + Minor + \cf5 "."\cf0  + ComputeBuild(now) + \cf5 "."\cf0  + ComputeRelease(now);\par ??        \}\par ??\par ??        \cf1 private\cf0  \cf1 static\cf0  \cf1 string\cf0  ComputeRelease(\cf4 DateTime\cf0  now)\par ??        \{\par ??            \cf1 return\cf0  \cf4 Math\cf0 .Round((now.TimeOfDay.TotalSeconds/10)).ToString();\par ??        \}\par ??\par ??        \cf1 private\cf0  \cf1 static\cf0  \cf1 string\cf0  ComputeBuild(\cf4 DateTime\cf0  now)\par ??        \{\par ??            \cf1 return\cf0  now.ToString(\cf5 "yy"\cf0 ) + now.DayOfYear.ToString(\cf5 "000"\cf0 );\par ??        \}\par ??\par ??        \cf1 public\cf0  \cf1 void\cf0  Run(\cf4 IIntegrationResult\cf0  result)\par ??        \{\par ??            result.Label = Generate(result);\par ??        \}\par ??    \}\par ??\}}<br />
-->
<div style="font-size: small; background: white; color: black; font-family: courier new">
<p style="margin: 0px"><font size="2"><span style="color: blue">using</span> System;</font></p>
<p style="margin: 0px"><font size="2"><span style="color: blue">using</span> Exortech.NetReflector;</font></p>
<p style="margin: 0px"><font size="2"><span style="color: blue">using</span> ThoughtWorks.CruiseControl.Core;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2"><span style="color: blue">namespace</span> Haugern.Util.CCNet</font></p>
<p style="margin: 0px"><font size="2">{</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af">ReflectorType</span>(<span style="color: #a31515">"versionLabeller"</span>)]</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">class</span> <span style="color: #2b91af">VersionLabeller</span> : <span style="color: #2b91af">ILabeller</span></font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp; {</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af">ReflectorProperty</span>(<span style="color: #a31515">"major"</span>, Required = <span style="color: blue">true</span>)] </font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">int</span> Major;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [<span style="color: #2b91af">ReflectorProperty</span>(<span style="color: #a31515">"minor"</span>, Required = <span style="color: blue">true</span>)] </font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">int</span> Minor;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">string</span> Generate(<span style="color: #2b91af">IIntegrationResult</span> integrationResult)</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">if</span>(integrationResult == <span style="color: blue">null</span>)</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">throw</span> <span style="color: blue">new</span> <span style="color: #2b91af">ArgumentNullException</span>(<span style="color: #a31515">&#8220;integrationResult&#8221;</span>);</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: #2b91af">DateTime</span> now = <span style="color: #2b91af">DateTime</span>.Now;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> Major + <span style="color: #a31515">&#8220;.&#8221;</span> + Minor + <span style="color: #a31515">&#8220;.&#8221;</span> + ComputeBuild(now) + <span style="color: #a31515">&#8220;.&#8221;</span> + ComputeRelease(now);</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">string</span> ComputeRelease(<span style="color: #2b91af">DateTime</span> now)</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> <span style="color: #2b91af">Math</span>.Round((now.TimeOfDay.TotalSeconds/10)).ToString();</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">private</span> <span style="color: blue">static</span> <span style="color: blue">string</span> ComputeBuild(<span style="color: #2b91af">DateTime</span> now)</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">return</span> now.ToString(<span style="color: #a31515">&#8220;yy&#8221;</span>) + now.DayOfYear.ToString(<span style="color: #a31515">&#8220;000&#8243;</span>);</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0px"><font size="2">&nbsp;</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style="color: blue">public</span> <span style="color: blue">void</span> Run(<span style="color: #2b91af">IIntegrationResult</span> result)</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result.Label = Generate(result);</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0px"><font size="2">&nbsp;&nbsp;&nbsp; }</font></p>
<p style="margin: 0px"><font size="2">}</font></p>
</div>
<h3>Consistent Build Number</h3>
<p>The second difference (well, in his defence, it&#8217;s not even mentioned), is that the exact same label should be set back into the source control system. In our case, we&#8217;re using TFS Source Control, and <a href="http://confluence.public.thoughtworks.org/display/CCNET/Visual+Studio+Team+Foundation+Server+Plugin" target="_blank">with the standard plugin it was easy</a> to apply it there as well.</p>
<p>Now we got this great setup where we can track everything that happens back to the build-number as it is the same across the whole environment:</p>
<p>Application &lt;-&gt; Build server &lt;-&gt; Source Control</p>
<p>Consistent build number across the production line also means every build is a candidate for release.</p>
<p>Should some bug find it way through our thorough unit-testing &amp; qa-scheme into the hands of our customers, finding the right version to search for it will not be a problem!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/automatic-versioning-with-cruisecontrolnet-and-nant/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>.Net Collection&lt;T&gt; vs. List&lt;T&gt;</title>
		<link>http://www.haugern.net/blog/net-collectiont-vs-listt/</link>
		<comments>http://www.haugern.net/blog/net-collectiont-vs-listt/#comments</comments>
		<pubDate>Sun, 02 Dec 2007 21:21:16 +0000</pubDate>
		<dc:creator>haugern</dc:creator>
				<category><![CDATA[best practice]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[dotnet]]></category>

		<guid isPermaLink="false">http://www.haugern.net/blog/net-collectiont-vs-listt/</guid>
		<description><![CDATA[Recently, we have gotten a couple of &#8220;fresh out of school&#8221; employees, and here the other day we went through the code of one of our applications and explained how it was built (at least how was supposed to be or &#8220;do as I tell you, don&#8217;t do&#160;as I do&#8221;).
Our O/R-mapper returns&#160;a generic Collection&#60;T&#62; when [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, we have gotten a couple of &#8220;fresh out of school&#8221; employees, and here the other day we went through the code of one of our applications and explained how it was built (at least how was supposed to be or &#8220;do as I tell you, don&#8217;t do&nbsp;as I do&#8221;).</p>
<p>Our O/R-mapper returns&nbsp;a generic Collection&lt;T&gt; when it is asked for a list / collection of some objects, and is consistent in doing so. The question however, was why that wasn&#8217;t a List&lt;T&gt;.</p>
<p>I had to admit I hadn&#8217;t dug into the material properly, so the question kindof got left there in open air. My bad excuse was of course I had been mostly doing managment stuff lately, and so was my companion presenter as well.</p>
<p>So to make a not so long story short, I had to dig into the collections that is found in .NET, and I explain them to myself for later reference, beginning with the aforementioned Collection&lt;T&gt; and List&lt;T&gt;.</p>
<h3>The difference</h3>
<p>Just to sum it up, Collection&lt;T&gt; is made for extensibility and List&lt;T&gt; is made for performance. See <a href="http://blogs.msdn.com/kcwalina/archive/2005/09/26/474010.aspx">this</a> and <a href="http://blogs.msdn.com/fxcop/archive/2006/04/27/585476.aspx">this</a>&nbsp;from the FxCop guys. </p>
<p>For a full blown explanation, a great <a href="http://blogs.msdn.com/kcwalina/archive/2005/09/23/Collections.aspx">reference is also found here</a>.</p>
<p><strong>Use List&lt;T&gt; for all your heavy lifting internally, and expose a Collection&lt;T&gt; in your public API.</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.haugern.net/blog/net-collectiont-vs-listt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
