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

<channel>
	<title>Gareth Townsend</title>
	<atom:link href="http://blog.garethtownsend.info/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.garethtownsend.info</link>
	<description></description>
	<lastBuildDate>Tue, 20 Sep 2011 01:25:16 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
		<item>
		<title>May I redirect your attention</title>
		<link>http://blog.garethtownsend.info/2011/09/may-i-redirect-your-attention/</link>
		<comments>http://blog.garethtownsend.info/2011/09/may-i-redirect-your-attention/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 01:25:16 +0000</pubDate>
		<dc:creator>Gareth Townsend</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.garethtownsend.info/?p=78</guid>
		<description><![CDATA[I&#8217;ve started blogging again, but not here. If you&#8217;re still subscribed, and you&#8217;re interested in programming and design nerdery, you might want to direct your feed reader at Inject is for Wizards.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve started blogging again, but not here. </p>
<p>If you&#8217;re still subscribed, and you&#8217;re interested in programming and design nerdery, you might want to direct your feed reader at <a href="http://injectisforwizards.com">Inject is for Wizards</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethtownsend.info/2011/09/may-i-redirect-your-attention/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Programming Erlang, Chapter 8, Exercise 2</title>
		<link>http://blog.garethtownsend.info/2010/11/programming-erlang-chapter-8-exercise-2/</link>
		<comments>http://blog.garethtownsend.info/2010/11/programming-erlang-chapter-8-exercise-2/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 08:56:17 +0000</pubDate>
		<dc:creator>Gareth Townsend</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Erlang]]></category>

		<guid isPermaLink="false">http://blog.garethtownsend.info/?p=44</guid>
		<description><![CDATA[After reading Joe Armstrong&#8217;s Programming Erlang on and off for about half a year I finally took the time during our recent i7 to sit down really get stuck into it. At the end of Chapter 8, Joe sets the first real programming tasks in the book: Write a ring benchmark. Create N processes in [...]]]></description>
			<content:encoded><![CDATA[<p>After reading Joe Armstrong&#8217;s <a href="http://pragprog.com/titles/jaerlang/programming-erlang">Programming Erlang</a> on and off for about half a year I finally took the time during our recent <abbr title="iteration 7">i7</abbr> to sit down really get stuck into it.</p>
<p>At the end of Chapter 8, Joe sets the first real programming tasks in the book:</p>
<blockquote>
<p>Write a ring benchmark. Create N processes in a ring. Send a message round the ring M times so that a total of N * M messages get sent. Time how long this takes for different values of N and M.</p>
</blockquote>
<p>Here&#8217;s my implementation, explained.</p>
<p>As we&#8217;re building a benchmark, the first thing we need to do is set up the timing code. Thankfully Joe covered this in a previous part of the book.</p>
<p><script src="https://gist.github.com/703130.js"> </script></p>
<p>In line 1 we declare the module, we need this in order to compile and run the code. Line 2 tells the erlang compiler to make all functions public, usually we would declare which functions can be exported or made public, but this isn&#8217;t production code so we&#8217;ll give ourselves access to everything.</p>
<p>Line 4 is a function declaration, all the code after the <code>-></code> symbol is contained in the function. So we&#8217;ve declared a function called <code>ringBenchmark</code> that takes three arguments: <code>NumberOfNodes</code>, <code>_Message</code> and <code>NumberOfLaps</code>.</p>
<p>The underscore in _Message tells the erlang compiler that we don&#8217;t care about this variable, so don&#8217;t complain about the fact that we don&#8217;t use it anywhere.</p>
<p>Using the <code><a href="http://www.erlang.org/doc/man/erlang.html#statistics-1">statistics/1</a></code> <abbr title="Built in Function">BIF</abbr> we can check the runtime (sum of run time of all erlang threads) and the wall_clock (real time passed). Each of these functions return the total time, and the time since the last call, in milliseconds.</p>
<p>In Lines 4 and 6 we run each of these methods once, then again in lines 7 and 8, capturing the time since last call of each. Finally we print them out in line 9. </p>
<p>Save the file as e21.erl and play along in the shell!</p>
<p><script src="https://gist.github.com/703132.js"> </script></p>
<p>It works, but it doesn&#8217;t really do anything just yet. The exercise requires that we create a ring of precesses and pass a message around them. So lets create the first process and give it something to do.</p>
<p><script src="https://gist.github.com/703135.js"> </script></p>
<p>To create a new process in erlang we can use the version of the <code><a href="http://www.erlang.org/doc/man/erlang.html#spawn-3">spawn/3</a></code> <abbr title="Built in Function">BIF</abbr> that takes 3 arguments: <code>Module</code>, <code>Function</code> and <code>Args</code>. It returns a <abbr title="process identifier">pid</abbr>.</p>
<p>This is done on line 8, we spawn a new process of the same module, running the <code>loop</code> function with an empty list as the arguments.</p>
<p>The <code>loop</code> function is defined on 14. It does nothing other than print the argument it was given.</p>
<p><script src="https://gist.github.com/703137.js"> </script></p>
<p>Again not much is happening. The new process is spawned and prints to the screen when the <code>loop</code> function is called. Now that we know how to spawn a new process we need to create the rest of the processes that will make up the ring.</p>
<p><script src="https://gist.github.com/703140.js"> </script></p>
<p>The <code>createNode</code> function does this job. Lines 18 through to 20 define the <code>createNode</code> function, which will continue to spawn processes recursively until it reaches the number defined by<code>NumberOfNodes</code>. This will build a linked list.</p>
<p>Erlang uses pattern matching to decide what to do when a function is called. Line 18 defines a pattern that matches: &#8220;When the first two arguments are the same, and the third is different&#8221;. When we match this pattern we want to simply return the third argument.</p>
<p><script src="https://gist.github.com/703150.js"> </script></p>
<p>This is how we break out of the recursive loop defined by lines 19 and 20. Line 19 defines a pattern that matches when all three arguments are different. When matched it calls itself, incrementing the first parameter, and replacing the third parameter with the <abbr title="process identifier">pid</abbr> of a newly created process.</p>
<p><script src="https://gist.github.com/703152.js"> </script></p>
<p>We kick start this chain of events on line 9, when we call <code>createNode</code> for the first time. If we run our program with <code>NumberOfNodes</code> set to 4, we will see 4 processes spawned, each pointing to the next one, creating a linked list.</p>
<p><script src="https://gist.github.com/703146.js"> </script></p>
<p>The exercise calls for a ring of processes, so the next step is to connect the first and last nodes together to form a ring.</p>
<p><script src="https://gist.github.com/703148.js"> </script></p>
<p>To do this we simply send the <code>FirstNode</code> a message with the <abbr title="process identifier">pid</abbr> of the <code>LastNode</code>. This is done on line 9 using the <code>!</code> syntax.</p>
<p><script src="https://gist.github.com/703153.js"> </script></p>
<p>So how do we capture and respond to that message in our processes? We use <code>receive</code>, to tell the process to wait for a message.</p>
<p><script src="https://gist.github.com/703154.js"> </script></p>
<p>Since we fire up every process using running the <code>loop</code> function, this is where we will tell each process to wait for a message. </p>
<p><script src="https://gist.github.com/703156.js"> </script></p>
<p>Inside the receive block we tell erlang that when a message that matches the pattern <code>NewNext</code> is received, and when <code>NextNode</code> is set to an empty list, that we should call <code>loop</code> again with the contents of <code>NewNext</code>.</p>
<p><script src="https://gist.github.com/703157.js"> </script></p>
<p>As you can see we now have 5 iterations of <code>loop</code> being called. This closes the ring of processes by telling the <code>FirstNode</code>, which was running <code>loop</code> with a <code>NextNode</code> of an empty list, to now run with a <code>NextNode</code> of the <code>LastNode</code>.</p>
<p>Now that we have a closed loop of processes, we need to send a message around it. We&#8217;ll write a function called <code>sendMessage</code> that will do just that.</p>
<p><script src="https://gist.github.com/703158.js"> </script></p>
<p>The first pattern matches when we&#8217;ve run out of messages to send, it does nothing. The second pattern matches and sends a message to <code>ToNode</code>.</p>
<p>Now that we have another type of message being sent out to our processes we need to handle it in <code>loop</code>.</p>
<p><script src="https://gist.github.com/703159.js"> </script></p>
<p>We write a pattern that will matches the one we send from <code>sendMessage</code>. We&#8217;ll print out what we receive, send the message on with 1 fewer hops remaining, and then start <code>loop</code> again to wait for another message to come in.</p>
<p>We then need to call <code>sendMessage</code> after closing the ring, passing it the <code>Message</code>, <code>FirstNode</code> and the total number of times the message should be passed on.</p>
<p><script src="https://gist.github.com/703160.js"> </script></p>
<p>Running it in the shell gives the following output:</p>
<p><script src="https://gist.github.com/703161.js"> </script></p>
<p>There we have it, a ring of 4 processes, sending a message around the ring 5 times. Except there&#8217;s a problem, because we&#8217;re using processes to do the work, our timing code is being called before the message has been passed around the ring. This can be clearly seen in the output, we declare 0 milliseconds to send 20 messages, then we see all of the action happening.</p>
<p>What we really want to do is have our timing process wait for a message that says we&#8217;re done sending messages around the loop. Here&#8217;s the final program.</p>
<p><script src="https://gist.github.com/703163.js"> </script></p>
<p>When run in the shell we can now see the timing code being run last.</p>
<p><script src="https://gist.github.com/703164.js"> </script></p>
<p>Printing to the screen is very time consuming, if we want to send 300 message around a ring of 1000 processes it will take a lot longer than it should. Remove the <code>io:fomrat</code> lines in the <code>loop</code> function and let rip!</p>
<p><script src="https://gist.github.com/703167.js"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethtownsend.info/2010/11/programming-erlang-chapter-8-exercise-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Refactoring an Objective-C Method</title>
		<link>http://blog.garethtownsend.info/2009/08/refactoring-an-objective-c-method/</link>
		<comments>http://blog.garethtownsend.info/2009/08/refactoring-an-objective-c-method/#comments</comments>
		<pubDate>Tue, 04 Aug 2009 05:10:52 +0000</pubDate>
		<dc:creator>Gareth Townsend</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Objective-C]]></category>

		<guid isPermaLink="false">http://blog.garethtownsend.info/?p=31</guid>
		<description><![CDATA[Sometimes you stumble across code that makes you think &#8220;WTF?&#8221;. Recently I discovered this Objective-C method in an iPhone project. I&#8217;ve renamed the method names and variables to protect the innocent. This method is called when a user taps a button inside a table cell. The purpose of the method is to find the table [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you stumble across code that makes you think &#8220;WTF?&#8221;. Recently I discovered this Objective-C method in an iPhone project. I&#8217;ve renamed the method names and variables to protect the innocent.</p>
<p><script src="http://gist.github.com/161037.js"></script></p>
<p>This method is called when a user taps a button inside a table cell. The purpose of the method is to find the table cell that the button belongs to, and then call <code>didSelectRowAtIndexPath</code> on that table cell.</p>
<p>Disregarding the fact that this methods purpose makes <code>didSelectRowAtIndexPath</code> one very bloated method, there are a few other improvements we can make to it.</p>
<p>First, this method uses a C-style for loop. Objective-C 2.0 supports <a href="http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocFastEnumeration.html">fast enumeration</a>. Fast enumeration is faster, looks better, and throws an exception if you attempt to modify the collection while it is being enumerated.</p>
<p><script src="http://gist.github.com/161038.js"></script></p>
<p>Because <code>NSArray</code> has a well defined order, and enumeration proceeds in that order, we can simply count the index.</p>
<p>We now have more lines of code than the original, but the intent is somewhat clearer. The implementation of this method however, still relies on a string comparison to find the correct table cell, which is not ideal.</p>
<p>Using our knowledge of the view hierarchy we can re-implement this method to forgo enumeration altogether.</p>
<p><script src="http://gist.github.com/161031.js"></script></p>
<p>Knowing that our button is inside a table cell we can ask it for its superview. Once we have the table cell, we can ask for its indexPath. We can then call didSelectRowAtIndexPath directly using the indexPath.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethtownsend.info/2009/08/refactoring-an-objective-c-method/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Much Ado About Todo</title>
		<link>http://blog.garethtownsend.info/2008/04/much-ado-about-todo/</link>
		<comments>http://blog.garethtownsend.info/2008/04/much-ado-about-todo/#comments</comments>
		<pubDate>Tue, 15 Apr 2008 10:18:33 +0000</pubDate>
		<dc:creator>Gareth Townsend</dc:creator>
				<category><![CDATA[Code Quality]]></category>
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://blog.garethtownsend.info/?p=5</guid>
		<description><![CDATA[How many times have you come across a comment block in a piece of code like this?: # TODO &#8211; Make this work properly for all cases. At some point in time this comment made sense. Someone, somewhere had every intention of fixing this and removing the comment. It&#8217;s quite possible that someone was you, [...]]]></description>
			<content:encoded><![CDATA[<p>How many times have you come across a comment block in a piece of code like this?:</p>
<blockquote><p># TODO &#8211; Make this work properly for all cases.</p></blockquote>
<p>At some point in time this comment made sense. Someone, somewhere had every intention of fixing this and removing the comment.</p>
<p>It&#8217;s quite possible that someone was you, but you don&#8217;t remember anymore.</p>
<h2>todos are irrelevant</h2>
<p>todos live in no-mans land. Stuck in a time warp for all eternity. Don&#8217;t kid yourself, you&#8217;re never going to re-visit a todo. They&#8217;re irrelevant.</p>
<p>They fly under the radar because they have no visibility. Out of sight, out of mind. If you&#8217;re not working on the code with the todo, then you don&#8217;t know it&#8217;s there, and you don&#8217;t care.</p>
<p>Other than doing a project wide search, you&#8217;re never going to find them all. Even if you do, you&#8217;re not going to understand the meaning of them all.</p>
<p>They&#8217;re irrelevant.</p>
<h2>making todos relevant again</h2>
<p>What&#8217;s the point of a todo list if nobody knows about it?</p>
<p>Take control of your todos and enshrine them in code that everyone sees every day. Write them into your test suite as pending tests.</p>
<p>Failing tests are bad. Passing tests are good. Pending tests are just plain annoying.</p>
<p>They clearly indicate that something hasn&#8217;t been finished properly. They&#8217;re visible every time you run your test suite. This means they annoy everyone until they&#8217;re fixed.</p>
<p>They define todos better than any other mechanism at your disposal.</p>
<h2>Sprinkle in a touch of guilt</h2>
<p>While a quick flick through <em>svn blame</em> will find the culprit, it&#8217;s not visible and it means work on your behalf.</p>
<p>Sprinkle in a touch of guilt by mandating all pending tests be created with the Authors name and todays date in the pending message.</p>
<p>That&#8217;ll ensure they don&#8217;t hang around like a bad smell for too long.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethtownsend.info/2008/04/much-ado-about-todo/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Short Stories Are Better Stories</title>
		<link>http://blog.garethtownsend.info/2008/04/short-stories-are-better-stories/</link>
		<comments>http://blog.garethtownsend.info/2008/04/short-stories-are-better-stories/#comments</comments>
		<pubDate>Tue, 01 Apr 2008 10:22:12 +0000</pubDate>
		<dc:creator>Gareth Townsend</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://blog.garethtownsend.info/?p=15</guid>
		<description><![CDATA[Any first year computer science student should be able to explain the divide and conquer, why it is important, and when to use it. But how many developers apply it to their software engineering practices? Stories Agile developers work with the concept of stories. Essentially these are short explanations of what someone should be able [...]]]></description>
			<content:encoded><![CDATA[<p>Any first year computer science student should be able to explain the <a href="http://en.wikipedia.org/wiki/Divide_and_conquer_algorithm">divide and conquer</a>, why it is important, and when to use it.</p>
<p>But how many developers apply it to their software engineering practices?</p>
<h2>Stories</h2>
<p>Agile developers work with the concept of stories. Essentially these are short explanations of what someone should be able to do with the software once the story is implemented.</p>
<blockquote><p>A user should be able to manage their account.</p></blockquote>
<p>This story is vague, open ended and typical of client feature requests.</p>
<p>Before estimating this story, you&#8217;re going to need to get some fine grained detail into it. After talking with your client you might end up with the following:</p>
<blockquote><p>Managing their account consists of changing their name, updating their contact details, changing their profile picture, resetting their password and swapping between username/password and open-id for authentication.</p></blockquote>
<p>Now you have enough information to estimate this story, you know what the client means by <em>&#8220;manage their account&#8221;.</em></p>
<p>You might come up with an estimate of say 100 points.</p>
<p>This example is contrived but if every story your client sends you follows this same process you&#8217;re heading straight for a world of pain.</p>
<h2>The Effect of Large Stories on Iterations</h2>
<p>So you start work on your iteration with 10 large stories with your team and half way through you&#8217;re looking at the number of stories you&#8217;ve sent to your client for testing.</p>
<p>That number is zero and you&#8217;re starting to feel a bit stressed out. It&#8217;s ok though because by the end of the day 5 stories have moved into the testing phase.</p>
<p>You move on to the rest of the stories in the iteration and your client gets started testing the stories you&#8217;ve completed. Some of them pass and others get sent back because something is not quite right.</p>
<p>The cumulative effect of multiple large stories is an exponential story completeness graph.</p>
<p><img src="http://chart.apis.google.com/chart?chs=320x320&amp;chd=t:0,2,4,8,16,32,64,128&amp;cht=lc&amp;chtt=Story%20Completeness%20is%20Exponential" alt="Story Completeness is Exponential" /></p>
<h2>The Effect of Large Stories on Developers</h2>
<p>Working on the same story for a long period of time is painful. As a developer you feel like you&#8217;re climbing a mountain that just keeps getting bigger.</p>
<p>You&#8217;re not sure where the top is, and sometimes you think you&#8217;ve reached it, but as it turns out you&#8217;ve forgotten something and you&#8217;re not quite at the top.</p>
<p>The effect on the team is that everyone goes through this same journey every iteration.</p>
<p>Your client experiences the same in reverse. They sit around waiting to climb the mountain, and they wait, and then bang, they&#8217;re expected to be half way up the mountain almost instantly.</p>
<h2>Divide and Conquer for Happiness</h2>
<p>Large stories can often be broken down into smaller stories. In fact you already did this when estimating your stories. But you finished one step before you should have.</p>
<p>You should have split the original story into multiple smaller ones:</p>
<blockquote><p>A user should be able to change their name.</p></blockquote>
<blockquote><p>A user should be able to change their contact details.</p></blockquote>
<blockquote><p>A user should be able to change their profile picture.</p></blockquote>
<blockquote><p>A user should be able to change their password.</p></blockquote>
<blockquote><p>A user should be able to switch between username/password and openid for authentication.</p></blockquote>
<p>Each one of these stories is smaller, has easier to meet acceptance criteria and will be finished earlier.</p>
<p>Your client will love you because they don&#8217;t spend half their time sitting around and waiting for stories to test.</p>
<p>The developers in your team will love you because instead of climbing one massive mountain, they are climbing 5 mounds.</p>
<p>Everyone feels like they are constantly moving forwards through the iteration.</p>
<p>The story completeness graph moves from being exponential to linear.</p>
<p><img src="http://chart.apis.google.com/chart?chs=320x320&amp;chd=t:0,128&amp;cht=lc&amp;chtt=Story%20Completeness%20is%20Linear" alt="Story Completeness is Linear" /></p>
<p>That&#8217;s a much more positive graph to have hanging on your office wall.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.garethtownsend.info/2008/04/short-stories-are-better-stories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 2.455 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-01-23 22:23:03 -->
<!-- Compression = gzip -->