<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Crafting software&#187; Refactoring</title>
	<atom:link href="http://davidlaing.com/category/software-craftmanship/refactoring/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidlaing.com</link>
	<description>David Laing&#039;s thoughts on software development</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:02:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Implementing the strategy pattern without an explosion of classes &#8211; part 3 of ??</title>
		<link>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of</link>
		<comments>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 21:51:25 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Code smells]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://davidlaing.radweb.co.za/?p=272</guid>
		<description><![CDATA[I feel uncomfortable when I see large switch statements. I appreciate how they break the Open Closed Principle. I have enough experience to know that they seem to attract extra conditions &#38; additional logic during maintenance, and quickly become bug hotspots. A refactoring I use frequently to deal with this is Replace Conditional with Polymorphism; [...]]]></description>
			<content:encoded><![CDATA[<p>I feel uncomfortable when I see large switch statements.  I appreciate how they break the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principle</a>.  I have enough experience to know that they seem to attract extra conditions &amp; additional logic during maintenance, and quickly become bug hotspots.</p>
<p>A refactoring I use frequently to deal with this is <a href="http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html">Replace Conditional with Polymorphism</a>; but for simple switches, its always seemed like a rather large hammer.</p>
<p>Take the following simple example that performs slightly different processing logic based on the credit card type:</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-switch.js"></script> Its highly likely that the number of credit card types will increase; and that the complexity of processing logic for each will also increase over time.  The traditional application of the <a href="http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html">Replace Conditional with Polymorphism</a> refactoring gives the following:  </p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-strategy.js"></script></p>
<p>This explosion of classes containing almost zero logic has always bothered me as quite a lot of boilerplate overhead for a relatively small reduction in complexity.</p>
<p>Consider however, the functional approach to the same refactoring:</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-functional.js"></script> </p>
<p>Here we have obtained the same simplification of the switch statement; but avoided the explosion of simple classes.  Whilst strictly speaking we are still violating the  <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principle</a>; we do have a collection of simple methods that are easy to comprehend and test.  It&#8217;s worth noting that when our logic becomes very complex; converting to the OO Strategy pattern becomes a more compelling option.  Consider the case when we include a collection of validation logic for each credit card:  <script src="https://gist.github.com/923516.js?file=CreditCard-complex-functional.js"></script></p>
<p>In this case the whole file starts to feel too complex to me; and having the logic partitioned into separate strategy classes / files seems more maintainable to me.</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-complex-strategy.js"></script></p>
<p>To conclude then, the fact that languages treat functions as first class constructs, gives us the flexibility to use them in a &#8220;polymorphic&#8221; way; where our &#8220;interface&#8221; is the function signature.  </p>
<p>And for some problems, like a refactoring a simple switch statement; I feel this gives us a more elegant solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>For a software craftsman, reducing technical debt should be as much of a habit as typing</title>
		<link>http://davidlaing.com/2009/03/02/for-a-software-craftsman-reducing-technical-debt-should-be-as-much-of-a-habit-as-typing/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=for-a-software-craftsman-reducing-technical-debt-should-be-as-much-of-a-habit-as-typing</link>
		<comments>http://davidlaing.com/2009/03/02/for-a-software-craftsman-reducing-technical-debt-should-be-as-much-of-a-habit-as-typing/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 08:40:05 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Refactoring]]></category>
		<category><![CDATA[Software Craftmanship]]></category>
		<category><![CDATA[Technical Debt]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=160</guid>
		<description><![CDATA[I was involved in an interesting group discussion with fellow craftsmen yesterday on Technical Debt at the 2009 Software Craftsmanship conference. The question put to the group was: &#8220;How should a team make time to reduce technical debt?&#8221; I was interested that there was a totally unanamious response &#8211; &#8220;You shouldn&#8217;t&#8221;. &#8220;You should be doing [...]]]></description>
			<content:encoded><![CDATA[<p>I was involved in an interesting group discussion with fellow craftsmen yesterday on Technical Debt at the <a href="http://www.softwarecraftsmanship.org.uk">2009 Software Craftsmanship conference</a>.</p>
<p>The question put to the group was:  &#8220;How should a team make time to reduce technical debt?&#8221;</p>
<p>I was interested that there was a totally unanamious response &#8211; &#8220;You shouldn&#8217;t&#8221;.  &#8220;You should be doing tiny pieces of technical debt reduction <strong>all</strong> the time&#8221;.</p>
<p>Previously I have advocated creating <a href="http://davidlaing.com/2008/06/30/when-to-make-technical-stories/">technical debt reduction stories</a>, and trying to schedule those into the iteration plan.  People thought this was in principal the wrong strategy; and indeed in my experience this approach doesn&#8217;t work.</p>
<p>The group felt that in general tackling technical debt reduction though large scale refactorings was the wrong approach &#8211; rather a craftsman should be making incremental improvements every time they touch the code.  </p>
<p><a href="http://www.informit.com/articles/article.aspx?p=1235624&amp;seqNum=6">Bob Martin&#8217;s Boy Scout Rule:</a> &#8211; <em>check in your code a little cleaner than what you checked out</em> &#8211; encapsulates this principal.  Its the little refactorings that you make &#8211; removing a tiny piece of duplication, changing a variable name to better reveal intent; extracting an expression into a intention revealing method &#8211; that, over time, result in a clean, maintainable code base.</p>
<p>In a way, this is similar to implementing the &#8220;<a href="http://en.wikipedia.org/wiki/Fixing_Broken_Windows">Fixing Broken Windows Theory</a>&#8221; in software development.  The theory is that having a zero tolerance attitude towards the little things makes a huge impact on the so called &#8220;bigger&#8221; things.  </p>
<p>Its perhaps easier understood if you consider what happens if you don&#8217;t care about the little things.  Its about the attitude &#8211; if I couldn&#8217;t care enough to clean up a messy bit of code; will my team mates care about a few broken tests?  If its okay to have a few broken tests; then it&#8217;s probably okay to ignore some bugs.  If its okay to ignore bugs; then who really needs to care about well defined acceptance tests?  And if the team doesn&#8217;t care about precise acceptance tests; why should the business care about unambiguous requirements.  You get the picture.</p>
<p>Its the little things, added up, that result in technical debt reduction.  </p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2009/03/02/for-a-software-craftsman-reducing-technical-debt-should-be-as-much-of-a-habit-as-typing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

