<?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>Brian Hartsock&#039;s Blog &#187; Programming</title>
	<atom:link href="http://blog.brianhartsock.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.brianhartsock.com</link>
	<description>The exciting life of a software developer and nerd</description>
	<lastBuildDate>Thu, 29 Jul 2010 02:40:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>My favorite thing, deleting code</title>
		<link>http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/</link>
		<comments>http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/#comments</comments>
		<pubDate>Sun, 12 Oct 2008 22:45:06 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=128</guid>
		<description><![CDATA[After months of development, one of your developers refactors a piece of code to be much better than before. In many cases, you end up with code that is no longer in use. Some people say Keep it around in case I need it but I say Delete it At first, this may seem counter-intuitive. [...]]]></description>
			<content:encoded><![CDATA[<p>After months of development, one of your developers refactors a piece of code to be much better than before.  In many cases, you end up with code that is no longer in use.  Some people say <em>Keep it around in case I need it</em> but I say <em>Delete it</em></p>
<p>At first, this may seem counter-intuitive.  Isn&#8217;t this gong to cause more work in case you do need that function?  No.  Delete it.  Don&#8217;t think twice.  Here is why.</p>
<p>Unused code isn&#8217;t being tested.  Used code is tested everyday, by your users if nothing else.  The last thing you want is a developer to use code that might be completely wrong.</p>
<p>It reduces your code base.  The less code you have, the less probability for problems exist.  The less code you have, the easier it is to learn the code base.</p>
<p>Lastly, your developers should be learning everyday.  If given a second chance, many developers would develop the same function completely differently a year apart.  They would code a better function, that is more thoroughly tested and uses best practices.</p>
<p>So, don&#8217;t worry about it.  Delete it.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+My+favorite+thing%2C+deleting+code+http://bit.ly/1MIo7L" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/&amp;title=My+favorite+thing%2C+deleting+code" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/&amp;t=My+favorite+thing%2C+deleting+code" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/&amp;title=My+favorite+thing%2C+deleting+code" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/10/12/my-favorite-thing-deleting-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mailtrust Developer Conference</title>
		<link>http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/</link>
		<comments>http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/#comments</comments>
		<pubDate>Wed, 08 Oct 2008 01:37:26 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Mailtrust]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=132</guid>
		<description><![CDATA[Today Mailtrust held its first all-day development conference. In my opinion, it was awesome. Not because it was great, but because it wasn&#8217;t bad. Like any first-time, there are a ton of things we can do better for future conferences, but the goal of spreading knowledge throughout the development environment was met. When I first [...]]]></description>
			<content:encoded><![CDATA[<p>Today <a href="http://www.mailtrust.com/">Mailtrust</a> held its first all-day development conference.  In my opinion, it was awesome.  Not because it was great, but because it wasn&#8217;t bad.  Like any first-time, there are a ton of things we can do better for future conferences, but the goal of spreading knowledge throughout the development environment was met.</p>
<p>When I first started coding in VB6 on <a href="http://web.archive.org/web/20050225090403/http://www.webmail.us/">Webmail.us&#8217;s corporate website</a>, I never imagined the day I would help organize a conference for all their developers (PS &#8211; That is the corporate website when I started found via <a href="http://www.archive.org/web/web.php">archive.org</a>.  You have to check it out).  Then, communicating a new concept was as simple as turning around in your chair or waiting till everyone met up for dinner and drinks after work.  With the growth of the company, communication isn&#8217;t as easy.</p>
<p>Our goal was to spread knowledge to everyone, and even more specifically the new people.  One of the key topics today was on MySQL, a topic some of us can talk about for hours.  Too often, we take that knowledge for granted.  Not everyone has had as much experience with MySQL, especially hires right out of college.  Getting everyone on the same page with certain topics was the goal today.  Hopefully screen casts of the talks can help future hires ramp up faster as well.</p>
<p>But, there are always things we can improve upon.  Here a list of 5 things that we can do better for next time:</p>
<ul>
<li>Plan the setup better.  Make sure everyones files are on the presentation machine, and have breaks setup so there aren&#8217;t lulls between talks.
</li>
<li>Don&#8217;t rely on the internet.  Holiday Inn&#8217;s free wifi isn&#8217;t geared towards 30 developers.</li>
<li>Don&#8217;t eat mexican for lunch.  It is delicious, but takes away from the second half of the conference if you know what I mean.</li>
<li>Give every speaker enough time, and push them to fill it but not go over.</li>
<li>Lastly, I would like to figure out how to go more in depth with some of the topics.  Maybe have different tracks so people can choose?  We might need 30 more developers before this is feasible though <img src='http://blog.brianhartsock.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </li>
</ul>
<p>Thanks to Lindsey, Matt, and Kevin for making it all happen.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+Mailtrust+Developer+Conference+http://bit.ly/zzWKE" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/&amp;title=Mailtrust+Developer+Conference" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/&amp;t=Mailtrust+Developer+Conference" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/&amp;title=Mailtrust+Developer+Conference" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/10/07/mailtrust-developer-conferenc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>sqlcmd.exe and MsBuild</title>
		<link>http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/</link>
		<comments>http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 19:00:23 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Databases]]></category>
		<category><![CDATA[MSBuild]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=118</guid>
		<description><![CDATA[Today I wrote my first MsBuild script that uses sqlcmd.exe to execute SQL Server commands remotely. It is awesome. Although it is fairly limited, for tasks like backing up databases, it is very simple and easy. &#60;Target Name=&#34;Backup&#34;&#62; &#60;Exec Command='sqlcmd -S $(server) -q &#34;$(sql)&#34;' /&#62; &#60;/Target&#62;]]></description>
			<content:encoded><![CDATA[<p>Today I wrote my first MsBuild script that uses sqlcmd.exe to execute SQL Server commands remotely.  It is awesome.  Although it is fairly limited, for tasks like backing up databases, it is very simple and easy.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;">  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;Backup&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
	<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">'sqlcmd -S $(server) -q &quot;$(sql)&quot;'</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+sqlcmd.exe+and+MsBuild+http://bit.ly/YvV5f" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/&amp;title=sqlcmd.exe+and+MsBuild" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/&amp;t=sqlcmd.exe+and+MsBuild" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/&amp;title=sqlcmd.exe+and+MsBuild" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/08/27/sqlcmdexe-and-msbuild/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>LINQ bites back</title>
		<link>http://blog.brianhartsock.com/2008/08/07/linq-bites-back/</link>
		<comments>http://blog.brianhartsock.com/2008/08/07/linq-bites-back/#comments</comments>
		<pubDate>Thu, 07 Aug 2008 19:59:31 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=114</guid>
		<description><![CDATA[Today I found some odd behavior when working with LINQ. It is hard to describe, so here is the code. public void Foo&#40;IEnumerable&#60;string&#62; strings&#41; &#123; IEnumberable&#60;string&#62; stringsInDb = strings.Where&#40;s =&#62; this.QueryTheDbAndTakeALongTime&#40;s&#41;&#41;; &#160; foreach&#40;string str in stringsInDb&#41; &#123; //Where clause in LINQ is actually executed &#125; &#160; foreach&#40;string str in stringsInDb&#41; &#123; //Where clause in LINQ [...]]]></description>
			<content:encoded><![CDATA[<p>Today I found some odd behavior when working with LINQ.  It is hard to describe, so here is the code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Foo<span style="color: #000000;">&#40;</span>IEnumerable<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> strings<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	IEnumberable<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> stringsInDb <span style="color: #008000;">=</span> strings.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>s <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">QueryTheDbAndTakeALongTime</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> str <span style="color: #0600FF;">in</span> stringsInDb<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//Where clause in LINQ is actually executed </span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">foreach</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> str <span style="color: #0600FF;">in</span> stringsInDb<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #008080; font-style: italic;">//Where clause in LINQ is actually executed  AGAIN</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Luckily, some unit tests detected this behavior.  It actually isn&#8217;t surprising when you think about it though.  The proper thing to do for this case is actually call <em>ToList()</em> after the <em>Where()</em>.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">IEnumberable<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span><span style="color: #008000;">&gt;</span> stringsInDb <span style="color: #008000;">=</span> strings.<span style="color: #0000FF;">Where</span><span style="color: #000000;">&#40;</span>s <span style="color: #008000;">=&gt;</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">QueryTheDbAndTakeALongTime</span><span style="color: #000000;">&#40;</span>s<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">ToList</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Don&#8217;t let this behavior bite you.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+LINQ+bites+back+http://bit.ly/eTQXA" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/08/07/linq-bites-back/&amp;title=LINQ+bites+back" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/08/07/linq-bites-back/&amp;t=LINQ+bites+back" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/08/07/linq-bites-back/&amp;title=LINQ+bites+back" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/08/07/linq-bites-back/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Code your Documents</title>
		<link>http://blog.brianhartsock.com/2008/07/26/code-your-documents/</link>
		<comments>http://blog.brianhartsock.com/2008/07/26/code-your-documents/#comments</comments>
		<pubDate>Sat, 26 Jul 2008 18:09:44 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Best Practices]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=111</guid>
		<description><![CDATA[Every developer has heard the phrase document your code. The reason this is important is the functionality is now coupled with a description of how it works. Now a future developer can load up a single source of information and understand the functionality. But, more importantly, the odds of the documentation staying updated are higher [...]]]></description>
			<content:encoded><![CDATA[<p>Every developer has heard the phrase <em>document your code</em>.  The reason this is important is the functionality is now coupled with a description of how it works.   Now a future developer can load up a single source of information and understand the functionality.  But, more importantly, the odds of the documentation staying updated are higher because of this coupling.  The same can&#8217;t be said for a standalone document.</p>
<p>Well, shouldn&#8217;t the same be true for documents, specifically those that describe some sort of process?  For example, a document describing the steps to setup an IIS web server for a particular application is perfect to convert to an automated script.  So, today, I started on a simple script to setup IIS compression using <a href="http://msdn.microsoft.com/en-us/library/wea2sca5(VS.80).aspx">MSBuild</a>.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
</pre></td><td class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Project</span> <span style="color: #000066;">xmlns</span>=<span style="color: #ff0000;">&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
  <span style="color: #808080; font-style: italic;">&lt;!-- Types --&gt;</span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;adsutilPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>C:\inetpub\AdminScripts\adsutil.vbs<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/adsutilPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;cscriptPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>cscript<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/cscriptPath<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;StaticFilesToCompress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>html htm js txt<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/StaticFilesToCompress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;DynamicFilesToCompress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>aspx asp dll exe axd<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/DynamicFilesToCompress<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/PropertyGroup<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Target</span> <span style="color: #000066;">Name</span>=<span style="color: #ff0000;">&quot;IisCompression&quot;</span><span style="color: #000000; font-weight: bold;">&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Turn on static and dynamic compression for all of IIS.&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/502ef631-3695-4616-b268-cbe7cf1351ce.mspx?mfr=true --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set w3svc/filters/compression/parameters/HcDoStaticCompression true&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set w3svc/filters/compression/parameters/HcDoDynamicCompression true &quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Message</span> <span style="color: #000066;">Text</span>=<span style="color: #ff0000;">&quot;Select files to compress for static and dyanamic compression.&quot;</span> <span style="color: #000066;">Importance</span>=<span style="color: #ff0000;">&quot;high&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #808080; font-style: italic;">&lt;!-- http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true --&gt;</span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set W3SVC/Filters/Compression/Deflate/HcFileExtensions $(StaticFilesToCompress)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set W3SVC/Filters/Compression/gzip/HcFileExtensions $(StaticFilesToCompress)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set W3SVC/Filters/Compression/Deflate/HcScriptFileExtensions $(DynamicFilesToCompress)&quot;</span> <span style="color: #000000; font-weight: bold;">/&gt;</span></span>
    <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Exec</span> <span style="color: #000066;">Command</span>=<span style="color: #ff0000;">&quot;$(cscriptPath) $(adsutilPath) set W3SVC/Filters/Compression/gzip/HcScriptFileExtensions $(DynamicFilesToCompress)&quot;</span><span style="color: #000000; font-weight: bold;">/&gt;</span></span>
&nbsp;
  <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Target<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Project<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></td></tr></table></div>

<p>Not only does this script automate the process, but it serves as a living document for the process.  By doing this, the documented process is now coupled to the task itself.</p>
<p>The next step to coding processes is coding tasks that can&#8217;t be automated.  For example, during a deployment, if some sort of fatal error occurs, the next task might be to call your boss and clean up your resume.  Why not code a message in the deploy script to give you the list of people and phone numbers to call in case of an emergency, then load up your resume in Word?  Again, the documented process is now coupled with the task itself.</p>
<p>Obviously, this article grows out of my dislike of documentation.  I dislike it, not because it isn&#8217;t useful, but because it takes a lot of time and, in my personal experience, isn&#8217;t used very often.  By integrating the documentation with the task itself, I think we gain more value from it.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+Code+your+Documents+http://bit.ly/bBQR3" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/07/26/code-your-documents/&amp;title=Code+your+Documents" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/07/26/code-your-documents/&amp;t=Code+your+Documents" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/07/26/code-your-documents/&amp;title=Code+your+Documents" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/07/26/code-your-documents/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Book Review: Continuous Integration</title>
		<link>http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/</link>
		<comments>http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/#comments</comments>
		<pubDate>Fri, 18 Jul 2008 19:17:03 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=104</guid>
		<description><![CDATA[Continuous Integration is an easy read that anyone directly involved in the software development process could gain a lot from. Even though it doesn&#8217;t really introduce anything new, it ties everything most developers have learned over time into a single process, called continuous integration. Here are a few of the things that I really liked [...]]]></description>
			<content:encoded><![CDATA[<p><a href='http://blog.brianhartsock.com/wp-content/uploads/2008/06/51jrahs3ggl_sl500_aa240_.jpg'><img src="http://blog.brianhartsock.com/wp-content/uploads/2008/06/51jrahs3ggl_sl500_aa240_.jpg" alt="Continuous Integration" title="Continuous Integration" width="240" height="240" class="alignright size-medium wp-image-105" /></a><br />
<a href="http://www.amazon.com/Continuous-Integration-Improving-Addison-Wesley-Signature/dp/0321336380">Continuous Integration</a> is an easy read that anyone directly involved in the software development process could gain a lot from.  Even though it doesn&#8217;t really introduce anything new, it ties everything most developers have learned over time into a single process, called continuous integration.  Here are a few of the things that I really liked about the book.</p>
<h4>Automation</h4>
<p>Automate everything.  Automation limits the ability for bugs to creep into a process and it also makes  processes easier to follow.  After reading this book, I was really motivated to automate everything and so far it has been a great decision.   Some good examples of things that should be automated are:</p>
<ul>
<li>Tests</li>
<li>Environment setup and teardown, especially databases</li>
<li>Code inspection</li>
<li>Deployment</li>
</ul>
<h4>Databases</h4>
<p>Very often, databases are not part of a build process or version control.  This allows differences between different environments to potentially cause bugs.  Putting database schemas and test data in version control can help prevent this.  But, what I like the most, is it documents the setup of the database so potentially any developer could setup a new one.  </p>
<p>For example, when a new developer starts, I can show him the <a href="http://nant.sourceforge.net/">NAnt</a> or <a href="http://msdn.microsoft.com/en-us/library/wea2sca5(VS.80).aspx">MSBuild</a> task to execute in order to generate a new developer DB.  This is much easier than having to guide someone through MySQL, MSSQL, or any other database for the first time.</p>
<h4>Transparency</h4>
<p>Lastly, the biggest thing I learned from this book is how easily continuous integration can provide project transparency.  In my experience, all to often the developers and the rest of an organization get out of touch regarding a project&#8217;s status.  Continuous integration, combined with more agile development practices, allows a project to be completely transparent throughout an organization, from developers, to QA, to designers, and even senior leadership.  No longer does a looming release date bring surprises for those outside the development team.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+Book+Review%3A+Continuous+Integration+http://bit.ly/kDqVS" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/&amp;title=Book+Review%3A+Continuous+Integration" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/&amp;t=Book+Review%3A+Continuous+Integration" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/&amp;title=Book+Review%3A+Continuous+Integration" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/07/18/book-review-continuous-integration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>LINQ&#8217;d up</title>
		<link>http://blog.brianhartsock.com/2008/07/08/linqd-up/</link>
		<comments>http://blog.brianhartsock.com/2008/07/08/linqd-up/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 01:27:48 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=107</guid>
		<description><![CDATA[I just used LINQ for the first time ever in code. Pretty exciting. For me, it doesn&#8217;t get much better than transforming some mundane 6 liner into an elegant one liner. This&#8230; int count = 0; foreach &#40;string email in this.emails&#41; &#123; if &#40;email.EndsWith&#40;&#34;@mydomain.com&#34;&#41;&#41; count++; &#125; return count; becomes this&#8230; return this.emails.Count&#40;email =&#62; email.EndsWith&#40;&#34;@mydomain.com&#34;&#41;&#41;; In [...]]]></description>
			<content:encoded><![CDATA[<p>I just used <a href="http://msdn.microsoft.com/en-us/netframework/aa904594.aspx">LINQ </a> for the first time ever in code.  Pretty exciting.  For me, it doesn&#8217;t get much better than transforming some mundane 6 liner into an elegant one liner.</p>
<p>This&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #FF0000;">int</span> count <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> email <span style="color: #0600FF;">in</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">emails</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>email.<span style="color: #0000FF;">EndsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@mydomain.com&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> count<span style="color: #008000;">++;</span>
<span style="color: #000000;">&#125;</span>
<span style="color: #0600FF;">return</span> count<span style="color: #008000;">;</span></pre></div></div>

<p>becomes this&#8230;</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">return</span> <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">emails</span>.<span style="color: #0000FF;">Count</span><span style="color: #000000;">&#40;</span>email <span style="color: #008000;">=&gt;</span> email.<span style="color: #0000FF;">EndsWith</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;@mydomain.com&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>In some weird kind of way, I feel like an emo Ruby developer.  Maybe I&#8217;ll start wearing some tighter clothes.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+LINQ%E2%80%99d+up+http://bit.ly/FcQki" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/07/08/linqd-up/&amp;title=LINQ%E2%80%99d+up" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/07/08/linqd-up/&amp;t=LINQ%E2%80%99d+up" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/07/08/linqd-up/&amp;title=LINQ%E2%80%99d+up" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/07/08/linqd-up/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>NUnit and RowTest</title>
		<link>http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/</link>
		<comments>http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 03:05:45 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=102</guid>
		<description><![CDATA[I have been researching different unit testing tools for .NET lately. Obviously, NUnit was the first I came across, but MbUnit had the RowTest attribute, which allows parameters to be added to tests. This saves a lot of code and is really a must have feature. Luckily, I found an NUnit addin for RowTest here. [...]]]></description>
			<content:encoded><![CDATA[<p>I have been researching different unit testing tools for .NET lately.  Obviously, <a href="http://www.nunit.org/index.php">NUnit</a> was the first I came across, but <a href="http://www.mbunit.com/">MbUnit</a> had the RowTest attribute, which allows parameters to be added to tests.  This saves a lot of code and is really a must have feature.  Luckily, I found an NUnit addin for RowTest <a href="http://www.andreas-schlapsi.com/projects/rowtest-extension-for-nunit/">here</a>.  The latest version here is linked to NUnit 2.4.6, so I rebuilt it from source to use NUnit 2.4.7.</p>
<p>To install for <a href="http://www.testdriven.net/">TestDriven.NET</a>, just create an addins folder in the <em>%install root%\TestDriven.NET 2.0\NUnit\2.4\</em> and copy NUnitExtension.RowTest.AddIn.dll to the newly created folder.  Then in your test project, just reference NUnitExtensino.RowTest and you are set to go.</p>
<p>Here is an example:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">namespace</span> TestExample
<span style="color: #000000;">&#123;</span>
     <span style="color: #000000;">&#91;</span>TestFixture<span style="color: #000000;">&#93;</span>
     <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> Tests
     <span style="color: #000000;">&#123;</span>
          <span style="color: #000000;">&#91;</span>RowTest<span style="color: #000000;">&#93;</span>
          <span style="color: #000000;">&#91;</span>Row<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">4</span>,<span style="color: #FF0000;">4</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
          <span style="color: #000000;">&#91;</span>Row<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">5</span>,<span style="color: #FF0000;">5</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
          <span style="color: #000000;">&#91;</span>Row<span style="color: #000000;">&#40;</span><span style="color: #008000;">-</span><span style="color: #FF0000;">6</span>,<span style="color: #FF0000;">6</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#93;</span>
          <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> TestAddEqualsZero<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> x, <span style="color: #FF0000;">int</span> y<span style="color: #000000;">&#41;</span>
          <span style="color: #000000;">&#123;</span>
               Assert.<span style="color: #0000FF;">IsTrue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>x <span style="color: #008000;">+</span> y<span style="color: #000000;">&#41;</span> <span style="color: #008000;">==</span> <span style="color: #FF0000;">0</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
          <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+NUnit+and+RowTest+http://bit.ly/aidHx" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/&amp;title=NUnit+and+RowTest" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/&amp;t=NUnit+and+RowTest" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/&amp;title=NUnit+and+RowTest" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/06/19/nunit-and-rowtest/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C# Destructors and IDisposable</title>
		<link>http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/</link>
		<comments>http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/#comments</comments>
		<pubDate>Fri, 20 Jun 2008 01:52:33 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=101</guid>
		<description><![CDATA[This week I found myself somewhat confused on when to use destructor. Originally I assumed that anytime you implement IDisposable you should have a destructor that calls Dispose(). This is not the case though. The only time you really need a destructor is when a class directly contains unmanaged resources, like file handles. A good [...]]]></description>
			<content:encoded><![CDATA[<p>This week I found myself somewhat confused on when to use destructor.  Originally I assumed that anytime you implement <em>IDisposable</em> you should have a destructor that calls <em>Dispose()</em>.</p>
<p>This is not the case though.  The only time you really need a destructor is when a class directly contains unmanaged resources, like file handles.</p>
<p>A good example of when not to use a destructor is a wrapper class.  For instance, if you have a database connection class wrapped with some sort of adapter class, the adapter class doesn&#8217;t need a destructor.  It still needs to implement <em>IDisposable</em> to enable early disposal of resources, but the destructor of the underlying database connection class will handle any potential leak cases if <em>Dispose()</em> isn&#8217;t called.</p>
<p>Here is a quote from a very good <a href="http://www.ondotnet.com/pub/a/dotnet/2002/02/11/csharp_traps.html">article</a> on C# traps:</p>
<blockquote><p>
The destructor should only release unmanaged resources that your object holds on to, and it should not reference other objects. If you have only managed references you do not need to (and should not) implement a destructor. You want this only for handling unmanaged resources. Because there is some cost to having a destructor, you ought to implement this only on methods that consume valuable, unmanaged resources.
</p></blockquote>
<p>The really powerful statement is &#8220;it should not reference other objects&#8221; which basically backs up my previous statement on wrapper classes.</p>
<p>Here is another good <a href="http://msdn.microsoft.com/en-us/library/fs2xkftw.aspx">article</a> on destructors and <em>IDisposable</em>.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+C%23+Destructors+and+IDisposable+http://bit.ly/KC1XC" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/&amp;title=C%23+Destructors+and+IDisposable" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/&amp;t=C%23+Destructors+and+IDisposable" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/&amp;title=C%23+Destructors+and+IDisposable" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/06/19/c-destructors-and-idisposable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to actually use trigonometry in web applications</title>
		<link>http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/</link>
		<comments>http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/#comments</comments>
		<pubDate>Wed, 18 Jun 2008 14:37:47 +0000</pubDate>
		<dc:creator>bhartsock</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://blog.brianhartsock.com/?p=100</guid>
		<description><![CDATA[Disclaimer: my teammate Dellanoce actually coded this, but is too cool to blog, so I am blogging for him. Mailtrust has many different customers, some of which like to have their own branded control panel or webmail interface. We allow them to customize many different facets of the user interface, including colors. This has some [...]]]></description>
			<content:encoded><![CDATA[<p>Disclaimer: my teammate Dellanoce actually coded this, but is too cool to blog, so I am blogging for him.</p>
<p><a href="http://www.mailtrust.com">Mailtrust</a> has many different customers, some of which like to have their own branded control panel or webmail interface.  We allow them to customize many different facets of the user interface, including colors.  This has some unintended consequences though.  Sometimes, a user might select a white font color on top of a white background.  This in turns causes support to get involved in fixing the problem, which wastes time on such a trivial problem.</p>
<p>But there is a better way.  Use trigonometry, or more specifically the Pythagorean theorem!  I had no idea how this worked, but Dellanoce coded up a few lines of C# to compare two colors.  It returns a distance value which can be compared to a threshold value you can set.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;">        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">double</span> ColorDifference<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> htmlColor1, <span style="color: #FF0000;">string</span> htmlColor2<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            Color color1 <span style="color: #008000;">=</span> ColorTranslator.<span style="color: #0000FF;">FromHtml</span><span style="color: #000000;">&#40;</span>htmlColor1<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Color color2 <span style="color: #008000;">=</span> ColorTranslator.<span style="color: #0000FF;">FromHtml</span><span style="color: #000000;">&#40;</span>htmlColor2<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #FF0000;">double</span> rDiff <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color1.<span style="color: #0000FF;">R</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color2.<span style="color: #0000FF;">R</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">double</span> gDiff <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color1.<span style="color: #0000FF;">G</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color2.<span style="color: #0000FF;">G</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #FF0000;">double</span> bDiff <span style="color: #008000;">=</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color1.<span style="color: #0000FF;">B</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">-</span> Convert.<span style="color: #0000FF;">ToDouble</span><span style="color: #000000;">&#40;</span>color2.<span style="color: #0000FF;">B</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> Math.<span style="color: #0000FF;">Sqrt</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>rDiff <span style="color: #008000;">*</span> rDiff<span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>gDiff <span style="color: #008000;">*</span> gDiff<span style="color: #000000;">&#41;</span> <span style="color: #008000;">+</span> <span style="color: #000000;">&#40;</span>bDiff <span style="color: #008000;">*</span> bDiff<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>I was quite impressed with the simplicity and elegance this solution provided.  I should probably go give my, or his, trig teacher a hug.  </p>
<p>If you want to learn more about how powerful Pythagorean theorem is to compare distance values of really any type of object, check this <a href="http://betterexplained.com/articles/measure-any-distance-with-the-pythagorean-theorem/">article</a> out.</p>
<p align="left"><a target="_blank" class="tt" href="http://twitter.com/home/?status=@brianhartsock+How+to+actually+use+trigonometry+in+web+applications+http://bit.ly/2kTrvq" title="Post to Twitter"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-twitter-micro3.png" alt="Post to Twitter" /></a> <a target="_blank" class="tt" href="http://digg.com/submit?url=http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/&amp;title=How+to+actually+use+trigonometry+in+web+applications" title="Post to Digg"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-digg-micro3.png" alt="Post to Digg" /></a> <a target="_blank" class="tt" href="http://www.facebook.com/share.php?u=http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/&amp;t=How+to+actually+use+trigonometry+in+web+applications" title="Post to Facebook"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-facebook-micro3.png" alt="Post to Facebook" /></a> <a target="_blank" class="tt" href="http://reddit.com/submit?url=http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/&amp;title=How+to+actually+use+trigonometry+in+web+applications" title="Post to Reddit"><img class="nothumb" src="http://blog.brianhartsock.com/wp-content/plugins/tweet-this/icons/tt-reddit-micro3.png" alt="Post to Reddit" /></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.brianhartsock.com/2008/06/18/how-to-actually-use-trigonometry-in-web-applications/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
