<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.0.5" -->
<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/"
	>

<channel>
	<title>chris clarke</title>
	<link>http://squadlimber.com/chris</link>
	<description>software development that works...or something</description>
	<pubDate>Mon, 07 Apr 2008 23:14:16 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.0.5</generator>
	<language>en</language>
			<item>
		<title>Ignoring Common Coding Practice (why you should be too)</title>
		<link>http://squadlimber.com/chris/2008/04/04/ignoring-common-coding-practice-why-you-should-be-too/</link>
		<comments>http://squadlimber.com/chris/2008/04/04/ignoring-common-coding-practice-why-you-should-be-too/#comments</comments>
		<pubDate>Fri, 04 Apr 2008 00:13:48 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Refactoring</category>

		<category>eXtreme Programming</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2008/04/04/ignoring-common-coding-practice-why-you-should-be-too/</guid>
		<description><![CDATA[Simon Baker wrote a quick blog entry on Common Sense and Common Practice.  It hit home with me because recently I&#8217;ve been pairing with developers who find it uncomfortable coding in certain ways because it doesn&#8217;t fit with Common Practice.  A lot of code I see, whether it be reading a programming book, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.agileinaction.com/">Simon Baker</a> wrote a quick blog entry on <a href="http://www.think-box.co.uk/blog/2008/01/common.html">Common Sense and Common Practice</a>.  It hit home with me because recently I&#8217;ve been pairing with developers who find it uncomfortable coding in certain ways because it doesn&#8217;t fit with Common Practice.  A lot of code I see, whether it be reading a programming book, looking at some code I Googled, or looking back at the way I was taught at University, is really just a bit rubbish in my opinion.  It works okay, and I&#8217;m sure a computer can understand it, but as a human I find myself struggling a bit.  Typically the code seems to be telling me <strong><em>how</em></strong> the computation is taking place rather than <strong><em>what</em></strong> it is doing.  Sure, you need some <strong><em>how</em></strong> code but put it behind a little <strong><em>what</em></strong> code and give me a chance.</p>
<p>Anyway, enough passive-aggressive blogging, here are some things that people tend to find uncomfortable and perhaps why they shouldn&#8217;t:</p>
<h3>Long names</h3>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
&nbsp; &nbsp; @Test <span style="color: #000080;">public</span> <span style="color: #000080;">void</span> findingXMLElementByNameThrowsExceptionWhenElementDoesNotExist<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky"><span style="color: #000080;">String</span></a> someXmlWithNoFrankTag = <span style="color: #008000;">&quot;...&quot;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3ADocument+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky"><span style="color: #000080;">Document</span></a> xmlDocument = XmlUtils.<span style="color: #000000;">toDocument</span><span style="color: #000000;">&#40;</span>someXmlWithNoFrankTag<span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">try</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; XmlUtils.<span style="color: #000000;">findElementByName</span><span style="color: #000000;">&#40;</span>xmlDocument, <span style="color: #008000;">&quot;frank&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fail<span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Expected exception to be thrown because the element 'frank' does not exist!&quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span> <span style="color: #000080;">catch</span> <span style="color: #000000;">&#40;</span>JDOMException expectedBecauseElementShouldNotBeFound<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp;</div>
<p>Long descriptive names seem uncomfortable to people because you don&#8217;t normally see them in Common Practice.  I think they help because it&#8217;s much easier to see what&#8217;s going on without looking in to the details of the languages implementation and its easier to find code that already does what you want.</p>
<h3>Extracting composed methods that don&#8217;t remove duplication</h3>
<p>Before:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #000080;">public</span> <span style="color: #000080;">void</span> somebodyCheckedIn<span style="color: #000000;">&#40;</span>CheckIn checkIn<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000080;">for</span> <span style="color: #000000;">&#40;</span>CheckIn checkIn : codeCheckIns<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;christopherc&quot;</span>.<span style="color: #000000;">equals</span><span style="color: #000000;">&#40;</span>checkIn.<span style="color: #000000;">committer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// update web page</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">printTitle</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Code changed by: &quot;</span>&nbsp; &nbsp;checkIn.<span style="color: #000000;">committer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">printHeader</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;On date: &quot;</span>&nbsp; &nbsp;checkIn.<span style="color: #000000;">date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">printBold</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Changes: &quot;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">for</span> <span style="color: #000000;">&#40;</span>CodeChange codeChange : checkIn.<span style="color: #000000;">codeChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;File &quot;</span>&nbsp; &nbsp;codeChange.<span style="color: #000000;">fileName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>&nbsp; &nbsp;<span style="color: #008000;">&quot;: &quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Diff: &quot;</span>&nbsp; &nbsp;PrettyDiffFormatter.<span style="color: #000000;">format</span><span style="color: #000000;">&#40;</span>codeChange.<span style="color: #000000;">diff</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// kick off build</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> <span style="color: #000000;">&#40;</span>builder.<span style="color: #000000;">isRunning</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">emptyBuildQueue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">addToBuildQueue</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">new</span> Build<span style="color: #000000;">&#40;</span>checkIn<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
&nbsp;</div>
<p>After:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #000080;">public</span> <span style="color: #000080;">void</span> somebodyCheckedIn<span style="color: #000000;">&#40;</span>CheckIn checkIn<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000080;">for</span> <span style="color: #000000;">&#40;</span>CheckIn checkIn : codeCheckIns<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;christopherc&quot;</span>.<span style="color: #000000;">equals</span><span style="color: #000000;">&#40;</span>checkIn.<span style="color: #000000;">committer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; updateWebPageWithCheckIn<span style="color: #000000;">&#40;</span>checkIn<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stopTheBuildIfItsRunningAndBuild<span style="color: #000000;">&#40;</span>checkIn<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000080;">private</span> <span style="color: #000080;">void</span> updateWebPageWithCheckIn<span style="color: #000000;">&#40;</span>CheckIn checkIn<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; page.<span style="color: #000000;">printTitle</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Code changed by: &quot;</span>&nbsp; &nbsp;checkIn.<span style="color: #000000;">committer</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; page.<span style="color: #000000;">printHeader</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;On date: &quot;</span>&nbsp; &nbsp;checkIn.<span style="color: #000000;">date</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; page.<span style="color: #000000;">printBold</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Changes: &quot;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">for</span> <span style="color: #000000;">&#40;</span>CodeChange codeChange : checkIn.<span style="color: #000000;">codeChanges</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;File &quot;</span>&nbsp; &nbsp;codeChange.<span style="color: #000000;">fileName</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>&nbsp; &nbsp;<span style="color: #008000;">&quot;: &quot;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; page.<span style="color: #000000;">print</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Diff: &quot;</span>&nbsp; &nbsp;PrettyDiffFormatter.<span style="color: #000000;">format</span><span style="color: #000000;">&#40;</span>codeChange.<span style="color: #000000;">diff</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<span style="color: #000000;">&#125;</span><br />
<br />
<span style="color: #000080;">private</span> <span style="color: #000080;">void</span> stopTheBuildIfItsRunningAndBuild<span style="color: #000000;">&#40;</span>CheckIn checkIn<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">if</span> <span style="color: #000000;">&#40;</span>builder.<span style="color: #000000;">isRunning</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">stop</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">reset</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">emptyBuildQueue</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; builder.<span style="color: #000000;">addToBuildQueue</span><span style="color: #000000;">&#40;</span><span style="color: #000080;">new</span> Build<span style="color: #000000;">&#40;</span>checkIn<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>;<br />
<span style="color: #000000;">&#125;</span><br />
&nbsp;</div>
<p>People seem a bit uncomfortable with this refactoring because they think it doesn&#8217;t achieve anything except adding more code.  Sure, no duplication has been removed but its now much clearer what the public method does without having to look in to the imperative details of how it does it in the private methods.  I can now understand this code at a glance after splitting out the two things that were happening inside the loop and as an added benefit I was able to remove some comments by naming the methods well.</p>
<h3>Creating classes to express your domain</h3>
<p><a href="http://ivan.truemesh.com/">Ivan Moore</a> and <a href="http://peripateticaxiom.blogspot.com/">Keith Braithwaite</a> ran a workshop at <a href="http://www.spaconference.org/">SPA 2008</a> on <a href="http://ivan.truemesh.com/archives/000733.html">Programming as if the domain mattered</a> which inspired me on this one.</p>
<p>For example, if you are writing a Banking application, you can create classes that express familiar language in Banking.</p>
<p>Without domain classes:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
&nbsp; &nbsp; <a href="http://www.google.com/search?hl=en&amp;q=allinurl%3AString+java.sun.com&amp;bntI=I%27m%20Feeling%20Lucky"><span style="color: #000080;">String</span></a> customer = <span style="color: #008000;">&quot;Mr Clarke&quot;</span>;<br />
&nbsp; &nbsp; <span style="color: #000080;">long</span> custId = <span style="color: #0000ff;">234234555</span>;<br />
&nbsp; &nbsp; <span style="color: #000080;">double</span> amount = <span style="color: #0000ff;">500.0</span>;<br />
&nbsp; &nbsp; <span style="color: #000080;">double</span> interest = <span style="color: #0000ff;">1.055</span>;<br />
&nbsp; &nbsp; Account account = <span style="color: #000080;">new</span> Account<span style="color: #000000;">&#40;</span>customer, custId, <span style="color: #000080;">null</span>, <span style="color: #000080;">null</span>, <span style="color: #0000ff;">0.0</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; account.<span style="color: #000000;">open</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; account.<span style="color: #000000;">setAmount</span><span style="color: #000000;">&#40;</span>amount * interest<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; database.<span style="color: #000000;">save</span><span style="color: #000000;">&#40;</span>account<span style="color: #000000;">&#41;</span>;<br />
&nbsp;</div>
<p>With domain classes:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
&nbsp; &nbsp; Customer customer = <span style="color: #000080;">new</span> Customer<span style="color: #000000;">&#40;</span><span style="color: #008000;">&quot;Mr Clarke&quot;</span>, <span style="color: #0000ff;">234234555</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; Money money = <span style="color: #000080;">new</span> Money<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">500.0</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; Interest interest = <span style="color: #000080;">new</span> Interest<span style="color: #000000;">&#40;</span><span style="color: #0000ff;">5.5</span><span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; Account account = customer.<span style="color: #000000;">openAccount</span><span style="color: #000000;">&#40;</span>money<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; account.<span style="color: #000000;">addInterest</span><span style="color: #000000;">&#40;</span>interest<span style="color: #000000;">&#41;</span>;<br />
&nbsp; &nbsp; database.<span style="color: #000000;">save</span><span style="color: #000000;">&#40;</span>account<span style="color: #000000;">&#41;</span>;<br />
&nbsp;</div>
<p>I&#8217;ve found people are put off by this domain language because a lot of the classes involved don&#8217;t achieve much, you&#8217;ll have to imagine a lot of them for yourself but for example the Money class could start life as pretty much a wrapper around a primitive:</p>
<div class="java" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #000080;">public</span> <span style="color: #000080;">class</span> Money <span style="color: #000000;">&#123;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">private</span> <span style="color: #000080;">double</span> amount;<br />
<br />
&nbsp; &nbsp; <span style="color: #000080;">public</span> Money <span style="color: #000000;">&#40;</span><span style="color: #000080;">double</span> amount<span style="color: #000000;">&#41;</span> <span style="color: #000000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000080;">this</span>.<span style="color: #000000;">amount</span> = amount;<br />
&nbsp; &nbsp; <span style="color: #000000;">&#125;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// ...</span><br />
<span style="color: #000000;">&#125;</span><br />
&nbsp;</div>
<p>Another argument against is that it increases memory footprint - and hey if that&#8217;s really really (come on is it really?) important to you then just use primitives.</p>
<h3>Be Brave</h3>
<p>I wish people would be a bit braver and use the code to express what they are trying to do and not worry about whether the way they are doing it is against Common Practice.  Remember, the majority of software projects are still failures, so why follow Common Practice - it isn&#8217;t working!</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2008/04/04/ignoring-common-coding-practice-why-you-should-be-too/feed/</wfw:commentRss>
		</item>
		<item>
		<title>eXtreme JavaScript</title>
		<link>http://squadlimber.com/chris/2007/08/05/extreme-javascript/</link>
		<comments>http://squadlimber.com/chris/2007/08/05/extreme-javascript/#comments</comments>
		<pubDate>Sun, 05 Aug 2007 23:32:29 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>eXtreme Programming</category>

		<category>JavaScript</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/08/05/extreme-javascript/</guid>
		<description><![CDATA[Over the past few months I&#8217;ve been working a lot with JavaScript.  The language is very deceptive as it has C-style syntax, and is mostly written with little regard to good programming practice.  However, it turns out to be quite a good object-oriented language which can lend itself to some very elegant code. [...]]]></description>
			<content:encoded><![CDATA[<p>Over the past few months I&#8217;ve been working a lot with JavaScript.  The language is very deceptive as it has C-style syntax, and is mostly written with little regard to good programming practice.  However, it turns out to be quite a good object-oriented language which <em>can</em> lend itself to some very elegant code.  </p>
<p>The language itself has a fair few problems for your average <a href="http://www.extremeprogramming.org/rules.html">extreme programmer</a>.  For starters it&#8217;s a dynamic language so a lot of errors won&#8217;t turn up until you run it, and because of its tendency to not throw Exceptions (which do exist in JavaScript), things may just quietly go wrong.  Code conventions don&#8217;t seem to have been established yet and there are an awful lot of different ways to do the same thing in JavaScript, for example declaring a class can be done like this:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">function</span> Monkey<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// constructor</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">getBanana</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>;<br />
<br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">this</span>.<span style="color: #006600;">eatBanana</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>;<br />
<span style="color: #66cc66;">&#125;</span><br />
&nbsp;</div>
<p>&#8230;or it can be done like this:</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
<span style="color: #003366; font-weight: bold;">function</span> Monkey <span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// constructor</span><br />
<span style="color: #66cc66;">&#125;</span><br />
<br />
Monkey.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">getBanana</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
<span style="color: #66cc66;">&#125;</span>;<br />
<br />
Monkey.<span style="color: #006600;">prototype</span>.<span style="color: #006600;">eatBanana</span> = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp;</div>
<p>or this&#8230;</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
Monkey = <span style="color: #66cc66;">&#123;</span><span style="color: #66cc66;">&#125;</span>;<br />
<br />
Monkey.<span style="color: #006600;">prototype</span> = <span style="color: #66cc66;">&#123;</span><br />
<br />
&nbsp; &nbsp; getBanana : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span>,<br />
<br />
&nbsp; &nbsp; eatBanana : <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// ...</span><br />
&nbsp; &nbsp; <span style="color: #66cc66;">&#125;</span><br />
<br />
<span style="color: #66cc66;">&#125;</span>;<br />
&nbsp;</div>
<p> &#8230; or you could even do it like this (although you&#8217;d have to be mad):</p>
<div class="javascript" style="margin: 35px; border: 1px dashed #eee; font-family: Arial, Monaco, Verdana, monospace; padding: 1em; color: black; background: #fcfcfc; overflow: auto;"><br />
Monkey = <span style="color: #003366; font-weight: bold;">function</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #009900; font-style: italic;">// constructor</span><br />
<span style="color: #66cc66;">&#125;</span>;<br />
<br />
Monkey<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">'eatBanana'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;alert('eating banana')&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
<br />
Monkey<span style="color: #66cc66;">&#91;</span><span style="color: #3366CC;">'getBanana'</span><span style="color: #66cc66;">&#93;</span> = <span style="color: #003366; font-weight: bold;">new</span> <span style="color: #003366; font-weight: bold;">Function</span><span style="color: #66cc66;">&#40;</span><span style="color: #3366CC;">&quot;alert('getting banana')&quot;</span><span style="color: #66cc66;">&#41;</span>;<br />
&nbsp;</div>
<p>If you are doing extreme programming it can be much harder to come up with agreed standards just because there are so many different ways of doing things.  This also makes refactoring a much more subjective affair and can lead to churn if developers enter the vicious circle of refactoring other peoples code to their preferred style.  Also, its very easy to do (and it seems fun for some people) clever and complicated things in JavaScript which means simplicity of the codebase often suffers.  </p>
<h3>Shared Coding Standards</h3>
<p>This makes me think when dealing with JavaScript it is very important to have <em>shared</em> coding standards agreed by the whole team.  For the benefit of rooting some values of simplicity in the team its probably a good idea to agree a set of things that just shouldn&#8217;t be done (i&#8217;m thinking about the needlessly complicated things here).  Similarly, when CSS and DOM manipulation are involved - the team should agree standard ways of doing things.
</p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/08/05/extreme-javascript/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Feature Crawl</title>
		<link>http://squadlimber.com/chris/2007/05/12/feature-crawl/</link>
		<comments>http://squadlimber.com/chris/2007/05/12/feature-crawl/#comments</comments>
		<pubDate>Sat, 12 May 2007 19:45:38 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>eXtreme Programming</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/05/12/feature-crawl/</guid>
		<description><![CDATA[Have you ever experienced feature crawl?  That time on a project when features seem to take longer and longer to develop and less seems to get done than it used to.  There are several reasons why this can happen, but I want to talk about problems relating to the growth of the codebase [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever experienced feature crawl?  That time on a project when features seem to take longer and longer to develop and less seems to get done than it used to.  There are several reasons why this can happen, but I want to talk about problems relating to the growth of the codebase over time.</p>
<p>As the codebase grows over time it seems to take longer to add a feature.  Adding a new feature often involves working out what the existing code does, seeing what functionality already exists that you need to use and finding the places where this functionality is available.  The bottom-line is, the more existing code you need to understand and navigate through - the more time it takes.</p>
<p>So what can you do to help?  Write <strong><em>Screamingly Obvious Code</em></strong> - code that your grandma could understand, code that&#8217;s so easy to understand what and why it&#8217;s doing something that a monkey with learning difficulties could understand it.</p>
<blockquote><p><i>&#8220;Any fool can write code that a computer can understand. Good programmers write code that humans can understand.&#8221; &#8212; Martin Fowler</i></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/05/12/feature-crawl/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Pair Programming Patterns</title>
		<link>http://squadlimber.com/chris/2007/05/10/pair-programming-patterns/</link>
		<comments>http://squadlimber.com/chris/2007/05/10/pair-programming-patterns/#comments</comments>
		<pubDate>Thu, 10 May 2007 22:47:27 +0000</pubDate>
		<dc:creator>chris.probably</dc:creator>
		
		<category>Pair Programming</category>

		<category>eXtreme Programming</category>

		<guid isPermaLink="false">http://squadlimber.com/chris/2007/05/10/pair-programming-patterns/</guid>
		<description><![CDATA[I&#8217;m trying to introduce more Pair Programming at the moment - so I&#8217;ve been trying to make it a fun thing to do.  One of the ways I&#8217;ve been doing this is making use of the Ping Pong Pattern which has been working quite well.  However, there are situations when this pattern doesn&#8217;t [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m trying to introduce more <a href="http://www.extremeprogramming.org/rules/pair.html">Pair Programming</a> at the moment - so I&#8217;ve been trying to make it a fun thing to do.  One of the ways I&#8217;ve been doing this is making use of the <a href="http://www.magpiebrain.com/blog/2007/02/13/pairing-pattern-ping-pong-pairing/">Ping Pong Pattern</a> which has been working quite well.  However, there are situations when this pattern doesn&#8217;t fit such as when debugging, refactoring, looking for something in the code or when their are big tasks which are hard to divide up.  When not using the Ping Pong Pattern, I find its easy for one pair to dominate, get bored, <strike>silently think &#8216;OMG WTF is he doing?!!!&#8217;</strike>, or fall asleep.</p>
<p>So I&#8217;m going to just make some patterns up and list some ones I found which might be fun for those new to Pair Programming <strike>and stop me falling asleep</strike>:</p>
<p><b>One Line Each</b> - Each programmer takes it in turns to write one line of code.  This can be done in silence as a kind of game, or normally to continuously discuss each programmers intentions.</p>
<p><b>Two Keyboards and Two Mice</b> - Both programmers can interact at any time - the idea is to stop one programmer dominating / hogging (via <a href="http://stevef.truemesh.com/archives/000675.html">Steve Freeman</a>).</p>
<p><b>Chess Clocks</b> - <a href="http://www.magpiebrain.com/blog/2007/02/13/pairing-pattern-ping-pong-pairing/">Sam Newman</a> describes it much better than I could.</p>
<p><b>Pair Poker</b> - Each programmer gets a limited number of cards at the start of the day, they can choose to play a card at anytime and gain immediate control of the keyboard.</p>
<p><b>Different Roles</b> - Each programmer takes on a different role, possible combinations:</p>
<ul>
<li><b>Refactorer / Programmer</b> : One programmer cannot do anything but refactor, the other can do anything.</li>
<li><b>Tester / Implementer</b> : One programmer cannot do anything but write tests, the other cannot do anything but make tests change from red to green.</li>
<li><b>Navigator / Programmer</b> : One programmer can only move between classes, the other can do anything but move between classes.</li>
<li><b>Adder / Remover</b> : One programmer can only add code, the other can only remove code.</li>
</ul>
<p>Roles can be switched every hour or just when one get&#8217;s bored.</p>
<p>Thinking of a fun thing to do whilst debugging, looking through logs, or looking through code was a lot harder.</p>
<p><b>Backseat Driver</b> - To keep both programmers attention, one drives and cannot do anything without being directed by the other.</p>
<p><b>Driver Buckaroo</b> - The driving programmer has to give up the keyboard every time some event happens (e.g. build breaks, someone swears, you get an email, the project manager cracks the whip, someone checks in, someone stands up).</p>
<p><b><a href="http://portal.acm.org/citation.cfm?id=1121987.1122100&#038;coll=&#038;dl=acm&#038;CFID=15151515&#038;CFTOKEN=6184618">Promiscuous Pairing</a></b> - Basically pairs rotate more often. <em>(I&#8217;ve tried this with a rotation every 90 minutes &#8212; it was fun but tiring.)</em></p>
]]></content:encoded>
			<wfw:commentRss>http://squadlimber.com/chris/2007/05/10/pair-programming-patterns/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
