<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[My hovercraft is full of eels]]></title>
  <link href="http://www.harukizaemon.com/atom.xml" rel="self"/>
  <link href="http://www.harukizaemon.com/"/>
  <updated>2012-12-19T22:32:46+11:00</updated>
  <id>http://www.harukizaemon.com/</id>
  <author>
    <name><![CDATA[Simon Harris]]></name>
    <email><![CDATA[haruki_zaemon@mac.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Enumerating results from an asynchronous network call in Objective-C]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/11/02/enumerating-results-from-an-asynchronous-network-call-in-objective-c/"/>
    <updated>2012-11-02T21:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/11/02/enumerating-results-from-an-asynchronous-network-call-in-objective-c</id>
    <content type="html"><![CDATA[<p>I have a facade over an asynchronous network call—that also performs pagination, ie multiple network calls in order to handle very large result sets—along the lines of this but I now want to use it in a context where knowing when it’s finished iterating is important (e.g in an <code>NSOperation</code>):</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
</pre></td><td class="code"><pre><code class="objective-c"><span class="line"><span class="p">[</span><span class="n">myClient</span> <span class="nl">enumerateFoosAtURL:</span><span class="n">URL</span> <span class="nl">usingBlock:</span><span class="o">^</span><span class="p">(</span><span class="kt">id</span> <span class="n">foo</span><span class="p">,</span> <span class="kt">BOOL</span> <span class="o">*</span><span class="n">stop</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}</span> <span class="nl">failure:</span><span class="o">^</span><span class="p">(</span><span class="n">NSError</span> <span class="o">*</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}];</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The simplest thing might be to add an extra block but that is so sucky I nearly vomited in my mouth just typing out the example below:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
</pre></td><td class="code"><pre><code class="objective-c"><span class="line"><span class="p">[</span><span class="n">myClient</span> <span class="nl">enumerateFoosAtURL:</span><span class="n">URL</span> <span class="nl">usingBlock:</span><span class="o">^</span><span class="p">(</span><span class="kt">id</span> <span class="n">foo</span><span class="p">,</span> <span class="kt">BOOL</span> <span class="o">*</span><span class="n">stop</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}</span> <span class="nl">success:</span><span class="o">^</span><span class="p">{</span>
</span><span class="line">  <span class="c1">// we&#39;re done</span>
</span><span class="line"><span class="p">}</span> <span class="nl">failure:</span><span class="o">^</span><span class="p">(</span><span class="n">NSError</span> <span class="o">*</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}];</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>A less sucky option might be to indicate if there are more to come:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
</pre></td><td class="code"><pre><code class="objective-c"><span class="line"><span class="p">[</span><span class="n">myClient</span> <span class="nl">enumerateFoosAtURL:</span><span class="n">URL</span> <span class="nl">usingBlock:</span><span class="o">^</span><span class="p">(</span><span class="kt">id</span> <span class="n">foo</span><span class="p">,</span> <span class="kt">BOOL</span> <span class="n">more</span><span class="p">,</span> <span class="kt">BOOL</span> <span class="o">*</span><span class="n">stop</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line">  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="n">more</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">    <span class="c1">// we&#39;re done</span>
</span><span class="line">  <span class="p">}</span>
</span><span class="line"><span class="p">}</span> <span class="nl">failure:</span><span class="o">^</span><span class="p">(</span><span class="n">NSError</span> <span class="o">*</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}];</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Yet another option that I think I like the most might be to simply transform the semantics of the original into this:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
</pre></td><td class="code"><pre><code class="objective-c"><span class="line"><span class="p">[</span><span class="n">myClient</span> <span class="nl">enumerateFoosAtURL:</span><span class="n">URL</span> <span class="nl">usingBlock:</span><span class="o">^</span><span class="p">(</span><span class="kt">id</span> <span class="n">foo</span><span class="p">,</span> <span class="kt">BOOL</span> <span class="o">*</span><span class="n">stop</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="p">...</span>
</span><span class="line"><span class="p">}</span> <span class="nl">finished:</span><span class="o">^</span><span class="p">(</span><span class="n">NSError</span> <span class="o">*</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">  <span class="k">if</span> <span class="p">(</span><span class="n">error</span><span class="p">)</span> <span class="p">{</span>
</span><span class="line">    <span class="c1">// an error occurred</span>
</span><span class="line">  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class="line">    <span class="c1">// we&#39;re done</span>
</span><span class="line">    <span class="p">...</span>
</span><span class="line">  <span class="p">}</span>
</span><span class="line"><span class="p">}];</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p><strong>Update</strong> <a href="http://tonywallace.com">Tony Wallace</a> suggested that he prefered the</p>

<blockquote>
  <p>“less sucky option” because it makes it more obvious that the method returns paginated results.</p>
</blockquote>

<p>And I have to say I agree with him on that. The only fly in the oitment however, turns out to be some filtering performed within the API methods which meant that determining if there were more results would have required some fancy look-ahead code.</p>

<p>In the end I went with my last option. It seems to have worked out rather painlessly :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Site44.com deploy task for Octopress]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/10/15/site44-dot-com-deploy-task-for-octopress/"/>
    <updated>2012-10-15T12:53:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/10/15/site44-dot-com-deploy-task-for-octopress</id>
    <content type="html"><![CDATA[<p>Further to my <a href="http://www.harukizaemon.com/blog/2012/10/15/generate-a-site44-dot-com-redirects-file-for-your-octopress-blog/">previous post</a>, I also added a rake task to my <code>Rakefile</code> that uses rsync to deploy:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="n">rsync_delete</span>   <span class="o">=</span> <span class="kp">false</span>
</span><span class="line"><span class="n">deploy_default</span> <span class="o">=</span> <span class="s2">&quot;local&quot;</span>
</span><span class="line">
</span><span class="line"><span class="c1"># snip</span>
</span><span class="line">
</span><span class="line"><span class="n">desc</span> <span class="s2">&quot;Deploy website via local rsync&quot;</span>
</span><span class="line"><span class="n">task</span> <span class="ss">:local</span> <span class="k">do</span>
</span><span class="line">  <span class="n">exclude</span> <span class="o">=</span> <span class="s2">&quot;&quot;</span>
</span><span class="line">  <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="s1">&#39;./rsync-exclude&#39;</span><span class="p">)</span>
</span><span class="line">    <span class="n">exclude</span> <span class="o">=</span> <span class="s2">&quot;--exclude-from &#39;</span><span class="si">#{</span><span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="s1">&#39;./rsync-exclude&#39;</span><span class="p">)</span><span class="si">}</span><span class="s2">&#39;&quot;</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">  <span class="nb">puts</span> <span class="s2">&quot;## Deploying website via local rsync&quot;</span>
</span><span class="line">  <span class="n">ok_failed</span> <span class="nb">system</span><span class="p">(</span><span class="s2">&quot;rsync -avz </span><span class="si">#{</span><span class="n">exclude</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="s2">&quot;--delete&quot;</span> <span class="k">unless</span> <span class="n">rsync_delete</span> <span class="o">==</span> <span class="kp">false</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">public_dir</span><span class="si">}</span><span class="s2">/ </span><span class="si">#{</span><span class="n">deploy_dir</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>I initally thought it would be pretty neat to work out the local website location in Dropbox but in the end I decided it was simpler to just leave the <code>deploy_dir</code> variable set to the default <code>"_deploy"</code> and have that directory symlinked to the approproprate Dropbox folder.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Generate a site44.com redirects file for your Octopress blog]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/10/15/generate-a-site44-dot-com-redirects-file-for-your-octopress-blog/"/>
    <updated>2012-10-15T09:51:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/10/15/generate-a-site44-dot-com-redirects-file-for-your-octopress-blog</id>
    <content type="html"><![CDATA[<p>Over the weekend I converted my, albeit languishing blog from straight <a href="http://jekyllrb.com">Jekyll</a> on <a href="http://pages.github.com">GitHub Pages</a> to use <a href="http://octopress.org">Octopress</a> served via <a href="http://www.site44.com">Site44</a>.</p>

<p>In the process I also took the opportunity to switch the URLs I was using for blog entries to the Octopress default. This in turn left me needing a bunch of redirects.</p>

<p>Site44 supports redirects via a <a href="http://www.site44.com/advanced">well-known text file</a> in the root of your website. The text file provides a mapping between source and destination paths. That’s all very well and good but I didn’t much feel like creating 300+ redirect mappings by hand. Besides the tedious nature of the task, the chances I was going to screw one or more of them up in the process were fairly high.</p>

<p>Thankfully, due to a previous blog move, I happened to have a bunch of <code>permalink</code> definitions in the front-matter of most of my blog entries. All I really needed then was a way to turn those into said text file.</p>

<p>A quick Google turned up the <a href="http://github.com/tsmango/jekyll_alias_generator">Alias Generator</a> plugin for Octopress by <a href="http://thomasmango.com">Thomas Mango</a> which was very close to, but not quite what I needed.</p>

<p>Hack hack hack on the plugin, a quick rename of all the <code>permalink</code> attributes in my posts to <code>alias</code>, and voila! a new plugin that generates a <code>redirects.site44.txt</code> with all my redirects:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
<span class="line-number">24</span>
<span class="line-number">25</span>
<span class="line-number">26</span>
<span class="line-number">27</span>
<span class="line-number">28</span>
<span class="line-number">29</span>
<span class="line-number">30</span>
<span class="line-number">31</span>
<span class="line-number">32</span>
<span class="line-number">33</span>
<span class="line-number">34</span>
<span class="line-number">35</span>
<span class="line-number">36</span>
<span class="line-number">37</span>
<span class="line-number">38</span>
<span class="line-number">39</span>
<span class="line-number">40</span>
<span class="line-number">41</span>
<span class="line-number">42</span>
<span class="line-number">43</span>
<span class="line-number">44</span>
<span class="line-number">45</span>
<span class="line-number">46</span>
<span class="line-number">47</span>
<span class="line-number">48</span>
<span class="line-number">49</span>
<span class="line-number">50</span>
<span class="line-number">51</span>
<span class="line-number">52</span>
<span class="line-number">53</span>
<span class="line-number">54</span>
<span class="line-number">55</span>
<span class="line-number">56</span>
<span class="line-number">57</span>
<span class="line-number">58</span>
<span class="line-number">59</span>
<span class="line-number">60</span>
<span class="line-number">61</span>
<span class="line-number">62</span>
<span class="line-number">63</span>
<span class="line-number">64</span>
<span class="line-number">65</span>
<span class="line-number">66</span>
<span class="line-number">67</span>
<span class="line-number">68</span>
<span class="line-number">69</span>
<span class="line-number">70</span>
<span class="line-number">71</span>
<span class="line-number">72</span>
<span class="line-number">73</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="c1"># Site 44 Redirects Text Generator for Posts.</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1"># Generates a www.site44.com compatible redirects file pages for posts with aliases set in the YAML Front Matter.</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1"># Place the full path of the alias (place to redirect from) inside the</span>
</span><span class="line"><span class="c1"># destination post&#39;s YAML Front Matter. One or more aliases may be given.</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1"># Example Post Configuration:</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1">#   ---</span>
</span><span class="line"><span class="c1">#     layout: post</span>
</span><span class="line"><span class="c1">#     title: &quot;How I Keep Limited Pressing Running&quot;</span>
</span><span class="line"><span class="c1">#     alias: /post/6301645915/how-i-keep-limited-pressing-running/index.html</span>
</span><span class="line"><span class="c1">#   ---</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1"># Example Post Configuration:</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1">#   ---</span>
</span><span class="line"><span class="c1">#     layout: post</span>
</span><span class="line"><span class="c1">#     title: &quot;How I Keep Limited Pressing Running&quot;</span>
</span><span class="line"><span class="c1">#     alias: [/first-alias/index.html, /second-alias/index.html]</span>
</span><span class="line"><span class="c1">#   ---</span>
</span><span class="line"><span class="c1">#</span>
</span><span class="line"><span class="c1"># Author: Simon Harris</span>
</span><span class="line"><span class="c1"># Site: http://harukizaemon.com</span>
</span><span class="line">
</span><span class="line"><span class="k">module</span> <span class="nn">Jekyll</span>
</span><span class="line">  <span class="no">REDIRECTS_SITE44_TXT_FILE_NAME</span> <span class="o">=</span> <span class="s2">&quot;redirects.site44.txt&quot;</span>
</span><span class="line">
</span><span class="line">  <span class="k">class</span> <span class="nc">RedirectsSite44TxtFile</span> <span class="o">&lt;</span> <span class="no">StaticFile</span>
</span><span class="line">    <span class="k">def</span> <span class="nf">write</span><span class="p">(</span><span class="n">dest</span><span class="p">)</span>
</span><span class="line">      <span class="k">begin</span>
</span><span class="line">        <span class="k">super</span><span class="p">(</span><span class="n">dest</span><span class="p">)</span>
</span><span class="line">      <span class="k">rescue</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">
</span><span class="line">      <span class="kp">true</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">class</span> <span class="nc">RedirectsSite44TxtGenerator</span> <span class="o">&lt;</span> <span class="no">Generator</span>
</span><span class="line">    <span class="k">def</span> <span class="nf">generate</span><span class="p">(</span><span class="n">site</span><span class="p">)</span>
</span><span class="line">      <span class="k">unless</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">dest</span><span class="p">)</span>
</span><span class="line">        <span class="no">FileUtils</span><span class="o">.</span><span class="n">mkdir_p</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">dest</span><span class="p">)</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">
</span><span class="line">      <span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="no">File</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">site</span><span class="o">.</span><span class="n">dest</span><span class="p">,</span> <span class="no">REDIRECTS_SITE44_TXT_FILE_NAME</span><span class="p">),</span> <span class="s2">&quot;w&quot;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">file</span><span class="o">|</span>
</span><span class="line">        <span class="n">process_posts</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</span><span class="line">        <span class="n">process_pages</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">
</span><span class="line">      <span class="n">site</span><span class="o">.</span><span class="n">static_files</span> <span class="o">&lt;&lt;</span> <span class="no">Jekyll</span><span class="o">::</span><span class="no">RedirectsSite44TxtFile</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">site</span><span class="o">.</span><span class="n">dest</span><span class="p">,</span> <span class="s2">&quot;/&quot;</span><span class="p">,</span> <span class="no">REDIRECTS_SITE44_TXT_FILE_NAME</span><span class="p">)</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">
</span><span class="line">    <span class="k">def</span> <span class="nf">process_posts</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</span><span class="line">      <span class="n">site</span><span class="o">.</span><span class="n">posts</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">post</span><span class="o">|</span>
</span><span class="line">        <span class="n">generate_aliases</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">post</span><span class="o">.</span><span class="n">url</span><span class="p">,</span> <span class="n">post</span><span class="o">.</span><span class="n">data</span><span class="o">[</span><span class="s1">&#39;alias&#39;</span><span class="o">]</span><span class="p">)</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">
</span><span class="line">    <span class="k">def</span> <span class="nf">process_pages</span><span class="p">(</span><span class="n">site</span><span class="p">,</span> <span class="n">file</span><span class="p">)</span>
</span><span class="line">      <span class="n">site</span><span class="o">.</span><span class="n">pages</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">page</span><span class="o">|</span>
</span><span class="line">        <span class="n">generate_aliases</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">page</span><span class="o">.</span><span class="n">destination</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">gsub</span><span class="p">(</span><span class="sr">/index\.(html|htm)$/</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">),</span> <span class="n">page</span><span class="o">.</span><span class="n">data</span><span class="o">[</span><span class="s1">&#39;alias&#39;</span><span class="o">]</span><span class="p">)</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">
</span><span class="line">    <span class="k">def</span> <span class="nf">generate_aliases</span><span class="p">(</span><span class="n">file</span><span class="p">,</span> <span class="n">destination_path</span><span class="p">,</span> <span class="n">aliases</span><span class="p">)</span>
</span><span class="line">      <span class="nb">Array</span><span class="p">(</span><span class="n">aliases</span><span class="p">)</span><span class="o">.</span><span class="n">compact</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">alias_path</span><span class="o">|</span>
</span><span class="line">        <span class="n">file</span><span class="o">.</span><span class="n">puts</span><span class="p">(</span><span class="s2">&quot;</span><span class="si">#{</span><span class="n">alias_path</span><span class="si">}</span><span class="s2"> </span><span class="si">#{</span><span class="n">destination_path</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">)</span>
</span><span class="line">      <span class="k">end</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Feed is moving, again]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/10/08/feed-is-moving-again/"/>
    <updated>2012-10-08T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/10/08/feed-is-moving-again</id>
    <content type="html"><![CDATA[<p>For the 3 of you that follow my blog, the feed URL has changed. You can now find it at <a href="http://www.harukizaemon.com/atom.xml">http://www.harukizaemon.com/atom.xml</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What a week]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/08/24/what-a-week/"/>
    <updated>2012-08-24T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/08/24/what-a-week</id>
    <content type="html"><![CDATA[<p>Six days ago, my extraordinary wife Jess gave birth to our third and final (yes, really!) child at home, a beautiful boy with a working title where his name shall shortly, hopefully, be.</p>

<p>Two days ago, I turned 40.</p>

<p>Today, I finally shipped my first iPhone app, <a href="http://www.readtimeapp.com">Readtime</a>, that I have been working on sporadically for a few months now with <a href="http://twitter.com/benjaminb">Benjamin Birnbaum</a> and <a href="http://twitter.com/bennyg">Ben Green</a>, and the support of the <a href="http://www.cogent.co">Cogent folk</a>.</p>

<p>I wish I had something pithy to end with but I don’t. I’m mostly just sitting here, wired, reflecting on what a crazy time it’s been, how utterly fortunate I am to have the life that I do, and hoping that by writing it all down, I might finally get to sleep. I think it’s worked :)</p>

<p><strong>Update</strong>: Our son has a name: George Samuel Harris.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Rediscovering my passion for Software Development]]></title>
    <link href="http://www.harukizaemon.com/blog/2012/06/02/rediscovering-my-passion-for-software-development/"/>
    <updated>2012-06-02T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2012/06/02/rediscovering-my-passion-for-software-development</id>
    <content type="html"><![CDATA[<p>I grew up at the dawn of personal computing. I was lucky enough to have been given a Commodore 64 as a christmas present and it blew my mind.</p>

<p>First Logo, then Basic, and before long I was scribbling down source code on reams of dot-matrix paper my step-Father brought home from work. I created screens that brought joy to my Mum by making “Happy Birthday” flash across our television screen in glorious 8-bit. I made a database to track every delivery of every test match in the Ashes Test series from England; an application that helped organise my Mum’s recipes so we wouldn’t lose all those great dishes my Hungarian Grandmother had scribbled down on bits of yellow, tabacco-stained paper; Mandelbrot sets – taking days to render until I realised that offscreen rendering was about 100 times faster - that had my friends jaws dropping at their beauty. I even copied verbatim the machine code from some magazine so that the kids at school could use a joystick to control simple sprites moving across the screen. I didn’t really understand what I was doing but they all thought I was a genius!</p>

<p>Eventually I started making a living writing software for very small Independent Software Vendors. Working in small teams, we produced amazing user experiences that I am still proud of 15-20 years later. It was as though I’d managed to con the world into paying me to do something that I really loved - creating software that put smiles on people’s faces.</p>

<p>For too many years now though, I have not really enjoyed my “chosen” profession. Sure, I’ve had moments here and there that have been thoroughly enjoyable but I’ve also had a sort of existential crisis every 12-18 months or so. “What was I doing this for?” “I’m clearly no good at this.” “Maybe I should find another line of work?”</p>

<!--more-->
<p>Thankfully I’ve usually had the fortune to work with great people that have helped me through. It’s amazing just how important having great people around is no matter what you do. But even still I’ve developed a real love-hate relationship with the only real money-making skill I posess.</p>

<p>Then recently I tweeted:</p>

<blockquote>
  <p>I suspect very few “agile” teams actively work towards eliminating all the ceremony: standups, retrospectives, etc. ironic really.</p>
</blockquote>

<p>What I meant by that is perhaps a discussion for another day but it did prompt a response from one of my colleagues:</p>

<blockquote>
  <p>I suspect the only way to remove all the ceremony is to remove all the other members of the team.</p>
</blockquote>

<p>And you know what?, I think he’s absolutely right. Software development, and specifically corporate software development, is almost entirely about the organisation and the people therein. More specifically, it is about addressing the needs and problems of the organisation which largely revolve around scaling people and processes. I’ve been saying almost precisely that for years - “software is a means to end; it is not even close to the most important problem to solve.”</p>

<p>Now, don’t get me wrong. I’m not suggesting that’s a bad thing at all. Large organisations exist to produce “value” for shareholders, be they employees, management boards, or actual stockholders and software is but one means to that end. Were I to work within a large organisation, I would continue to deliver the same message.</p>

<p>The thing is though, I never took that line of thinking to its logical conclusion. Until that tweet. When I did, I realised that my growing apathy towards software development was completely unfounded. What I’d grown weary of had nothing to do with software development. Rather, I was tired of solving organisational problems. I was tired of focusing inwardly. I missed working in a team of people that implicitly and explicitly trusted one another to build software that addressed the needs and problems of people outside the organisation. I wanted to rekindle that love I had of using software as my tool to delight people. I realised that’s why I enjoy product development, real product development - not the kind that goes under the guise of “innovation” within large corporates.</p>

<p>Thankfully, for the past 18 months or so I’ve been working in a company that has supported my family-work balance, and with colleagues whose passion reminded me of my own. I feel as though I can work towards getting closer to my software development roots. Ultimately, I want to go back to working in small teams of highly motivated and trusting people building, importantly, end user products. I realise that I actually LOVE software development, just not as many now commonly know it.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Choosing my religion]]></title>
    <link href="http://www.harukizaemon.com/blog/2011/10/02/choosing-my-religion/"/>
    <updated>2011-10-02T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2011/10/02/choosing-my-religion</id>
    <content type="html"><![CDATA[<p>I’d always been a spiritual person but my practices had been somewhat ad-hoc in nature. Then, in my late 20s, I met a group of people that seemed to speak my language. They belonged to a local church and so I went along. I converted soon thereafter and have been devout for more than a decade. However, it has been a somewhat rocky road. So much so that I recently went to see my local pastor.</p>

<p>I told him that no matter how often I practiced, how hard I prayed, or how diligently I followed the rituals, I still encountered problems I couldn’t resolve. That not everything I turned my hand to was a success. I told him that I was beginning to have my doubts. That there didn’t seem to be any scientific proof for any of his beliefs or for that matter anything written in the scriptures. That I sometimes preferred to meditate alone and that I found the gatherings to be succumbing to a kind of group-think. In reply he offered some words of advice.</p>

<p>He told me that no matter what, I should believe. That scientific evidence was unnecessary and that what mattered most was that I believed and followed all the practices as set out in the scriptures. He urged me to read and study the scriptures and to attend church gatherings to discuss my understanding with others wiser than I, who may have more insight into my spirituality. God is there, he said, to help those that are willing to take the time to understand his teachings. That I should not be disappointed if my prayers were not answered, and that not everything I do will turn out for the best, as I am not yet enlightened. For when I am able to worship fully and sincerely and in the correct manner, all will be revealed.</p>

<p>Actually, I’ve never been particularly spiritual, I’ve certainly never joined a church, and I think the only time I’ve ever had any kind of religious instruction was at High School – although I have read various parts of the Old and New Testaments. That said, I have been witness to this kind of discussion both in person and via blogs, Twitter, etc. only you’ll need to replace Religion with Agile, Pastor with Coach, Church with XP User Group, etc.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Detecting unspecified method arguments in Ruby]]></title>
    <link href="http://www.harukizaemon.com/blog/2011/04/11/detecting-unspecified-method-arguments-in-ruby/"/>
    <updated>2011-04-11T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2011/04/11/detecting-unspecified-method-arguments-in-ruby</id>
    <content type="html"><![CDATA[<p>Unlike some languages, Ruby has no real way (that I know of) to define overloaded methods. Instead, you can specify that certain arguments are optional. For example, if we were to re-implement the <code>Enumerable#reduce</code> method, we might do so like this:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">reduce</span><span class="p">(</span><span class="n">memo</span> <span class="o">=</span> <span class="kp">nil</span><span class="p">)</span>
</span><span class="line">  <span class="k">return</span> <span class="n">slice</span><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">first</span><span class="p">)</span> <span class="k">if</span> <span class="n">memo</span><span class="o">.</span><span class="n">nil?</span>
</span><span class="line">  <span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">element</span><span class="o">|</span> <span class="n">memo</span> <span class="o">=</span> <span class="k">yield</span><span class="p">(</span><span class="n">memo</span><span class="p">,</span> <span class="n">element</span><span class="p">)</span> <span class="p">}</span>
</span><span class="line">  <span class="n">memo</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>That is, if no memo was specified, use the first element as the memo with a call to <code>#reduce</code> on the remaining elements of the array.</p>

<!--more-->
<p>This approach generally works out fine unless either <code>nil</code> is actually a valid value, or interestingly, when it’s not. In the first case, I don’t want <code>nil</code> to trigger the special behaviour, I want it passed to my block. In the latter case, I’ve encountered times when a programming bug has meant that I’ve explicitly passed nil to a method in error which has triggered the special behaviour.</p>

<p>At first I attempted to solve this problem using a splat:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">reduce</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span>
</span><span class="line">  <span class="k">return</span> <span class="n">slice</span><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">first</span><span class="p">)</span> <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">length</span>
</span><span class="line">  <span class="k">raise</span> <span class="no">ArgumentError</span><span class="p">,</span> <span class="s2">&quot;wrong number of arguments(</span><span class="si">#{</span><span class="n">args</span><span class="o">.</span><span class="n">length</span><span class="si">}</span><span class="s2"> for 0..1)&quot;</span> <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="mi">1</span>
</span><span class="line">  <span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">element</span><span class="o">|</span> <span class="n">memo</span> <span class="o">=</span> <span class="k">yield</span><span class="p">(</span><span class="n">memo</span><span class="p">,</span> <span class="n">element</span><span class="p">)</span> <span class="p">}</span>
</span><span class="line">  <span class="n">memo</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Which on the face of it isn’t too bad I suppose but get’s awfully complex when you have methods that accept multiple arguments.</p>

<p>Another option might be to use named arguments and a hash. For example:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">reduce</span><span class="p">(</span><span class="n">args</span> <span class="o">=</span> <span class="p">{})</span>
</span><span class="line">  <span class="k">return</span> <span class="n">slice</span><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">first</span><span class="p">)</span> <span class="k">unless</span> <span class="n">args</span><span class="o">.</span><span class="n">has_key?</span><span class="p">(</span><span class="ss">:memo</span><span class="p">)</span>
</span><span class="line">  <span class="k">raise</span> <span class="no">ArgumentError</span><span class="p">,</span> <span class="s2">&quot;wrong number of arguments(</span><span class="si">#{</span><span class="n">args</span><span class="o">.</span><span class="n">length</span><span class="si">}</span><span class="s2"> for 0..1)&quot;</span> <span class="k">if</span> <span class="n">args</span><span class="o">.</span><span class="n">length</span> <span class="o">&gt;</span> <span class="mi">1</span>
</span><span class="line">  <span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">element</span><span class="o">|</span> <span class="n">memo</span> <span class="o">=</span> <span class="k">yield</span><span class="p">(</span><span class="n">memo</span><span class="p">,</span> <span class="n">element</span><span class="p">)</span> <span class="p">}</span>
</span><span class="line">  <span class="n">memo</span>
</span><span class="line"><span class="k">end</span>
</span><span class="line">
</span><span class="line"><span class="n">some_array</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">memo</span><span class="p">:</span> <span class="s2">&quot;some memo&quot;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>But from experience, this makes the calling code unnecessarily complicated and is no better with multiple arguments.</p>

<p>The solution I settled on, and believe me I’m open to suggestions, is to use a default value that I know won’t be used by calling code:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="no">UNSPECIFIED</span> <span class="o">=</span> <span class="no">Object</span><span class="o">.</span><span class="n">new</span>
</span><span class="line">
</span><span class="line"><span class="k">def</span> <span class="nf">reduce</span><span class="p">(</span><span class="n">memo</span> <span class="o">=</span> <span class="no">UNSPECIFIED</span><span class="p">)</span>
</span><span class="line">  <span class="k">return</span> <span class="n">slice</span><span class="p">(</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">reduce</span><span class="p">(</span><span class="n">first</span><span class="p">)</span> <span class="k">if</span> <span class="n">memo</span><span class="o">.</span><span class="n">equal?</span><span class="p">(</span><span class="no">UNSPECIFIED</span><span class="p">)</span>
</span><span class="line">  <span class="n">each</span> <span class="p">{</span> <span class="o">|</span><span class="n">element</span><span class="o">|</span> <span class="n">memo</span> <span class="o">=</span> <span class="k">yield</span><span class="p">(</span><span class="n">memo</span><span class="p">,</span> <span class="n">element</span><span class="p">)</span> <span class="p">}</span>
</span><span class="line">  <span class="n">memo</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>This way the calling code remains the same, the method definition remains largely the same, and to my mind explicitly calls out the case where the arguments aren’t specified by the caller – much the same way you can call <code>#block_given?</code> to determine if a block has been passed to a method.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[How I tell a story]]></title>
    <link href="http://www.harukizaemon.com/blog/2010/08/05/how-i-tell-a-story/"/>
    <updated>2010-08-05T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2010/08/05/how-i-tell-a-story</id>
    <content type="html"><![CDATA[<p>As far as I can tell, the most widely accepted format for agile user stories looks like this:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a [role]
</span><span class="line">I would like to [action]
</span><span class="line">So that [reason for action]
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>I’m not entirely certain of the origins. Some have suggested <a href="http://blog.dannorth.net/whats-in-a-story/">Dan North</a> and others have have suggested much earlier use. In any event, it’s use is so common I can’t recall a single “agile” project where that wasn’t the format but I’ve also never really been that comfortable with it and I’ve not really known why until recently.</p>

<p>Here’s an example:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a domain novice
</span><span class="line">I want the domain experts names made prominent on a domain listing
</span><span class="line">So that I know who to turn to for help on a given domain
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Though entirely contrived for the purpose of this discussion, it demonstrates the kind of stories people are inclined to write.</p>

<p>On the positive side, the format seems quite natural – people often have an implementation in mind and they can articulate it quite easily but find it much harder to articulate the intent. This seems to be reflected in the format with the primary focus (“I want”) expressed as the desired behaviour and the intent (“So that”) of conceptually lesser importance. The problem I have is the story centres around how the user will interact with the system and only then describes why. It presupposes an implementation with a cursory nod as to the user’s intent.</p>

<!--more-->
<p>In my various roles from analyst to developer, I’ve always wanted to understand why we’re building a new feature. Experience has taught me that when I understand the why, I am better able to build a solution that satisfies the real need. As a consequence, when running workshops, I’ve always tried to have the intent stated as the primary desire/need. For example:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a domain novice
</span><span class="line">I want to know who to turn to for help on a given domain
</span><span class="line">So that .... [what the hell goes here?]
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>When people go to the trouble of putting the intent first, the “So that” becomes a bit of a WTF, often resulting in a simple re-statement of the intent just to satisfy the template:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a domain novice
</span><span class="line">I want to know who to turn to for help on a given domain
</span><span class="line">So that I can learn more about the domain [well d&#39;uh!]
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Moreover, we’ve now lost the implementation detail which, although we’re more interested in the intent, is still of value by providing context for further discussion/understanding.</p>

<p>What I’ve wanted was a way to encourage people to describe their intent and leave the implementation details to be decided closer to the iteration in which the story will be delivered. Yes, training is one way to achieve this but my experience is that the standard format effectively devalues the intent in favour of implementation detail. What I’d really like is to somehow <a href="http://www.amazon.com/Nudge-Improving-Decisions-Health-Happiness/dp/0300122233">nudge</a> people into writing a story where the primary focus is the intent.</p>

<p>Enter the format I’ve been using recently and really liking:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a [role]
</span><span class="line">I want to [intent]
</span><span class="line">[For example] By [action]
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>It’s a small but subtle change. To some so subtle that it verges on the trivial. However, my experience is that it’s similar enough to the original format so as not to seem too radical a change and at the same time different enough to encourage the behaviour I am looking for. By way of example:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">As a domain novice
</span><span class="line">I want to know who to turn to for help on a given domain
</span><span class="line">e.g by having the domain experts names made prominent on a domain listing
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The intent is now first and clearly specified as a higher order issue. It makes no sense to express the intent as “For example by wanting to know who to turn to for help on a given domain” so the only sensible place for it is as “I want …”.</p>

<p>That the last line begins with “By” identifies it as an implementation detail, acknowledging that most people have some idea of how they want it implemented and allowing them to express that without feeling awkward. With the addition of “For example” or “e.g.”– as suggested by <a href="http://dogbiscuit.org/mdub/weblog/">Mike Williams</a> – we further clarify that it as up for debate once the story hits an iteration. Finally, by placing it last and making it optional we indicate that it lends less weight than the intent.</p>

<p>The more I use this format the more it becomes clear when the intent is expressed as implementation, my stories tend to read much more like a plot or a narrative of the software, and I’m finding it nudges/leads me to write stories that express the intent rather than work backwards from the implementation. I’ve also noticed I’m developing some heuristics for “validation”:</p>

<ul>
  <li>When the implementation contains a conjunction (and) it probably indicates the story is an epic.</li>
  <li>When the intent contains a conjunction, it probably indicates more than one story/epic.</li>
</ul>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Trading Design Pain for Runtime Pain]]></title>
    <link href="http://www.harukizaemon.com/blog/2010/06/03/trading-design-pain-for-runtime-pain/"/>
    <updated>2010-06-03T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2010/06/03/trading-design-pain-for-runtime-pain</id>
    <content type="html"><![CDATA[<p>So<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>, since my post on <a href="http://www.harukizaemon.com/blog/2010/03/01/functional-programming-in-object-oriented-languages">functional programming in object-oriented languages</a> I’ve continued to tread the path with a mixture of gratification and despair. This morning the latter became overwhelming, I’d just had enough. My brain hurt and I just wanted to pump out some code, run it. I threw out the concepts I had been using as my guide and fell back on years of “old-school” object-oriented code.</p>

<p>Unfortunately, I was no more productive. In fact, I’d argue I was less productive. Things began to fail in weird and unexpected ways. The number of tests I needed to write to catch errors at least doubled. I soon returned to the comfort of my hybrid world.</p>

<!--more-->
<p>In hindsight, I had traded design pain for runtime pain. All the mental gymnastics that went into working out how to build classes that are inter-related and at the same time immutable, etc. was replaced with time spent writing tests for anticipated edge cases as well as debugging the unexpected ones.</p>

<p>I concluded that the “pain” I had been experiencing was largely the result of being forced to deal with the complexity of the underlying problem. Once solved however, the code fell out with few or no bugs. By contrast, when I reverted to my previous approach, the code flowed far more freely but I spent a lot more time working out how to ensure the code didn’t do nasty things to itself.</p>

<p>What’s perhaps as interesting to me is that my designs are resulting in smaller and smaller classes. The more I think about problems in a functional way, the more I’m am able to design solutions that are essentially pipelines. The irony being that even though we think of imperative code as being step-by-step, it more often than not turns out to be a big, intertwined blob. Functional code on the other hand is almost by definition a series of steps, or transformations applied one after the other on some input.</p>

<p>These two observations are drawing me ever closer to just “getting over it” and using a functional language. The issue for me is the only FP language I know and actually like is Haskell and the only FP language I’d be likely to get into production is Clojure. Which is all I’ll say in public as I have no desire to start a flame war :)</p>

<div class="footnotes">
  <ol>
    <li id="fn:1">
      <p><a href="http://www.nytimes.com/2010/05/22/us/22iht-currents.html">A Connective Word Takes the Lead</a><a href="#fnref:1" rel="reference">&#8617;</a></p>
    </li>
  </ol>
</div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Functional programming in object oriented languages]]></title>
    <link href="http://www.harukizaemon.com/blog/2010/03/01/functional-programming-in-object-oriented-languages/"/>
    <updated>2010-03-01T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2010/03/01/functional-programming-in-object-oriented-languages</id>
    <content type="html"><![CDATA[<p>In my current job, I spend about 40% of my time with my underpants on the outside, digging around in production code, generally making stuff better. The other 60% of the time is R&amp;D. The R&amp;D part has some very concrete objectives but there is certainly leeway to explore different ways of developing software.</p>

<p>Like many programmers, my first formal introduction to OO was all about classes and inheritance. What mattered most was getting the “structure” right. Next, I came to understand the importance of encapsulation, and after that polymorphism.</p>

<p>Over the past 6-12 months or so I’ve become more and more interested in functional programming concepts if not functional programming languages. I’ve always been a big fan of declarative programming, business rules, etc. and yet I’ve also always been a big fan of OO. Even when I was an assembler programmer I tended to structure my code and data as if it were object-oriented, even if the <code>self</code> pointer was explicit.</p>

<p>More recently I re-read <a href="http://mitpress.mit.edu/sicp/">SICP</a>, learned <a href="http://www.haskell.org/">Haskell</a> which I unashamedly love, played with <a href="http://clojure.org/">Clojure</a> on and off, and briefly looked at <a href="http://www.scala-lang.org/">Scala</a>. Co-incidentally, I also read <a href="http://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215">Domain Driven Design</a>, and <a href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a> along with a number of other very interesting articles on functional programming, immutability in general and recursion in object-oriented languages.<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup><sup id="fnref:2"><a href="#fn:2" rel="footnote">2</a></sup><sup id="fnref:3"><a href="#fn:3" rel="footnote">3</a></sup><sup id="fnref:4"><a href="#fn:4" rel="footnote">4</a></sup> All of which got me thinking, once again, that perhaps I’d been doing this OO thing all wrong.</p>

<p>Here I’d like to present a few observations from my exploration into functional programming in an object-oriented world.</p>

<!--more-->
<ul>
  <li>Immutable objects good; Mutable objects bad</li>
  <li>An object is a collection of partially applied functions</li>
  <li>An object’s API provides a clear separation between Commands and Queries</li>
  <li>An object is a snapshot of state and possible outcomes</li>
  <li>An object is a persistent data structure</li>
</ul>

<p>Clear as mud hey?</p>

<h2 id="immutable-objects-good-mutable-objects-bad">Immutable objects good; Mutable objects bad</h2>

<blockquote>
  <p>“Classes should be immutable unless there’s a very good reason to make them mutable….If a class cannot be made immutable, limit its mutability as much as possible.” – Joshua Bloch, Effective Java</p>
</blockquote>

<p>I won’t go into a lot of detail as to why I believe this to be true. There are plenty of arguments to be found both for and against. Suffice it to say, the direction I’m taking and the conclusions I draw from my experiences are predicated on this belief. What I will say however, is that the effect it has on my designs quite often gives me the same sense of satisfaction as when practising Test Driven Design.</p>

<p>It’s not as though immutability in object-oriented programming is anything new. Many years ago I wrote code where all my value objects were immutable as was the occasional service class, etc. The difference in my current approach is that everything is immutable except for a tiny layer at the fringes where I need to save data for later retrieval, consume HTTP requests, etc. Yes, even my “entities” are immutable.</p>

<h2 id="an-object-is-a-collection-of-partially-applied-functions">An object is a collection of partially applied functions</h2>

<blockquote>
  <p>“The ideal number of arguments for a function is zero … More than three requires very special justification – and then shouldn’t be used anyway.” – Bob Martin, Clean Code</p>
</blockquote>

<p>In functional languages, partial application of a function allows us to define a new function by “pre-populating” some of the arguments. For example, we can take a very simple Haskell function that calculates the amount of applicable sales tax:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="haskell"><span class="line"><span class="nf">applicableSalesTax</span> <span class="n">percentage</span> <span class="n">amount</span> <span class="ow">=</span> <span class="p">(</span><span class="n">percentage</span> <span class="o">/</span> <span class="mi">100</span><span class="p">)</span> <span class="o">*</span> <span class="n">amount</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>and then partially apply it to create another function that has a fixed sales tax:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="haskell"><span class="line"><span class="nf">applicableGST</span> <span class="ow">=</span> <span class="n">applicableSalesTax</span> <span class="mi">10</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The function <code>applicableGST</code> partially applies <code>applicableSalesTax</code> with the value 10. Anytime we call <code>applicableGST</code> it will invoke <code>applicableSalesTax</code> with a rate of 10% and whatever amount we pass to it.</p>

<p>Now consider an object-oriented approach (in Ruby). Imagine a very simple <code>SalesTax</code> class that holds the rate:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">class</span> <span class="nc">SalesTax</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">percentage</span><span class="p">)</span>
</span><span class="line">    <span class="vi">@rate</span> <span class="o">=</span> <span class="n">percentage</span> <span class="o">/</span> <span class="mi">100</span><span class="o">.</span><span class="mi">0</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">applicable_for</span><span class="p">(</span><span class="n">amount</span><span class="p">)</span>
</span><span class="line">    <span class="p">(</span><span class="n">amount</span> <span class="o">*</span> <span class="vi">@rate</span><span class="p">)</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">included_in</span><span class="p">(</span><span class="n">amount</span><span class="p">)</span>
</span><span class="line">    <span class="n">amount</span> <span class="o">-</span> <span class="n">excluded_from</span><span class="p">(</span><span class="n">amount</span><span class="p">)</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">excluded_from</span><span class="p">(</span><span class="n">amount</span><span class="p">)</span>
</span><span class="line">    <span class="n">amount</span> <span class="o">/</span> <span class="p">(</span><span class="mi">1</span> <span class="o">+</span> <span class="vi">@rate</span><span class="p">)</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Here, the constructor sets up the context within which each of the methods then operates, just the way we always read good OO code should be.</p>

<p>I’ve starting to think of constructor arguments as the mechanism for partially applying all the methods on an object. Considering an object as a partial application of a set of methods is really quite interesting to me. It almost dictates that methods MUST operate, in some way, on the state of the object – just as we always read good OO code should – only there’s a nice explanation as to why: If they didn’t operate on the object’s state, they wouldn’t be partially applied.</p>

<p>When I apply this principle in my designs I find I have smaller, more cohesive classes – ie the methods are all related more closely to the shared state. I also find I have far fewer private methods and more often than not, none at all. (This coincidentally fits in nicely with my relatively long held belief that <a href="http://www.harukizaemon.com/2004/02/dont-touch-my-privates.html">private methods are a smell</a> though this is a perhaps a topic for another discussion.) I also find that the constructor then becomes a meaningful, nay critical, part of my API.</p>

<h2 id="an-objects-api-provides-a-clear-separation-between-commands-and-queries">An object’s API provides a clear separation between Commands and Queries</h2>

<blockquote>
  <p>“Methods should return a value only if they are referentially transparent and hence possess no side effects.” – Bertrand Meyer</p>
</blockquote>

<p>Interestingly, when we deal with immutable objects we really have little choice but to do just this.</p>

<p>If we want an object to “answer something” (a query) no modification is expected and we simply return a (potentially calculated) value:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">full_name</span>
</span><span class="line">  <span class="s2">&quot;</span><span class="si">#{</span><span class="vi">@first_name</span><span class="si">}</span><span class="s2">, </span><span class="si">#{</span><span class="vi">@last_name</span><span class="si">}</span><span class="s2">&quot;</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>If we want an object to “do something” (a command) we’ll be expecting some kind of representation of the new state as the result:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">set_first</span><span class="p">(</span><span class="n">new_last_name</span><span class="p">)</span>
</span><span class="line">  <span class="no">Person</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="vi">@first_name</span><span class="p">,</span> <span class="n">new_last_name</span><span class="p">)</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>If we assume we only want to return one thing from a method, and that a change in state necessitates returning a handle to the new state, then a method can only ever be either a query or command but not both.</p>

<p>After discussing this with a colleague, they suggested that in a sense commands are now queries, eg. that ask the question: “what would a system look like if I asked you to do something?” Given <a href="http://martinfowler.com/bliki/CommandQuerySeparation.html">this definition of Commands and Queries</a> I can certainly see it from that perspective.</p>

<p>In the example just given we merely returned a newly created object but it could just as easily have inserted a record into a database. So, I still like to think of commands in the original sense except they now return a handle to the new state. Much like an HTTP PUT/POST/DELETE request does when following the principles of <a href="http://en.wikipedia.org/wiki/Representational_State_Transfer">REST</a>.</p>

<p>(As an aside, one consequence of this approach is that objects are <a href="http://en.wikipedia.org/wiki/Closure_%28mathematics%29">closed under modification</a>. That is, whenever we modify an object, we receive the result in the form of a new object of the same type.)</p>

<h2 id="an-object-is-a-snapshot-of-state-and-possible-outcomes">An object is a snapshot of state and possible outcomes</h2>

<blockquote>
  <p>“Domain Events represent the state of entities at a given time when an important event occurred and decouple subsystems with event streams. Domain Events give us clearer, more expressive models in those cases.” – Eric Evans</p>
</blockquote>

<p>I presume it would be largely uncontroversial to describe immutable objects as a snapshot of some state. When I also consider an object as a collection of partially applied functions, I begin to think of an object – and therefore the system as a whole – as a snapshot not only of state but also possible outcomes.</p>

<p>I suspect thinking about the difference between a system that undergoes state changes in situ and one that in effect represents every possible outcome simultaneously without needing to materialise them all in advance leads to a very different way of modelling a problem.</p>

<p>While pondering this, I recalled that as a kid I loved <a href="http://en.wikipedia.org/wiki/Choose_Your_Own_Adventure">Choose Your Own Adventure books</a>? At the end of each page (or few pages) you are presented with a set of choices: Do you turn left? Do we Open the door? Do you run away? Depending on the choice we make, the story takes a different course. Objects seem a bit like pages in a Choose Your Own Adventure Book, frozen in time. The methods are like the choices we make – each one takes us to a different page, itself frozen in time. I used to bookmark pages with my thumb, like a save-point. If I didn’t like the way the story was headed I simply turned back to the last known “good” point in the book.</p>

<h2 id="an-object-is-a-persistent-data-structure">An object is a persistent data structure</h2>

<p>A <a href="http://en.wikipedia.org/wiki/Persistent_data_structure">persistent data structure</a> is one that efficiently preserves the previous version of itself when it is modified. One of the simplest persistent data structures is the singly-linked (cons) list but almost any tree structure can be adapted to be persistent.</p>

<p>If we’re creating snapshots in order to preserve the initial state we’ll need to make a copy that can be modified. It’s reasonable to assume that all these redundant copies will take precious memory and computing cycles and in doing so create quite a bit of garbage. Assuming a naive copying strategy that makes deep, nested copies, this will certainly be the case. Thankfully, there are some pretty neat optimisations we can make by because every object is immutable.</p>

<p>When thought of as a tree with the references to other objects as the children, an object can be treated just like a persistent data structure. If we need to make a copy and modify something, all we need do is create a shallow copy and change the necessary fields. In this way, each copy is like a delta from the previous, sharing as much state as possible and reducing not only the time to copy but also the amount of memory needed.</p>

<p>When I first started down this path, I used constructors for this purpose. For example, if I wanted to create a new <code>Money</code> object, I’d create a new version using regular object construction:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">class</span> <span class="nc">Money</span>
</span><span class="line">
</span><span class="line">  <span class="kp">attr_reader</span> <span class="ss">:currency</span><span class="p">,</span> <span class="n">amount</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">initialize</span><span class="p">(</span><span class="n">currency</span><span class="p">,</span> <span class="n">amount</span><span class="p">)</span>
</span><span class="line">    <span class="vi">@currency</span> <span class="o">=</span> <span class="n">currency</span>
</span><span class="line">    <span class="vi">@amount</span> <span class="o">=</span> <span class="n">amount</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
</span><span class="line">    <span class="no">Money</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="vi">@currency</span><span class="p">,</span> <span class="vi">@amount</span> <span class="o">+</span> <span class="vi">@currency</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">currency</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">money</span><span class="p">))</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>I found this approach worked fine for small, value-object sized, classes however for objects that reference more than two or three values, constructing new instances became cumbersome. Moreover, if an object had internal state that was hidden but necessary when copying, the constructor API would become polluted. Even in languages such as Java that provide method overloading, or Ruby with first-class associative arrays, it still felt overly complicated to construct a new instance just to change a single value.</p>

<p>Instead I’ve started using an approach that involves cloning. Whenever I need to make a change, I perform a shallow copy, update the appropriate fields and return the result. In a language such as Ruby, this is quite simple to implement and make safe. Instead of using object construction, anytime I wish to make a change I do something like this:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="n">other</span><span class="p">)</span>
</span><span class="line">  <span class="n">transform</span> <span class="k">do</span>
</span><span class="line">    <span class="vi">@amount</span> <span class="o">=</span> <span class="vi">@amount</span> <span class="o">+</span> <span class="n">currency</span><span class="o">.</span><span class="n">convert</span><span class="p">(</span><span class="n">other</span><span class="o">.</span><span class="n">currency</span><span class="p">,</span> <span class="n">other</span><span class="o">.</span><span class="n">money</span><span class="p">)</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The <code>add</code> method now looks similar to a method you’d write if you were able to modify state; we assign a new amount based on some calculation. The <code>transform</code> method<sup id="fnref:5"><a href="#fn:5" rel="footnote">5</a></sup> is the key here by making a shallow copy of the object, running the block within the context of the copy, then freezing the result to prevent modification before returning it to the caller. I’m finding this approach to have a number of advantages.</p>

<p>My constructor API isn’t “polluted” with internal implementation concerns. The constructor remains a part of the public API.</p>

<p>The construction of the modified copy isn’t leaking into the implementation of the method itself. Instead, the method can focus on the job at hand.</p>

<p>Because the method only ever needs to concern itself with the data upon which it operates, the rest of the class can vary relatively independently. When we were explicitly constructing a new object, the <code>add</code> method had to concern itself with also copying the currency. When using <code>transform</code> that problem goes away. No matter how many other fields need to be copied, the <code>add</code> method remains unchanged.</p>

<p>In a sense each method describes the delta between the current state and the new state. Just like a persistent data structure. It reminds me of branching in a Version Control System.</p>

<h2 id="more-to-explore">More to explore</h2>

<p>As I mentioned very early on, I’m working with designs that are almost completely immutable, even at the entity level. This approach results in some really positive benefits but also presents some interesting implementation challenges as well as challenging some of my long held beliefs.</p>

<p>Immutable designs <em>feel</em> easier to reason about. I have no empirical evidence for this just a gut feel. When I’m trying to work out why something isn’t working as expected, more often than not I can just read through the code and work out what happened. I’m not trying to keep a mental mode of all the side effects.</p>

<p>When dealing with any kind of RDBMS, immutable objects lend themselves to a model where changes to the database are written as events rather than updates to individual records. Unlike a traditional ORM, I don’t have the “luxury” of modifying an object to assign an ID. This hasn’t presented much of a problem as yet though I suspect it might become more interesting as the object model increases in complexity.</p>

<p>I’ve been contemplating trying out an OODB such as <a href="http://github.com/MagLev/maglev">MagLev</a> to see how that might fit in. I suspect it should be no more difficult than with mutable objects and perhaps even simpler.</p>

<p>I’m also working on a project at the moment that uses an immutable RDF store wrapped in an object model to make it actually useable. So far it’s fit really nicely.</p>

<p>I’m wary of my code turning into a collection of function objects. Ie. objects that effectively have a single <code>doIt</code> method. It doesn’t happen too often to be a concern but it certainly does happen and I’m still not certain how I feel about it.</p>

<p>I sometimes find myself exposing state I wouldn’t otherwise have needed when I used mutable objects. It feels a tad icky but thus far I haven’t found it to be much of an issue.</p>

<p>Testing has also been interesting. I find I’m doing far less mocking and much more state-based testing. I find the tests I’m writing to be far more declarative than when I do interaction based testing. Define the initial state of the system, run the code, and compare against the expected state. Even (especially?) at the unit level this has been very effective. Again, I’m not sure how I feel about this but so far, it’s worked out well.</p>

<p>Of course not everything is immutable. The database isn’t nor is the file system though in both cases I try my best to treat them as if they were by only ever writing new records/files. The system runtime isn’t immutable either – the act of creating a new object proves that.</p>

<p>Perhaps it really is a natural progression from here to the use of more functional languages as some of my colleagues tell me I should. However there does seem to be a general lack of distinction between the benefits of functional programming concepts and functional programming languages. I’m thoroughly enjoying incorporating functional programming concepts into object-oriented languages.</p>

<div class="footnotes">
  <ol>
    <li id="fn:1">
      <p><a href="http://www.cs.chalmers.se/~rjmh/Papers/whyfp.pdf">Why Functional Programming Matters</a><a href="#fnref:1" rel="reference">&#8617;</a></p>
    </li>
    <li id="fn:2">
      <p><a href="http://weblog.raganwald.com/2007/03/why-why-functional-programming-matters.html">Why Why Functional Programming Matters Matters</a><a href="#fnref:2" rel="reference">&#8617;</a></p>
    </li>
    <li id="fn:3">
      <p><a href="http://www.ccs.neu.edu/home/matthias/Presentations/ecoop2004.pdf">Functional Objects</a><a href="#fnref:3" rel="reference">&#8617;</a></p>
    </li>
    <li id="fn:4">
      <p><a href="http://lambda-the-ultimate.org/node/3702">Why Object Oriented Languages Need Tail Calls</a><a href="#fnref:4" rel="reference">&#8617;</a></p>
    </li>
    <li id="fn:5">
      <p><a href="http://github.com/harukizaemon/hamster/">Hamster - Efficient, Immutable, Thread-Safe Collection classes for Ruby</a><a href="#fnref:5" rel="reference">&#8617;</a></p>
    </li>
  </ol>
</div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Tests as documentation]]></title>
    <link href="http://www.harukizaemon.com/blog/2010/02/11/tests-as-documentation/"/>
    <updated>2010-02-11T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2010/02/11/tests-as-documentation</id>
    <content type="html"><![CDATA[<p>Whilst I’ve been playing around with <a href="http://github.com/harukizaemon/hamster">immutable collection classes in Ruby</a>, I’ve also been working on ways to document behaviour without writing loads of RDOC that goes stale really quickly.</p>

<p>Tests have always been touted as a form of documentation but I’ve rarely – if ever come to think of it – seen that work in practice. <a href="http://cukes.info/">Cucumber</a> comes very close but I wanted something a little closer to the metal, something that allowed me to write unit tests with something like <a href="http://rspec.info/">RSpec</a>.</p>

<p>For sometime now, I’d been structuring my specs with this in mind and I thought I was doing a reasonably good approximation. Then today I finally had cause to test my work. As part of a feature I was implementing in another project, I wanted to use a list method I thought provided just what I required but I couldn’t remember exactly how it behaved or what the interface was so, naturally, I consulted the documentation. D’oh! But wait, I thought smugly, I’ve been writing these specs and as we all know, specs are documentation. Moreover, I’ve been putting in quite a bit of effort to make them read as such so why not go read the specs?</p>

<p>Suffice to say, they didn’t live up to my expectations. After running <code>spec -f nested spec/hamster/list/span_spec.rb</code> the result wasn’t bad but wasn’t great either:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
<span class="line-number">24</span>
<span class="line-number">25</span>
<span class="line-number">26</span>
<span class="line-number">27</span>
<span class="line-number">28</span>
<span class="line-number">29</span>
<span class="line-number">30</span>
<span class="line-number">31</span>
<span class="line-number">32</span>
<span class="line-number">33</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">Hamster::List
</span><span class="line">  #span
</span><span class="line">    is lazy
</span><span class="line">    on []
</span><span class="line">      with a block
</span><span class="line">        preserves the original
</span><span class="line">        returns a tuple with two items
</span><span class="line">        correctly identifies the prefix
</span><span class="line">        correctly identifies the remainder
</span><span class="line">      without a block
</span><span class="line">        returns a tuple with two items
</span><span class="line">        returns self as the prefix
</span><span class="line">        leaves the remainder empty
</span><span class="line">    on [1]
</span><span class="line">      with a block
</span><span class="line">        preserves the original
</span><span class="line">        returns a tuple with two items
</span><span class="line">        correctly identifies the prefix
</span><span class="line">        correctly identifies the remainder
</span><span class="line">      without a block
</span><span class="line">        returns a tuple with two items
</span><span class="line">        returns self as the prefix
</span><span class="line">        leaves the remainder empty
</span><span class="line">    on [1, 2, 3, 4]
</span><span class="line">      with a block
</span><span class="line">        preserves the original
</span><span class="line">        returns a tuple with two items
</span><span class="line">        correctly identifies the prefix
</span><span class="line">        correctly identifies the remainder
</span><span class="line">      without a block
</span><span class="line">        returns a tuple with two items
</span><span class="line">        returns self as the prefix
</span><span class="line">        leaves the remainder empty
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>For a start, there was no narrative, nothing telling me what the desired outcome was; why do I want to use this method? Secondly, whilst the individual assertions seemed to make sense when reading the spec code, once they were in this purely textual form they were somewhat useless in helping me understand what to expect. And lastly, a purely aesthetic complaint, I didn’t really like the indentation so much. Right when all that hard work should have paid off, it failed me. But not completely. I was still convinced there was some merit in what I wanted and perhaps a little more tweaking could get me closer to my ideal.</p>

<p>After a few iterations of modifying the code, running the specs, and reading the output, I finally hit upon something I think is pretty close to what I’ve been after:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
<span class="line-number">24</span>
<span class="line-number">25</span>
<span class="line-number">26</span>
<span class="line-number">27</span>
<span class="line-number">28</span>
<span class="line-number">29</span>
<span class="line-number">30</span>
<span class="line-number">31</span>
<span class="line-number">32</span>
<span class="line-number">33</span>
<span class="line-number">34</span>
</pre></td><td class="code"><pre><code class="text"><span class="line">Hamster.list#span
</span><span class="line">  is lazy
</span><span class="line">  given a predicate (in the form of a block), splits the list into two lists
</span><span class="line">  (returned as a tuple) such that elements in the first list (the prefix) are
</span><span class="line">  taken from the head of the list while the predicate is satisfied, and elements
</span><span class="line">  in the second list (the remainder) are the remaining elements from the list
</span><span class="line">  once the predicate is not satisfied. For example:
</span><span class="line">    given the list []
</span><span class="line">      and a predicate that returns true for values &lt;= 2
</span><span class="line">        preserves the original
</span><span class="line">        returns the prefix as []
</span><span class="line">        returns the remainder as []
</span><span class="line">      without a predicate
</span><span class="line">        returns a tuple
</span><span class="line">        returns self as the prefix
</span><span class="line">        returns an empty list as the remainder
</span><span class="line">    given the list [1]
</span><span class="line">      and a predicate that returns true for values &lt;= 2
</span><span class="line">        preserves the original
</span><span class="line">        returns the prefix as [1]
</span><span class="line">        returns the remainder as []
</span><span class="line">      without a predicate
</span><span class="line">        returns a tuple
</span><span class="line">        returns self as the prefix
</span><span class="line">        returns an empty list as the remainder
</span><span class="line">    given the list [1, 2, 3, 4]
</span><span class="line">      and a predicate that returns true for values &lt;= 2
</span><span class="line">        preserves the original
</span><span class="line">        returns the prefix as [1, 2]
</span><span class="line">        returns the remainder as [3, 4]
</span><span class="line">      without a predicate
</span><span class="line">        returns a tuple
</span><span class="line">        returns self as the prefix
</span><span class="line">        returns an empty list as the remainder
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>This time there’s a narrative describing what the method does, followed by a series of examples not only describing the behaviour but also providing concrete values. Now the output reads more like documentation only rather than duplicated as RDOC that rapidly becomes disconnected from reality, it’s generated from the tests and automatically stays up-to-date.</p>

<p>The underlying spec is not perfect by any stretch – there is certainly a modicum of duplication between the test code and the descriptive text – but I think it strikes a reasonable balance between tests that are readable as code as well as plain text documentation. I’d certainly love to know what, if anything, others have done.</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
<span class="line-number">19</span>
<span class="line-number">20</span>
<span class="line-number">21</span>
<span class="line-number">22</span>
<span class="line-number">23</span>
<span class="line-number">24</span>
<span class="line-number">25</span>
<span class="line-number">26</span>
<span class="line-number">27</span>
<span class="line-number">28</span>
<span class="line-number">29</span>
<span class="line-number">30</span>
<span class="line-number">31</span>
<span class="line-number">32</span>
<span class="line-number">33</span>
<span class="line-number">34</span>
<span class="line-number">35</span>
<span class="line-number">36</span>
<span class="line-number">37</span>
<span class="line-number">38</span>
<span class="line-number">39</span>
<span class="line-number">40</span>
<span class="line-number">41</span>
<span class="line-number">42</span>
<span class="line-number">43</span>
<span class="line-number">44</span>
<span class="line-number">45</span>
<span class="line-number">46</span>
<span class="line-number">47</span>
<span class="line-number">48</span>
<span class="line-number">49</span>
<span class="line-number">50</span>
<span class="line-number">51</span>
<span class="line-number">52</span>
<span class="line-number">53</span>
<span class="line-number">54</span>
<span class="line-number">55</span>
<span class="line-number">56</span>
<span class="line-number">57</span>
<span class="line-number">58</span>
<span class="line-number">59</span>
<span class="line-number">60</span>
<span class="line-number">61</span>
<span class="line-number">62</span>
<span class="line-number">63</span>
<span class="line-number">64</span>
<span class="line-number">65</span>
<span class="line-number">66</span>
<span class="line-number">67</span>
<span class="line-number">68</span>
<span class="line-number">69</span>
<span class="line-number">70</span>
<span class="line-number">71</span>
<span class="line-number">72</span>
<span class="line-number">73</span>
<span class="line-number">74</span>
<span class="line-number">75</span>
<span class="line-number">76</span>
<span class="line-number">77</span>
<span class="line-number">78</span>
<span class="line-number">79</span>
<span class="line-number">80</span>
<span class="line-number">81</span>
<span class="line-number">82</span>
<span class="line-number">83</span>
<span class="line-number">84</span>
<span class="line-number">85</span>
<span class="line-number">86</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="nb">require</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span><span class="p">(</span><span class="s1">&#39;../../../spec_helper&#39;</span><span class="p">,</span> <span class="bp">__FILE__</span><span class="p">)</span>
</span><span class="line">
</span><span class="line"><span class="nb">require</span> <span class="s1">&#39;hamster/list&#39;</span>
</span><span class="line">
</span><span class="line"><span class="n">describe</span> <span class="s2">&quot;Hamster.list#span&quot;</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">  <span class="n">it</span> <span class="s2">&quot;is lazy&quot;</span> <span class="k">do</span>
</span><span class="line">    <span class="nb">lambda</span> <span class="p">{</span> <span class="no">Hamster</span><span class="o">.</span><span class="n">stream</span> <span class="p">{</span> <span class="o">|</span><span class="n">item</span><span class="o">|</span> <span class="nb">fail</span> <span class="p">}</span><span class="o">.</span><span class="n">span</span> <span class="p">{</span> <span class="kp">true</span> <span class="p">}</span> <span class="p">}</span><span class="o">.</span><span class="n">should_not</span> <span class="n">raise_error</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="n">describe</span> <span class="o">&lt;&lt;-</span><span class="no">DESC</span> <span class="k">do</span>
</span><span class="line"><span class="sh">given a predicate (in the form of a block), splits the list into two lists</span>
</span><span class="line"><span class="sh">  (returned as a tuple) such that elements in the first list (the prefix) are</span>
</span><span class="line"><span class="sh">  taken from the head of the list while the predicate is satisfied, and elements</span>
</span><span class="line"><span class="sh">  in the second list (the remainder) are the remaining elements from the list</span>
</span><span class="line"><span class="sh">  once the predicate is not satisfied. For example:</span>
</span><span class="line"><span class="no">DESC</span>
</span><span class="line">
</span><span class="line">    <span class="o">[</span>
</span><span class="line">      <span class="o">[[]</span><span class="p">,</span> <span class="o">[]</span><span class="p">,</span> <span class="o">[]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">1</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="o">]</span><span class="p">,</span> <span class="o">[]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">3</span><span class="o">]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">2</span><span class="o">]</span><span class="p">,</span> <span class="o">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="o">[]</span><span class="p">,</span> <span class="o">[</span><span class="mi">3</span><span class="p">,</span> <span class="mi">4</span><span class="o">]]</span><span class="p">,</span>
</span><span class="line">      <span class="o">[[</span><span class="mi">4</span><span class="o">]</span><span class="p">,</span> <span class="o">[]</span><span class="p">,</span> <span class="o">[</span><span class="mi">4</span><span class="o">]]</span><span class="p">,</span>
</span><span class="line">    <span class="o">].</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">values</span><span class="p">,</span> <span class="n">expected_prefix</span><span class="p">,</span> <span class="n">expected_remainder</span><span class="o">|</span>
</span><span class="line">
</span><span class="line">      <span class="n">describe</span> <span class="s2">&quot;given the list </span><span class="si">#{</span><span class="n">values</span><span class="o">.</span><span class="n">inspect</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">        <span class="n">before</span> <span class="k">do</span>
</span><span class="line">          <span class="vi">@original</span> <span class="o">=</span> <span class="no">Hamster</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">*</span><span class="n">values</span><span class="p">)</span>
</span><span class="line">        <span class="k">end</span>
</span><span class="line">
</span><span class="line">        <span class="n">describe</span> <span class="s2">&quot;and a predicate that returns true for values &lt;= 2&quot;</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">          <span class="n">before</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@result</span> <span class="o">=</span> <span class="vi">@original</span><span class="o">.</span><span class="n">span</span> <span class="p">{</span> <span class="o">|</span><span class="n">item</span><span class="o">|</span> <span class="n">item</span> <span class="o">&lt;=</span> <span class="mi">2</span> <span class="p">}</span>
</span><span class="line">            <span class="vi">@prefix</span> <span class="o">=</span> <span class="vi">@result</span><span class="o">.</span><span class="n">first</span>
</span><span class="line">            <span class="vi">@remainder</span> <span class="o">=</span> <span class="vi">@result</span><span class="o">.</span><span class="n">last</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;preserves the original&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@original</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="no">Hamster</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">*</span><span class="n">values</span><span class="p">)</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;returns the prefix as </span><span class="si">#{</span><span class="n">expected_prefix</span><span class="o">.</span><span class="n">inspect</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@prefix</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="no">Hamster</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">*</span><span class="n">expected_prefix</span><span class="p">)</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;returns the remainder as </span><span class="si">#{</span><span class="n">expected_remainder</span><span class="o">.</span><span class="n">inspect</span><span class="si">}</span><span class="s2">&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@remainder</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="no">Hamster</span><span class="o">.</span><span class="n">list</span><span class="p">(</span><span class="o">*</span><span class="n">expected_remainder</span><span class="p">)</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">        <span class="k">end</span>
</span><span class="line">
</span><span class="line">        <span class="n">describe</span> <span class="s2">&quot;without a predicate&quot;</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">          <span class="n">before</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@result</span> <span class="o">=</span> <span class="vi">@original</span><span class="o">.</span><span class="n">span</span>
</span><span class="line">            <span class="vi">@prefix</span> <span class="o">=</span> <span class="vi">@result</span><span class="o">.</span><span class="n">first</span>
</span><span class="line">            <span class="vi">@remainder</span> <span class="o">=</span> <span class="vi">@result</span><span class="o">.</span><span class="n">last</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;returns a tuple&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@result</span><span class="o">.</span><span class="n">is_a?</span><span class="p">(</span><span class="no">Hamster</span><span class="o">::</span><span class="no">Tuple</span><span class="p">)</span><span class="o">.</span><span class="n">should</span> <span class="o">==</span> <span class="kp">true</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;returns self as the prefix&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@prefix</span><span class="o">.</span><span class="n">should</span> <span class="n">equal</span><span class="p">(</span><span class="vi">@original</span><span class="p">)</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">          <span class="n">it</span> <span class="s2">&quot;returns an empty list as the remainder&quot;</span> <span class="k">do</span>
</span><span class="line">            <span class="vi">@remainder</span><span class="o">.</span><span class="n">should</span> <span class="n">be_empty</span>
</span><span class="line">          <span class="k">end</span>
</span><span class="line">
</span><span class="line">        <span class="k">end</span>
</span><span class="line">
</span><span class="line">      <span class="k">end</span>
</span><span class="line">
</span><span class="line">    <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Lazy spec task creation]]></title>
    <link href="http://www.harukizaemon.com/blog/2010/01/21/lazy-spec-task-creation/"/>
    <updated>2010-01-21T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2010/01/21/lazy-spec-task-creation</id>
    <content type="html"><![CDATA[<p>I converted a Ruby project over to use <a href="http://github.com/wycats/bundler">Bundler</a> for gem dependency management today. For the most part it worked flawlessly except, that is, when the CI build ran for the first time after the conversion:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
</pre></td><td class="code"><pre><code class="console"><span class="line"><span class="go">LoadError: no such file to load -- vendor/gems/environment</span>
</span><span class="line">
</span><span class="line"><span class="go">Stacktrace:</span>
</span><span class="line"><span class="go">tasks/spec.rb:8:in `require&#39;</span>
</span><span class="line"><span class="go">tasks/spec.rb:8:in `&lt;top (required)&gt;&#39;</span>
</span><span class="line"><span class="go">...</span>
</span><span class="line"><span class="go">Rake aborted!</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The short story: The spec task definition needed the RSpec gem to be loaded but it wasn’t until <em>after</em> all tasks had been defined.</p>

<p>Now, I could single out the spec task definition and ensure it was loaded last but that would mean adding a bunch of code to my otherwise trivial <code>Rakefile</code>. The other option was to somehow defer the creation of the spec task until actually needed. After a bit of searching I couldn’t find anything particularly useful so I rolled my own:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
<span class="line-number">6</span>
<span class="line-number">7</span>
<span class="line-number">8</span>
<span class="line-number">9</span>
<span class="line-number">10</span>
<span class="line-number">11</span>
<span class="line-number">12</span>
<span class="line-number">13</span>
<span class="line-number">14</span>
<span class="line-number">15</span>
<span class="line-number">16</span>
<span class="line-number">17</span>
<span class="line-number">18</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="n">namespace</span> <span class="ss">:spec</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">  <span class="n">desc</span> <span class="s2">&quot;Run specifications&quot;</span>
</span><span class="line">  <span class="n">task</span> <span class="ss">:run</span> <span class="o">=&gt;</span> <span class="ss">:define</span> <span class="k">do</span>
</span><span class="line">    <span class="no">Rake</span><span class="o">::</span><span class="no">Task</span><span class="o">[</span><span class="ss">:_run</span><span class="o">].</span><span class="n">invoke</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="n">task</span> <span class="ss">:define</span> <span class="k">do</span>
</span><span class="line">
</span><span class="line">    <span class="nb">require</span> <span class="s1">&#39;spec/rake/spectask&#39;</span>
</span><span class="line">
</span><span class="line">    <span class="no">Spec</span><span class="o">::</span><span class="no">Rake</span><span class="o">::</span><span class="no">SpecTask</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="ss">:_run</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">t</span><span class="o">|</span>
</span><span class="line">      <span class="n">t</span><span class="o">.</span><span class="n">spec_opts</span> <span class="o">&lt;&lt;</span> <span class="s2">&quot;--options&quot;</span> <span class="o">&lt;&lt;</span> <span class="s2">&quot;spec/spec.opts&quot;</span> <span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span><span class="p">(</span><span class="s2">&quot;spec/spec.opts&quot;</span><span class="p">)</span>
</span><span class="line">    <span class="k">end</span>
</span><span class="line">
</span><span class="line">  <span class="k">end</span>
</span><span class="line">
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>The <code>spec:run</code> task depends on the <code>spec:define</code> task to create a “hidden” <code>spec:_run</code> task to actually do the work.</p>

<p>The nice thing about this all the ickiness is hidden – remove the <code>tasks/spec.rb</code> file and nothing else really cares – and means I can treat the spec task like any other when creating my task dependencies.</p>

<p>As always, YMMV.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why Object-Oriented Languages Need Tail Calls]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/12/24/why-object-oriented-languages-need-tail-calls/"/>
    <updated>2009-12-24T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/12/24/why-object-oriented-languages-need-tail-calls</id>
    <content type="html"><![CDATA[<p>Disclaimer: I unashamedly stole the title after reading <a href="http://projectfortress.sun.com/Projects/Community/blog/ObjectOrientedTailRecursion">another article</a> on the same topic.</p>

<p>Some of you may know of a <a href="http://github.com/harukizaemon/hamster">little project</a> I’ve been working on in my, albeit very limited, spare time. Hamster started out as an implementation of <a href="http://lamp.epfl.ch/papers/idealhashtrees.pdf">Hash Array Mapped Trees</a> (HAMT) for Ruby and has since expanded to include implementations of other <a href="http://en.wikipedia.org/wiki/Persistent_data_structure">Persistent Data Structures</a> such as Sets, Lists, Stacks, etc.</p>

<p>For those that aren’t up with HAMTs or persistent data structures in general, they have a really neat property: very efficient copy-on-write operations. This allows us to create immutable data-structures that only need copying when something changes, making them a very effective when writing multi-threaded code.</p>

<p>Hamster also contains an implementation of <a href="http://en.wikipedia.org/wiki/Cons">Cons Lists</a> with all the usual methods you’d expect from a Ruby collection such as <code>map</code>, <code>select</code>, <code>reject</code>, etc. thrown in for good measure.</p>

<p>One of the things I really wanted to investigate was laziness. So, for example, when evaluating:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="no">Hamster</span><span class="o">.</span><span class="n">interval</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1000000</span><span class="p">)</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:odd?</span><span class="p">)</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="mi">10</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Rather than generate a list with a million values, evaluate them all against the filter, and then select the first ten, Hamster lazily generates the list, the evaluation of <code>filter</code>, and even <code>take</code>. In fact, as it stands, the example code won’t <em>actually</em> do anything; you would need to call <code>head</code> to kick-start anything happening at all. This behaviour extends, to the extent possible, to all other collection methods.</p>

<p>Hamster also supports infinite lists. For example, the following code produces an infinite list of integers:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="k">def</span> <span class="nf">integers</span>
</span><span class="line">  <span class="n">value</span> <span class="o">=</span> <span class="mi">0</span>
</span><span class="line">  <span class="no">Hamster</span><span class="o">.</span><span class="n">stream</span> <span class="p">{</span> <span class="n">value</span> <span class="o">+=</span> <span class="mi">1</span> <span class="p">}</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Now we can easily generate a list of odd numbers:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="n">integers</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:odd?</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Again, rather than generate every possible integer and filter those into odd numbers, the list is generated as necessary.</p>

<p>OK, so enough with the apparent shameless self-promotion. Let’s get to the point.</p>

<p>My first implementation of lists used recursion for collection methods. The code was succinct, and, IMHO elegant. It conveyed the essence of what I was trying to achieve. It was easier to understand and thus, I would surmise, easier to maintain. The problem was that for any reasonably large list, stack overflows were common place. The lack of Tail-Call-Optimisation (TCO) meant that the recursive code would eventually blow whatever arbitrary stack limits were in place. The solution: convert the recursive code to an equivalent iterative form.</p>

<p>Once all methods had been re-implemented using iteration, the code ran just fine on large lists; no more stack overflow errors. The downside was, the code had almost doubled in size–1~2 lines of code became 2~4 or in some cases even more. The code was now harder to read and far less intention revealing. In short, the lack of Tail-Call-Optimisation lead to less maintainable and I’d hazard a guess, more error prone code.</p>

<p>The story however, doesn’t end there. Take another (albeit contrived) example that partitions integers into odds and evens:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="n">partitions</span> <span class="o">=</span> <span class="n">integers</span><span class="o">.</span><span class="n">partition</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:odd?</span><span class="p">)</span>
</span><span class="line"><span class="n">odds</span> <span class="o">=</span> <span class="n">partitions</span><span class="o">.</span><span class="n">car</span>
</span><span class="line"><span class="n">evens</span> <span class="o">=</span> <span class="n">partitions</span><span class="o">.</span><span class="n">cadr</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>You would expect <code>odds</code> to contain <code>[1, 3, 5, 7, 9, ...]</code>, and <code>evens</code> to contain <code>[2, 4, 6, 8, 10, ...]</code>. But the way I initially implemented the code it didn’t. Here’s an example to show what happened:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="n">odds</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>    <span class="c1"># =&gt; [1, 3, 5, 7, 9]</span>
</span><span class="line"><span class="n">evens</span><span class="o">.</span><span class="n">take</span><span class="p">(</span><span class="mi">5</span><span class="p">)</span>   <span class="c1"># =&gt; [2, 12, 14, 16, 18]</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Confused? So was I until it dawned on me that I had broken a fundamental principle: immutability. The underlying block that generates the list of integers has state! Enumerating the odd values first produces the expected results but once we get around to enumerating the even values, the state of the block is such that it no longer starts at 1–reversing the order of enumeration produces a corresponding reversal of the error. Pure functional Languages such as Haskell have mechanisms for dealing with this but in Ruby, the only construct I really have available to me is explicit caching of generated values.</p>

<p>Once I had cached the values all was well, or so I thought. I started to write some examples that used files as lists:</p>

<div class="bogus-wrapper"><notextile><figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
<span class="line-number">2</span>
<span class="line-number">3</span>
<span class="line-number">4</span>
<span class="line-number">5</span>
</pre></td><td class="code"><pre><code class="ruby"><span class="line"><span class="no">File</span><span class="o">.</span><span class="n">open</span><span class="p">(</span><span class="s2">&quot;my_100_mb_file.txt&quot;</span><span class="p">)</span> <span class="k">do</span> <span class="o">|</span><span class="n">io</span><span class="o">|</span>
</span><span class="line">  <span class="n">io</span><span class="o">.</span><span class="n">to_list</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:chomp</span><span class="p">)</span><span class="o">.</span><span class="n">map</span><span class="p">(</span><span class="o">&amp;</span><span class="ss">:downcase</span><span class="p">)</span><span class="o">.</span><span class="n">each</span> <span class="k">do</span> <span class="o">|</span><span class="n">line</span><span class="o">|</span>
</span><span class="line">    <span class="nb">puts</span> <span class="n">line</span>
</span><span class="line">  <span class="k">end</span>
</span><span class="line"><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure></notextile></div>

<p>Running the code above took forever to run, much slower than the non-list equivalent. I expected a little slow down sure, but nothing like that which I was seeing.</p>

<p>At first I suspected garbage collection–perhaps the virtual machine was being crushed by the sheer number of discarded objects; I could find no evidence for this. Next, I suspected synchronisation–anything with state needs synchronisation. Again, I found no evidence for this either. A bit more fiddling and a few dozen print statements later–Ruby has no real profiling tools that I’m aware of, something that frustrates me no end at times–I realised what the problem was.</p>

<p>When I failed to find any evidence of garbage collection as the culprit, it had seemed a bit odd but I wasn’t sure why I felt that way and thus moved on. Had I stopped and thought about it for a while I may have realised that in fact that was <em>exactly</em> the problem: there was NO evidence of garbage collection at all. How could that be? Processing hundreds of thousands of lines in a 100MB text file using a linked list was sure to generate lots of garbage. Once a line had been processed, the corresponding list element should no longer have been referenced and thus made available for garbage collection, unless… unless for some mysterious reason each element was still being referenced.</p>

<p>My caching implementation worked like this: As each value is generated, it’s stored in an element and linked to from the previous element: <code>[A] -&gt; [B] -&gt; [C]</code>. At face value this works well–if you never hold a references to “A” or “B”, they will become available for garbage collection. So what could possibly have been going wrong? Each line was being processed and then discarded. Surely, that meant each corresponding element should have become available for garbage collection?</p>

<p>Now recall that I had converted the recursive code to an iterative equivalent. This had now come back to bite me, hard!–though to be fair the recursive code would have suffered in a similar and perhaps more obvious way. The call to <code>map</code> runs in the context of the very first line which, because of the caching, directly and indirectly references every other line that is processed! The lack of Tail-Call-Optimisation in Ruby means that whether I use recursion or iteration, if I process all elements from the head of a stream, the garbage collector can never reclaim anything because the head element is always referenced until the end of the process!</p>

<p>Some of my colleagues have suggested that I just get over it and use a “real” language like <a href="http://clojure.org/">Clojure</a>. Whilst I understand the sentiment, the point of Hamster is not necessarily to implement a functional language in Ruby. Rather, it is to see what can be done in object-oriented languages and, in this case, Ruby.</p>

<p>Hamster has allowed me to demonstrate that functional language idioms can, for the most part, translate quite well into object-oriented equivalents. However, the lack of Tail-Call-Optimisation severely limits what is possible.</p>

<p><strong>Update 2009/12/30</strong>: MacRuby supports a limited form of TCO as well. I received similar results as for YARV (see below) the differences being you’re not limited to the call being the <em>last</em> statement in the method and there’s a bug where you receive a segmentation fault rather than a stack overflow.</p>

<p><strong>Update 2009/12/27</strong>: According to <a href="http://redmine.ruby-lang.org/issues/show/1256">this redmine ticket</a>, YARV has some limited TCO support which is disabled by default. I performed the necessary incantations to enable it, only to discover the true meaning of “limited”: optimise calls to the same method in the same instance <em>iff</em> the call is the last statement in the method.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Responsibility Traps]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/10/31/responsibility-traps/"/>
    <updated>2009-10-31T00:00:00+11:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/10/31/responsibility-traps</id>
    <content type="html"><![CDATA[<p>I recently watched a wonderfully insightful presentation by Eric Evans on <a href="http://www.infoq.com/presentations/design-strategic-eric-evans">Responsibility Traps</a>. In it he describes a number of traps into which otherwise well meaning and capable developers fall. Among others these include:</p>

<ul>
  <li>Building a platform to make other (lesser) programmers more productive</li>
  <li>Cleaning up other people’s mess; being a janitor</li>
  <li>Making hackers (pejorative) look even better</li>
</ul>

<p>He concludes that the responsible developer often focuses her energy on solving the wrong problem, incorrectly believing it to be in the best interests of the project/company/etc. as a whole.</p>

<p>Since then I have subconsciously been on the lookout for other areas of life where this anti-pattern arises and to my delight (or perhaps horror), I see it everywhere.</p>

<p>I thought about the number of relationships that I had dragged on for much longer than was probably good for either party, where, as a result of my desire to avoid hurting anyone, both parties suffered needlessly.</p>

<p>I spoke with a colleague who told me how, in a recent attempt to both fulfil his unspoken promise to help a project out of trouble and preserve the reputation of his sponsors, he continued to engage with the client well beyond his own reasonable belief of success. A near stress-related break down followed shortly thereafter leading to strained relationships all ‘round.</p>

<p>I can’t count the number of times I’ve tried to “rescue” a project I thought was doomed to failure, implement an unnecessarily complex story, “protect” a friend/relative/colleague/client from some bad news. In almost all cases the outcome was as bad as, if not worse than, it might have been had I confronted the reality at the outset.</p>

<p>Why do I fall into these traps when I believe I’m primarily motivated by of a sense of duty and responsibility? Partly I think it’s about taking a path of least resistance – It seems easier to try and press ahead to “fix” the symptom than to address the underlying cause; partly it’s about self-esteem – I’m a failure unless I can solve the problem; there’s an aspect of self-importance – few others can see what I see, so it’s up to me to do something about it. And then there’s just a plain old misguided sense of responsibility.</p>

<p>Many years ago, someone handed me a copy of a Garfield cartoon – ironically it was probably a technically illegal copy. The cartoon showed Garfield in bed on a Monday morning with Jon telling him to “Get out of bed Garfield!” Garfield wonders to himself “What’s my motivation?” Taken literally that doesn’t really say much but the message it has left with me is to be honest with myself about what really drives my decisions.</p>

<p>As a professional software developer, I believe I have a duty of care to act in the best interests of my employer even if that means delivering the news nobody wants to hear– “I think we’d be better off killing this project than sinking anymore money into it.” – and that doing so is ultimately better for me as well.</p>

<p>More often than not, the way a message is received has far more to do with the way in which it is delivered than with the substance of the message itself. Telling someone they’re screwed unless they do what you say probably won’t get you anywhere; suggesting humbly that they are spending double what they could be paying if all they are after is someone who’ll unquestioningly implement whatever whacky ideas they present, has historically worked out much better for me.</p>

<p>I’ve come to the conclusion that, more important than acting responsibly is to act ethically – fairly and honestly. If you act ethically you will necessarily end up acting responsibly but not necessarily the other way ‘round. Acting ethically takes courage, determination and optimism and that’s bloody hard work™. I encourage you to be brave, take a risk, act ethically and do the right thing.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Plugins: Grab 'em while they're stale]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/09/19/plugins-grab-em-while-theyre-stale/"/>
    <updated>2009-09-19T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/09/19/plugins-grab-em-while-theyre-stale</id>
    <content type="html"><![CDATA[<p>I don’t like leaving unused code lying around, unused applications installed, unused clothes in the wardrobe, etc. As a consequence I’m often referred to as ‘Mr. Detritus’.</p>

<p>As you probably know, I’ve created a number of Ruby on Rails plugins over the years. Most of them when I first started out with Rails and for that matter, Ruby. Most of them had poor (if any) test coverage and the code looked generally like a dog’s breakfast but they satisfied a need – scratched an itch if you like – I had at the time.</p>

<p>Time marches on and although I will continue to use Ruby as a language, I no longer have any desire to use Rails. Some of my plugins ended up in Rails core, I’ve continued to use others on recent projects but most of them have been left to rot – some of them I wouldn’t use even if I did another Rails project having long since considered them failed experiments.</p>

<p>And so it is that I will very shortly (within the next month) delete most of the plugins from my <a href="http://github.com/harukizaemon">GitHub account</a>. If you wish to continue using them, feel free to fork and keep a copy for yourself. Republish them under your own name if you wish for they will no doubt be better cared for by you than me.</p>

<p><strong>Update:</strong> By popular demand, a <a href="http://github.com/harukizaemon/redhillonrails">Once off never to be repeated copy of the UNSUPPORTED Rails plugins</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Random thoughts on our current Agile process]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/08/31/random-thoughts-on-our-current-agile/"/>
    <updated>2009-08-31T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/08/31/random-thoughts-on-our-current-agile</id>
    <content type="html"><![CDATA[<p>It’s late and I don’t seem to be able to sleep so for something to do I thought I’d jot down (ok copy from an email I sent out earlier in the week) some thoughts about our development process as it has evolved over the last few months or so.</p>

<p>As always, I can only speak from personal experience (one data point doesn’t really count for much) so here’s my totally subjective perspective, YMMV:</p>

<ul>
  <li>Full-time pairing when possible/practical</li>
  <li>No more than one card per pair in dev at any time</li>
  <li>No more than one card per pair in ready-for-dev at any time</li>
  <li>Nothing to be blocked; If it’s blocked we work to remove the blockage</li>
  <li>New cards are demand pulled into read-for-dev as cards are moved from dev to ready-for-test</li>
  <li>We have big picture story card sessions as required</li>
  <li>We have planning meetings at the start of each iteration where we discuss what’s “planned”</li>
  <li>We give everything t-shirt sizes (S, M, L)</li>
  <li>No technical stories; everything must be done because it delivers business value</li>
  <li>We don’t measure velocity</li>
  <li>We aggressively split cards</li>
  <li>I repeat, we aggressively split cards</li>
  <li>Daily stand-ups</li>
  <li>Parking lot for post-stand up discussions</li>
  <li>2-week iterations with retro followed by a kick-off to discuss the stories</li>
  <li>We try to focus on doing things as simply as possible</li>
  <li>We try to focus on building things correctly rather than as fast as possible</li>
  <li>We fight to have a REAL user available to better understand their needs</li>
  <li>We rally against the usual cries of “but I know we’ll need it”; We trust that by building things simply we can always add on the extra functionality later</li>
  <li>Trying to deliver everything to everyone leads to delivering nothing at all to anyone</li>
  <li>T-shirt sizes help the business prioritise not estimate delivery dates; Business value is a function of, among other things, time/cost to build</li>
  <li>Rolling technical stories into stories that deliver business value force us to change course slowly and justify changes</li>
  <li>We usually have parallel implementations of some things as a consequence</li>
  <li>Minimal changes are allowed on “old” implementations; anything substantial requires a migration to the “new” implementation</li>
  <li>If we can deliver <em>some</em> business value early by splitting the cards we do so as soon as possible; Eg. business can view existing data in the new form but editing is a new card because they can still use the old mechanism for that.</li>
  <li>It’s critical that the whole team is taken on the “journey” so they understand <em>why</em> things are being built. Doing so brings the team into alignment and also allows the team to make informed decisions such as re-structuring work to enable splitting cards for aggressively.</li>
  <li>Bringing the team along for the journey can be painful, never gets easier, and is always worth the effort.</li>
  <li>Just-in-time stories really does enable the business to leave the decision as to what’s important to the last possible moment</li>
  <li>Implementing the smallest amount of code possible for each story is critical to enabling just-in-time development; less code == greater flexibility; E.g. don’t use a database when the data comes from a spreadsheet and presently only ever changes in a spreadsheet.</li>
  <li>We do as much forward thinking as possible/practical; We think of as many likely scenarios as we can and keep reducing the scope of the implementation so as not to preclude implementing them later on</li>
  <li>Almost nothing ends up looking as we thought it would when first envisaged.</li>
  <li>More important than writing the code is working out how to structure the implementation so that we get the job done without precluding possible future work; sometimes this means at least thinking through a strategy for migrating from one implementation to another later on if necessary.</li>
  <li>It’s amazing how splitting stories reveals just how little the business value certain aspects of stories</li>
  <li>We almost never get through everything that was “planned”</li>
  <li>We almost always end up doing stories that weren’t “planned”</li>
  <li>We are as close as we can get (due to the bureaucratic nature of the client’s operations group) to on-demand deployment into production. Ideally we’d like it to be automated but that’s just not going to happen anytime soon</li>
  <li>We’re motivated by getting things done; call that velocity if you will but we really haven’t found a need to measure velocity. Delivering a constant stream of small but valuable stuff into production every week is VERY motivating.</li>
  <li>We value delivering something over delivering nothing</li>
  <li>
    <p>We actively plan for change
Caveats:</p>
  </li>
  <li>We have a highly competent team</li>
  <li>We have a fixed budget</li>
  <li>We have internal and external users</li>
  <li>We have UI and data-only users</li>
  <li>We have an existing implementation we are evolving away from
It’s far from perfect and is constantly evolving but as <a href="http://www.prozacblues.com/">Travis</a> observed, it kinda represents a snapshot of what being Agile means to me right now.</li>
</ul>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[We're Recruiting]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/08/01/were-recruiting/"/>
    <updated>2009-08-01T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/08/01/were-recruiting</id>
    <content type="html"><![CDATA[<p>If you haven’t heard already, <a href="http://www.cogentconsulting.com.au/">Cogent Consulting</a> are recruiting.</p>

<p>Cogent Consulting prides itself on the depth of its experience with agile software  development, and its ability to leverage this experience to benefit Cogent clients. We are an open-book company, with comprehensive employee participation in decision-making.</p>

<p>What do we do? We’re a three part story. We go out on site as consultants to help our clients get better at producing good software, by both coaching them in agile techniques and working as integral part of their development teams. We produce high-quality websites  for clients from our own premises. Finally, we build our own (mostly web-based) products, using the range of great talents that make up our team.</p>

<p>Right now we’re looking for people who can perform hands-on web application development both in our offices and on client sites, predominantly in Ruby on Rails.</p>

<p>We’re also looking for people who can provide hands-on support to clients undertaking agile transformations at both the small and large scale, as well as help out with internal product development</p>

<p>In either case You’ll need to show us that you:</p>

<ul>
  <li>understand the principles of agile software development and have experience working on agile projects</li>
  <li>are collaborative, but willing to be a benevolent dictator when required</li>
  <li>can represent us on a client site in a way that makes us proud</li>
  <li>have a passion for software development and you continue your professional development outside of work hours</li>
  <li>have experience with Ruby on Rails, or you are able to learn it very quickly. Extra points if you’re a Smalltalk or Haskell expert</li>
  <li>understand that “done” means the software is in production</li>
  <li>have a demonstrated track record of successful delivery</li>
  <li>have a passion for software development and you continue your professional development outside of work hours</li>
  <li>think that the time after five o’clock belongs to your family (yes, that’s contradictory - we want to know how you deal with that contradiction)</li>
  <li>understand that software and process should be opinionated, but not bigoted</li>
  <li>can read, you choose to read, and you understand what you read</li>
  <li>are intellectually omnivorous</li>
  <li>consider communication (written and verbal) to be amongst your strongest skills</li>
</ul>

<p>In return, we’ll provide you with a collegial environment that rewards inquisitiveness rather than being an ongoing inquisition. We’ll treat you as part of the Cogent family, and give you a share of the profit and/or the products that we develop. We’ll provide an environment where you can work with your peers, be challenged, and be the best that you can be.</p>

<p>If this sounds like your thing, you can visit our <a href="http://www.cogentconsulting.com.au/">website</a> for more information about Cogent, or email us directly: <a href="mailto:info@cogentconsulting.com.au">info@cogentconsulting.com.au</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Less delicious, yet more satisfying]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/07/14/less-delicious-yet-more-satisfying/"/>
    <updated>2009-07-14T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/07/14/less-delicious-yet-more-satisfying</id>
    <content type="html"><![CDATA[<p>These days, I spread my research and reading between <a href="http://www.instapaper.com/">Instapaper</a> and <a href="http://evernote.com/">Evernote</a>. IMHO, <a href="http://delicious.com/">delicious</a> is essentially a big old shed with crap in it and no way to actually use any of it other than marvel at how much stuff I’ve collected.</p>

<p>On the other hand, both Instapaper and Evernote add value to the stuff I’ve collected: Instapaper allows me to read blogs and websites on my phone, and Evernote allows me to collect and organise information according to project, tags, etc.</p>

<p>As <a href="http://www.prozacblues.com/">Travis</a> pointed out, this makes it difficult (nay impossible) for others to see what I’m reading and is largely the reason I send out almost daily emails to colleagues on stuff I think is more generally interesting.</p>

<p>This morning I noticed that Instapaper helpfully provide a read-only feed of my list. So, for anyone interested, here is the link: <a href="http://www.instapaper.com/rss/175381/1rDOvQp1xwBTeMIoml2TuzPjlmM">http://www.instapaper.com/rss/175381/1rDOvQp1xwBTeMIoml2TuzPjlmM</a></p>

<p><strong>Update:</strong>If you’d rather not wade through everything I read to find the good bits, I’ve started “starring” items I found insightful and/or think are of more general interest. Here’s the feed: <a href="http://www.instapaper.com/starred/rss/175381/ttNEuQvOmmM5sX94f0HCO7ns">http://www.instapaper.com/starred/rss/175381/ttNEuQvOmmM5sX94f0HCO7ns</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Problem Solving]]></title>
    <link href="http://www.harukizaemon.com/blog/2009/06/25/problem-solving/"/>
    <updated>2009-06-25T00:00:00+10:00</updated>
    <id>http://www.harukizaemon.com/blog/2009/06/25/problem-solving</id>
    <content type="html"><![CDATA[<p>It occurred to me recently that I have this notion of programming as a process that involves breaking a problem down into a sets of smaller and smaller problems until I have something I know how to solve. (I mentioned this to <a href="http://iridescenturchin.blogspot.com/">Steve</a> yesterday which reminded him of a <a href="http://www.electronics.dit.ie/staff/sofearghail/mathematicians.htm">joke about an engineer and a mathematician</a>.)</p>

<p>I have previously just assumed that I therefore follow this process when I’m actually problem solving however, on reflection, I’n not so sure. More specifically, I’m either not doing it at all or, at the very least, I’m doing it intuitively.</p>

<p>I wonder how many people do (or have done) this as an explicit part of their own problem solving and if so, what effects they’ve noticed as a consequence.</p>
]]></content>
  </entry>
  
</feed>
