<?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>Steve Freeman &#187; Agile Programming</title>
	<atom:link href="http://www.higherorderlogic.com/category/things-to-do-with-work/agile-programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.higherorderlogic.com</link>
	<description>Working software daily</description>
	<lastBuildDate>Mon, 24 Oct 2011 20:24:40 +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>An example of an unhedged software call option</title>
		<link>http://www.higherorderlogic.com/2011/09/an-example-of-an-unhedged-software-call-option/</link>
		<comments>http://www.higherorderlogic.com/2011/09/an-example-of-an-unhedged-software-call-option/#comments</comments>
		<pubDate>Sat, 10 Sep 2011 22:36:57 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.higherorderlogic.com/?p=743</guid>
		<description><![CDATA[At a client, we&#8217;ve been reworking some particularly hairy calculation code. For better or worse, the convention is that we call a FooFetcher to get hold of a Foo when we need one. Here&#8217;s an example that returns Transfers, which are payments to and from an account. In this case, we&#8217;re mostly getting hold of [...]]]></description>
			<content:encoded><![CDATA[<p>At a client, we&#8217;ve been reworking some particularly hairy calculation code. For better or worse, the convention is that we call a <em>FooFetcher</em> to get hold of a <em>Foo</em> when we need one. Here&#8217;s an example that returns Transfers, which are payments to and from an account. In this case, we&#8217;re mostly getting hold of Transfers directly because can identify them<sup>1</sup>.</p>



<pre>public interface TransferFetcher {
  Transfer      fetchFor(TransferId id);
  Transfer      fetchOffsetFor(Transfer transfer);
  Set&lt;Transfer&gt; fetchOutstandingFor(Client client, CustomerReference reference);
  Transfer      fetchFor(CustomerReference reference);
}</pre>



<p>This looks like a reasonable design&mdash;all the methods are to do with retrieving Transfers&mdash;but it&#8217;s odd that only one of them returns a collection of Transfers. That&#8217;s a clue.</p>

<p>When we looked at the class, we discovered that the <code>fetchOutstandingFor()</code> method has a different implementation from the other methods and pulls in several dependencies that only it needs. In addition, unlike the other methods, it has only one caller (apart from its tests, of course). It doesn&#8217;t really fit in the Fetcher implementation which is now inconsistent.</p>

<p>It&#8217;s easy to imagine how this method got added. The programmers needed to get a feature written, and the code already had a dependency that was concerned with Transfers. It was quicker to add a method to the existing Fetcher, even if that meant making it much more complicated, than to introduce a new collaborator. They <a href="http://www.higherorderlogic.com/2010/07/bad-code-isnt-technical-debt-its-an-unhedged-call-option/" title="unhedged call option" target="_blank">sold a Call Option</a>&mdash;they cashed in the immediate benefit at the cost of weakening the model. The team would be ahead so long as no-one needed to change that code.</p>

<p>The option got called on us. As part of our reworking, we needed to change how Transfer objects were constructed so we could handle a new kind of transaction. The structure we planned meant changing another object, say <code>Accounts</code>, to depend on a <code>TransferFetcher</code>, but the current implementation of <code>TransferFetcher</code> depended on <code>Accounts</code> to implement <code>fetchOutstandingFor()</code>. We had a dependency loop. We should have taken a diversion and moved the behaviour of <code>fetchOutstandingFor()</code> into an appropriate object, but then we had our own delivery pressures. In the end, we found a workaround that allowed us to finish the task we were in the middle of, with a note to come back and fix the Fetcher.</p>

<p>The cost of recovery includes not just the effort of investigating and applying a solution (which would have been less when the code was introduced) but also the drag on motivation. It&#8217;s a huge <a href="http://en.wikipedia.org/wiki/Gumption_trap" title="from Zen and the Art of Motrocycle Maintenance" target="_blank">gumption trap</a> to be making steady progress towards a goal and then be knocked off course by an unnecessary design flaw. The research described in <a href="http://www.progressprinciple.com/">The Progress Principal</a> suggests that small blockers like this have a disproportionate impact compared to their size. Time to break for a cup of tea.</p>

<p>I believe that software quality is a cumulative property. It&#8217;s the accumulation of many small good or bad design decisions that either make a codebase productive to work with or just too expensive to maintain.</p> 

<p>&hellip;and, right on cue, Rangwald talks about <a href="http://raganwald.posterous.com/javas-comb-over" title="Tyranny of the urgent" target="_blank">The Tyranny of the Urgent</a>.</p>

<hr/><br />
<p style="font-size: 0.8em;">1) The details of the domain have been changed to protect the innocent, so please don&#8217;t worry too much about the detail.</p>
<p style="font-size: 0.8em;">Thanks to @aparker42 for his comments</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2011/09/an-example-of-an-unhedged-software-call-option/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Going to Goto (twice)</title>
		<link>http://www.higherorderlogic.com/2011/09/going-to-goto-twice/</link>
		<comments>http://www.higherorderlogic.com/2011/09/going-to-goto-twice/#comments</comments>
		<pubDate>Sun, 04 Sep 2011 20:49:00 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.higherorderlogic.com/?p=727</guid>
		<description><![CDATA[I&#8217;ll be at Goto Aarhus October 9-14 this year, giving a presentation and workshop on Nat Pryce and my material on using Test-Driven Development at multiple levels, guiding the design of system components as well as the objects within them. If you register with the code free1250, you&#8217;ll get a discount of 1250 DKK and [...]]]></description>
			<content:encoded><![CDATA[<p><img alt="GOTO Conferences" src="/images/goto_logo.png" class="alignright" width="93" height="90" />I&#8217;ll be at Goto <a href="http://gotocon.com/aarhus-2011/" title="Goto Aarhus">Aarhus</a> October 9-14 this year, giving a <a href="http://gotocon.com/aarhus-2011/presentation/Fractal%20TDD.%20Using%20tests%20to%20drive%20system%20design">presentation</a> and <a href="http://gotocon.com/aarhus-2011/presentation/Hands-On%20:%20TDD%20at%20the%20System%20Scale" target="_blank">workshop</a> on <a href="http://www.natpryce.com/" target="_blank">Nat Pryce</a> and my material on using Test-Driven Development at multiple levels, guiding the design of system components as well as the objects within them. </p>

<p>If you register with the code <em>free1250</em>, you&#8217;ll get a discount of 1250 <span class="caps">DKK </span>and Goto will donate the same amount to <a href="http://www.computersforcharities.co.uk/" target="_blank">Computers for Charities</a></p>

<p>Some of us are then rushing to Goto <a href="http://gotocon.com/amsterdam-2011/">Amsterdam</a>, where I&#8217;ll be giving the talk again on Friday. Again the code <em>free1250</em> will do something wonderful, but I&#8217;m not quite sure what.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2011/09/going-to-goto-twice/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Bad code isn&#8217;t Technical Debt, it&#8217;s an unhedged Call Option</title>
		<link>http://www.higherorderlogic.com/2010/07/bad-code-isnt-technical-debt-its-an-unhedged-call-option/</link>
		<comments>http://www.higherorderlogic.com/2010/07/bad-code-isnt-technical-debt-its-an-unhedged-call-option/#comments</comments>
		<pubDate>Fri, 23 Jul 2010 14:15:15 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/?p=503</guid>
		<description><![CDATA[I&#8217;d been meaning to write this up for a while, and now Nat Pryce has written up the 140 character version. This is all Chris Matts&#8216; idea. He realised that the problem with the &#8220;Technical Debt&#8221; metaphor is that for managers debt can be a good thing. Executives can be required to take on more [...]]]></description>
			<content:encoded><![CDATA[<p style="font-size: 0.8em">I&#8217;d been meaning to write this up for a while, and now Nat Pryce has written up the <a href="http://twitter.com/natpryce/status/19286162811">140 character version</a>.</p>

<p><img style="float:right" src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Short_call_option.svg/200px-Short_call_option.svg.png" alt="Payoff from writing a call." /></p>

<p>This is all <a href="http://abc.truemesh.com/">Chris Matts</a>&#8216; idea. He realised that the problem with the &#8220;Technical Debt&#8221; metaphor is that for managers debt can be a good thing. Executives can be required to take on more debt because it makes the finances work better, it might even be encouraged by tax breaks. This is not the same debt as your personal credit card. Chris came up with a better metaphor, the <em>Call Option</em>.</p>

<p>I &#8220;write&#8221; a <a href="http://en.wikipedia.org/wiki/Call_option">Call Option</a> when I sell someone the right, but not the obligation, to buy in the future an agreed quantity of something at an price that is fixed now. So, for a payment now, I agree to sell you 10,000 chocolate santas<sup class="footnote"><a href="#fn1">1</a></sup> at 56 pence each, at any time up to 10th December. You&#8217;re prepared to pay the premium because you want to know that you&#8217;ll have santas in your stores at a price you can sell.</p>

<p>From my side, if the price of the santas stays low, I get to keep your payment and I&#8217;m ahead. But, I also run the risk of having to provide these santas when the price has rocketed to 72 pence. I can protect myself by making arrangements with another party to acquire them at 56 pence or less, or by actually having them in stock. <em>Or</em>, I can take a chance and just collect the premium. This is called an unhedged, or <a href="http://en.wikipedia.org/wiki/Naked_call">&#8220;Naked&#8221;</a>, Call. In the financial world this is risky because it has unlimited downside, I have to supply the santas <em>whatever</em> they cost me to provide.</p>

<p>Call options are a better model than debt for cruddy code (without tests) because they capture the unpredictability of what we do. If I slap in an a feature without cleaning up then I get the benefit immediately, I collect the premium. If I never see that code again, then I&#8217;m ahead and, in retrospect, it would have been foolish to have spent time cleaning it up.</p>

<p>On the other hand, if a radical new feature comes in that I have to do, all those quick fixes suddenly become very expensive to work with. Examples I&#8217;ve seen are a big new client that requires a port to a different platform, or a new regulatory requirement that needs a new report. I get equivalent problems if there&#8217;s a failure I have to interpret and fix just before a deadline, or the team members turn over completely and no-one remembers the tacit knowledge that helps the code make sense. The market has moved away from where I thought it was going to be and my option has been called.</p>

<p>Even if it is more expensive to do things cleanly (and I&#8217;m not convinced of that beyond a two-week horizon), it&#8217;s also less risky. A messy system is full of unhedged calls, each of which can cost an unpredictable amount should they ever be exercised. We&#8217;ve all seen what this can do in the financial markets, and the scary thing is that failure, if it comes, can be sudden&mdash;everything is fine until it isn&#8217;t. I&#8217;ve seen a few systems which are just too hard to change to keep up with the competition and the owners are in real trouble.</p>

<p>So that makes refactoring like buying an option too. I pay a premium now so that I have more choices about where I might take the code later. This is a mundane and obvious activity in many aspects of business&mdash;although not, it seems, software development. I don&#8217;t need to spend this money if I know exactly what will happen, if I have perfect knowledge of the relevant parts of the future, but I don&#8217;t recall when I last saw this happen.</p>

<p>So, the next time you have to deal with implausible delivery dates, don&#8217;t talk about Technical Debt. Debt is predictable and can be managed, it&#8217;s just another tool. Try talking about an Unhedged Call. Now all we need is a way to price Code Smells.</p>

<hr/><br />
<p>1) There is an apocryphal story about a trader buying chocolate santa futures and forgetting to sell them on. Eventually a truckload turned up at the Wall Street headquarters.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2010/07/bad-code-isnt-technical-debt-its-an-unhedged-call-option/feed/</wfw:commentRss>
		<slash:comments>60</slash:comments>
		</item>
		<item>
		<title>Machiavelli on code quality</title>
		<link>http://www.higherorderlogic.com/2010/04/machiavelli-on-code-quality/</link>
		<comments>http://www.higherorderlogic.com/2010/04/machiavelli-on-code-quality/#comments</comments>
		<pubDate>Sun, 25 Apr 2010 08:04:22 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/?p=488</guid>
		<description><![CDATA[As the doctors say of a wasting disease, to start with, it is easy to cure but difficult to diagnose. After a time, unless it has been diagnosed and treated at the outset, it becomes easy to diagnose but difficult to cure. &#8212;&#160;Nicolo Machiavelli, The Prince via Dee Hock, Birth of the Chaordic Age]]></description>
			<content:encoded><![CDATA[<blockquote>As the doctors say of a wasting disease, to start with, it is easy to cure but difficult to diagnose. After a time, unless it has been diagnosed and treated at the outset, it becomes easy to diagnose but difficult to cure.</blockquote>
<p style="text-align:right;">&mdash;&nbsp;Nicolo Machiavelli, <em>The Prince</em></p>
<em>via</em> Dee Hock, <i>Birth of the Chaordic Age</i>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2010/04/machiavelli-on-code-quality/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Responding to Brian Marick</title>
		<link>http://www.higherorderlogic.com/2010/01/responding-to-brian-marick/</link>
		<comments>http://www.higherorderlogic.com/2010/01/responding-to-brian-marick/#comments</comments>
		<pubDate>Sun, 17 Jan 2010 22:10:39 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Book]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/?p=385</guid>
		<description><![CDATA[Brian&#8217;s been paying us the compliment of taking our book seriously and working through our extended example, translating it to Ruby. He has a point of contention in that he&#8217;s doubtful about the value of our end-to-end tests. To be more precise, he&#8217;s doubtful about the value of our automated end-to-end tests, a view shared [...]]]></description>
			<content:encoded><![CDATA[<p>Brian&#8217;s been paying us the compliment of taking <a href="http://www.growing-object-oriented-software.com/">our book</a> seriously and working through our extended example, translating it to Ruby. </p>

<p>He has a <a href="http://www.exampler.com/blog/2010/01/08/some-preliminary-thoughts-on-end-to-end-testing-in-growing-object-oriented-software/">point of contention</a> in that he&#8217;s doubtful about the value of our end-to-end tests. To be more precise, he&#8217;s doubtful about the value of our <em>automated</em> end-to-end tests, a view shared by <a href="http://www.jbrains.ca/integration_tests_are_a_scam"><span class="caps">J.B.R</span>ainsberger</a>, and <a href="http://agile2009.agilealliance.org/node/1010">Arlo Belshee and Jim Shore</a>. That&#8217;s a pretty serious group. I think the answer, as always, is &ldquo;it depends&rdquo;. </p>

<p>There are real advantages to writing automated end-to-end tests. As Nat pointed out in <a href="http://groups.google.com/group/growing-object-oriented-software/browse_thread/thread/5525c6acdd143be6">an extended message</a> to the mailing list for the book, </p>

<blockquote>Most significantly to me, however, is the difference between &#8220;testing&#8221; end-to-end or through the <span class="caps">GUI </span>and &#8220;test-driving&#8221;. A lot of people who are evangelical about <span class="caps">TDD </span>for coding do not use end-to-end tests for driving design at the system scale. I have found that writing tests gives useful design feedback, no matter what the scale.</blockquote>

<p>For example, during Arlo and Jim&#8217;s session, I was struck by how many of the &ldquo;failure stories&rdquo; described situations where the acceptance tests were actually doing their job: revealing problems (such as deployment difficulties) that needed to be fixed.</p>

<p>Automating an end-to-end test helps me think more carefully about what <em>exactly</em> I care about in the next feature.  Automating tests for many features encourages me to work out a language to describe them, which clarifies how I describe the system and makes new features easier to test.</p>

<p>And then there&#8217;s scale. Pretty much anything will work for a small system (although Alan Shalloway <a href="http://www.netobjectives.com/blogs/smart-people-xp-scrum-is-there-a-pattern">has a story</a> about how even a quick demonstrator project can get out of hand). For larger systems, things get complicated, people come and go, and the team isn&#8217;t quite as confident as it needs to be about where things are connected. Perhaps these are symptoms of weaknesses in the team culture, but it seems wasteful to me to take the design experience we gained while writing the features not encode it somewhere.</p>

<p>Of course this comes at a price. Effective end-to-end tests take skill, experience, and (most important) commitment. Not every system I&#8217;ve seen has been programmed by people who are as rigorous as Nat about making the test code expressive or allowing testing to drive the design. Worse, a large collection of badly written end-to-end tests (a pattern I&#8217;ve seen a few times) is a huge drag on development. Is that price worth paying? It (ahem) depends, and part of the skill is in finding the right places to test.</p>

<p>So, let me turn Brian&#8217;s final question around. What would it take to make automated end-to-end tests less scary?</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2010/01/responding-to-brian-marick/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Do do XP</title>
		<link>http://www.higherorderlogic.com/2009/10/do-do-xp/</link>
		<comments>http://www.higherorderlogic.com/2009/10/do-do-xp/#comments</comments>
		<pubDate>Tue, 13 Oct 2009 10:58:07 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/?p=290</guid>
		<description><![CDATA[In this post, Tobias Mayer argues against doing Extreme Programming (XP). I have a lot of time for Tobias, but I think he&#8217;s wrong on this one. I don&#8217;t know who he&#8217;s been talking to, but some of this is &#8220;strawman&#8221; argument, and I&#8217;d be more likely to be convinced if Tobias had tried XP [...]]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://agileanarchy.wordpress.com/2009/10/12/dont-do-xp/">this post</a>, Tobias Mayer argues against doing Extreme Programming (XP). I have a lot of time for Tobias, but I think he&#8217;s wrong on this one. I don&#8217;t know who he&#8217;s been talking to, but some of this is &#8220;strawman&#8221; argument, and I&#8217;d be more likely to be convinced if Tobias had tried XP just the once. XP is not a universal solution, but it is one  possible choice and we know how to make it work.</p>

<p>As an occasional XP advocate, I don&#8217;t &#8220;blame Scrum for the lack of good development practices in the software industry&#8221;, I blame the software industry. If we worked in an effective industry, we wouldn&#8217;t be having methodology wars because things would just work. Now this same industry is messing up Scrum too by just taking on its ceremonial aspects.  On the other hand, to blame XP for blocking good practice is just bizarre. </p>

<p>XP is a tiny movement that attracted some attention. What XP (version 1) <em>did</em> achieve was to show that it is possible to break through the logjam of cautious procrastination that still cripples many development teams, but without resorting to hackery. It gave teams a reliable package of practices that just worked. <em>Of course</em> XP didn&#8217;t take over the world because it&#8217;s not suitable for everyone&#8211;not least because it requires a degree of focus and skill that is not appropriate for many teams. Kent Beck&#8217;s presentation of XP version 1 was extreme on purpose: it was designed to inspire us huddled masses, and to stretch the boundaries of what was considered possible in software development, to reframe the discussion.</p>

<p>I think Tobias has forgotten just how far we&#8217;ve come in the last decade. That we have a craft movement at all is because XP put the actual writing of code back into the centre of the discussion&#8211;just look at who&#8217;s involved, it&#8217;s the same people. He also forgets just how counter-intuitive many of the XP practices are, especially compared to the direction the industry was moving at the time.</p>

<p>Tobias writes that the good development practices were spreading slowly at the time, but I&#8217;d argue that without XP we&#8217;d still be waiting. Test-Driven Development is still not that widely accepted and even the original C3 team didn&#8217;t adopt it fully until Kent was writing his book. Refactoring had a small academic following, but it&#8217;s not very safe without the compensating practice of <span class="caps">TDD.</span> I suspect most teams still ban changing code unless it&#8217;s to change a feature. Pair programming is still a very hard sell and, again, works much better in the context of <span class="caps">TDD.</span> I&#8217;ve seen enough Scrum teams that have <em>not</em> found a coherent set of technical practices. To say that they just need to improve their Scrum implementation begs the question of how Scrum is adopted and the limits of self-organisation.</p>

<p>Some final nit-picks. There are two editions of the XP book, the second is more recent than 12 years and has a &#8220;softer&#8221; approach to the methodology. As for the relevancy of the practices, the C3 project worked in an environment (Smalltalk/Gemstone) that still outclasses what most of us use today. Much of the work in the XP community has been to try to recreate that flexibility in inadequate current technical environments. What&#8217;s <em>really</em> scary is how slowly this industry moves.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/10/do-do-xp/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Keep tests concrete</title>
		<link>http://www.higherorderlogic.com/2009/09/keep-tests-concrete/</link>
		<comments>http://www.higherorderlogic.com/2009/09/keep-tests-concrete/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 12:01:07 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/?p=244</guid>
		<description><![CDATA[This popped up on a technical discussion site recently. The original question was how to write tests for code that invokes a method on particular values in a list. The problem was that the tests were messy, and the author was looking for a cleaner alternative. Here&#8217;s the example test, it asserts that the even-positioned [...]]]></description>
			<content:encoded><![CDATA[<p>This popped up on a technical discussion site recently. The original question was how to write tests for code that invokes a method on particular values in a list. The problem was that the tests were messy, and the author was looking for a cleaner alternative. Here&#8217;s the example test, it asserts that the even-positioned elements in the parameters are passed to <code>bar</code> in the appropriate sequence.</p>


<pre>public void testExecuteEven() {
  Mockery mockery = new Mockery();

  final Bar bar = mockery.mock(Bar.class);
  final Sequence sequence = new NamedSequence(&quot;sequence&quot;);

  final List&lt;String&gt; allParameters = new ArrayList&lt;String&gt;();
  final List&lt;String&gt; expectedParameters = new ArrayList&lt;String&gt;();

  for (int i = 0; i &lt; 3; i++) {
    allParameters.add(&quot;param&quot; + i);
    if (i % 2 == 0) {
      expectedParameters.add(&quot;param&quot; + i);
    }
  }
  final Iterator&lt;String&gt; iter = expectedParameters.iterator();

  mockery.checking(new Expectations() {
   {
     while (iter.hasNext()) {
       one(bar).doIt(iter.next());
        inSequence(sequence);
      }
    }
  });

  Foo subject = new Foo();
  subject.setBar(bar);
  subject.executeEven(allParameters);
  mockery.assertIsSatisfied();
}</pre>


<p>The intentions of the test are good, but its most striking feature is that there&#8217;s so much computation going on. This doesn&#8217;t need a new technique to make it more readable, it just needs to be simplified.</p>
<p>A unit test should be small and focussed enough that we don&#8217;t need any general behaviour. It just has to deal with one example, so we can make it as concrete as we like. With that in mind, we can collapse the test to this:</p>


<pre>public void testCallsDoItOnEvenIndexedElementsInList() {
  final Mockery mockery = new Mockery();
  final Bar bar = mockery.mock(Bar.class);
  final Sequence evens = mockery.sequence(&quot;evens&quot;);

  final  List&lt;String&gt; params = 
    Arrays.asList(&quot;param0&quot;, &quot;param1&quot;, &quot;param2&quot;, &quot;param3&quot;);

  mockery.checking(new Expectations() {{
    oneOf(bar).doIt(params.get(0)); inSequence(evens);
    oneOf(bar).doIt(params.get(2)); inSequence(evens);
  }});

  Foo subject = new Foo();
  subject.setBar(bar);
  subject.executeEven(params);
  mockery.assertIsSatisfied();
}</pre>


<p>To me, this is more direct, a simpler statement of the example&mdash;if nothing else, there&#8217;s just less code to understand. I don&#8217;t need any loops because there aren&#8217;t enough values to justify them. The expectations are clearer because they show the indices of the elements I want from the list (an alternative would have been to put in the expected values directly). And if I pulled the common features, such as the mockery and the target object, into the test class, the test would be even shorter.</p>
<p>The short version of this post is: be wary of any general behaviour written into a unit test. The scope should be small enough that values can be coded directly. Be especially wary of anything with an <code>if</code> statement. If the data setup is more complicated, then consider using a <a href="http://nat.truemesh.com/archives/000714.html">Test Data Builder</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/09/keep-tests-concrete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mock Roles not Objects, live and in person.</title>
		<link>http://www.higherorderlogic.com/2009/03/mock-roles-not-objects-live-and-in-person/</link>
		<comments>http://www.higherorderlogic.com/2009/03/mock-roles-not-objects-live-and-in-person/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 22:07:51 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Coding]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2009/03/08/mock-roles-not-objects-live-and-in-person/</guid>
		<description><![CDATA[At the recent Software Craftsmanship conference in London, Willem and Marc ran a session on Responsibility-Driven Development with Mocks for about 30 people. Nat Pryce and I were sitting at the back watching and occasionally heckling. The first striking thing was that when Willem and Marc asked who was using &#8220;Mock Objects&#8221; most everyone put [...]]]></description>
			<content:encoded><![CDATA[<p>At the recent Software Craftsmanship conference in London, Willem and Marc ran <a href="http://parlezuml.com/softwarecraftsmanship/sessions/responsibility_driven_design_with_mock_objects.htm">a session on Responsibility-Driven Development with Mocks</a> for about 30 people. <a href="http://www.natpryce.com/">Nat Pryce</a> and I were sitting at the back watching and occasionally heckling. </p>

<p>The first striking thing was that when Willem and Marc asked who was using &#8220;Mock Objects&#8221; most everyone put their hand up (which was nice), but then only a handful also said they were thinking about Roles and Responsibilities when they did (which was frustrating). We first wrote up these ideas in our paper <a href="http://www.mockobjects.com/files/mockrolesnotobjects.pdf">&#8220;Mock Roles Not Objects&#8221;</a> and much of the difficulty we see people have with the technique of Mock Objects comes from focussing on classes rather than relationships.</p> 

<p>As it happens, an example popped up in the rest of the session, which was run as a Coding Dojo. What was interesting to me was how the group managed to turn around its design ideas. Here&#8217;s what I can remember about how it worked out.</p>

<p>The domain was some kind of game, with a hero who moves around an environment slaying dragons and so forth. The first couple of stories were to do with displaying the current room, and then moving from one room to another. It was a little difficult getting started because the limitations of the event didn&#8217;t allow enough time to really drive the design from outer-level requirements, but the group managed to get started with something like:</p>



<pre>describe Hero do
  it &quot;should describe its surroundings&quot; do
    hero = Hero.new(room)  
    
    room.stub!(:description).and_return(&quot;a room with twisty passages&quot;)
    
    console.should_receive(:show).with(&quot;in a room with twisty passages&quot;)
    hero.look(console)
  end
end</pre>

<p>  </p>

<p>The expectation here says that when looking, the hero should write a text describing the room to the console. This was a place to start, but it doesn&#8217;t look right. Why is a hero attached to a room? And <code>hero.look(console)</code> just doesn&#8217;t read well, it&#8217;s hard to tell what it means. The tensions became clearer with the next feature, which was to have the hero move from one room to another. If we write</p>



<pre>hero.move_to(other_room)</pre>


  <br />
<p>how can we tell that this has worked? We could ask the hero to <code>look()</code> again, but that means making an extra call for testing, which is not related to the intent of the test. We could ask the hero what his current room is, but that&#8217;s starting to leak into Asking rather than Telling. There may be a need for the hero to hold on to his current location, but we haven&#8217;t seen it yet.</p>

<p>Suddenly, it became clear that the dependencies were wrong. We already have a feature that can be told about the hero&#8217;s situation, which we can build on. If the feature were to be told about what is happening to the hero, we could use <em>that</em> to detect the change in room. So, our example now becomes:</p>



<pre>describe Hero do
  it &quot;should move to a room&quot; do
    hero = Hero.new(console)  
    
    room.stub!(:description).and_return(&quot;a room with twisty passages&quot;)
    
    console.should_receive(:show).with(&quot;in a room with twisty passages&quot;)
    
    hero.move_to(room)
  end
end</pre>



<p>That&#8217;s better, but it&#8217;s not finished. The term Console sounds like an implementation, not a role. Most of the sword-wielding adventurers that I know don&#8217;t know how to work a Console, but they&#8217;re quite happy to tell of their great deeds to, say, a Narrator (as <a href="http://blog.davidpeterson.co.uk/">David Peterson</a> suggested). If we adjust our example we get.</p>



<pre>describe Hero do
  it &quot;should move to a room&quot; do
    hero = Hero.new(narrator)  
    
    room.stub!(:description).and_return(&quot;a room with twisty passages&quot;)
    
    narrator.should_receive(:says).with(&quot;in a room with twisty passages&quot;)
    
    hero.move_to(room)
  end
end</pre>



<p>The whole example now reads as if it&#8217;s in the same domain, in the language of a <span class="caps">D&amp;D </span>game. It doesn&#8217;t refer to implementation details such as a Console&mdash;we might see that code when we get to the detailed implementation of a Narrator. Obviously, there&#8217;s a lot more we could do, for a start I&#8217;d like to see more structured messages between Hero and Narrator, but the session ran out of time at about this point.</p>

<p>Some lessons:</p>
<ol>
<li>Naming, naming, naming. It&#8217;s the most important thing. A coherent unit of code should have a coherent vocabulary, it should <em>read well</em>. If not, I&#8217;m probably mixing concepts which will make the code harder to understand and more brittle to change than it needs to be.</li>
<li>When I&#8217;m about to write a test, I ask &#8220;if this were to work, who would know&#8221;. That&#8217;s the most revealing question in B/TDD. If there&#8217;s no visible effect from an event, except perhaps for changing a field in the target object, then maybe it&#8217;s worth waiting until there is a visible effect, or maybe there&#8217;s a concept missing, or maybe the structure isn&#8217;t quite right. Before writing more code, I try to make sure I understand its motivation.</li>
</ol>

<p>Willem&#8217;s (and many other people&#8217;s) approach is slightly different. He likes to explore a bit further with the code before really sorting out the names, and he&#8217;s right that there&#8217;s a risk of Analysis-Paralysis. I do that occasionally, but my experience is that the effort of being really picky at this stage forces me to be clearer about what I&#8217;m trying to achieve, to ask those questions I really ought to have answers to, before I get in too deep.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/03/mock-roles-not-objects-live-and-in-person/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>&#8220;He doesn&#8217;t mean that about Scrum&#8221;</title>
		<link>http://www.higherorderlogic.com/2009/02/he-doesnt-mean-that-about-scrum/</link>
		<comments>http://www.higherorderlogic.com/2009/02/he-doesnt-mean-that-about-scrum/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 10:38:41 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2009/02/22/he-doesnt-mean-that-about-scrum/</guid>
		<description><![CDATA[In very bad taste, but very funny: &#8220;Hitler&#8217;s Nightly build fails&#8221;. and we should remember that Stalin won&#8230;]]></description>
			<content:encoded><![CDATA[<p>In very bad taste, but very funny: <a href="http://www.youtube.com/watch?v=Azl4nqLn4-Y">&#8220;Hitler&#8217;s Nightly build fails&#8221;</a>. </p>

<p style="font-size: 0.8em">and we should remember that Stalin won&#8230;</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/02/he-doesnt-mean-that-about-scrum/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Experienced Agilista&#8217;s proved wrong (again)</title>
		<link>http://www.higherorderlogic.com/2009/02/experienced-agilistas-proved-wrong-again/</link>
		<comments>http://www.higherorderlogic.com/2009/02/experienced-agilistas-proved-wrong-again/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 18:46:29 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Organisations]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2009/02/17/experienced-agilistas-proved-wrong-again/</guid>
		<description><![CDATA[So, Jurgen Appelo is unhappy that some of the more experienced Agile names have been telling him what to do. In particular, apparently they&#8217;ve been doing so without understanding complexity theory; he&#8217;s not reacting well. In between the ranting, much of what Jurgen says is obviously true. For disorganised teams, adopting Scrum and nothing else [...]]]></description>
			<content:encoded><![CDATA[<p>So, <a href="http://www.noop.nl/2009/02/the-decline-and-fall-of-agilists.html">Jurgen Appelo is unhappy</a> that some of the more experienced Agile names have been telling him what to do. In particular, apparently they&#8217;ve been doing so without understanding complexity theory; he&#8217;s not reacting well.</p>

<p>In between the ranting, much of what Jurgen says is obviously true. For disorganised teams, adopting Scrum and nothing else will help them get more organised and productive, as seems to be his case. But he then goes on to say that anyone who tries to clip his wings and tell him how to develop software cannot be agile because they&#8217;re not adaptive enough&mdash;and by the way, he knows lots of stuff about complex adaptive systems that other people don&#8217;t.</p>

<p>My first reaction is to suggest that he not underestimate some of the people he&#8217;s reacting to. Ron Jeffries can certainly be provocative, but I don&#8217;t think he does it to try to convince people he&#8217;s smart. And <a href="http://www.infoq.com/news/2008/04/joseph-pelrine-complexity">some of us</a> have been investigating complex adaptive systems for years.</p>

<p>What I think Jurgen is missing (or at least not making explicit) is that there isn&#8217;t a single axis between chaos and ordered, some aspects of an organisation <em>do</em> need to be ordered (in the end, we&#8217;re dealing with physical machines here) and some things complex (the people bits, usually). I may use complex adaptive techniques to understand what to build and how to communicate that, but I also want the thing to work reliably and not to be dragged down by a fear of making changes.</p>

<p>Sure, people in the community say dumb things, but we have actually learned <em>some</em> things over the last ten years. One is that we see team after team that has hit the wall because they didn&#8217;t work cleanly. Some have the luxury of a financial buffer which allows them to continue working sub-optimally. Just a few teams have understood the real trade-offs and can undercut the opposition by delivering faster and more reliably&mdash;and no-one promised that it would be easy or quick to achieve.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/02/experienced-agilistas-proved-wrong-again/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lean and Agile: should cousins marry?</title>
		<link>http://www.higherorderlogic.com/2009/02/lean-and-agile-should-cousins-marry/</link>
		<comments>http://www.higherorderlogic.com/2009/02/lean-and-agile-should-cousins-marry/#comments</comments>
		<pubDate>Sat, 14 Feb 2009 19:41:35 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2009/02/14/lean-and-agile-should-cousins-marry/</guid>
		<description><![CDATA[Dave West has written a cautionary posting (Lean and Agile: Marriage Made in Heaven or Oxymoron?) on the dangers of taking a simplistic view of Lean and Agile. He&#8217;s right that a naive reading of a Lean approach to software will just trap us in another metaphor, manufacturing, that&#8217;s as inappropriate (or appropriate) as we [...]]]></description>
			<content:encoded><![CDATA[<p>Dave West has written a cautionary posting <a href="http://www.infoq.com/articles/backlog-not-waste">(Lean and Agile: Marriage Made in Heaven or Oxymoron?)</a> on the dangers of taking a simplistic view of Lean and Agile. He&#8217;s right that a naive reading of a Lean approach to software will just trap us in another metaphor, manufacturing, that&#8217;s as inappropriate (or appropriate) as we once thought building construction was. And yes, there will be teams that adopt the techniques without understanding the meaning behind them, just as we&#8217;ve seen with all the Agile methodologies. I particularly like his reminder to show the bigger picture by making visible the current product backlog, with all its inconsistencies and misunderstandings.</p>

<p>I think there <em>is</em> a place for the production features of Lean in software practice, such as the idea that when I get something working, it really works and it stays working. I think there&#8217;s value within development on staying focussed on the task at hand and getting in &#8220;Done, done&#8221;. For some teams, just getting their system to a state where they can safely make and deploy changes is a huge advance. As Martin Fowler <a href="http://martinfowler.com/bliki/FlaccidScrum.html">points out</a>, there are quite a few &#8220;Agile&#8221; teams that can&#8217;t achieve that. Working in a reliable code base where all the mechanical stuff just works is so much more productive than the alternative, which counts, I think, as removing waste. 
</p>

<p>David Anderson claims that nowadays the most significant waste is usually <a href="http://www.agilemanagement.net/Articles/Weblog/Whywelostfocusondevelopme.html">around development</a> rather than within it. It&#8217;s in the weakness of the organisation&#8217;s communication and prioritisation,  the stuff that Dave has pointed out we need to support; teams waste effort when they don&#8217;t communicate and understand.</p>

<p>Once I started exploring deeper into the Lean material, I discovered the Toyota Product Development System which some think is even more important than their Production system. From a Production point of view, it looks very wasteful because they work on multiple possible solutions but choose only one, which allows them always to deliver on time. From a Product point of view it&#8217;s worth the cost because slipping the date is too expensive, and it&#8217;s not totally waste because they record what they&#8217;ve learned from the failures and use it the next generation of products. I think this is where much of the activity that Dave wants to remind us about belongs, and many software teams just don&#8217;t spend enough on exploring the range of features and technical issues available to them.</p>

<p>To mangle Dave&#8217;s metaphor, I don&#8217;t think we should expect wedding bells because the couple is already too closely related. There will be mistakes of interpretation in the field, such as dismissing retrospectives as waste, but, properly understood, the underlying values share too much <span class="caps">DNA.</span></p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2009/02/lean-and-agile-should-cousins-marry/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>&#8220;Hammers considered harmful&#8221;</title>
		<link>http://www.higherorderlogic.com/2008/08/hammers-considered-harmful/</link>
		<comments>http://www.higherorderlogic.com/2008/08/hammers-considered-harmful/#comments</comments>
		<pubDate>Mon, 18 Aug 2008 18:37:12 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2008/08/18/hammers-considered-harmful/</guid>
		<description><![CDATA[Here&#8217;s another post on the lines of: &#8220;Hammers considered harmful. Every time I use one, it strips the threads from my screws.&#8221; One of the clues is in the list of symptoms at the end of the first paragraph: &#8220;mammoth test set-ups&#8221;. The tests were complaining but not being heard. In truth, we&#8217;ve done a [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://merecomplexities.com/2008/08/mocks-considered-harmful-some-time-ago.html">Here&#8217;s</a> another post on the lines of: <em>&ldquo;Hammers considered harmful. Every time I use one, it strips the threads from my screws.&rdquo;</em> One of the clues is in the list of symptoms at the end of  the first paragraph: &ldquo;mammoth test set-ups&rdquo;. The tests were complaining but not being heard. </p>

<p>In truth, we&#8217;ve done a dreadful job of explaining where interaction-based techniques are relevant and where they aren&#8217;t. I keep bumping into codebases that are supposed to be written that way but where the unit tests have baroque, inflexible setups because the team weren&#8217;t <a href="http://www.mockobjects.com/2007/03/synaesthesia-listening-to-test-smells.html">listening to the tests</a>. I even saw <a href="http://radio.javaranch.com/lasse/">Lasse Koskela</a>, who knows what he&#8217;s doing, during a programming demo at the recent <a href="http://www.agile2008.org/stage-developers.html">Agile Conference</a>, slip into writing expectations for a simple clock object that should have just returned a series of values; <a href="http://www.jbrains.ca/"><span class="caps">J.B.</span> Rainsberger</a>, being more forthright than me, called him on it.</p>

<p><a href="http://www.cocking.co.uk/blog/">Romilly</a>, one of my <strike>partners in crime</strike> collaborators, once said he was surprised when he started working with <a href="http://nat.truemesh.com/">Nat</a> and me, how simple our unit tests are and how few expectations we set. That degree of focus is one of the points we try to get across whenever we talk about our approach. I find that the best use of interaction-based testing is to nudge me into thinking about objects and their relationships, not as a single solution for all my <span class="caps">TDD </span>needs.</p>

<p>In the meantime, we&#8217;re working on <a href="http://www.mockobjects.com/2008/07/growing-object-oriented-software-guided.html">making our ideas more accessible</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2008/08/hammers-considered-harmful/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Test-Driven Development. A Cognitive Justification?</title>
		<link>http://www.higherorderlogic.com/2008/06/test-driven-development-a-cognitive-justification/</link>
		<comments>http://www.higherorderlogic.com/2008/06/test-driven-development-a-cognitive-justification/#comments</comments>
		<pubDate>Sun, 15 Jun 2008 09:54:18 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2008/06/15/test-driven-development-a-cognitive-justification/</guid>
		<description><![CDATA[It&#8217;s been a busy week. Michael Feathers has an interesting post on the nature of Test-Driven Development, to which Keith has responded. I think Michael overstated my position on &#8220;most&#8221; people (it was probably a bar discussion) but over the years I&#8217;ve seen a lot of TDD code that doesn&#8217;t look right. Incidentally, Tim Mackinnon, [...]]]></description>
			<content:encoded><![CDATA[<div style="margin-left: 2em"><p>It&#8217;s been a busy week. Michael Feathers has an interesting post on the <a href="http://michaelfeathers.typepad.com/michael_feathers_blog/2008/06/the-flawed-theo.html">nature of Test-Driven Development</a>, to which Keith has <a href="http://peripateticaxiom.blogspot.com/2008/06/tdd-mocks-and-design.html">responded</a>. I think Michael overstated my position on &ldquo;most&rdquo; people (it was probably a bar discussion) but over the years I&#8217;ve seen a lot of <span class="caps">TDD </span>code that doesn&#8217;t look right. Incidentally, Tim Mackinnon, who was there, tells the origin of Mocks story at the bottom of <a href="http://www.macta.f2s.com/Thoughts/smock.html">this page</a>.</p>

<p>With that out of the way, I&#8217;d like to get to the real point of this posting</p>
</div>

<h4>A Cognitive Justification for Test-Driven Development</h4>

<p>Two influences coincided for me at <a href="http://www.xp2008.org"><span class="caps">XP2008</span></a> this week: <a href="http://www.cognitive-edge.com/blogs/dave/2008/06/computer_science.php">Dave Snowden</a> talking about social complexity, including current understanding of the how the mind works, and <a href="http://blogs.agilefaqs.com/">Naresh Jain</a> pairing to understand different people&#8217;s approaches to Test-Driven Development.</p>

<p>Dave has spent a lot of time exploring how decision-making happens. In particular, it turns out that people don&#8217;t actually spend their time carefully working out the trade-offs and then picking the best option. Instead, we employ a &ldquo;first-fit&rdquo; approach: work through an ordered list of learned responses and pick the first one that looks good enough. All of this happens subconsciously, then our slower rational brain catches up and justifies the existing decision&mdash;we can&#8217;t even tell it&#8217;s happening. Being an expert means that we&#8217;ve built up more patterns to match so that we can respond more quickly and to more complicated situations than a novice, which is obviously a good thing in most situations. It can also be a bad thing because the nature of our perception means that experts literally <em>cannot receive</em> certain kinds of information that falls outside their training, not because they&#8217;re inadequate people but because that&#8217;s how the brain works.</p>

<p>Part of Dave&#8217;s practice is concerned with breaking through what he calls this &ldquo;Expert Entrainment&rdquo;. He has developed exercises to shuffle our list of response patterns and allow other ideas to break through the crust of skills we&#8217;ve worked so hard to acquire. One motivation for doing this is to stop experts jumping to a known solution when they haven&#8217;t really understood the situation.</p>

<p>Naresh, meanwhile, is on a mission to pair program with the world to understand how different people approach Test-Driven Development, with an example problem that he uses with everyone. My preference these days is to start with a very specific example of the use of the system and then, as I add more examples, extract structure by refactoring. As we talked this through, Naresh described another programmer who noticed that the problem was an instance of a more general type of system and coded that up directly, there was nothing in his solution that included the language of the example. The other programmer had used his expertise to recognise an underlying solution and short-circuit the discovery process&mdash;that&#8217;s why we claim higher rates for experience. This programmer was right about his solution, so why did the leap to a design bother me (apart from my own Expert Entrainment)?</p>

<p>Then it struck me, Test-Driven Development, at least as practised by the school that I follow, progresses by focussing on the immediate, on addressing narrow, concrete examples. Don&#8217;t worry about all those ideas buzzing around your head for how the larger structure should be, just make a note and park them. For now, just do something to address this little concrete example. Later on, when you&#8217;ve gathered some empirical evidence, you can see if you were right and move the code in that direction.</p>

<p>I think what this means is that Test-Driven Development works (or should do) by breaking our first-fit pattern matching. It stops us being expert and steam-rolling over the problem with, literally, the first thing that came into our minds. It forces us out of our comfort zone long enough to consider the real requirements we should be addressing. Even better, starting with a test forces us to think <em>first</em> about the need (what&#8217;s the test for that?), and <em>then</em> about a solution that our expert mind is so keen to provide.</p>

<p>Just in case you missed that (and it took me a while to see it), <em>it makes a cognitive difference whether you write the tests first or the code</em>.</p>

<p>The best supporting evidence is Arlo Belshee&#8217;s group that implemented <a href="http://svn.arlim.org/arlo_papers/Promiscuous%20pairing/Agile%202005/paper.doc">Promiscuous Pairing</a>. They found empirically that they were most productive when switching pairs every couple of hours, contrary to what anyone would expect; their view was that were taking advantage of constantly being in a state of &ldquo;Beginner&#8217;s Mind&rdquo;. Of course, to make <span class="caps">TDD </span>work in practice, we still need all that expertise underneath to draw on but to <em>support</em>, not to <em>control</em>.</p>

<p>Personally, I&#8217;m constantly surprised at the interesting solutions that come up from being very focussed on the immediate and concrete, with a background awareness of the larger picture. By letting go, I discover more possibilities. Very Zen.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2008/06/test-driven-development-a-cognitive-justification/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Incremental and decremental development</title>
		<link>http://www.higherorderlogic.com/2008/05/incremental-and-decremental-development/</link>
		<comments>http://www.higherorderlogic.com/2008/05/incremental-and-decremental-development/#comments</comments>
		<pubDate>Wed, 28 May 2008 11:36:38 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2008/05/28/incremental-and-decremental-development/</guid>
		<description><![CDATA[Nat Pryce just wrote this sidebar for our book Incremental and Iterative Development In a project organised as a set of nested feedback loops, development is incremental and iterative. Incremental Development builds a system feature by feature, not module by module. Each feature is implemented as an end-to-end &#8220;slice&#8221; through all the modules of the [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://nat.truemesh.com/">Nat Pryce</a> just wrote this sidebar for our book</p>

<blockquote>
  <h4>Incremental and Iterative Development</h4>

  <p>In a project organised as a set of nested feedback loops, development is  <em>incremental</em> and <em>iterative</em>.</p>

  <p>Incremental Development builds a system feature by feature, not module by module. Each feature is implemented as an end-to-end &ldquo;slice&rdquo; through all the modules of the system. The system is always integrated and ready for deployment.</p>

  <p>Iterative Development progressively refines the implementation of features in response to feedback until they are good enough for purpose.</p>
</blockquote>

<p>Yesterday we realised that there are two other categories of development:</p>

<p><em>Decremental</em> development is where you improve the system by removing code; most systems could do with more of this.</p>

<p><em>Detrimental</em> development is where the code you&#8217;ve just written has made the system worse.</p>

<div style="font-size: 0.9em; margin-left: 2em; border-top: solid grey thin;">
<p>Actually, we&#8217;ve found a couple of references for Decremental Development, one from <a href="http://accu.org/index.php/journals/1420">Kevlin Henney</a>, and a whole research proposal from <a href="http://wiki.hsr.ch/SimpleCode/files/Tweakfest.pdf">Peter Sommerlad</a>.</p>

<p>Actually, Nat might have thought of Detrimental Development first.</p>
</div>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2008/05/incremental-and-decremental-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming, it&#8217;s really about language</title>
		<link>http://www.higherorderlogic.com/2008/03/its-really-about-language/</link>
		<comments>http://www.higherorderlogic.com/2008/03/its-really-about-language/#comments</comments>
		<pubDate>Fri, 14 Mar 2008 11:55:38 +0000</pubDate>
		<dc:creator>steve.freeman</dc:creator>
				<category><![CDATA[Agile Programming]]></category>
		<category><![CDATA[Software culture]]></category>
		<category><![CDATA[Test-Driven]]></category>

		<guid isPermaLink="false">http://www.m3p.co.uk/blog/2008/03/14/its-really-about-language/</guid>
		<description><![CDATA[Yesterday, during the XpDay Sampler track at QCon, Keith Braithwaite presented the latest version of his talk on measuring the characteristics of Test-Driven code. Very briefly, many natural phenomena follow a power law distribution (read the slides for more explanation), in spoken language this is usually known as Zipf&#8217;s Law. Keith found that tracking the [...]]]></description>
			<content:encoded><![CDATA[<p>Yesterday, during the <a href="http://jaoo.dk/london-2008/tracks/show_track.jsp?trackOID=108">XpDay Sampler track at QCon</a>, Keith Braithwaite presented the <a href="http://peripateticaxiom.blogspot.com/2008/03/tdd-at-qcon.html">latest version of his talk</a> on measuring the characteristics of Test-Driven code. Very briefly, many natural phenomena follow a power law distribution (read the slides for more explanation), in spoken language this is usually known as <a href="http://en.wikipedia.org/wiki/Zipf's_law">Zipf&#8217;s Law</a>. Keith found that tracking the number of methods in a code base for each level of <a href="http://en.wikipedia.org/wiki/Cyclomatic_complexity">cyclomatic complexity</a> looks like such a power law distribution where the code has comprehensive unit tests, and in practice all the conforming examples were written Test-First; trust a physicist to notice this. This matters because low-complexity methods contain many fewer mistakes.</p>

<p>Keith used <a href="http://www.jmock.org">jMock</a> as his example of code at the &#8220;good&#8221; end of the scale (thanks Keith) and, as he was showing some examples of its implementation, it struck me that a great many of those small, low complexity methods were syntactic sugar, they were there to attach a meaningful name to a little piece of code. We put a great deal of emphasis in our coding style on readability, on teasing out concepts and expressing them directly in code and trying to minimize the accidental noise from the language; we don&#8217;t always succeed, but that&#8217;s what we&#8217;re trying to do.</p>

<p>Is this why our code conforms to Zipf&#8217;s Law, because we&#8217;re trying to think in terms of language and expression, rather than in terms of procedures? Hmmmm.</p>

<p><hr /></p>

<p>The other question about Keith&#8217;s discovery is that it doesn&#8217;t yet say anything about causality. The first conclusion one might come to is that Test-Driving code leads to power-law structure, but I&#8217;ve seen <span class="caps">TDD </span>code that definitely does not have that characteristic. An alternative explanation might be that the sort of people who write that sort of code were amongst the first to be drawn to <span class="caps">TDD, </span>and that maybe <span class="caps">TDD </span>encourages the trend if you&#8217;re already mostly there. I&#8217;m not sure what an appropriate experiment would be, perhaps mining some old code that the <span class="caps">TDD</span>ers wrote before they learned the practice? There are just too many variables.</p>]]></content:encoded>
			<wfw:commentRss>http://www.higherorderlogic.com/2008/03/its-really-about-language/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

