<?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>Fri, 06 Jan 2012 00:40:20 +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>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&amp;blog=8154832&amp;post=103&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/103/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/103/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/103/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=103&amp;subd=chrismelinn&amp;ref=&amp;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&amp;blog=8154832&amp;post=77&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/77/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/77/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/77/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=77&amp;subd=chrismelinn&amp;ref=&amp;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&amp;blog=8154832&amp;post=70&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/70/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/70/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/70/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=70&amp;subd=chrismelinn&amp;ref=&amp;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&amp;blog=8154832&amp;post=62&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/62/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/62/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/62/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=62&amp;subd=chrismelinn&amp;ref=&amp;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&amp;blog=8154832&amp;post=58&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/58/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/58/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/58/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=58&amp;subd=chrismelinn&amp;ref=&amp;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&amp;blog=8154832&amp;post=39&amp;subd=chrismelinn&amp;ref=&amp;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> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/39/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/39/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/39/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=39&amp;subd=chrismelinn&amp;ref=&amp;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>
		<item>
		<title>Shortcomings of the Technical Debt Metaphor</title>
		<link>http://chrismelinn.wordpress.com/2009/07/16/shortcomings-of-the-technical-debt-metaphor/</link>
		<comments>http://chrismelinn.wordpress.com/2009/07/16/shortcomings-of-the-technical-debt-metaphor/#comments</comments>
		<pubDate>Thu, 16 Jul 2009 13:13:48 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Quality]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=37</guid>
		<description><![CDATA[The metaphor of “technical debt” is gaining in popularity to describe the implications of taking shortcuts in developing software.  Steve McConnell has an excellent post on technical debt, where he begins his discussion: The term &#8220;technical debt&#8221; was coined by Ward Cunningham to describe the obligation that a software organization incurs when it chooses a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=37&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The metaphor of “<a href="http://www.martinfowler.com/bliki/TechnicalDebt.html">technical debt</a>” is gaining in popularity to describe the implications of taking shortcuts in developing software.  Steve McConnell has an <a href="http://blogs.construx.com/blogs/stevemcc/archive/2007/11/01/technical-debt-2.aspx">excellent post on technical debt</a>, where he begins his discussion:</p>
<blockquote><p>The term &#8220;technical debt&#8221; was coined by Ward Cunningham to describe the obligation that a software organization incurs when it chooses a design or construction approach that&#8217;s expedient in the short term but that increases complexity and is more costly in the long term.</p></blockquote>
<p>As many others have already already written on this subject, I will instead focus on this question from his summary:</p>
<blockquote><p>What do you think? Do you like the technical debt metaphor? Do you think it&#8217;s a useful way to communicate the implications of technical/business decision making to non-technical project stakeholders?</p></blockquote>
<h4>The “Good”</h4>
<p>Firstly, yes – I believe the technical debt metaphor is a useful way to communicate such implications to non-technical stakeholders.  I’m sure most developers can relate to some version of a conversation going something like this:</p>
<blockquote><p>The Big Boss:   Thanks, that was an excellent demo!  Let’s make sure to get this into tomorrow’s release!</p>
<p>You:  Umm… I still have some things to finish up.  I’m planning to have it ready for testing sometime next week.  I am on track to meet the scheduled deadline.</p>
<p>The Big Boss:  Finish up?  Everything is working great!  What do you have left to do?</p>
<p>You:  Well, there’s just a few changes I need to make… strengthening the exception handling, making a few improvements to the design, cleaning the code up a bit…</p>
<p>The Big Boss:  Ah, don’t worry!  The demo looked fine to me and the customers don’t care about all that!  Besides, Friday is the end of the quarter and it will be great to get this feature out now!</p>
<p>You:  (sigh…)</p></blockquote>
<p>Of course, as developers we try to explain to The Big Boss that we still need to do the last iteration of refactoring.  We want to deliver code with a level of quality that we expect of ourselves.  However, often The Big Boss cannot relate.  Or, at least, he doesn’t think it’s as important as we do.  In this situation, the technical debt metaphor can be an helpful way to describe such issues using terminology that he is more likely to appreciate.</p>
<h4>The “Bad”</h4>
<p>Although the metaphor can be useful, it also has some important shortcomings.  These shortcomings are especially significant in dealing with non-technical stakeholders.</p>
<h4>Concern # 1 – The term “debt” is too soft</h4>
<h5>Overly Acceptable</h5>
<p>Financial debt is abundant and widespread, often accepted as a fact of life.  I agree that some level of technical debt is also unavoidable in doing real software development.  However, especially with a non-technical manager, the decision may be made too readily to accept technical debt without understanding the full implications.</p>
<h5>“Interest rates” are usually low</h5>
<p>The metaphor of “interest payments” is used to illustrate the implications of taking a more “quick and dirty” approach.  In these days of low interest loans, the connotations of this analogy may not be strong enough to describe the real impact of accepting lesser quality workmanship.</p>
<h4>Concern # 2 – The “Interest Rate” Varies</h4>
<p>When describing technical debt, the individual issue incurring the “debt” should be highlighted in terms of severity (it’s interest rate).  Take two possible examples of technical debt a team may choose to incur:</p>
<ol>
<li>Refactoring to improve naming of methods/variables of a new class is not performed.</li>
<li>Unit tests are not created on this same new classes.</li>
</ol>
<p>The first example of debt may certainly impact readability/maintainability, particularly in the long run.  However, this is probably not severe and would probably be fairly to change in the next release or two.  It is this type of debt where the use of this metaphor seems most appropriate.</p>
<p>The second example of debt is more severe and will be harder to “service”.  The initial code will be released without sufficient testing from the beginning.  Unnecessary dependencies may have been introduced that are difficult to extract later.  Future development may be severely hindered without the “safety net” of unit tests to refactor…  Whatever the impact, the point is that each instance of technical debt is different and must be considered independently.</p>
<h4>Summary – Should quality be compromised?  When?</h4>
<p>In any case, my biggest concern is 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>
<p><strong>Update</strong>:  My <a href="http://chrismelinn.wordpress.com/2009/07/21/sacrificing-quality-costs-more-than-you-think/">next post</a> further describes the issues of compromising quality</p>
<br />Posted in Quality Tagged: Quality <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/37/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/37/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/37/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=37&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/07/16/shortcomings-of-the-technical-debt-metaphor/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>Trustworthy Unit Tests &#8211; Testing the Data Access Layer</title>
		<link>http://chrismelinn.wordpress.com/2009/07/09/trustworthy-unit-tests-testing-the-data-access-layer-dal/</link>
		<comments>http://chrismelinn.wordpress.com/2009/07/09/trustworthy-unit-tests-testing-the-data-access-layer-dal/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 23:45:54 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/2009/07/09/trustworthy-unit-tests-testing-the-data-access-layer-dal/</guid>
		<description><![CDATA[In the latest Hanselminutes podcast, Roy Osherove describes some of his best practices in unit testing techniques.  In the discussion, Roy describes one of the key tenets from his book which says that a unit test must be “trustworthy”. On the surface, this tenet seems fairly obvious.  Of course, we need to trust our tests!  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=32&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In the <a href="http://www.hanselman.com/blog/HanselminutesPodcast169TheArtOfUnitTestingWithRoyOsherove.aspx">latest Hanselminutes podcast</a>, <a href="http://weblogs.asp.net/rosherove/archive/2009/07/07/art-of-unit-testing-on-hanselminutes.aspx">Roy Osherove</a> <a href="http://www.hanselminutes.com/default.aspx?showID=187">describes some of his best practices in unit testing techniques</a>.  In the discussion, Roy describes one of the key tenets from <a href="http://www.amazon.com/gp/product/1933988274?ie=UTF8&amp;tag=chrismelinnsw-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=1933988274">his book</a> which says that a unit test must be “trustworthy”.</p>
<p>On the surface, this tenet seems fairly obvious.  Of course, we need to trust our tests!  However, as he describes some situations where this rule is often violated, I realize I would be guilty on many occasions.</p>
<p>For example, I always struggle with the idea to include data access layer tests in my unit tests.  Yes, I know that testing the database is really an integration test and “purists” would argue these should not be included.  However, I feel the only way to test the data access code in a meaningful way is to hit the database.  In other words, the code in the data access layer and the related code in the database are a single logical unit.</p>
<p>In <a href="http://www.hanselminutes.com/default.aspx?showID=187">this podcast</a>, Roy helps me to understand the difference, which I have summarized here:</p>
<h2>Clarification # 1 – Data Access Layer Unit Tests are not trustworthy</h2>
<p>With a trustworthy test, you must be able trust the results 100% of the time.  If the test fails, I know the code is broken and must be fixed.  This means I shouldn’t have to ask things like “Was the database down?”, “Was the connection string OK?”, “Was the stored procedure modified?”.  By asking these questions, it shows that I don’t trust the results and I have a poorly designed “unit test”.</p>
<h2>Clarification # 2 – Data Access Layer tests must be integration tests</h2>
<p>In <a href="http://www.hanselminutes.com/default.aspx?showID=187">the podcast</a>, Roy also states that the data access layer is generally a very thin layer on top of the database, invoking some execution logic within the database itself.  For example, the data access layer will issue a command/query such as a SELECT, INSERT, UPDATE, DELETE or similar set of statements using a stored procedure.  There generally is not much else that sits inside the data access code.  So, Roy also believes that this type of code must be tested as a single unit.</p>
<p>However, Roy also points out that these must be also be integration tests.  I had made the assumption that since they must be tested as a unit, then they must be unit tests!  However, by doing so, I have created untrustworthy tests.  Now, it makes sense to me that the data access layer will likely not include any unit tests at all!  They will only be created as integration tests.</p>
<h2>Clarification # 3 – Separation of Unit Tests from Integration Tests</h2>
<p>It probably seems like an obvious observation to make, but I feel its important to distinguish:  Unit Tests and Integration Tests are often both developed using a “Unit Test Framework”.  We’re using the same tools to create both types of tests.</p>
<p>However, the problem occurs when we blend the two types of tests together.  Instead, we should create different projects/assemblies, so they can be run easily and independently from one other.  It should be obvious and easy for someone to get all the code out of source control, build the solution, and know which tests should pass from the beginning.  If you mix integration tests into the same project, the other developer will have to determine which tests “should” pass and which “should” fail.  This makes things more difficult than necessary for other developers and may likely mean that your tests will ignored and no longer maintained.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/32/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/32/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/32/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=32&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/07/09/trustworthy-unit-tests-testing-the-data-access-layer-dal/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>IEnumerable and Lazy Evaluation</title>
		<link>http://chrismelinn.wordpress.com/2009/07/03/ienumerable-and-lazy-evaluation/</link>
		<comments>http://chrismelinn.wordpress.com/2009/07/03/ienumerable-and-lazy-evaluation/#comments</comments>
		<pubDate>Fri, 03 Jul 2009 13:07:11 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=25</guid>
		<description><![CDATA[Similar to my last post, this topic was also inspired by our discussions at this month’s Melbourne Patterns Group meeting.  In our meeting, it was mentioned that closures (see my last post) also assist in performing lazy evaluation. Pedram Rezaei wrote an excellent article on lazy evaluation in C#, which helped me better understand lazy [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=25&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Similar to <a href="http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/">my last post</a>, this topic was also inspired by our discussions at <a href="http://melbournepatterns.org/2009/06/08/next-meeting-july-1st-2009-wednesday-at-645pm/">this month’s</a> <a href="http://melbournepatterns.org/">Melbourne Patterns Group</a> meeting.  In our meeting, it was mentioned that closures (<a href="http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/">see my last post</a>) also assist in performing lazy evaluation.</p>
<p>Pedram Rezaei wrote an <a href="http://blogs.msdn.com/pedram/archive/2007/06/02/lazy-evaluation-in-c.aspx">excellent article</a> on lazy evaluation in C#, which helped me better understand lazy evaluation support in C#.  However, a seemingly minor comment from his post also struck me:</p>
<blockquote><p>As you can see both Where and Select methods also return an instance of a type implementing IEnumerable&lt;string&gt; meaning that they are not executed until an enumerator is created… and its MoveNext method is called…</p></blockquote>
<p>For some reason, I never realized returning IEnumerable&lt;&gt; meant the closure would not be evaluated until each MoveNext invocation.  Even though I knew that LINQ queries were generally “lazily evaluated”, I had not realized that this was the reason.</p>
<p>In learning this, I should expand on this statement from <a href="http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/">my last post</a>:</p>
<blockquote><p>** ToList( ) is only required if you want to maintain the return type as List&lt;Employee&gt;.  Otherwise, it is probably more appropriate to change to IEnumerable&lt;Employee&gt; here.</p></blockquote>
<p>The referenced code block:</p>
<p><pre class="brush: csharp;">
public List&lt;employee&gt; Managers(List&lt;employee&gt; emps)
{
return emps.Where(e =&gt; e.IsManager).ToList();
}
</pre></p>
<p>Although the statement and code above is still acceptable, it will behave in a way that wasn’t obvious to me at the time.  By converting the IEnumerable&lt;&gt; to a List&lt;&gt;, I had changed the implementation from being ‘lazily evaluated’ to being ‘eagerly evaluated’.  This isn’t necessarily a bad thing, but it is important to be aware of the difference (see <a href="http://dotnetperls.com/lazy-linq-queries">this article</a> by Sam Allen for more information).</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/25/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/25/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/25/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=25&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/07/03/ienumerable-and-lazy-evaluation/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>Closures in C# 3.0 and 3.5</title>
		<link>http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/</link>
		<comments>http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/#comments</comments>
		<pubDate>Thu, 02 Jul 2009 13:07:49 +0000</pubDate>
		<dc:creator>Chris Melinn</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://chrismelinn.wordpress.com/?p=12</guid>
		<description><![CDATA[This month’s Melbourne Patterns Group meeting included discussions on functional programming.  There were some topics and terms used in the discussion that encouraged me to do more research. One of the terms I wanted to understand better was “closures”.  In the demonstration, I was familiar with the usages (like anonymous delegates in C# or blocks [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=12&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://melbournepatterns.org/2009/06/08/next-meeting-july-1st-2009-wednesday-at-645pm/">This month’s</a> <a href="http://melbournepatterns.org/">Melbourne Patterns Group</a> meeting included discussions on functional programming.  There were some topics and terms used in the discussion that encouraged me to do more research.</p>
<p>One of the terms I wanted to understand better was “closures”.  In the demonstration, I was familiar with the usages (like anonymous delegates in C# or blocks from Smalltalk), but I wanted to learn more.  My investigation led me to a relatively old <a href="http://martinfowler.com/bliki/Closure.html">post on the topic</a> from <a href="http://martinfowler.com/">Martin Fowler</a>.  At the bottom of his article is another <a href="http://joe.truemesh.com/blog//000390.html">reference to the C# implementation of closures</a>, based on C# 2.0.</p>
<p>As these articles were written in 2004, C# has since added more support for closures in C# 3.0 with lamba expressions, and again with LINQ and extension methods in 3.5.  I found it interesting to rewrite the same examples in both C# 3.0 and 3.5:</p>
<h3><strong>Example 1 &#8211; List of Employees who are Managers<br />
</strong></h3>
<h4>Fowler&#8217;s Original Example in Ruby</h4>
<p><pre class="brush: ruby;">
def managers(emps)
  return emps.select {|e| e.isManager}
end
</pre></p>
<h4>C# 2.0 Example from Walnes</h4>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; Managers(List&lt;Employee&gt; emps)
{
    return emps.FindAll(
        delegate(Employee e)
        {
            return e.IsManager;
        }
    );
}
</pre></p>
<h4>C# 3.0</h4>
<p>We can now replace the anonymous delegate with a smaller lamba expression:</p>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; Managers(List&lt;Employee&gt; emps)
{
    return emps.FindAll(e =&gt; e.IsManager);
}
</pre></p>
<h4>LINQ and 3.5</h4>
<p>We can now use the extension methods on IEnumerable&lt;T&gt; from which List&lt;T&gt; derives.  In this case, the <a href="http://msdn.microsoft.com/en-us/library/bb534803.aspx">Where</a> method is appropriate.</p>
<p>** ToList( ) is only required if you want to maintain the return type as List&lt;Employee&gt;.  Otherwise, it is probably more appropriate to change to IEnumerable&lt;Employee&gt; here.  [Update: see <a href="http://chrismelinn.wordpress.com/2009/07/03/ienumerable-and-lazy-evaluation/">this post</a> for more differences regarding these return types.]</p>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; Managers(List&lt;Employee&gt; emps)
{
    return emps.Where(e =&gt; e.IsManager).ToList();
}
</pre></p>
<p>Now, in 3.5, the C# code is nearly identical in structure and clarity as the orginal ruby example.</p>
<h3><strong>Example 2 &#8211; referring to a local variable in the closure block<br />
</strong></h3>
<h4>Fowler&#8217;s Original Example in Ruby</h4>
<p><pre class="brush: ruby;">
def highPaid(emps)
  threshold = 150
  return emps.select {|e| e.salary &gt; threshold}
end
</pre></p>
<h4>C# 2.0 Example from Walnes</h4>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; HighPaid(List&lt;Employee&gt; emps)
{
    int threshold = 150;
    return emps.FindAll(delegate(Employee e)
    {
        return e.Salary &gt; threshold;
    });
}
</pre></p>
<h4>C# 3.0</h4>
<p>Again, we can now replace the anonymous delegate with a smaller lamba expression:</p>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; HighPaid(List&lt;Employee&gt; emps)
{
    int threshold = 150;
    return emps.FindAll(e =&gt; e.Salary &gt; threshold);
}
</pre></p>
<h4>LINQ and 3.5</h4>
<p>Again, we can now use the extension methods on IEnumerable&lt;T&gt; from which List&lt;T&gt; derives.  In this case, the <a href="http://msdn.microsoft.com/en-us/library/bb534803.aspx">Where</a> method is appropriate.</p>
<p>** Again, ToList( ) is only required if you want to maintain the return type as List&lt;Employee&gt;.  Otherwise, it is probably more appropriate to change to IEnumerable&lt;Employee&gt; here.  [Update: see <a href="../2009/07/03/ienumerable-and-lazy-evaluation/">this post</a> for more differences regarding these return types.]</p>
<p><pre class="brush: csharp;">
public List&lt;Employee&gt; HighPaid(List&lt;Employee&gt; emps)
{
    int threshold = 150;
    return (List&lt;Employee&gt;) emps.Where(e =&gt; e.Salary &gt; threshold).ToList();
}
</pre></p>
<p>Now, in 3.5, the C# code is nearly identical in structure and clarity as the orginal ruby example.</p>
<h3><strong>Example 3 &#8211; returning a closure from a method<br />
</strong></h3>
<h4>Fowler&#8217;s Original Example in Ruby</h4>
<p><pre class="brush: ruby;">
def paidMore(amount)
  return Proc.new {|e| e.salary &gt; amount}
end
</pre></p>
<h4>C# 2.0 Example from Walnes</h4>
<p><pre class="brush: csharp;">
public Predicate&lt;Employee&gt; PaidMore(int amount)
{
    return delegate(Employee e)
    {
        return e.Salary &gt; amount;
    };
}
</pre></p>
<h4>C# 3.0</h4>
<p>Again, we can now replace the anonymous delegate with a smaller lamba expression:</p>
<p><pre class="brush: csharp;">
public Predicate&lt;Employee&gt; PaidMore(int amount)
{
    return e =&gt; e.Salary &gt; amount;
}
</pre></p>
<p>There would be no change to the above in 3.5 (same as C# 3.0) here.</p>
<h3><strong>Example 4 &#8211; Create a function using the closure &amp; assign to a variable<br />
</strong></h3>
<h4>Fowler&#8217;s Original Example in Ruby</h4>
<p><pre class="brush: ruby;">
highPaid = paidMore(150)
john = Employee.new
john.salary = 200
print highPaid.call(john)
</pre></p>
<h4>C# 2.0 Example from Walnes</h4>
<p><pre class="brush: csharp;">
Predicate&lt;employee&gt; highPaid = PaidMore(150);
Employee john = new Employee();
john.Salary = 200;
Console.WriteLine(highPaid(john));
</pre></p>
<p>There would be no change to the above in 3.0 or 3.5 (same as C# 2.0) here.</p>
<p>Download source <a href="http://cid-7f3aa0b5673d4b18.skydrive.live.com/self.aspx/.Public/ChrisMelinn.Closures.zip">here</a> to see complete C# examples.</p>
<br />Posted in Uncategorized  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/chrismelinn.wordpress.com/12/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/chrismelinn.wordpress.com/12/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/chrismelinn.wordpress.com/12/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=chrismelinn.wordpress.com&amp;blog=8154832&amp;post=12&amp;subd=chrismelinn&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://chrismelinn.wordpress.com/2009/07/02/closures-in-c-3-0-and-3-5/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>
	</channel>
</rss>
