<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Chris Melinn</title>
	<atom:link href="http://chrismelinn.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrismelinn.wordpress.com</link>
	<description>People.  Software.</description>
	<lastBuildDate>Wed, 08 May 2013 06:41:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='chrismelinn.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/46fb893491377a661299777433138d70?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Chris Melinn</title>
		<link>http://chrismelinn.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://chrismelinn.wordpress.com/osd.xml" title="Chris Melinn" />
	<atom:link rel='hub' href='http://chrismelinn.wordpress.com/?pushpress=hub'/>
		<item>
		<title>The Gilded Rose Kata and the Approval Tests Library</title>
		<link>http://chrismelinn.wordpress.com/2013/05/08/gilded-rose-kata-and-the-approval-tests-library/</link>
		<comments>http://chrismelinn.wordpress.com/2013/05/08/gilded-rose-kata-and-the-approval-tests-library/#comments</comments>
		<pubDate>Wed, 08 May 2013 06:38:34 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Golden Master]]></category>
		<category><![CDATA[Legacy Code]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=212</guid>
		<description><![CDATA[Note: It may be helpful to read my previous post on the Golden Master Technique before seeing an example of its application here. The Gilded Rose Kata I encountered the Gilded Rose Kata after reading this blog post on Why Most Solutions to the Gilded Rose Miss The Bigger Picture. The Gilded Rose code kata is particularly appealing [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=212&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<hr />
<p><strong>Note</strong>: It may be helpful to read <a href="http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/">my previous post on the Golden Master Technique</a> before seeing an example of its application here.</p>
<hr />
<h2>The Gilded Rose Kata</h2>
<p>I encountered the <a title="Gilded Rose Kata" href="https://github.com/NotMyself/GildedRose">Gilded Rose Kata</a> after reading this blog post on <a title="Why Most Solutions to the Gilded Rose Kata Miss The Bigger Picture" href="http://iamnotmyself.com/2012/12/07/why-most-solutions-to-gilded-rose-miss-the-bigger-picture/">Why Most Solutions to the Gilded Rose Miss The Bigger Picture</a>. The Gilded Rose <a title="Code Katas" href="http://codekata.pragprog.com/codekata/">code kata</a> is particularly appealing because it requires modification of a poorly written (simulated) code base. It is excellent practice for our typical daily work, yet it is still small enough to learn and jump in quickly.</p>
<p>I encourage you to try the <a title="Gilded Rose Kata" href="https://github.com/NotMyself/GildedRose">Gilded Rose Kata</a> before reading further. At a minimum, please read the overview and consider how you would approach the problem.</p>
<p>Please give it a try and come back&#8230;</p>
<p>Ok, you&#8217;re back. How would you start?</p>
<h2>The Golden Master Technique</h2>
<p>This type of problem is a great example of when the <a href="http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/">Golden Master technique</a> can be a better starting point than going straight into unit tests.</p>
<p>The overview of Gilded Rose states that the existing application &#8220;works&#8221;. This describes a &#8221;real application&#8221;, working in production, that is useful enough to enhance with new features. Thus, it is as important, if not more so, to preserve existing behavior of the application as it is to add new features.</p>
<p>In order to unit test the code properly, we would need to modify the code somewhat significantly (in proportion to the existing code base) to be able to create the seams required for good unit tests. And to get complete coverage of the requirements would require a fair number of tests, some of which may not be obvious or explicit.</p>
<h2>Applying the Golden Master Technique</h2>
<p>So, let&#8217;s get started in creating our &#8220;golden master&#8221;. We need to execute a sufficient number iterations of the code to generate enough output to create a meaningful baseline. For this example, 50-100 iterations would be more than sufficient coverage.  In a larger code base, we would need to create a more diverse range of input values. In this case, however, the initial setup appears sufficient to cover the necessary code paths.</p>
<p>To generate the Golden Master, we need to:</p>
<ol>
<li>Open/Create a file for saving the output</li>
<li>Modify code to output state to the file, e.g. write the Item properties (Name/SellIn/Quality) out for each execution of UpdateQuality()</li>
<li>Modify the code to iterate through through a sufficient number of days, 100 days for example</li>
<li>Close/Save the file</li>
</ol>
<p>Performing the above steps in code would not be difficult. However, this is even easier using the <a title="ApprovalTests Library" href="http://approvaltests.sourceforge.net/">Approval Tests Library</a>. The framework does exactly what we need:</p>
<ol>
<li>Runs a specified &#8220;test&#8221;</li>
<li>At the end of the test, asserts/verifies a given state</li>
<li>Compares the resulting execution, with an accepted master. If an accepted master doesn&#8217;t already exist, you accept &amp; save it (or fix it until you are happy with it). If the master does exists, but is different, it fails the test. Which can again, either be fixed, or accepted as a new master.</li>
</ol>
<p>To get started:</p>
<ol>
<li>Open the GildedRose solution</li>
<li>Add/Install ApprovalTests into our solution.  For .NET, the easiest way, of course, is <a href="http://nuget.org/packages/ApprovalTests/">via NuGet</a>. Otherwise, it can be <a href="http://approvaltests.sourceforge.net">downloaded from here</a>.</li>
<li>Enhance the application to be able to capture its state, for example using a string representation of the items &amp; their current values</li>
<li>Create a test that will verify the state from the previous step</li>
<li>Run and fix the tests until you are happy with the accepted golden master</li>
</ol>
<h4>How to enhance the application to capture state (step 3)</h4>
<pre class="brush: csharp; title: ; notranslate">
public string GetSnapshot()
{
    var snapshot = new StringBuilder();

    foreach (var item in Items)
    {
        snapshot.AppendLine(string.Format(&quot;Name: {0}, SellIn: {1}, Quality: {2}&quot;, item.Name, item.SellIn, item.Quality));
    }

    snapshot.AppendLine(&quot;------------------------&quot;);

    return snapshot.ToString();
}
</pre>
<h4>How to Create a test that will verify the state in the previous step (step 4)</h4>
<p>1.  Let&#8217;s create a basic approval test, simply to validate the state from the initial setup (before any iterations):</p>
<pre class="brush: csharp; title: ; notranslate">
[Test]
[UseReporter(typeof(DiffReporter))]
public void TestThis()
{
    var app = Program.Initialise();

    var initialSetup = app.GetSnapshot();

    Approvals.Verify(initialSetup);
}
</pre>
<p>To make our test compile and run&#8230;</p>
<p>2. Change the Program class to public&#8230;</p>
<pre class="brush: csharp; title: ; notranslate">
public class Program
</pre>
<p>3. &#8230; and extract the initial setup into an Initialize() method:</p>
<pre class="brush: csharp; title: ; notranslate">
public static Program Initialize()
{
    return new Program
    {
        Items = new List
        {
            new Item {Name = &quot;+5 Dexterity Vest&quot;, SellIn = 10, Quality = 20},
            new Item {Name = &quot;Aged Brie&quot;, SellIn = 2, Quality = 0},
            new Item {Name = &quot;Elixir of the Mongoose&quot;, SellIn = 5, Quality = 7},
            new Item {Name = &quot;Sulfuras, Hand of Ragnaros&quot;, SellIn = 0, Quality = 80},
            new Item {Name = &quot;Backstage passes to a TAFKAL80ETC concert&quot;, SellIn = 15, Quality = 20},
            new Item {Name = &quot;Conjured Mana Cake&quot;, SellIn = 3, Quality = 6}
        }
    };
}
</pre>
<p>Now, our Main() looks like this:</p>
<pre class="brush: csharp; title: ; notranslate">
static void Main(string[] args)
{
    System.Console.WriteLine(&quot;OMGHAI!&quot;);

    var app = Initialise();

    app.UpdateQuality();

    System.Console.ReadKey();
}
</pre>
<p>4.  Finally, we can add another test, to execute with a 100 iterations, which creates our &#8220;golden master&#8221;:</p>
<pre class="brush: csharp; title: ; notranslate">
[Test]
[UseReporter(typeof(DiffReporter))]
public void TestThisTimes100()
{
    var app = Program.Initialise();

    var snapshotForHundredIterations = new StringBuilder();

    var initialSnapshot = app.GetSnapshot();

    snapshotForHundredIterations.Append(initialSnapshot);

    for (int i = 0; i &lt; 100; i++ )
    {
        app.UpdateQuality();
        var currentSnapshot = app.GetSnapshot();
        snapshotForHundredIterations.Append(currentSnapshot);
    }

    Approvals.Verify(snapshotForHundredIterations);
}
</pre>
<p>When, approval tests execute with the [UseReporter(typeof(DiffReporter))] attribute, the framework launches an installed diff tool. If you save the resulting file, formatted as SomeTestName.approved.txt, it becomes the accepted &#8220;golden master&#8221;.</p>
<p>That&#8217;s it! If you find it slightly confusing the first time, try a couple examples yourself. Once you understand the concept of the ApprovalTest framework, it is a simple and effective way to create a &#8220;golden master&#8221; test quickly.</p>
<p>At this point, you could proceed with the Gilded Rose Kata, making enhancements, or if desired, creating a set of explicit unit tests to more accurately describe the given requirements &amp; for future readability &amp; maintainability.</p>
<p><strong>Other Resources</strong></p>
<ul>
<li>In writing this post, I can across a similar<a href="http://emilybache.blogspot.se/2013/03/writing-good-tests-for-gilded-rose-kata.html"> blog post from Emily Bache</a>, which is definitely worth reading.</li>
<li>Emily Bache&#8217;s blog post above references an <a href="https://github.com/NotMyself/GildedRose/blob/first_refactor/src/GildedRose.Tests/UpdateItemsTests.cs">example of unit test approach</a>, which is well written.  You can see how it is more work to get started, but they are meaningful and easy to understand.  With a real client, I would write these type of unit tests as well, but I would write them <strong>after</strong> creating <a href="http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/">our characterization tests with a golden master</a>.</li>
<li>Here&#8217;s a similar <a href="http://craftedsw.blogspot.com.au/2012/11/testing-legacy-code-with-golden-master.html">Java solution with Approval Tests</a></li>
<li>My previous post on <a href="http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/">Using the Golden Master Technique</a></li>
</ul>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/refactoring/'>Refactoring</a> Tagged: <a href='http://chrismelinn.wordpress.com/tag/golden-master/'>Golden Master</a>, <a href='http://chrismelinn.wordpress.com/tag/legacy-code/'>Legacy Code</a>, <a href='http://chrismelinn.wordpress.com/tag/refactoring/'>Refactoring</a>, <a href='http://chrismelinn.wordpress.com/tag/testing/'>Testing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/212/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/212/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=212&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2013/05/08/gilded-rose-kata-and-the-approval-tests-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Using the Golden Master technique to test legacy code</title>
		<link>http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/</link>
		<comments>http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/#comments</comments>
		<pubDate>Fri, 12 Apr 2013 01:27:33 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Golden Master]]></category>
		<category><![CDATA[Legacy Code]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=206</guid>
		<description><![CDATA[Working with legacy code is a scary proposition. Generally, we lack an understanding of the application and its codebase, and we don&#8217;t have automated test coverage. In fact, in his book Working Effectively with Legacy Code, Michael Feathers defines legacy code as &#8220;code without tests&#8221;. Therefore, before making changes to legacy code, it is important [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=206&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Working with legacy code is a scary proposition. Generally, we lack an understanding of the application and its codebase, and we don&#8217;t have automated test coverage. In fact, in his book <a title="Working Effectively with Legacy Code" href="http://www.amazon.com/Working-Effectively-Legacy-Michael-Feathers/dp/0131177052">Working Effectively with Legacy Code</a>, Michael Feathers <a title="Defines legacy code as code without tests" href="http://en.wikipedia.org/wiki/Legacy_code">defines legacy code as &#8220;code without tests&#8221;</a>.</p>
<p>Therefore, before making changes to legacy code, it is important to guard against unintended changes. These days, developers are often too quick to assume unit tests are the (only) way to do this. However, in a large code base, where requirements are missing or unclear, this may not be a viable option. We could even introduce bugs by &#8220;fixing&#8221; behavior,  if downstream systems assume an existing (incorrect) behavior. Therefore, it may be important to first capture and lock down existing behavior before writing unit tests or modifying the existing code. <a title="Characterization Tests" href="http://en.wikipedia.org/wiki/Characterization_Test">Characterization tests</a> are a means of capturing the existing behaviour.</p>
<p>To create the characterization tests, we can generate a large set of diverse inputs and run them against the existing codebase. By recording and saving these outputs, we capture the existing behavior. These outputs from the original code base are called the &#8220;Golden Master&#8221;. Later, when we need to modify the code, we can replay the same set of inputs and compare them against the original &#8220;master&#8221; outputs. Any differences between the original and new outputs help to identify unintended behaviour changes (or can be accepted if intentionally changed).</p>
<p>I have used this technique in real life scenarios, which previously, had been difficult to cover sufficiently with tests. The 80/20 rule applies here; we spent 80% of our time trying to cover 20% (less, really) of the fringe cases. In the end, the golden master technique has been more effective. Once in place, this technique can be combined with unit testing and other test methods.</p>
<p>Thanks to <a title="JBrains" href="http://www.jbrains.ca/">jbrains</a>&#8216;s posts on <a title="Legacy Code Retreat" href="http://www.jbrains.ca/legacy-code-retreat">Legacy Code Retreat</a> for introducing me to this technique. In particular, I recommend <a title="How to run a Legacy Code Retreat" href="http://legacycoderetreat.typepad.com/blog/2011/11/how-i-run-legacy-code-retreat.html">this</a> for more information.</p>
<p>I will provide more details, examples, and tools for this technique in future posts.</p>
<hr />
<p><strong>Update</strong>: See an example of using this technique with my follow up post, <a href="http://chrismelinn.wordpress.com/2013/05/08/gilded-rose-kata-and-the-approval-tests-library/">The Gilded Rose Kata and The Approval Tests Library</a></p>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/refactoring/'>Refactoring</a> Tagged: <a href='http://chrismelinn.wordpress.com/tag/golden-master/'>Golden Master</a>, <a href='http://chrismelinn.wordpress.com/tag/legacy-code/'>Legacy Code</a>, <a href='http://chrismelinn.wordpress.com/tag/refactoring/'>Refactoring</a>, <a href='http://chrismelinn.wordpress.com/tag/testing/'>Testing</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=206&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2013/04/12/using-the-golden-master-technique-to-test-legacy-code/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Primitive Obsession Example # 1 &#8211; KeyValuePair</title>
		<link>http://chrismelinn.wordpress.com/2012/03/25/primitive-obsession-example-1-keyvaluepair/</link>
		<comments>http://chrismelinn.wordpress.com/2012/03/25/primitive-obsession-example-1-keyvaluepair/#comments</comments>
		<pubDate>Sun, 25 Mar 2012 05:20:15 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[DDD]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=152</guid>
		<description><![CDATA[My last post described how removing cases of &#8220;Primitive Obsession&#8221; is one of the best ways to improve the readability of your code. Replacing primitives with domain specific types helps reveal the intention of the code, which helps others to read, maintain, and use the code we write. This post will be the first in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=152&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>My <a href="http://chrismelinn.wordpress.com/2012/01/31/improve-code-by-removing-primitive-obsession/">last post</a> described how removing cases of &#8220;Primitive Obsession&#8221; is one of the best ways to improve the readability of your code. Replacing primitives with domain specific types helps reveal the intention of the code, which helps others to read, maintain, and use the code we write.</p>
<p>This post will be the first in a series of examples illustrating the primitive obsession code smell. In each post, I will provide a &#8220;before&#8221; code sample where primitives are used, and then an &#8220;after&#8221; sample, where the usage of a primitive type is replaced with a domain specific type.</p>
<p>The first example will illustrate using a .NET built-in type, the <a href="http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx">KeyValuePair</a>.</p>
<blockquote><p><strong>Disclaimer # 1</strong>: It is perfectly acceptable and appropriate to use this type  in some cases. However, the type is often overused and can make code less readable. My intention with this post is for you to compare the &#8220;before&#8221; and &#8220;after&#8221; versions to see which approach is more readable for your situation.</p></blockquote>
<p>Now, on to our example&#8230;</p>
<p><strong>&#8220;Before&#8221;- </strong>code using the built-in generic type, <a href="http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx">KeyValuePair&lt;TKey, TValue&gt;</a>:</p>
<pre class="brush: csharp; title: ; notranslate">
class Program
{
    static void Main()
    {
        var list = new List&lt;KeyValuePair&gt;();

        list.Add(new KeyValuePair(&quot;Chris Melinn&quot;, &quot;FAKE123&quot;));
        list.Add(new KeyValuePair(&quot;Lisa Simpson&quot;, &quot;ABC456&quot;));
        list.Add(new KeyValuePair(&quot;Waylan Smithers&quot;, &quot;XYZ789&quot;));

        // Outputs (as strings):
        // Chris Melinn, 'FAKE123'
        // Lisa Simpson, 'ABC456'
        // Waylan Smithers, 'XYZ789'
        foreach (var item in list)
        {
            var message = string.Format(&quot;{0} , '{1}'&quot;,
                        item.Key,
                        item.Value);

            Console.WriteLine(message);
        }
    }
}
</pre>
<p>Even in this simple example, it can be hard to tell what data is captured by the List of KeyValuePairs. Each KeyValuePair contains a <strong>Key </strong>of type <code>string</code>, and a <strong>Value</strong> also of type <code>string</code>. In a real application, <em>hopefully</em>, we would also have better variable names to help us determine what these objects contain. However, in this case, I have intentionally left generic variable names (such as item and list) to highlight the loss of meaning by using the primitive type.</p>
<p>After inspecting the data values in the sample, we could probably <em>guess</em> that our Key&#8217;s are people&#8217;s names. However, we might not be able to guess what our Value&#8217;s hold. </p>
<hr />
<p>This example will assume that our code intends to print out the company&#8217;s computer inventory, with a list of machines issued to various staff members. In other words, in our example, <strong>the Key is the employee name</strong> and the <strong>Value is the machine serial number</strong>. Unfortunately, the primitive type does not capture that information.  However, we will see this is easy information to convey when we refactor to a domain specific type.</p>
<hr />
<p>Also, notice that, in this example, our type is created <em>and</em> used within the same block of code.  In a real application, it is much more likely that another class would create the list (e.g. by reading from a database), and then return the values it to seperate class to consume the data.  In such a case, we would only see an interface or method such as:</p>
<pre class="brush: csharp; title: ; notranslate">
public List&lt;KeyValuePair&lt;string, string&gt;&gt; GetEmployeeMachines()
</pre>
<p>Even with a well-named method, the developer will probably need to navigate to the class and method and view the source code (if possible) to confirm that the keys and values are what she expects them to be (not to mention, code signatures like these are fairly ugly and unpleasant).</p>
<p>Now, let&#8217;s refactor our original sample to remove the primitive KeyValuePair type and replace it with a domain-specific type. It would look something like the following (affected/modified lines are highlighted):</p>
<p><strong>&#8220;After&#8221;- </strong><a href="http://msdn.microsoft.com/en-us/library/5tbh8a42.aspx">KeyValuePair&lt;TKey, TValue&gt;</a> replaced with a domain specific type, EmployeeMachine:</p>
<pre class="brush: csharp; highlight: [5,7,8,9,18,19]; title: ; notranslate">
class Program
{
    static void Main()
    {
        var list = new List();

        list.Add(new EmployeeMachine(&quot;Chris Melinn&quot;, &quot;FAKE123&quot;));
        list.Add(new EmployeeMachine(&quot;Lisa Simpson&quot;, &quot;ABC456&quot;));
        list.Add(new EmployeeMachine(&quot;Waylan Smithers&quot;, &quot;XYZ789&quot;));

        // Outputs (as strings):
        // Chris Melinn, 'FAKE123'
        // Lisa Simpson, 'ABC456'
        // Waylan Smithers, 'XYZ789'
        foreach (var item in list)
        {
            var message = string.Format(&quot;{0} , '{1}'&quot;,
                        item.EmployeeName,
                        item.MachineSerialNumber);

             Console.WriteLine(message);
        }
    }
}

class EmployeeMachine
{
    public string EmployeeName { get; private set; }
    public string MachineSerialNumber { get; private set; }

    public EmployeeMachine(string employeeName, 
                           string machineSerialNumber)
    {
        EmployeeName = employeeName;
        MachineSerialNumber = machineSerialNumber;
    }
}
</pre>
<p>The final result is more intention revealing and better conveys what data is captured in the EmployeeMachine class. Even with other generic, poorly named variables still left in the code (such as <code>item</code> and <code>list</code>), the reader can still understand what the code is doing without navigating and inspecting other classes.</p>
<p>Most importantly, I believe this refactoring is one of the easy &#8220;little things&#8221; you can do to <strong>increase the satisfaction of others who read, maintain, and use your code</strong>.</p>
<hr />
<p>As always, I would love to hear from readers &#8212; especially if you have any personal experiences (or even code examples!) to share.</p>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/ddd/'>DDD</a>, <a href='http://chrismelinn.wordpress.com/category/refactoring/'>Refactoring</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=152&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2012/03/25/primitive-obsession-example-1-keyvaluepair/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Improving Code &#8211; Remove &#8220;Primitive Obsession&#8221;</title>
		<link>http://chrismelinn.wordpress.com/2012/01/31/improve-code-by-removing-primitive-obsession/</link>
		<comments>http://chrismelinn.wordpress.com/2012/01/31/improve-code-by-removing-primitive-obsession/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 05:31:12 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[DDD]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=141</guid>
		<description><![CDATA[One of the best ways to improve code is to remove cases of Primitive Obsession. This particular code smell arises when we use primitive types (such strings or integers) to represent what should be explicit types in our domain. In some cases, primitive types are quite appropriate. For example, we may only need an instance [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=141&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>One of the best ways to improve code is to remove cases of <a title="Primitive Obsession" href="http://sourcemaking.com/refactoring/primitive-obsession">Primitive Obsession</a>. This particular <a href="http://martinfowler.com/bliki/CodeSmell.html">code smell</a> arises when we use primitive types (such strings or integers) to represent what <em>should be</em> explicit types in our domain.</p>
<p>In some cases, primitive types are quite appropriate. For example, we may only need an instance of some string to display somewhere in our UI. However, in other cases, our &#8220;simple string&#8221; should be a better abstraction within our domain.</p>
<p>For example, using a string to store my name (&#8220;Chris Melinn&#8221;) would likely be a loss of an abstraction. This probably needs to be modeled as a something more explicit such as a User or a Person, having a FirstName and a LastName. This is particularly true when other places in the application do things such as parse this string to derive a first name and a last name. These behaivors are telling us that our &#8220;name&#8221; is trying to be more than just a string.</p>
<p>At first, it may seem silly to create a whole new class that possibly contains just one or two members (like our Person with a Name or FirstName and LastName). However, by creating this &#8220;placeholder&#8221;, we are defining its place in our domain. More importantly, you may find that other behavior begins to find its way into your &#8220;simple&#8221; class (such as the conversion and calculation logic that would otherwise be spread around your application). When this happens, you know you did the right thing.</p>
<p>For a much better description and discussion, please take the time to watch this video by <a href="http://programmingtour.blogspot.com/">Corey Haines</a> and <a href="http://blog.thecodewhisperer.com/">J.B. Rainsberger</a>. They are both excellent <a href="http://manifesto.softwarecraftsmanship.org/">craftsmen</a>, and, if you haven&#8217;t already, I recommend you take the time to explore their blogs as well.</p>
<div class='embed-vimeo' style='text-align:center;'><iframe src='http://player.vimeo.com/video/9870277' width='400' height='300' frameborder='0'></iframe></div>
<p><a href="http://vimeo.com/9870277">JB Rainsberger &#8211; Primitive Obsession</a> from <a href="http://vimeo.com/coreyhaines">Corey Haines</a> on <a href="http://vimeo.com">Vimeo</a>.</p>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/ddd/'>DDD</a>, <a href='http://chrismelinn.wordpress.com/category/refactoring/'>Refactoring</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/141/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/141/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=141&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2012/01/31/improve-code-by-removing-primitive-obsession/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Questions Before Refactoring</title>
		<link>http://chrismelinn.wordpress.com/2011/06/18/questions-before-refactoring-2/</link>
		<comments>http://chrismelinn.wordpress.com/2011/06/18/questions-before-refactoring-2/#comments</comments>
		<pubDate>Sat, 18 Jun 2011 03:16:36 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=103</guid>
		<description><![CDATA[I want to discuss a question I found quite some time ago on StackOverflow, which posted a code sample (to follow) along with these questions and comments (bold highlights are mine): (clipped)  “… this is the perfect time to refactor this puppy and make it more portable, reusable, reliable, easier to configure etc. Now that&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=103&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I want to discuss <a href="http://stackoverflow.com/questions/1177861/how-to-approach-refactoring-a-class-vb-net/1200935">a question I found</a> quite some time ago on <a href="http://stackoverflow.com">StackOverflow</a>, which posted a code sample (to follow) along with these questions and comments (<strong>bold</strong> highlights are mine):</p>
<blockquote><p>(clipped)  “… this is the perfect time to refactor this puppy and make it more portable, reusable, reliable, easier to configure etc. Now that&#8217;s fine and dandy, but then I started feeling a tad overwhelmed regarding to where to start. Should it be a separate library? How should it be configured? Should it use IoC? DI?</p>
<p>So my [admittedly subjective] question is this &#8212; given a relatively small, but quite useful class like the one below, <strong>what is a good approach to refactoring it</strong>? <strong>What questions do you ask</strong> and how do you decide what to implement or not implement? Where do you draw the line regarding configuration flexibility?</p>
<p>[Note: Please don't bash this code too much okay? It was written a long time ago and has functioned perfectly well baked into an in house application.]”</p></blockquote>
<p>Before we get into the code sample, let’s address some of the key questions…</p>
<h4>“What is a good approach to refactoring it?  What questions do you ask…?”</h4>
<p>The first question I would ask is:</p>
<h4>1.  Do I need to refactor this code at all?</h4>
<p>In this case, the author commented at the end of his question that the code “was written a long time ago and has functioned perfectly well baked into an in house application”.  This comment suggests there may not be a need to refactor at all!  If the code has survived and hasn&#8217;t been modified in a long time, it probably doesn’t make sense to change it now.  However, let’s assume we have good reasons to start (e.g. need to start making a changes)…</p>
<h4>2.  What is my objective in refactoring the code?</h4>
<p>The term “refactoring” is becoming quite commonplace, and it is often used interchangeably with any type of code modification.  However, in <a href="http://www.amazon.com/gp/product/B000OZ0N4Y?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=B000OZ0N4Y">Refactoring: Improving the Design of Existing Code</a><img src="http://www.assoc-amazon.com/e/ir?t=chrismelinnsw-20&amp;l=as2&amp;o=1&amp;a=B000OZ0N4Y" alt="" width="1" height="1" border="0" />, Fowler defined it as</p>
<blockquote><p>“Refactoring (noun):  a change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior.”</p></blockquote>
<p>With this definition, Fowler highlights that <strong>refactoring is not any general modification to the code</strong>, but specifically a change with the intention to “make it easier to understand”.</p>
<p>In <a href="http://www.hanselminutes.com/default.aspx?showID=189">this episode</a> of <a href="http://www.hanselminutes.com">Hanselminutes</a>, <a href="http://www.objectmentor.com/omTeam/martin_r.html">“Uncle Bob” Martin</a> makes the comment:</p>
<blockquote><p>“You are constantly mercilessly refactoring systems,<br />
not necessarily because they need to be refactored<br />
but <strong>because they need to remain flexible</strong>. So it&#8217;s<br />
rather like moving the gears on a bicycle or driving<br />
your car for no other reason than to keep it well<br />
lubricated, and in order to make those kinds of<br />
changes you need tests, it all boils down to tests in<br />
the end.”</p></blockquote>
<p>(Before we move on, I want to highlight another important fact.  You cannot be sure you haven&#8217;t changed behavior unless the code is covered by good unit tests.  So, without good unit tests, you are not really refactoring.)</p>
<p>With this context in mind, we can determine how to make the code more flexible, easier to understand, and cheaper to modify.</p>
<h4>3.  What should I do?  What should I refactor?</h4>
<p>The reason I was attracted to this particular code sample to highlight is that it is actually a fairly decent piece of code.  I can see, as the author points out, that it could have been good enough to support an existing application without many problems.  I also think this sample is reflective of the type of code I generally see in the wild: <strong> functional, but not expressive</strong>.</p>
<p>Additionally, even for a small code sample, it contains quite a bit of <strong>code duplication</strong>. I feel this amount of duplication is typical (unfortunately) of the average application.</p>
<p><strong>The biggest step you can make to improve your code is learning <strong>(1) how to remove duplication, and</strong> (2) how to make your code more expressive.</strong></p>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/refactoring/'>Refactoring</a>, <a href='http://chrismelinn.wordpress.com/category/uncategorized/'>Uncategorized</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=103&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2011/06/18/questions-before-refactoring-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>

		<media:content url="http://www.assoc-amazon.com/e/ir?t=chrismelinnsw-20&#38;l=as2&#38;o=1&#38;a=B000OZ0N4Y" medium="image" />
	</item>
		<item>
		<title>DevEvening Presentation &#8211; T4</title>
		<link>http://chrismelinn.wordpress.com/2010/02/03/t4-presentation/</link>
		<comments>http://chrismelinn.wordpress.com/2010/02/03/t4-presentation/#comments</comments>
		<pubDate>Wed, 03 Feb 2010 05:56:27 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[DevEvening]]></category>
		<category><![CDATA[presentation]]></category>
		<category><![CDATA[t4]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=77</guid>
		<description><![CDATA[As part of our first DevEvening, I did a presentation on T4, the little-known code generation technology built-in to Visual Studio.  It was a pleasure meeting everyone at our first meeting, and I hope it was the first of many more to come.  I also want to give a big thank you to Alex Mackey [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=77&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As part of our <a href="http://deveveningoz1.eventbrite.com/">first</a> <a href="http://www.deveve.net/">DevEvening</a>, I did a presentation on T4, the little-known code generation technology built-in to Visual Studio.  It was a pleasure meeting everyone at our first meeting, and I hope it was the first of many more to come.  I also want to give a big thank you to <a href="http://www.simpleisbest.co.uk">Alex Mackey</a> for making it all happen &#8211; We are lucky to have you in Melbourne!  Thanks also to <a href="http://www.clariusconsulting.net/">Clarius </a>for their generous donation of two professional licenses of their <a href="http://www.visualt4.com/">Visual T4 Editor</a> &#8212; congratulations <a href="http://twitter.com/tarnacious">Tarn</a> and David!</p>
<p>The slides from the presentation are below:</p>
<iframe src='http://www.slideshare.net/slideshow/embed_code/3049706' width='480' height='394'></iframe>
<p>This was one of my first presentations in this type of forum, but I think it went relatively well.  It’s surprising how much effort goes into making a successful presentation, and I have a newfound respect to those who do this regularly!</p>
<p>If you have any feedback on the presentation, please comment here or <a href="http://twitter.com/ChrisMelinn">let me know on twitter</a>.  I would appreciate any feedback to help me improve.</p>
<p><strong>Relevant Links</strong></p>
<ul>
<li><a href="http://www.deveve.net/">DevEvening Melbourne (Richmond)</a></li>
<li><a href="http://www.olegsych.com/2007/12/text-template-transformation-toolkit/">Oleg Sych’s Resources on T4</a></li>
<li><a href="http://aspnet.codeplex.com/wikipage?title=T4MVC">T4MVC Project on CodePlex</a></li>
<li><a href="http://haacked.com/archive/2009/12/02/t4-template-for-less-css.aspx">T4CSS</a></li>
<li><a href="http://www.visualt4.com/">Clarius Visual T4 Editor</a></li>
</ul>
<br />Filed under: <a href='http://chrismelinn.wordpress.com/category/uncategorized/'>Uncategorized</a> Tagged: <a href='http://chrismelinn.wordpress.com/tag/devevening/'>DevEvening</a>, <a href='http://chrismelinn.wordpress.com/tag/presentation/'>presentation</a>, <a href='http://chrismelinn.wordpress.com/tag/t4/'>t4</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=77&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2010/02/03/t4-presentation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Is Ubiquitous Language Possible?</title>
		<link>http://chrismelinn.wordpress.com/2009/12/17/is-ubiquitous-language-possible/</link>
		<comments>http://chrismelinn.wordpress.com/2009/12/17/is-ubiquitous-language-possible/#comments</comments>
		<pubDate>Thu, 17 Dec 2009 03:23:10 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[DDD]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=70</guid>
		<description><![CDATA[The Goal There have been some interesting discussions recently about the importance of having a “common language” between developers and business domain experts.  DDD refers to this concept as its “Ubiquitous Language”: “The concept is simple, that developers and the business should share a common language, that both understand to mean the same things, and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=70&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2>The Goal</h2>
<p>There have been some <a href="http://sarahtaraporewalla.com/thoughts/design/the-importance-of-words/">interesting</a> <a href="http://www.markhneedham.com/blog/2009/12/16/coding-naming/">discussions</a> recently about the importance of having a “common language” between developers and business domain experts.  DDD refers to this concept as its “<a href="http://devlicio.us/blogs/casey/archive/2009/02/09/ddd-the-ubiquitous-language.aspx">Ubiquitous Language</a>”:</p>
<blockquote><p>“The concept is simple, that developers and the business should share a common language, that both understand to mean the same things, and more importantly, that is set in business terminology, not technical terminology.”</p></blockquote>
<p>The intention is that once we share a common vocabulary, we can improve our requirements and design.  The class design (the business entities and their relationships) hopefully better reflects the true interactions of the business we are trying serve.</p>
<h2>The Problem / An Example</h2>
<p>The difficultly in <a href="http://www.markhneedham.com/blog/2009/12/16/coding-naming/">identifying the “real names”</a> typically lies somewhere between developers and the business domain experts.  However, on some very large projects, I seemed to have encountered another variation of this problem.</p>
<p>Let’s consider a large project, divided into multiple teams.  Each team is responsible to design and implement separate functionality, but each team has significant overlap with the other.</p>
<p>For example, imagine Really Big Company’s executive  management has decided to build an “improved” customized version of their current email system to communicate better with customers.  So, in assemblies our project teams, we decide to divide the project into two primary teams: Team A will build the “inbox” functionality, and Team B will build the contact management module.</p>
<p>Since Team A and Team B follow good DDD principles, they being working on creating their common language (shared names).  Team A discovers that the domain experts for the Inbox system refer to their mail recipients as “contacts”, and, ironically, Team B’s domain experts refer to their contacts as “customers”.</p>
<p>At some point, they realize that “customers” are really just one “type” of contact.  With this shared understanding, the developers create a design where [Customer] will be a subclass/child of [Contact].  The domain experts readily agree the improved design.</p>
<p>So now, developers will distinguish contacts from customers.  And the next time they hear domain experts refer to a “customer”, they think they can assume a[Customer].  The business agreed on it, right?!</p>
<p>So, the real question &#8212; did the business user really mean [Customer]?  Or did they really mean [Contact]?</p>
<h2>Conclusion</h2>
<p>It is unlikely that the vocabulary of the business users will change, especially when the business users are not part of the full time project staff.  Remember, the developer staff isn’t the only interaction that these domain experts will have!  So, even when we have “agreement”, it is unlikely (and probably undesirable) to change the language of the business.</p>
<p>So then what?</p>
<p>After all this, we may be tempted to throw out our ideas on common language, shared names, and ubiquitous language.  However, let’s stop to see what we have accomplished.</p>
<p>In our theoretical meeting, when the domain expert mentioned “customer”, the technical team can now ask “Do you mean [Customer] or [Contact]?”.  And, with any luck, the business now understands what we mean, and can give a simple answer.  “Ah, yes, you’re right.  I do mean [Contact]”.</p>
<p>Common language isn’t a cure-all.  But it sure helps.</p>
<p>I’m curious to hear your experiences as well.</p>
<br />Posted in DDD Tagged: DDD <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=70&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/12/17/is-ubiquitous-language-possible/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Sacrificing Quality &#8211; Part II &#8211; Kaizen</title>
		<link>http://chrismelinn.wordpress.com/2009/09/15/sacrificing-quality-and-kaizen/</link>
		<comments>http://chrismelinn.wordpress.com/2009/09/15/sacrificing-quality-and-kaizen/#comments</comments>
		<pubDate>Tue, 15 Sep 2009 05:29:05 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Quality]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=62</guid>
		<description><![CDATA[Recap of Part I In my last post, I described how sacrificing quality can adversely impact the morale of your development team.  In that post, I cited a particular quotation from Tom DeMarco in Peopleware: “We all tend to tie our self-esteem strongly to the quality of the product we produce… Any step that you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=62&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<h2>Recap of Part I</h2>
<p>In my last post, I described how <a href="http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/">sacrificing quality can adversely impact the morale of your development team</a>.  In that post, I cited a particular quotation from <a href="http://en.wikipedia.org/wiki/Tom_DeMarco">Tom DeMarco</a> in <a href="http://www.amazon.com/gp/product/0932633439?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0932633439">Peopleware</a>:</p>
<blockquote><p>“We all tend to tie our self-esteem strongly to the quality of the product we produce… Any step that you take that may jeopardize the quality of the product is like to set the emotions of your staff directly against you…</p>
<p>…the decision to pressure people into delivering a product that doesn’t measure up to their own quality standards is almost always a mistake.”</p></blockquote>
<p>The rest of <a href="http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/">that post</a> described the psychological affects that compromising quality may have on a development team.</p>
<p>This post will highlight another problem that compromising quality can have on your development team – making it more difficult to attract (and keep) the best developers.</p>
<h2>Part II</h2>
<p>In addition to the quote above, <a href="http://en.wikipedia.org/wiki/Tom_DeMarco">Tom DeMarco</a> continued in <a href="http://www.amazon.com/gp/product/0932633439?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0932633439">Peopleware</a>:</p>
<blockquote><p>“We managers tend to think of quality as just another attribute of the product, something that may be supplied in varying degrees…</p>
<p>…The builders’ view of quality, on the other hand, is very different.  Since their self-esteem is strongly tied to the product, they tend to impose quality standards of their own.  The minimum that will satisfy them is more or less the best quality they have achieved in the past.”</p></blockquote>
<p>In particular, notice the last sentence:  “<em>The minimum that will satisfy them is more or less the best quality they have achieved in the past.</em>”  This characteristic is one of the best traits we developers have – the desire to <em>continuously improve</em>.  <a href="http://en.wikipedia.org/wiki/Kaizen">Kaizen</a>, the process of continuous improvement, is increasingly attracting attention as a key factor in making huge long term gains, both for <a href="http://www.amazon.com/gp/product/007554332X?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=007554332X">companies</a> and <a href="http://www.amazon.com/gp/product/0761129235?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0761129235">individuals</a>. It is also a key principle behind agile techniques such as Extreme Programming and Scrum.</p>
<p>In our industry, continuous improvement is not just a desire, but also a survival technique.  Things change so quickly, if we do not improve continuously, we will not only fall behind, but become obsolete in a few short years.</p>
<p>With these thoughts in mind, now consider what happens when a developer is told to accept a lesser quality product.  On the rare occasion, the developer might only be disappointed or annoyed.  If it becomes a rule, rather than an exception, any good developer will realize this approach will lead them quickly down a dead-end path.  And the more passionate your developer is about their career, the faster they will reach this conclusion.</p>
<p>Again, taking shortcuts on quality is likely to affect you more in the long run.  Where you might be able to deliver things sooner in the short term, you are more likely to lose the developers that can deliver faster in the long run.  Don’t risk losing your best people by not allowing them to do their best.</p>
<br />Posted in Quality Tagged: Quality <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=62&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/09/15/sacrificing-quality-and-kaizen/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Extract Method &#8211; How Much is Too Much?</title>
		<link>http://chrismelinn.wordpress.com/2009/09/14/extract-method-how-much-is-too-much/</link>
		<comments>http://chrismelinn.wordpress.com/2009/09/14/extract-method-how-much-is-too-much/#comments</comments>
		<pubDate>Mon, 14 Sep 2009 06:37:50 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=58</guid>
		<description><![CDATA[Extract Method is one of the most basic and common refactorings. In Refactoring: Improving the Design of Existing Code, Martin Fowler gives the following motivation for using Extract Method: &#8220;Extract Method is one of the most common refactorings I do.  I look at a method that is too long or look at code that needs [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=58&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.refactoring.com/catalog/extractMethod.html">Extract Method</a> is one of the most basic and common <a href="http://www.refactoring.com/catalog/index.html">refactorings</a>. In <a href="http://www.amazon.com/gp/product/0201485672?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=0201485672">Refactoring: Improving the Design of Existing Code</a>, Martin Fowler gives the following motivation for using Extract Method:</p>
<blockquote><p>&#8220;Extract Method is one of the most common refactorings I do.  I look at a method that is too long or look at code that needs a comment to understand its purpose.  I then turn that fragment of code into its own method.</p>
<p>I prefer short, well-named methods for several reasons.  First, it increases the chances that other methods can use a method when the method is finely grained.  Second, it allows the higher-level methods to read more like a series of comments.  Overriding also is easier when the methods are finely grained.</p>
<p>It does take a little getting used to if you are used to seeing larger methods.  And small methods really work only when you have good names, so you need to pay attention to naming.  People sometimes ask me what length I look for in a method.  To me length is not the issue.  The key is the semantic distance between the method name and the method body.  If extracting improves clarity, do it, even<br />
if the name is longer than the code you have extracted.&#8221;</p></blockquote>
<p>Few would argue with the benefits of this refactoring.</p>
<p>But, what happens if we perform Extract Method to the extreme?  What happens if we follow <a href="http://www.objectmentor.com/omTeam/martin_r.html">Uncle Bob</a>&#8216;s advice and <a href="http://blog.objectmentor.com/articles/2009/09/11/one-thing-extract-till-you-drop">extract till we drop</a>?</p>
<blockquote><p>‘For years authors and consultants (like me) have been telling us that functions should do <em>one thing</em>. They should do it well. They should do it only.</p>
<p>The question is: What the hell does “one thing” mean?</p>
<p>After all, one man’s “one thing” might be someone else’s “two things”.’</p></blockquote>
<p><a href="http://blog.objectmentor.com/articles/2009/09/11/one-thing-extract-till-you-drop">Uncle Bob’s post</a> provides an example of extracting until nothing else can be done, and then he ends with this comment:</p>
<blockquote><p>“Perhaps you think this is taking things too far. I used to think so too. But after programming for over 40+ years, I’m beginning to come to the conclusion that this level of extraction is not taking things too far at all. In fact, to me, it looks just about right.</p>
<p>So, my advice: Extract till you just can’t extract any more. Extract till you drop.”</p></blockquote>
<p>As he predicts, many people do think he’s going too far.  Here&#8217;s a couple excerpts from the <a href="http://blog.objectmentor.com/articles/2009/09/11/one-thing-extract-till-you-drop#comments">post&#8217;s comments</a>:</p>
<blockquote><p>“Following the flow of the data through the fully extracted version becomes difficult, since the developer will need to jump around constantly throughout the body of the class.</p>
<p>If the goal is to make development and maintenance easier and fully extracting the class makes it more difficult for a developer to follow the flow of the data is it better to fully extract just for the sake of following a rule?</p>
<p>My point is that patterns in code are easier to see when things are not broken down into such small chunks. At the fully decomposed state it isn’t obvious that an Adapter on the Matcher would simply fit into place. By decomposing the methods so fine you lose context, so much so it isn’t evident how the method relates to the accomplishing the goal of the class.”</p></blockquote>
<p>and, another:</p>
<blockquote><p>‘A function by definition, returns 1 result from 1 input. If there’s no reuse, there is no “should”. Decomposition is for reuse, not just to decompose. Depending on the language/compiler there may be additional decision weights.</p>
<p>What I see from the example is you’ve gone and polluted your namespace with increasingly complex,longer,more obscure, function name mangling which could have been achieved (quick and readable) with whitespace and comments. To mirror a previous poster, I rather see a javadoc with proper commenting than to trace what’s going on for such a simplistic case. I’m afraid to ask what you plan to do when the class is more complex and symbolExpression(..) isn&#8217;t descriptive enough!’</p></blockquote>
<p>These arguments make a good point.  However, these arguments also apply to object-oriented code in general.  Reading and navigating object-oriented code can often be more difficult than its procedural counterparts.  However, we hope to overcome these disadvantages by creating a structure that is more readable and reusable overall.</p>
<p>In Uncle Bob’s example, the newer, more granular methods provide a more complete and accurate view of the behaviors and capabilities of the SymbolReplacer class.  In isolation, it might appear as overkill and &#8220;polluted namespaces&#8221;.  However, if you were maintaining a large codebase and needed to understand how to use (or reuse) SymbolReplacer, I believe Uncle Bob&#8217;s approach would make your task much easier.  You don&#8217;t need to read through javadoc (as one commenter prefers).  Instead, the method names are more clear, the size is smaller and easier to override, and the class itself <em>almost </em>becomes readable English.  In my opinion, these advantages outweigh the loss of navigability.</p>
<p>But, perhaps, as Martin Fowler mentions &#8220;it does take a little getting used to&#8221;.  Uncle Bob said almost the same thing: &#8220;Perhaps you think this is taking things too far. I used to think so too. But after programming for over 40+ years, I’m beginning to come to the conclusion that this level of extraction is not taking things too far at all. In fact, to me, it looks just about right.&#8221;</p>
<p>With the wisdom of those two, I think we owe it to ourselves to set aside our skepticism and give it a real try.  We can come back later, compare results, and make a decision then.  I have found that those who are willing to try their advice, in the end, never go back.  Perhaps, you will will find that your code gets cleaner and opportunities for reuse start showing themselves in surprising ways.</p>
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;">
<div id="codeSnippetWrapper" style="text-align:left;line-height:12pt;background-color:#f4f4f4;width:97.5%;"></div>
</div>
<br />Posted in Refactoring Tagged: Refactoring <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=58&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/09/14/extract-method-how-much-is-too-much/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
		<item>
		<title>Sacrificing Quality Costs More Than You Think</title>
		<link>http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/</link>
		<comments>http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/#comments</comments>
		<pubDate>Tue, 21 Jul 2009 12:03:40 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Quality]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=39</guid>
		<description><![CDATA[My last post highlighted my concerns with the use of the “technical debt” metaphor, ending with this question and summary: Should quality be compromised?  When? …the metaphor of technical debt seems to open the issue of quality as being a gray area, something that can be “traded away”.  The decision to compromise quality should not [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=39&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>My <a href="http://chrismelinn.wordpress.com/2009/07/16/shortcomings-of-the-technical-debt-metaphor/">last post</a> highlighted my concerns with the use of the “technical debt” metaphor, ending with this question and summary:</p>
<blockquote>
<h4>Should quality be compromised?  When?</h4>
<p>…the metaphor of technical debt seems to open the issue of quality as being a gray area, something that can be “traded away”.  The decision to compromise quality should not be made lightly under any circumstances.</p></blockquote>
<p>I realize this statement doesn’t exactly blow your mind.  Of course, quality is important.  We all believe so.</p>
<p>So, let’s discuss a seemingly innocent scenario we may face as a development team:</p>
<blockquote><p>In this iteration, we need to release our software slightly earlier than anticipated.  We won’t have the time to do the usual refactoring cycle after development.</p></blockquote>
<p>Doesn’t seem like such a big deal.  And, on paper, it’s not.</p>
<p>However, <strong>what message did we just send</strong> to our developers?</p>
<p>In <a href="http://www.amazon.com/gp/product/0932633439?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0932633439">Peopleware</a> (a <em>must </em>read), <a href="http://en.wikipedia.org/wiki/Tom_DeMarco">Tom DeMarco</a> has this to say:</p>
<blockquote><p>“We all tend to tie our self-esteem strongly to the quality of the product we produce… Any step that you take that may jeopardize the quality of the product is like to set the emotions of your staff directly against you…</p>
<p>…the decision to pressure people into delivering a product that doesn’t measure up to their own quality standards is almost always a mistake.”</p></blockquote>
<p>Many managers and team leaders may think such a reaction to a relatively small decision is inappropriate.  They would be right.  However, as humans, we seem to be programmed this way.</p>
<p>To understand better, consider the <a href="http://en.wikipedia.org/wiki/Fixing_Broken_Windows">Broken Window Theory</a>, which provides further examples and research outside of software development:</p>
<blockquote><p>“Consider a building with a few broken windows. If the windows are not repaired, the tendency is for vandals to break a few more windows. Eventually, they may even break into the building, and if it&#8217;s unoccupied, perhaps become squatters or light fires inside.</p>
<p>Or consider a sidewalk. Some litter accumulates. Soon, more litter accumulates. Eventually, people even start leaving bags of trash from take-out restaurants there or breaking into cars.”</p></blockquote>
<p>As humans, <strong>we have subconscious feelings about quality</strong> of things around us, and <strong>we treat those things accordingly</strong>.  If we have a beautiful new car, flawless and free of scratches, we keep it clean and polish it regularly.  The first ding hurts the most.  Over time, we get more scratches, they hurt less, we worry less, clean the car less, and <strong>care less</strong>.</p>
<p>Looking back to our example, the decision to fast-track the release by a few days was probably not worth the harm to our team’s morale and self esteem.  The impact is <strong>largely subconscious</strong>, but very real, and does the most damage.</p>
<p>As creators and builders, we developers are driven by the desire to produce something which makes us proud.  When robbed of this feeling, for whatever reason, it hurts more than we may even want to recognize.</p>
<br />Posted in Quality Tagged: Quality <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&#038;blog=8154832&#038;post=39&#038;subd=chrismelinn&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/665997a2683791aaaeaf501194e6f869?s=96&#38;d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Chris</media:title>
		</media:content>
	</item>
	</channel>
</rss>
