<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Dave Chestnutt: SparklingCode and CodeGaffes</title>
        <link>http://geekswithblogs.net/dchestnutt/Default.aspx</link>
        <description>Writing better code; for fun and profit</description>
        <language>en-US</language>
        <copyright>Dave Chestnutt</copyright>
        <managingEditor>hlzsfc102@sneakemail.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <image>
            <title>Dave Chestnutt: SparklingCode and CodeGaffes</title>
            <url>http://geekswithblogs.net/images/RSS2Image.gif</url>
            <link>http://geekswithblogs.net/dchestnutt/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <item>
            <title>Perseverance &amp;ndash; or &amp;ndash; how to stop whining and embrace unit testing</title>
            <category>NUnit Tips</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2009/03/28/130484.aspx</link>
            <description>&lt;p&gt;We’ve all heard the mantra – Unit Testing is good for the soul.  We hear about the goodness of things like JUnit, NUnit, and TDD from other people.&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/dchestnutt/WindowsLiveWriter/JUnitNUnitlevelsofawareness_12934/image_2.png"&gt;&lt;img height="139" border="0" align="right" width="139" src="http://geekswithblogs.net/images/geekswithblogs_net/dchestnutt/WindowsLiveWriter/JUnitNUnitlevelsofawareness_12934/image_thumb.png" alt="image" style="border-width: 0px; margin: 10px 0px 10px 10px; display: inline;" title="image" /&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;But you’re not convinced. &lt;/p&gt;
&lt;p&gt;After all, it takes more time to write unit test code – and you’d rather get on with the next feature.  Besides, whether it’s true or not, you certainly feel like your progress is measured by how many features you crank out.&lt;/p&gt;
&lt;p&gt;In my own journey, I found I went through three distinct stages to testing heaven.  Look at my “diary” for the first few unit tested projects I was on.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stage 1: "I believe, it's stupid but I believe" &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Unit Testing, huh?  Great, now I have to spend time writing these stupid tests before I can say I’m done. It’s not really hard, but it takes additional time to create these tests. Time that I think would be better spent moving the project along with more features.  I was told to do it, so I will, but I don't see or feel the benefit yet.  I write tests because I have to.&lt;/p&gt;
&lt;p&gt;&lt;a href="http://geekswithblogs.net/images/geekswithblogs_net/dchestnutt/WindowsLiveWriter/JUnitNUnitlevelsofawareness_12934/image_4.png"&gt;&lt;img height="98" border="0" align="left" width="130" src="http://geekswithblogs.net/images/geekswithblogs_net/dchestnutt/WindowsLiveWriter/JUnitNUnitlevelsofawareness_12934/image_thumb_1.png" alt="image" style="border-width: 0px; margin: 0px 10px 0px 0px; display: inline;" title="image" /&gt;&lt;/a&gt;&lt;strong&gt;Stage 2: OK, it’s good for the project &lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Hmm, I added a new feature today – and someone else’s test broke.  As I checked it out, I found that indeed, I had modified some code that no longer worked for another scenario.  So, for the first time I saw a benefit from the tests.  Of course, I still think my time is better spent adding new features – but I begin to see that they’re a good thing to have, especially if other people write them.  So now I’m voluntarily writing tests for some of the new code I write.  The project is better for it.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stage 3: Hey, I can code faster&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;And gradually it happened.  Bit by bit the the second level effects of testing crept into my work.&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;I can write a small test to reproduce a bug, and I don’t need to get a whole test environment set up.  This lets me debug my solution much much faster. &lt;/li&gt;
    &lt;li&gt;I can write a small test to exercise some code that I can’t even get to from the main application yet.  This is cool, because I can implement a feature before someone else needs it.  And put it through its paces. &lt;/li&gt;
    &lt;li&gt;Now that I’ve gotten the hang of writing tests, I find it extremely easy to write lots of test cases for the same piece of functionality.  After writing the first test, it’s real easy to tweak it for many test cases.  We always talked about testing all the edge cases – now I can actually do so. &lt;/li&gt;
    &lt;li&gt;I can modify code (like redesign the innards of a class) with high confidence that I won’t break something that depends on it – because I have a set of tests to make sure I don’t break behavior.  This is where Unit Testing plus Refactoring have a real synergy.  The two combined offer a great advantage over either practice by itself.  Better quality code that’s easier to maintain. &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So that’s how it finally happened. I actively use tests to develop and debug code.  In fact – TDD (writing the tests first) as a process kind of snuck up on me. I can’t imagine writing code without tests anymore.&lt;/p&gt;
&lt;p&gt;So if you’re not there yet – don’t worry.  Especially if your boss is on your case.  It’ll come.  And when it does, you’ll wonder how you ever ever did without it.&lt;/p&gt;
&lt;div&gt;&lt;em&gt;&lt;font size="1"&gt;Technorati tags: &lt;a rel="tag" href="http://technorati.com/tag/unit testing"&gt;unit testing&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tag/junit"&gt;junit&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tag/nunit"&gt;nunit&lt;/a&gt;, &lt;a rel="tag" href="http://technorati.com/tag/CodeGaffes"&gt;CodeGaffes&lt;/a&gt;&lt;/font&gt;&lt;a rel="tag" href="http://technorati.com/tag/CodeGaffes"&gt;&lt;/a&gt;&lt;/em&gt;&lt;/div&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/130484.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2009/03/28/130484.aspx</guid>
            <pubDate>Sat, 28 Mar 2009 07:43:40 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/130484.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2009/03/28/130484.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/130484.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/130484.aspx</trackback:ping>
        </item>
        <item>
            <title>Path.Combine() - parameters are mis-named</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2007/03/13/108682.aspx</link>
            <description>&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The CLR is full of surprises.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Microsoft has a built-in &lt;SPAN style="FONT-WEIGHT: bold"&gt;System.IO.Path &lt;/SPAN&gt;class, to deal with all the path parsing issues we often run across.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;One of the most useful methods in there&amp;nbsp;can get rid of all the special case code we write to combine path strings.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;How many times have you written something like this to combine two path strings -- taking into account whether you need to add a slash between the path strings or not:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;String path1 = @"C:\ABC";&amp;nbsp;&amp;nbsp;&amp;nbsp;// may or may not end in a slash&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;String path2 = @"DEF";&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// may or may not start with a slash&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;String path = path1.TrimEnd('\\') + "\\" + path2.TrimStart('\\')&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;That one line of code works, but it creates 3 strings, calls two methods, and in general looks ugly.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Enter the Path class.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT size=3&gt;Path.Combine( path1, path2 )&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This is a sweet routine - you use it to combine two strings and it takes care of figuring out whether you need a slash between the parts of the path or not.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But there's a hitch.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;See if you can predict the output of these lines:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Console.WriteLine( Path.Combine( @"C:\ABC",&amp;nbsp; @"DEF" ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Console.WriteLine( Path.Combine( @"C:\ABC\", @"DEF" ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Console.WriteLine( Path.Combine( @"C:\ABC",&amp;nbsp; @"\DEF" ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Console.WriteLine( Path.Combine( @"C:\ABC\", @"\DEF" ));&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;When you think you know the answer, read on...&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The first two work as expected.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It correctly builds the path.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Path.Combine( @"C:\ABC",&amp;nbsp; @"DEF" ) -&amp;gt; C:\ABC\DEF&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Path.Combine( @"C:\ABC\", @"DEF" ) -&amp;gt; C:\ABC\DEF&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;But here's the surprise.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If your second piece of the path starts with a backslash, it assumes you must want it to be the root.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;So it ignores the first parameter!&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Path.Combine( @"C:\ABC",&amp;nbsp; @"\DEF" ) -&amp;gt; \DEF&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Courier New"&gt;Path.Combine( @"C:\ABC\", @"\DEF" ) -&amp;gt; \DEF&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The documentation for Path.Combine makes this clear in its remarks.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But really now, is this a useful feature?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Path.Combine would have been much &lt;SPAN style="FONT-WEIGHT: bold; FONT-STYLE: italic"&gt;more &lt;/SPAN&gt;useful if it simply took two paths and concatenated them properly. For my money, having these four examples return C:\ABC\DEF would have been a better choice.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;What Path.Combine &lt;STRONG&gt;&lt;EM&gt;IS&lt;/EM&gt;&lt;/STRONG&gt; useful for would be better documented like this:&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Path.Combine( defaultDirectory, userPath );&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;If I had seen that as the description of the parameters, this annoying behavior would not have surprised me.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;More importantly: I wouldn't have dreamed of using it for "&lt;STRONG&gt;combining&lt;/STRONG&gt;" &lt;STRONG&gt;paths&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Ok, I'll stop dreaming.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;FONT size=1&gt;Technorati tags: &lt;A href="http://technorati.com/tag/C#" rel=tag&gt;C#&lt;/A&gt;, &lt;A href="http://technorati.com/tag/CodeGaffes" rel=tag&gt;CodeGaffes&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/108682.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2007/03/13/108682.aspx</guid>
            <pubDate>Tue, 13 Mar 2007 21:09:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/108682.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2007/03/13/108682.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/108682.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/108682.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Copy &amp; Paste (and ReSharper to the rescue)</title>
            <category>CodeGaffes</category>
            <category>Visual Studio Tips</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/12/11/100867.aspx</link>
            <description>&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;I use a coding tool called ReSharper - and I was pleasantly surprised the other day when it pointed out a copy &amp;amp; paste bug that was waiting to explode.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You see, copy and paste programming is so very easy to do - that we all do it.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Even the best of us accidentally leave in duplicate code snippets from time to time.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Why Cut &amp;amp; Paste is so bad&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;There are two big reasons why this is an anti-pattern:&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=1&gt;If the code you cut and pasted has a bug in it (and it invariably will), what do you think are the chances that you'll find and fix all occurrences of it? 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=2&gt;If you're rubber-stamping code (copy and paste, paste, paste…) so that you can make minor edits to the pasted version, it's too easy to make a mistake - and the code will compile fine.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It won't fall over until a customer runs it.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Rubber-stamping typically happens in a switch statement or a batch or if/else-if statements (where the cases are nearly identical).&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;It's this second case that ReSharper showed me a bug that wouldn't have been found until run-time.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It surprised me because ReSharper doesn't look for duplicate code snippets.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But one of its rules can get triggered if you copy &amp;amp; paste code incorrectly.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;ReSharper is...&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This is an add-in to Visual Studio.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It does many things, but one thing it does well is point out flaws in your C# code via highlighting - so you can quickly see suspicious or questionable practices.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;There are other tools that do the same for C#, and there are similar tools for Java. &lt;SPAN style="FONT-STYLE: italic"&gt;[Disclaimer: I do not work for JetBrains. I paid for my own copy out of my own pocket. I'm just a happy user.]&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This is not a tutorial on using ReSharper - I'm just showing one tiny example of how it can help you.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Here is some legacy code opened in Visual Studio with ReSharper:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in; mso-outline-level: 1"&gt;&lt;IMG title="ReSharper Example on Legacy Code" src="http://static.flickr.com/136/319646018_564ffc8d19.jpg?v=0" border=0&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Notice the highlights on the right of the source window.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Those give an indication of where there might be problems in the source.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You can click those lines and it will jump to the place in the code with the problem.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It highlights the error and offers fixes, too.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The orange lines are approximately lined up with where the scroll bar would be when you view the code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Orange means warning, and red means error.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Opening up legacy code often shows many many orange lines because ReSharper warns about suspicious or bad practices.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;These are things that the compiler is happy with, but you'll be unhappy about in the long run.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Here's what ReSharper found&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So, back to how I was pleasantly surprised.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Look at this code example.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It's pretty obvious at first glance that this code was rubber-stamped to handle many cases - with slight edits in each version.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This code will compile, but it won't work right.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Here's what it looks like in normal Visual Studio:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in; mso-outline-level: 1"&gt;&lt;IMG title=blah src="http://static.flickr.com/140/319646020_5f56459b17.jpg?v=0&gt;&lt;/P&gt;&lt;P style=" FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1?&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-FAMILY: Verdana"&gt;Do you see the problem?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It's in line 41.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;When copying and pasting, the person forgot to modify the &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Lucida Console'"&gt;if &lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: Verdana"&gt;statement to use htmlButtonMatch instead of htmlTextboxMatch.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It's clearly wrong, but it might not show up as a bug until months after someone wrote this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Look at what ReSharper shows (it does additional highlighting of things like method names, etc.):&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in; mso-outline-level: 1"&gt;&lt;IMG title=blah src="http://static.flickr.com/129/319646021_8dedd5c3ee.jpg?v=0&gt;&lt;/P&gt;&lt;P style=" FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1?&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;With this cool tool, I'm immediately alerted to the problem.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;The tool tip for the grayed out variable warns me that it wasn't used.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;From that, I can easily spot the error in line 41.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The important thing is that ReSharper alerted me that there was a problem.&lt;/P&gt;
&lt;BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px"&gt;
&lt;P style="MARGIN: 0in; mso-outline-level: 1"&gt;&lt;IMG title=blah src="http://static.flickr.com/131/319646022_9546887e59.jpg?v=0&gt;&lt;/P&gt;&lt;P style=" FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1?&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This was some actual legacy code that I opened up one day - when I noticed the problem.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;I was&amp;nbsp;fix it and find out why unit tests didn't cover this case.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;You know, if I didn't tell people I used ReSharper, they'd think I was really smart.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;But I am smart enough to use good tools.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;See also: &lt;A href="http://en.wikipedia.org/wiki/Copy_and_paste_programming"&gt;http://en.wikipedia.org/wiki/Copy_and_paste_programming&lt;/A&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;FONT size=1&gt;Technorati tags: &lt;A href="http://technorati.com/tag/Visual%20Studio" rel=tag&gt;Visual Studio&lt;/A&gt;, &lt;A href="http://technorati.com/tag/CodeGaffes" rel=tag&gt;CodeGaffes&lt;/A&gt;, &lt;A href="http://technorati.com/tag/Geekswithblogs" rel=tag&gt;Geekswithblogs&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/100867.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/12/11/100867.aspx</guid>
            <pubDate>Mon, 11 Dec 2006 18:22:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/100867.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/12/11/100867.aspx#feedback</comments>
            <slash:comments>5</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/100867.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/100867.aspx</trackback:ping>
        </item>
        <item>
            <title>Intentional Programming</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/11/09/96626.aspx</link>
            <description>&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;Christopher Diggins has an interesting post on &lt;STRONG&gt;Intentional Programming&lt;/STRONG&gt;.&amp;nbsp;&amp;nbsp; This is a new way of applying top-down design.&amp;nbsp; It's a very good idea: you write your code nice and clear, with calls to sub-methods that "do the right thing" - sub-methods that you'll write later.&amp;nbsp; The advantage of this is that your code will be quite readable.&amp;nbsp; And since our code always lasts much longer than we ever intended, clear readable code is more maintainable (and likely to haveless bugs, too).&amp;nbsp; An idea well worth thinking about and adding to your bag of tricks.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Arial size=2&gt;See: &lt;/FONT&gt;&lt;A href="http://www.artima.com/forums/flat.jsp?forum=106&amp;amp;thread=179611"&gt;&lt;FONT face=Arial size=2&gt;http://www.artima.com/forums/flat.jsp?forum=106&amp;amp;thread=179611&lt;/FONT&gt;&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;FONT size=1&gt;Technorati tags: &lt;/FONT&gt;&lt;/EM&gt;&lt;A href="http://technorati.com/tag/CodeGaffes" rel=tag&gt;&lt;EM&gt;&lt;FONT size=1&gt;CodeGaffes&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;&lt;FONT size=1&gt;, &lt;/FONT&gt;&lt;/EM&gt;&lt;A href="http://technorati.com/tag/Geekswithblogs" rel=tag&gt;&lt;EM&gt;&lt;FONT size=1&gt;Geekswithblogs&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;/DIV&gt;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/96626.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/11/09/96626.aspx</guid>
            <pubDate>Thu, 09 Nov 2006 16:28:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/96626.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/11/09/96626.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/96626.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/96626.aspx</trackback:ping>
        </item>
        <item>
            <title>Want to ride the shuttle?</title>
            <category>Random</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/11/08/96530.aspx</link>
            <description>&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;Imagine hanging onto one of the solid rocket boosters when the Space Shuttle goes up.&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;This is a cool 4 minute video of a camera on one of the Atlantis flights.&amp;nbsp; It's on from takeoff - to separation - to splashdown.&amp;nbsp; There's no sound, but just try to imagine everything shaking around you...&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;A title=http://mfile.akamai.com/18566/asf/etouchsyst2.download.akamai.com/18355/wm.nasa-global/sts-115/fd01/115_SRB_LeftSide.1.asx href="http://mfile.akamai.com/18566/asf/etouchsyst2.download.akamai.com/18355/wm.nasa-global/sts-115/fd01/115_SRB_LeftSide.1.asx"&gt;http://mfile.akamai.com/18566/asf/etouchsyst2.download.akamai.com/18355/wm.nasa-global/sts-115/fd01/115_SRB_LeftSide.1.asx&lt;/A&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Arial"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/96530.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/11/08/96530.aspx</guid>
            <pubDate>Wed, 08 Nov 2006 18:03:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/96530.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/11/08/96530.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/96530.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/96530.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Checking for Null Fields is BAD</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/10/21/94740.aspx</link>
            <description>&lt;DIV&gt;The other day, I had to&amp;nbsp;fix a particularly nasty bug with a &lt;FONT color=#000000&gt;&lt;STRONG&gt;NullReferenceException&lt;/STRONG&gt;&lt;/FONT&gt;.&amp;nbsp; During the process, I came up with a couple alternatives to fix it and decided to document why &lt;STRONG&gt;Checking for Null Fields is BAD&lt;/STRONG&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;A id=Editor_Edit_hlEntryLink title="view: CodeGaffe: Checking for Null Fields is BAD" href="/dchestnutt/articles/94744.aspx" target=_blank&gt;http://geekswithblogs.net/dchestnutt/articles/94744.aspx&lt;/A&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;EM&gt;&lt;FONT size=2&gt;Technorati tags: &lt;/FONT&gt;&lt;/EM&gt;&lt;A href="http://technorati.com/tag/CodeGaffes" rel=tag&gt;&lt;EM&gt;&lt;FONT size=2&gt;CodeGaffes&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;EM&gt;&lt;FONT size=2&gt;, &lt;/FONT&gt;&lt;/EM&gt;&lt;A href="http://technorati.com/tag/Geekswithblogs" rel=tag&gt;&lt;EM&gt;&lt;FONT size=2&gt;Geekswithblogs&lt;/FONT&gt;&lt;/EM&gt;&lt;/A&gt;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/94740.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/10/21/94740.aspx</guid>
            <pubDate>Sat, 21 Oct 2006 22:10:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/94740.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/10/21/94740.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/94740.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/94740.aspx</trackback:ping>
        </item>
        <item>
            <title>What are CodeGaffes?</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66067.aspx</link>
            <description>&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;In my company, I've been able to join various projects over the years.  As a result, I'm usually modifying or adding to legacy code.  Of course, in reality, all code is legacy code after about a week.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;In looking at code (written by others as well as myself) I sometimes see bad coding practices.  These are always obvious in hindsight.  &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;In the spirit of blogging, I'm going to share these as &lt;strong&gt;CodeGaffes&lt;/strong&gt;.   Look to understand the reason why these are bad, as well as how to fix or avoid them.  In a sense, these are like design patterns, only in miniature.  By and large, they apply to all three languages, C#, Java, and C++.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;Hopefully you can be amused (as you recognize them) or instructed (by avoiding them). &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;I am certainly not the first (nor the last) to point out these coding problems.  You can find them mentioned elsewhere in blogs and books, I'm just pulling some of them together.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;Feel free to add comments, whether you agree or not.  And, of course, we all love to hear war stories where you've seen the effects of such gaffes.  &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt;Sparkling code - this is what you strive for.  Stuff to be proud of.&lt;/font&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;div&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div&gt;&lt;font size="1"&gt;&lt;em&gt;See recent posts: &lt;/em&gt;&lt;/font&gt;&lt;a href="http://geekswithblogs/dchestnutt"&gt;&lt;font size="1"&gt;&lt;em&gt;http://geekswithblogs/dchestnutt&lt;/em&gt;&lt;/font&gt;&lt;/a&gt; &lt;/div&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000" size="2"&gt; &lt;/font&gt;
&lt;div&gt;&lt;font face="Verdana" color="#000000"&gt;&lt;em&gt;&lt;font size="1"&gt;Technorati tags: &lt;/font&gt;&lt;/em&gt;&lt;a rel="tag" href="http://technorati.com/tag/CodeGaffes"&gt;&lt;em&gt;&lt;font size="1"&gt;CodeGaffes&lt;/font&gt;&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&lt;font size="1"&gt;, &lt;/font&gt;&lt;/em&gt;&lt;a rel="tag" href="http://technorati.com/tag/Geekswithblogs"&gt;&lt;em&gt;&lt;font size="1"&gt;Geekswithblogs&lt;/font&gt;&lt;/em&gt;&lt;/a&gt;&lt;em&gt;&lt;font size="1"&gt; &lt;/font&gt;&lt;/em&gt;&lt;/font&gt;&lt;/div&gt;
&lt;/div&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/66067.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66067.aspx</guid>
            <pubDate>Mon, 16 Jan 2006 22:26:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/66067.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66067.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/66067.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/66067.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Unreinforced Concrete Classes</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66071.aspx</link>
            <description>&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;One of the benefits of object oriented design, is that some problems show up during compile-time instead of at run-time.&amp;nbsp; And you know that run-time issues always show up at the worst possible time, like at a customer site.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;This CodeGaffe happens when a programmer writes code that "enforces" something with comments, or Assertions.&amp;nbsp; Have you ever seen a method defined in a base class with a comment or Assertion telling you to override it?&amp;nbsp; Of course, if the subclass doesn't override it, you can be certain the method will be called at an inopportune time. This is a simple misunderstanding of an object oriented feature because there is a way to make the language work for you to force the subclass author to override the method.&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;So what's this CodeGaffe look like?&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;BR&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color=#000000&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class TableBase&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public virtual int CountLines()&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Debug.Assert(false, "override me");&amp;nbsp; // *** Don't do this&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 0;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MyTableSubclass : TableBase&amp;nbsp; // subclass&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void Main(string[] args)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // here is code to use it&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyTableSubclass table = new MyTableSubclass ();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(table.CountLines());&amp;nbsp; // prints 0 after assert &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;&lt;BR&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;See the problem?&amp;nbsp; As the original author of TableBase, you want to make sure people who write subclasses implement their own CountLines method.&amp;nbsp; But if they forget to override it, they won't know until the method is called at runtime.&amp;nbsp;&amp;nbsp; Possibly at a customer site, but more likely during testing.&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana&gt;&lt;FONT color=#000000 size=2&gt;Instead, define your base class this way:&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana&gt;&lt;FONT size=2&gt;&lt;BR&gt;&lt;/DIV&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face=Verdana size=2&gt;
&lt;DIV&gt;&lt;FONT color=#000000&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;U&gt;abstract&lt;/U&gt; class TableBase&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // *** Do use "abstract"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;U&gt;abstract&lt;/U&gt; int CountLines();&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; // *** Do use "abstract"&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000080 size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana size=2&gt;&lt;FONT color=#000080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MyTableSubclass : TableBase&amp;nbsp; // &lt;EM&gt;now this won't compile&lt;/EM&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/FONT&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT face=Verdana color=#000000 size=2&gt;&amp;nbsp;&lt;/FONT&gt; 
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;Now, if someone extends your class, they'll find out at compile-time -- that's about as immediate as you can get without standing behind them, watching over their shoulder as they code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And fixing the subclass at this time is trivial because the error points to the actual problem: a missing definition for CountLines.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;U&gt;abstract&lt;/U&gt; class TableBase&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public &lt;U&gt;abstract&lt;/U&gt; int CountLines(); // ***&amp;nbsp;"abstract" forces your intent&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public class MyTableSubclass : TableBase&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public override int CountLines() // the new method definition&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return 1;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000080&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;&lt;FONT color=#000080&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public static void Main(string[] args) // here is code to use it&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyTableSubclass table = new MyTableSubclass ();&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Console.WriteLine(table.CountLines());&amp;nbsp; // outputs "1", as it should&amp;nbsp;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;&lt;/FONT&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;
&lt;HR id=null&gt;
&lt;/FONT&gt;
&lt;P&gt;&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&lt;/FONT&gt; 
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;The moral?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If you find yourself creating (or maintaining)&amp;nbsp;a method with comments or assertions telling people to override it -- make&amp;nbsp;the method abstract.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And you'll enforce your intention.&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT color=#000000&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;
Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt;&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/66071.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66071.aspx</guid>
            <pubDate>Mon, 16 Jan 2006 22:51:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/66071.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/01/16/66071.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/66071.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/66071.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Clueless Comments - Never Say Never</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/01/18/66336.aspx</link>
            <description>&lt;DIV&gt;
&lt;P style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1"&gt;I was fixing a bug the other day, when I ran across this comment (&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;marked in red&lt;/STRONG&gt;&lt;/FONT&gt;):&lt;/P&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (condition1)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//… some useful code …&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (condition2)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//… some useful code …&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;&lt;FONT color=#ff0000&gt;&lt;STRONG&gt;// this can never happen&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;My first thought was, if this can never happen then why not throw an exception in case it does? So I added a line to throw an exception. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (condition1)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//… some useful code …&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (condition2)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;//… some useful code …&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// this can never happen&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;FONT color=#ff0000&gt;&lt;STRONG&gt;throw new ApplicationException("this can never happen");&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;And you can guess what happened. The next night, some of our tests failed. Because of course "it" did happen.&lt;/DIV&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1"&gt;There are a couple of reasons why this pattern appears in code. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;DIV style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;Overconfidence. The programmer is sure that their prior code has caught all cases, so it won't happen – but they want to be good citizens and document that fact with a comment or assertion. And their comment is correct – at first. But of course, all code gets modified and unfortunately, over time the original assumptions no longer hold. Since the assumptions are just that – &lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-STYLE: italic; FONT-FAMILY: 'Times New Roman'"&gt;assumed&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt; – and not checked by the code, you end up with brittle code.&lt;BR&gt;&lt;/SPAN&gt;&lt;/DIV&gt;
&lt;LI&gt;
&lt;DIV style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-FAMILY: 'Times New Roman'"&gt;Time Crunch. The programmer, under the gun to fix a bug or finish a feature, doesn't really know what the code should do if this actually happens. There's no apparent recovery that the code can do, but they're pretty sure it won't happen. They're not 100% sure so they leave a comment or Debug Assertion behind.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In this scenario, unit tests are usually skipped, too. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1"&gt;So what's the right thing to do?&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 12pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1" value=1&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Throw an exception&lt;/SPAN&gt;. You can leave the comment or assertion in, but DO throw an exception so you see the problem exactly when it happens.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It will be much easier to spot the problem when you have an exception pointing directly at the offending line, than it is to figure out what's wrong when the code doesn't fall over until another thousand lines of code execute. When it breaks, as it did in my case, you can fix the code to handle the new situation and move on. &lt;BR&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 12pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1" value=2&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;Write recovery code&lt;/SPAN&gt;.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Sometimes, there's a perfectly reasonable action you can do - so recover and let the code continue.&amp;nbsp;For example, this code was checking values from&amp;nbsp;a settings file, and if the file was&amp;nbsp;ever corrupted, there was&amp;nbsp;a perfectly reasonable default&amp;nbsp;we could use.&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;In essence, this CodeGaffe is like neglecting to add a&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;default&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; case to a &lt;FONT face="Courier New" color=#000080 size=2&gt;&lt;STRONG&gt;switch&lt;/STRONG&gt;&lt;/FONT&gt; statement. &lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;Many&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; times, you really should have a final&amp;nbsp;&lt;STRONG&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;else&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; on your &lt;STRONG&gt;&lt;FONT face="Courier New" color=#000080 size=2&gt;if&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; statements. They won't all throw exceptions of course, but you should &lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;always&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; think about what &lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt;should&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; happen if your execution did fall through your &lt;/SPAN&gt;&lt;SPAN style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'"&gt;&lt;FONT color=#000080&gt;if&lt;/FONT&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 12pt; FONT-FAMILY: 'Times New Roman'"&gt; statements. Then do the right thing with some actual code, not with clueless comments.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Ah, if only the compiler would do what I meant, not what I wrote.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 12pt; MARGIN: 0in; FONT-FAMILY: 'Times New Roman'; mso-outline-level: 1"&gt;Have you ever seen this gaffe in your projects?&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;
Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/66336.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/01/18/66336.aspx</guid>
            <pubDate>Wed, 18 Jan 2006 23:45:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/66336.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/01/18/66336.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/66336.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/66336.aspx</trackback:ping>
        </item>
        <item>
            <title>SparklingCode: Count the cost with Line Numbers</title>
            <category>CodeGaffes</category>
            <category>Visual Studio Tips</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/01/30/67659.aspx</link>
            <description>&lt;DIV&gt;One of the benefits of using modern editors is that it's really easy to navigate your code base. If you're looking at a method call, for example, you can use a keystroke combination to jump to the method definition. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;But there's a drawback to this. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;If you're not careful, as you add new code you can end up with monster methods, or monster-sized classes. Let me ask you this - what do you think the maximum size of a class should be? 100 lines? 500 lines? 10,000 lines? While we won't agree on an exact number, we can all agree that a class with 10,000 lines in it is much more likely to have bugs in it than one with 100 lines. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;But no one sets out to write such a huge class. How does it get this way? Simple - over time, various people make little modifications to a class. How many times have you looked at a modification and thought to yourself, "Perfect, I'll just add these lines of code here, and it'll support the new feature." After enough people do that, your 500 line class grows and grows. And grows! &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Here's a fairly innocuous bit of code. If I had just added this, without line numbers being displayed, I might not realize how big the class already is. But, as the screen shot on the right shows, I might be more inclined to realize that I shouldn't grow this class any further since it already has nearly 20,000 lines of code in it! &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;TABLE border=1&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH vAlign=top align=left width="50%"&gt;No Line Numbers&lt;/TH&gt;
&lt;TH vAlign=top align=left width="50%"&gt;Line Numbers show a problem!&lt;/TH&gt;&lt;/TR&gt;
&lt;TR&gt;
&lt;TD vAlign=top&gt;&amp;nbsp;&lt;IMG title="Code snippet without line numbers" src="http://static.flickr.com/33/93377523_8d711f7d70.jpg?v=0" border=0&gt;&amp;nbsp; &lt;/TD&gt;
&lt;TD vAlign=top&gt;&amp;nbsp;&lt;IMG title="Code snippet with line numbers" src="http://static.flickr.com/42/93377526_cc384d99f5.jpg?v=0" border=0&gt;&amp;nbsp; &lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Thus, my advice: turn on line number display in your editor. In Visual Studio, turn on Line Numbers by going to &lt;B&gt;Tools | Options | Text Editor&lt;/B&gt; and check &lt;U&gt;&lt;B&gt;Line Numbers&lt;/B&gt;&lt;/U&gt; &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;&lt;IMG title="Turn on Line Number Display in Visual Studio" src="http://static.flickr.com/14/93377527_63d3a3e801.jpg?v=0" border=0&gt; &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Now, when you're fixing bugs or adding features, you'll see line numbers. And when you get near the bottom of a file, you'll have another reminder that the class is growing out of control. Then you can plan some refactoring to break up the monster method or class. And improve your code base. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;Turn on line numbers in your editor. They're an early warning system. &lt;/DIV&gt;
&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV&gt;
Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/67659.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/01/30/67659.aspx</guid>
            <pubDate>Tue, 31 Jan 2006 00:46:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/67659.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/01/30/67659.aspx#feedback</comments>
            <slash:comments>6</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/67659.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/67659.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Surprising Assignments</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/02/06/68437.aspx</link>
            <description>&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;This CodeGaffe covers two similar problems.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;The first one involves Booleans, while the second covers any variable type.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Here's some code that contains 2 bugs in one line.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;This is a practice to avoid.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Can you spot the 2 bugs?&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_condition = &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;) { &lt;SPAN style="COLOR: green"&gt;// *** DON'T DO THIS!&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// do something&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;/o:p&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;If you had any trouble spotting the problem, that's because you're normal.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And if you didn't have any trouble, that's because you were looking for a problem.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;If you didn't know there was anything wrong with that code, you might just have easily read the code as the author undoubtedly intended: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_condition == &lt;SPAN style="COLOR: blue"&gt;true&lt;/SPAN&gt;) { &lt;SPAN style="COLOR: green"&gt;// legal but error prone&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// do something&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; mso-outline-level: 2"&gt;&lt;!--EndFragment--&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;And while &lt;STRONG&gt;you&lt;/STRONG&gt; wouldn't accidentally leave out one of the equal signs, it's a bear to find this problem when someone else does.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And this is a case where the compiler doesn't help you.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It's quite happy to compile this code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Which is why we get two bugs: 1) it always sets m_condition to true and, 2) always enters the block of code.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Instead, let a Boolean be a Boolean and test it naturally: &lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_condition) {&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// natural test for bool&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// do something&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; mso-outline-level: 2"&gt;&lt;!--EndFragment--&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;This is a problem for all three languages, C#, Java, and C++.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; But, t&lt;/SPAN&gt;est Booleans naturally and you'll avoid the problem.&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Now, for the second half of the CodeGaffe. &lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&lt;/SPAN&gt;What about other types besides Boolean, like integers?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Don't you have to test them this way?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Well it turns out, that because this was a source of bugs, the designers of Java and C# made the language prevent you from putting anything other than a Boolean expression inside an if statement.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;So, dropping an equal sign on the floor will result in a compiler warning.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; I&lt;/SPAN&gt;f you write this it won't compile.&amp;nbsp; The compiler will save you:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_flag = 3) {&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// won't compile in Java and C#&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// do something&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;&lt;/SPAN&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;But what about C++?&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; That code&lt;/SPAN&gt; will compile, and suffer the same bugs as the first example with Booleans.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;So, to be safe, g&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;et into the habit of doing this (I know, it looks weird at first):&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (3 == m_flag) {&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// put constant first&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp; &lt;SPAN style="COLOR: green"&gt;// do something&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P style="MARGIN: 0in 0in 0pt 0.5in; mso-outline-level: 2"&gt;&lt;!--EndFragment--&gt;&lt;/SPAN&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&amp;nbsp;&lt;o:p&gt;&lt;/o:p&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;Now the compiler is your friend.&amp;nbsp; If you inadvertently forget the second equal sign, you'll get a compiler error instead of a run-time bug.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And that's much more productive!&amp;nbsp; I'll take a compiler error over a runtime bug any day of the week.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt; mso-outline-level: 1"&gt;&lt;SPAN style="FONT-SIZE: 10pt; FONT-FAMILY: Verdana"&gt;&lt;/SPAN&gt;
Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/68437.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/02/06/68437.aspx</guid>
            <pubDate>Mon, 06 Feb 2006 23:35:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/68437.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/02/06/68437.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/68437.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/68437.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Really Private Data</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/02/16/69798.aspx</link>
            <description>&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Today's CodeGaffe is something I see all the time.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It creeps into your code over time.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Here's the scenario: Your class has grown from its humble beginnings, and there are now fields in your class that should &lt;SPAN style="FONT-STYLE: italic; TEXT-DECORATION: underline"&gt;not&lt;/SPAN&gt; be used by some of your methods.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;In essence, you want some of your data to be private from part of your class.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;As in "really private". &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;If you've ever found yourself thinking, "&lt;U&gt;&lt;EM&gt;Most&lt;/EM&gt;&lt;/U&gt; of this class shouldn't access field &lt;EM&gt;foo&lt;/EM&gt;,” then you've experienced this.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Here's an example I ran across recently - this class has two slightly different copies of an object, called a Thingee,&amp;nbsp;but only one should be used by the majority of the class.&amp;nbsp; Which one would you use if you were adding new code?&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; This class has a Thingee that it works with.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; But, in reality it contains 2 Thingee objects, &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; and dynamically chooses which one should be used.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;/SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; PrivatePrivateBad&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; OurThingee&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_CatIsAround)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; m_Thing1;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; m_Thing2;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; m_CatIsAround;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; m_Thing1;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; m_Thing2;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; PrivatePrivateBad()&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_CatIsAround = &lt;SPAN style="COLOR: blue"&gt;...&lt;/SPAN&gt;;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_Thing1 = ...;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_Thing2 = ...;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SomeMethod()&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; &lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;STRONG&gt;&lt;SPAN style="COLOR: green"&gt;&lt;FONT color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/FONT&gt;&lt;U&gt;// I can access both fields, but really shouldn't&lt;/U&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;Console.Out.WriteLine(m_Thing1);&lt;/U&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;Console.Out.WriteLine(m_Thing2);&lt;/U&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/STRONG&gt;&lt;SPAN style="COLOR: green"&gt;// Accessing the property is OK&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; Console.Out.WriteLine(OurThingee);&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The most common solution to this problem is to dictate (in comments, where else?) that you must always use the property &lt;SPAN style="FONT-WEIGHT: bold"&gt;&lt;FONT face="Courier New"&gt;OurThingee&lt;/FONT&gt; &lt;/SPAN&gt;instead of accessing the two fields directly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And that will work - as long as everyone follows the rules.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;But there's no way to enforce it.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Without enforcement, as the code evolves, eventually someone will not know about this convention.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They'll access &lt;FONT face="Courier New"&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;m_Thing1&lt;/SPAN&gt; &lt;FONT face=Arial&gt;or&lt;/FONT&gt; &lt;/FONT&gt;&lt;SPAN style="FONT-WEIGHT: bold"&gt;&lt;FONT face="Courier New"&gt;m_Thing2&lt;/FONT&gt; &lt;/SPAN&gt;directly.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;After all, both fields are private to this class, so it is reasonable for a new person on your project to use any of the fields as they add new code.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And in a large class, once someone does this, future developers are much more likely to follow the same example&amp;nbsp;and reference stuff that should have been "really private".&amp;nbsp; This is how good code goes bad.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So, the intent of the original design gets lost.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;And bugs appear.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Fortunately, there's a simple way to enforce your design. You need to create another class.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;The new class will contain both Thingee objects, and hide the details of which Thingee you're supposed to use.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;It will simply have a property or assessor method to return the proper object. The new class will enforce our design, so we'll call it a ThingeeEnforcer, like so:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; This class hides the details of how we dynamically&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; choose which Thingee should be used.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;/SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; ThingeeEnforcer&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; CurrentThingee&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;if&lt;/SPAN&gt; (m_CatIsAround)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; m_Thing1;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;else&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; m_Thing2;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;bool&lt;/SPAN&gt; m_CatIsAround;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; m_Thing1;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; m_Thing2;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SetThingee()&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_CatIsAround = &lt;FONT color=#0000ff&gt;...&lt;/FONT&gt;;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_Thing1 = ...;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; m_Thing2 = ...;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Refactoring our original class is actually pretty easy.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;You need to move the relevant fields to the enforcer class, and change the &lt;FONT face="Courier New"&gt;&lt;STRONG&gt;OurThingee&lt;/STRONG&gt;&lt;/FONT&gt; property to access our new class.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Wherever you set the initial values of the objects, you now delegate the work to the new enforcer class.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Here's what the refactored original class looks like.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;Notice you can't possibly reference the wrong object anymore:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; In this class, you can only access Thingee via&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; the ThingeeEnforcer, so there's no way to &lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; get the wrong one.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: gray"&gt;///&lt;/SPAN&gt;&lt;SPAN style="COLOR: green"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: gray"&gt;&lt;/SUMMARY&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;class&lt;/SPAN&gt; PrivatePrivateGood&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;{&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; ThingeeEnforcer te = &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; ThingeeEnforcer();&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;private&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;object&lt;/SPAN&gt; OurThingee&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;get&lt;/SPAN&gt; { &lt;SPAN style="COLOR: blue"&gt;return&lt;/SPAN&gt; te.CurrentThingee; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; PrivatePrivateGood()&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; te.SetThingee();&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;public&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; SomeMethod()&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; &lt;SPAN style="COLOR: green"&gt;&lt;U&gt;// This is the only Thingee we can access&lt;/U&gt;&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;U&gt;Console.Out.WriteLine(OurThingee);&lt;/U&gt;&lt;/STRONG&gt;&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;}&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The steps for refactoring the Thingee stuff into a separate class are straightforward.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=1&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=1&gt;First, review the original class's code and make sure all code references the appropriate property or accessor method. 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=2&gt;You're likely to see only two or three places that truly need to access the fields directly: 
&lt;OL style="MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in; MARGIN-LEFT: 0.5in; DIRECTION: ltr; unicode-bidi: embed" type=a&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=1&gt;The constructor (or some initialization method) that sets their values 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=2&gt;The property, or accessor method that gets the right value 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 2" value=3&gt;Possibly a method that clears their values&lt;/LI&gt;&lt;/OL&gt;
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=3&gt;Create a new class; we called it ThingeeEnforcer as it enforced the rules of access. 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=4&gt;Move the fields to the new class 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=5&gt;Add method(s) to set/clear the values 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=6&gt;Add a property or accessor to get the correct value 
&lt;LI style="MARGIN-TOP: 0px; FONT-SIZE: 10pt; MARGIN-BOTTOM: 0px; VERTICAL-ALIGN: middle; FONT-FAMILY: Verdana; mso-outline-level: 1" value=7&gt;Convert all code in the original class to use the new methods/accessors from the enforcer class.&amp;nbsp; In our case, this was pretty simple since (in step 1) we made sure all the code was accessing our property.&amp;nbsp; The good thing is, by moving the fields (in step 4) the compiler will help you find every single reference that needs fixing.&lt;/LI&gt;&lt;/OL&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Now, when people add new features to your class &lt;SPAN style="FONT-STYLE: italic; TEXT-DECORATION: underline"&gt;next&lt;/SPAN&gt; time, they won't be tempted to access the "really private" fields.&lt;SPAN style="mso-spacerun: yes"&gt;&amp;nbsp; &lt;/SPAN&gt;They're safely tucked away in your enforcer class.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;As I said at the outset, the key is to realize that as soon as you find yourself thinking, "&lt;U&gt;&lt;EM&gt;Most&lt;/EM&gt;&lt;/U&gt; of my class shouldn't access &lt;EM&gt;something&lt;/EM&gt;" you've hit the point where you need another class to impose that restriction. &lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;It's OK to create small classes like this to enforce some condition.&amp;nbsp; That's exactly what object oriented design is all about.&amp;nbsp; And your code will sparkle.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;
Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/69798.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/02/16/69798.aspx</guid>
            <pubDate>Fri, 17 Feb 2006 02:10:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/69798.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/02/16/69798.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/69798.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/69798.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Avoid .NET “partial” classes in C# and VB</title>
            <category>CodeGaffes</category>
            <category>Visual Studio Tips</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/04/05/74442.aspx</link>
            <description>&lt;P&gt;Microsoft added a new keyword to C# and VB for 2005 (CLR 2.0): &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;&lt;SPAN&gt;&lt;STRONG&gt;&lt;EM&gt;Don't use it.&lt;/EM&gt;&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;/EM&gt;&lt;/STRONG&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; is used to physically break up a class definition into multiple files. When the compiler sees the keyword &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; it finds all the related partial files in order to compile the class. This makes it possible to split the code for a single class across multiple files. By and large, though, this is a bad idea. Let’s look at why that is. 
&lt;P&gt;&lt;SPAN class=pullquote style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-WEIGHT: normal; FONT-SIZE: 16pt; FLOAT: right; PADDING-BOTTOM: 5px; MARGIN: 20px; WIDTH: 207px; LINE-HEIGHT: normal; PADDING-TOP: 5px; FONT-STYLE: normal; HEIGHT: 133px; TEXT-ALIGN: right"&gt;
&lt;P align=left&gt;&lt;FONT face=Papyrus&gt;If you find &lt;BR&gt;yourself typing&lt;BR&gt;"p-a-r-t-i-a-l" &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face=Papyrus&gt;Stop!&lt;/FONT&gt;&lt;/P&gt;&lt;/SPAN&gt;
&lt;P&gt;&lt;FONT face="Arial Black"&gt;Reasons Given To Use the “partial” keyword&lt;/FONT&gt; 
&lt;P&gt;There are three main incentives I’ve heard for using &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt;, according to Microsoft and others: 
&lt;OL&gt;
&lt;LI&gt;If a class is really large, break it into multiple files so more than one person can work on it at a time. 
&lt;LI&gt;If a class implements multiple interfaces, put the methods that implement each interface into a separate file. 
&lt;LI&gt;When the IDE generates code, it puts the code into a separate file so you don't see it or accidentally modify it.&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Let's examine each of these reasons in detail. 
&lt;P&gt;&lt;FONT face="Arial Black"&gt;1. Avoid using “partial” to break large files into many smaller files&lt;/FONT&gt;—so multiple people can work on them. This is a bad practice.&lt;/P&gt;
&lt;P&gt;Why? 
&lt;P&gt;No matter how you try to group code in various partial files, &lt;STRONG&gt;&lt;EM&gt;you will never see the big picture for the class anymore&lt;/EM&gt;&lt;/STRONG&gt;. It’ll become brittle, easily broken. By only viewing a portion of the class, you can too easily break some assumption or dependency in the rest of the class. For example, you won’t see all the internal fields. If a field needs updating, and it’s not referenced in the portion of the class you’re editing, you’ll never even realize that you are breaking the class. &lt;EM&gt;&lt;/EM&gt;People will make incompatible changes and no one will know until Humpty Dumpty is put back together again. Are your unit tests good enough to catch this?&lt;/P&gt;
&lt;P&gt;So what's the right solution for really large files?&lt;/P&gt;
&lt;P&gt;If you’re thinking of using &lt;FONT face="Courier New"&gt;&lt;STRONG&gt;partial&lt;/STRONG&gt;&lt;/FONT&gt; because your class file is large, then consider it a warning sign that it's time to break the class up—not by using &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; but by using object oriented design. Break your monster class into multiple classes, grouped by responsibility. That way, you can hide details inside classes, and it will be much harder for developers who work on the new smaller classes to make incompatible changes with each other. As a bonus, breaking it up will also make your code easier to read, test, and maintain. &lt;/P&gt;
&lt;P&gt;&lt;FONT face="Arial Black"&gt;2.&lt;FONT face="Arial Black"&gt;&lt;/FONT&gt; Avoid using “partial” to organize your class file.&lt;/FONT&gt; Some people suggest putting the implementations of each interface into their own files. This sounds reasonable at first, but it contains a pitfall—the class implements 2 or more interfaces, but it is still one class that has its own private data (and all the assumptions that go with that). If you only read code in one file and make changes, you may not realize the side effects you introduce on other methods that are in other partial files. This is a bad practice for the same reason that it was for reason #1, large class files.&lt;/P&gt;
&lt;P&gt;
&lt;P&gt;&lt;FONT face="Arial Black"&gt;3. “partial” is ok if the compiler puts it there. &lt;/FONT&gt;This is the only safe reason to use &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt;. When the compiler adds &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; to your class, it does so to hide the code that it generates. While there are other solutions to handling generated code, this is the one that Microsoft chose, and it works fine. You can't ever modify the generated code (well, not easily) so it's just as well that it's hidden in a separate file. Note the key phrase here: the &lt;EM&gt;&lt;STRONG&gt;compiler&lt;/STRONG&gt;&lt;/EM&gt; adds partial—not you. 
&lt;BLOCKQUOTE&gt;&lt;IMG title="Visual Studio generates partial for you" src="http://static.flickr.com/43/123941420_caa05a9621.jpg?v=0" border=0&gt; &lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Arial Black"&gt;Recommendations&lt;/FONT&gt; 
&lt;UL&gt;
&lt;LI&gt;If you find yourself typing "p-a-r-t-i-a-l" — stop! Don’t do it. 
&lt;LI&gt;If the class you’re working on is marked &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt;, make sure that the other partial bits are compiler-generated. If they’re not, you should consider putting the class files back together and re-factoring the large class into smaller classes.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;&lt;STRONG&gt;One final Note&lt;/STRONG&gt;: in VB, since the &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; keyword is optional, you can really confuse someone reading the code because they may not even realize that other code exists for this class. If you work in VB, be aware that your entire class may not be in the file you’re looking at.&lt;/P&gt;
&lt;P&gt;For another viewpoint, see these articles: 
&lt;UL&gt;
&lt;LI&gt;This is a well written article describing &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; classes: &lt;A href="http://www.devx.com/dotnet/Article/22603"&gt;http://www.devx.com/dotnet/Article/22603&lt;/A&gt; 
&lt;LI&gt;Microsoft’s article on &lt;STRONG&gt;&lt;FONT face="Courier New"&gt;partial&lt;/FONT&gt;&lt;/STRONG&gt; (and other things): &lt;A href="http://msdn.microsoft.com/msdnmag/issues/06/00/C20/default.aspx"&gt;http://msdn.microsoft.com/msdnmag/issues/06/00/C20/default.aspx&lt;/A&gt; &lt;/LI&gt;&lt;/UL&gt;
&lt;DIV&gt;Technorati tags: 
&lt;a href="http://technorati.com/tag/C%2523" rel="tag"&gt;C#&lt;/a&gt;,
&lt;a href="http://technorati.com/tag/Visual%20Basic" rel="tag"&gt;Visual Basic&lt;/a&gt;,
&lt;A href="http://technorati.com/tag/Visual%20Studio" rel=tag&gt;Visual Studio&lt;/A&gt;, &lt;A href="http://technorati.com/tag/CodeGaffes" rel=tag&gt;CodeGaffes&lt;/A&gt;, &lt;A href="http://technorati.com/tag/Geekswithblogs" rel=tag&gt;Geekswithblogs&lt;/A&gt; &lt;/DIV&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/74442.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/04/05/74442.aspx</guid>
            <pubDate>Wed, 05 Apr 2006 23:34:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/74442.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/04/05/74442.aspx#feedback</comments>
            <slash:comments>15</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/74442.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/74442.aspx</trackback:ping>
        </item>
        <item>
            <title>Gotcha! Visual Studio Pre/Post-Build Events</title>
            <category>Visual Studio Tips</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx</link>
            <description>&lt;P&gt;Visual Studio has a nifty feature called Pre-Build and Post-Build events. These are used to include extra DOS commands before or after the build.&lt;/P&gt;
&lt;P&gt;But there's a gotcha! And it will bite you when you least expect it. In Visual Studio, there is NO ERROR CHECKING except at the end of an event. Any errors that happen prior to the final step are lost. Keep reading to see a workaround. 
&lt;H2&gt;Setting Build Events&lt;/H2&gt;
&lt;P&gt;Build Events are accessed by right-clicking on a Project in the solution explorer and choosing "Build Events": 
&lt;BLOCKQUOTE&gt;&lt;IMG title="Property Window for a project" src="http://static.flickr.com/73/156561127_8e7f825b97.jpg?v=0?v=0" border=0&gt; &lt;/BLOCKQUOTE&gt;
&lt;P&gt;It looks like these were originally intended as one-line DOS commands to do tweaks in your build. But they obviously grew - and you can put any number of DOS commands in there to copy files, clean up directories, even run unit tests! 
&lt;P&gt;Before describing the gotcha, there are a few things you need to know if you've never used these before. One is that you can put any DOS commands in here. It's really nothing more than a place to save a batch file that's run before (or after) the project build. It also offers "macros". The build process actually creates a batch file from your commands by replacing the macro text. &lt;/P&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;In this example, MYDEPLOY is just a regular DOS environment variable. The advantage to macros is they take into account the various differences between developers (and their file directory structure) as well as handling Debug vs. Release builds.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;IMG title="This is where you type your pre or post build event, using macros" src="http://static.flickr.com/75/156561128_7760a09ea8.jpg?v=0?v=0" border=0&gt; &lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;For example, this command: &lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;Copy $(OutDir)*.* %MYDEPLOY%&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;&lt;/P&gt;
&lt;P&gt;Gets converted to this, and placed in a batch file: &lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;Copy bin\Debug\*.* %MYDEPLOY%&lt;/DIV&gt;
&lt;P&gt;
&lt;H2&gt;The Gotcha&lt;/H2&gt;
&lt;P&gt;So, what's the problem? 
&lt;P&gt;Well, VS puts these commands in a batch file and runs it. VS checks for build failures so it can tell you about them. However - it only checks for a failure of the batch file that it created - not for any failures within the batch file. 
&lt;P&gt;What does this mean? If you only place one command in the build event, VS will correctly report any errors that happen. But if you place multiple commands in here, the net effect is that VS will only detect an error in the last statement. 
&lt;P&gt;So, for example, if you put &lt;EM&gt;three&lt;/EM&gt; copy commands in here, VS will only report an error if the &lt;EM&gt;final&lt;/EM&gt; command fails. 
&lt;P&gt;Ouch. 
&lt;H2&gt;The Workaround&lt;/H2&gt;
&lt;P&gt;So how can we fix this? Since VS is just creating a batch file, we use normal batch file commands to detect errors and report them. Here's what I do: 
&lt;UL&gt;
&lt;LI&gt;I add a check for error after every meaningful step: &lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE style="MARGIN-RIGHT: 0px"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;if errorlevel 1 goto BuildEventFailed&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;!--EndFragment--&gt;
&lt;UL&gt;
&lt;LI&gt;I add code at the end to handle the error so VS will report it:&lt;/LI&gt;&lt;/UL&gt;
&lt;BLOCKQUOTE style="MARGIN-RIGHT: 0px"&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;REM Exit properly because the build will not fail&lt;PRE style="MARGIN: 0px"&gt;REM unless the final step exits with an error code&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;goto BuildEventOK&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;:BuildEventFailed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;echo POSTBUILDSTEP for $(ProjectName) FAILED&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;exit 1&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;:BuildEventOK&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;echo POSTBUILDSTEP for $(ProjectName) COMPLETED OK&lt;/PRE&gt;&lt;/DIV&gt;&lt;/BLOCKQUOTE&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;
&lt;P&gt;&lt;BR&gt;Here's an example of one of my actual post build events: &lt;BR&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;echo POSTBUILDSTEP for $(ProjectName)&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;xcopy "$(TargetPath)" "$(SolutionDir)$(OutDir)" /i /d /y&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;if errorlevel 1 goto BuildEventFailed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;xcopy "$(TargetDir)$(TargetName).pdb" "$(SolutionDir)$(OutDir)" /i /d /y&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;if errorlevel 1 goto BuildEventFailed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;echo GAC of: "$(SolutionDir)$(OutDir)$(TargetFileName)"&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;gacutil.exe /nologo /i "$(SolutionDir)$(OutDir)$(TargetFileName)" /f&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;if errorlevel 1 goto BuildEventFailed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt; &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;REM Exit properly because the build will not fail &lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;REM unless the final step exits with an error code&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;goto BuildEventOK&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;:BuildEventFailed&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;echo POSTBUILDSTEP for $(ProjectName) FAILED&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;exit 1&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;:BuildEventOK&lt;/PRE&gt;&lt;PRE style="MARGIN: 0px"&gt;echo POSTBUILDSTEP for $(ProjectName) COMPLETED OK&lt;/PRE&gt;&lt;/DIV&gt;&lt;!--EndFragment--&gt;
&lt;P&gt;You don't have to be as fancy, with the extra "echo" statements, but do the error checking you need so errors don't slip through the cracks. 
&lt;P&gt;One final note: don’t put too much in these events. They’re pretty hard to debug when things go wrong. If you have something complex to do, put the commands in a batch file and reference the batch file yourself in the event. 
&lt;P&gt;But now at least, you can get notified if (make that &lt;U&gt;when&lt;/U&gt;) something fails. &lt;/P&gt;
&lt;P&gt; Technorati tags: 
&lt;a href="http://technorati.com/tag/Visual%20Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;,
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/80113.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx</guid>
            <pubDate>Tue, 30 May 2006 16:23:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/80113.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/05/30/80113.aspx#feedback</comments>
            <slash:comments>185</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/80113.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/80113.aspx</trackback:ping>
        </item>
        <item>
            <title>CodeGaffe: Commented Out Code</title>
            <category>CodeGaffes</category>
            <link>http://geekswithblogs.net/dchestnutt/archive/2006/08/20/88563.aspx</link>
            <description>&lt;P&gt;&lt;FONT face="Verdana, sans-serif" size=2&gt;We all have old code snippets in our code base. Whether it’s a method that’s no longer used, or a few lines that we’ve replaced - our code has sections commented out. When should we remove them? How should we comment them out? If you’re not careful, &lt;STRONG&gt;&lt;EM&gt;commented out code can cause future problems&lt;/EM&gt;&lt;/STRONG&gt;. Read on.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Verdana, sans-serif" size=2&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;FONT face="Verdana, sans-serif"&gt;&lt;STRONG&gt;Code Gaffe #1: Sneaky Commented out code&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Commented out code should be, well, &lt;SPAN style="FONT-WEIGHT: bold"&gt;really &lt;/SPAN&gt;commented out.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Really comment it out&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Don't put a /* at the top and */ at the bottom of code you want to remove:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;/*&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;code block line 1&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;code block line 2&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;*/&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Why?&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;If the code block is of any size, someone reading the file may not realize that the code is commented out.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;And you're simply causing them to waste time. Instead, comment out each line:&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;DIV style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 5pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 5pt; FONT-SIZE: 10pt; BACKGROUND: #f0f0f0; PADDING-BOTTOM: 5pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 5pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;PRE style="MARGIN: 0px"&gt;&lt;SPAN style="COLOR: green"&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;//&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;// code block line 1&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/SPAN&gt;// code block line 2&lt;/P&gt;&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;//&lt;/P&gt;&lt;/SPAN&gt;&lt;/PRE&gt;&lt;/DIV&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Of course, in modern editors with syntax coloring, this should not be an issue because the commented out code will be colorized as a comment.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;But we don't all have color printers, and sometimes we still use printouts.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;And we use other tools besides editors (like file differencing tools, change reports, etc.) that don't have syntax smarts.&lt;SPAN style="mso-spacerun: yes"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Besides, if you have a modern editor (and even with some ancient ones), you can select the code block to comment out, press a key, and it'll add "//" to every line - so there's really no excuse to not do it this way.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;I knew a guy who was very puzzled while trying to fix code in an overloaded method that he didn't realize was commented out.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Due to the nature of the code, he couldn't use a debugger, he had to dump info to a log file for debugging (and he didn't have syntax coloring).&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;After wasting a day doing this, he finally saw the comment markers on an early page, and with appropriate *&amp;amp;^*% language, found the correct overload.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-WEIGHT: bold; FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;CodeGaffe #2: Old Commented out Code&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;SPAN class=pullquote style="PADDING-RIGHT: 8px; PADDING-LEFT: 8px; FONT-WEIGHT: normal; FONT-SIZE: 16pt; FLOAT: right; PADDING-BOTTOM: 5px; MARGIN: 20px; WIDTH: 250px; LINE-HEIGHT: normal; PADDING-TOP: 5px; FONT-STYLE: normal; TEXT-ALIGN: right; FONT-VARIANT: normal"&gt;The real reason we can't bear to delete old code is that we spent so much time writing the code in the first place&lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Of course, the best tack by far is to delete the unused code.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;The code will rot when it's unused, and after a while, you wouldn't be able to simply uncomment it anyway.&lt;SPAN style="mso-spacerun: yes"&gt; I&lt;/SPAN&gt;f you really can't bear to delete it, make it obvious that it's commented out.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;What do I mean by "rot"?&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Once the code is commented out, it's never getting executed.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;As the rest of the code base evolves (adding new features, fixing bugs, refactoring), the code will be out of date—perhaps very subtly.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;STRONG&gt;Delete the old code (I know, it’s hard to part with it )&lt;/STRONG&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;The rule of thumb I use is to comment out code if I think I might need it again very soon.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Then, the very next time I'm in the same module, I delete it.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Thanks to the wonders of source control systems, it's now very easy to see that I intended to remove the code, since it'll be commented out in one version and gone in the next.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;That's a little more obvious than simply removing it.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;This suggestion (comment then delete)&amp;nbsp;is really for those of us who hate to delete the code outright, "because I might want it back someday".&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Usually though, the real reason we can't bear to part with it is that we spent a lot of time writing the code in the first place.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;But my advice is to delete it once it's no longer used.&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;So clean up that old code.&lt;SPAN style="mso-spacerun: yes"&gt; &lt;/SPAN&gt;Get to it!&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P style="FONT-SIZE: 10pt; MARGIN: 0in; FONT-FAMILY: Verdana; mso-outline-level: 1"&gt;Technorati tags: 
&lt;a href="http://technorati.com/tag/CodeGaffes" rel="tag"&gt;CodeGaffes&lt;/a&gt;, 
&lt;a href="http://technorati.com/tag/Geekswithblogs" rel="tag"&gt;Geekswithblogs&lt;/a&gt;
&lt;/P&gt; &lt;img src="http://geekswithblogs.net/dchestnutt/aggbug/88563.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave Chestnutt</dc:creator>
            <guid>http://geekswithblogs.net/dchestnutt/archive/2006/08/20/88563.aspx</guid>
            <pubDate>Sun, 20 Aug 2006 21:16:00 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/dchestnutt/comments/88563.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/dchestnutt/archive/2006/08/20/88563.aspx#feedback</comments>
            <slash:comments>8</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/dchestnutt/comments/commentRss/88563.aspx</wfw:commentRss>
            <trackback:ping>http://geekswithblogs.net/dchestnutt/services/trackbacks/88563.aspx</trackback:ping>
        </item>
    </channel>
</rss>
