<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Actively Lazy</title>
	<atom:link href="http://blog.activelylazy.co.uk/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.activelylazy.co.uk</link>
	<description>Smart software development is avoiding as much work as possible, yet getting the job done</description>
	<lastBuildDate>Wed, 22 May 2013 06:06:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='blog.activelylazy.co.uk' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Actively Lazy</title>
		<link>http://blog.activelylazy.co.uk</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://blog.activelylazy.co.uk/osd.xml" title="Actively Lazy" />
	<atom:link rel='hub' href='http://blog.activelylazy.co.uk/?pushpress=hub'/>
		<item>
		<title>The future&#8217;s software: the future&#8217;s shit</title>
		<link>http://blog.activelylazy.co.uk/2013/05/14/the-future-is-software-the-future-is-shit/</link>
		<comments>http://blog.activelylazy.co.uk/2013/05/14/the-future-is-software-the-future-is-shit/#comments</comments>
		<pubDate>Tue, 14 May 2013 19:34:37 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[quality]]></category>
		<category><![CDATA[rant]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=997</guid>
		<description><![CDATA[Software is taking over the world. Arguably software has already taken over the world. The trouble is: software is all shit &#8211; and it&#8217;s all your fault. I had one of those seconds-from-flinging-something-heavy-through-my-tv days yesterday: I really have had it with crappy software. First, I decided to relax and catch up with last week&#8217;s Have [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=997&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Software is taking over the world. Arguably software has already taken over the world. The trouble is: software is all shit &#8211; and it&#8217;s all your fault.</p>
<p>I had one of those seconds-from-flinging-something-heavy-through-my-tv days yesterday: I really have had it with crappy software. First, I decided to relax and catch up with last week&#8217;s Have I Got News For You on BBC iPlayer. Unfortunately, for some unfathomable reason, the XBox iPlayer app has become shit in recent months. Last night, it played 0.5 seconds of the show and hung. Network traffic was still flying by, but none of it was appearing on my TV. Fine, I switched to using iPlayer on my laptop &#8211; at least that normally works.</p>
<p>Afterwards I decided to watch another of the (excellent, by the way) American remake of House of Cards on Netflix. First, my router had got its knickers in a twist and switched the VPN so Netflix thought I was in the US, so all of my recently watched had disappeared. Boot up laptop (again), login to admin page on the router, fiddle with settings, reboot, reboot XBox, login again: there we go, UK Netflix is back, I can finally watch House of Cards. Except now the TV has crashed and refuses to decode the HDCP signal from the XBox. Reboot TV: no. Reboot xbox, again. Yes! We have signal!</p>
<p>I sat back and started watching. I have to get up, <em>three times</em>, because the volume is quieter than a quiet thing on quiet day in quiet land. Eventually it was so damned quiet I manage to miss some dialog, so I get to use the, occasionally awesome, XBox kinect voice control feature that saves me scrabbling to find the controller: &#8220;xbox rewind&#8221;. Excellent, it starts rewinding. &#8220;xbox stop&#8221;. &#8220;XBOX, STOP!&#8221; &#8220;Oh for fuck&#8217;s fucking sake xbox, fucking stop you fucking retarded demon, STOP!&#8221;. Find the controller. Wait for <em>it</em> to boot up. Now the Netflix app has resumed its entirely random bug where I lose all the on screen navigation controls, so I have to guess which combination of up, down, A, A, B, up, down stops the bloody rewind and not the one that invokes the super Netflix boss level. Eventually the button mashing exits Netflix, not what I intended but at least it&#8217;s stopped rewinding. I launch Netflix again. This time the on screen controls work. Woohoo! Now volume has switched back to slightly louder than a jet engine piped directly against your ear drum, so I jump up and turn the volume down before it wakes my little boy up.</p>
<p>By now, I&#8217;m in no mood for political intrigue &#8211; killing every developer that was involved in any of the pieces of software that have ruined my mood and my evening, quite gladly: pass me the knife, I&#8217;m <em>happy</em> to relieve each them of their useless lives and hopelessly misapplied careers.</p>
<p>The trouble is: it&#8217;s not their fault. All software is shit. As software takes over more and more of my life I realise: it&#8217;s not getting any better. My phone crashes, my TV crashes, my hi-fi crashes. My sat nav gets lost and my car needs a BIOS upgrade. This is all before I get to work and get to use any actual computers. Actual computers that I actually hate.</p>
<p>Every step of every day, software is pissing me off. And you know what? It&#8217;s only going to get worse. As software invades more and more of our lives our complete inability to create decent, stable software is becoming a plague. The future will be dominated by people swearing at every little computer they come into contact with. In our bright software future where everything is digital and we&#8217;re constantly plugged into the metaverse I will spend my entire life swearing at it for being so unutterably, unnecessarily shit.</p>
<p>You know what else? As software developers: it&#8217;s all our fault.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/997/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/997/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=997&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2013/05/14/the-future-is-software-the-future-is-shit/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Visualizing Code</title>
		<link>http://blog.activelylazy.co.uk/2013/05/06/visualizing-code/</link>
		<comments>http://blog.activelylazy.co.uk/2013/05/06/visualizing-code/#comments</comments>
		<pubDate>Mon, 06 May 2013 19:58:31 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[ddd]]></category>
		<category><![CDATA[modelling]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[reading code]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=987</guid>
		<description><![CDATA[When writing software we&#8217;re working at two levels: Creating an executable specification of exactly what we want the machine to do Creating a living document that describes the intent of what we want the machine to do, to be read by humans The first part is the easy part, the second part takes a lifetime to [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=987&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>When writing software we&#8217;re working at two levels:</p>
<ol>
<li><span style="line-height:13px;">Creating an executable specification of exactly what we want the machine to do</span></li>
<li>Creating a living document that describes the <em>intent</em> of what we want the machine to do, to be read by humans</li>
</ol>
<p>The first part is the easy part, the second part takes a lifetime to master. I read a really great post today pointing out <a href="http://www.yacoset.com/Home/signs-that-you-re-a-bad-programmer">signs that you&#8217;re a bad programmer</a>. Whether you&#8217;re a bad programmer or just inexperienced, I think the biggest barrier is being able to quickly and accurately <em>visualize</em> code. You need to visualize what the application actually <em>does, </em>what happens at <em>runtime; </em>but all your IDE shows you is the raw, static, source code. From this static view of the world you have to infer the runtime behaviour, you have to infer the actual shape of the application and the patterns of interaction; while closely related, the two are <em>separate</em>. Given just source code, you need to be able to visualize what code <em>does.</em></p>
<p>What does it mean to <em>visualize</em> code? At the simplest level, it&#8217;s understanding what individual statements do.</p>
<pre class="brush: java; title: ; notranslate">
string a = &quot;Hello&quot;:
string b = &quot;world&quot;;
a = b;
</pre>
<p>It might sound trivial, but the first necessary step is being able to quickly parse code and mentally step through what will happen. First for basic statements, then for code that iterates:</p>
<pre class="brush: java; title: ; notranslate">
while (stack.Count() &gt; 1)
{
    var operation = stack.Pop() as IOperation;
    var result = operation.Execute(stack.Pop(), stack.Pop());
    stack.Push(result);
}
</pre>
<p>Where you need to understand looping mechanics and mentally model what happens <em>overall</em> not just each iteration. Then you need to be able to parse recursive code:</p>
<pre class="brush: java; title: ; notranslate">
int Depth(ITreeNode node)
{
    if (node == null)
        return 0;
    return 1 + Math.Max(Depth(node.Left), Depth(node.Right));
}
</pre>
<p>Which is generally harder for inexperienced programmers to understand and reason about; even though once you&#8217;ve learned the <em>pattern</em> it can be clearer and more concise.</p>
<p>Once you&#8217;ve mastered how to understand what a single method does, you have to understand how methods become composed together. In the OO world, this means understanding classes and interfaces; it means understanding <em>design patterns</em>; you need to understand how code is grouped together into cohesive, loosely coupled units with clear responsibilities.</p>
<p>For example, the visitor pattern has a certain mental structure &#8211; it&#8217;s about implementing something akin to a virtual method outside of the class hierarchy; in my mind it factors a set of classes into a set of methods.</p>
<pre class="brush: plain; title: ; notranslate">
public interface IAnimal
{
    void Accept(IAnimalVisitor visitor);
}

public class Dog : IAnimal { ... }
public class Cat : IAnimal { ... }
public class Fox : IAnimal { ... }

public interface IAnimalVisitor
{
    void VisitDog(Dog dog);
    void VisitCat(Cat cat);
    void VisitFox(Fox fox);
}
</pre>
<p>The first step in reading code is being able to read something like a visitor pattern (assuming you&#8217;d never heard of it before) and understand what it does and develop a mental model of what that shape looks like. Then, you can use the term &#8220;visitor&#8221; in your code and in discussions with colleagues. This shared language is critical when talking about code: it&#8217;s not practical to design a system by looking at individual lines of code, we need to be able to draw boxes on a whiteboard and discuss shapes and patterns. This <em>shared mental model </em>is a key part of team design work; we need a shared language that maps to a shared mental model, both of the existing system and of changes we&#8217;d like to make.</p>
<p>In large systems this is where a common language is important: if the implementation uses the same terms the domain uses, it becomes simpler to understand how the parts of the system interact. By giving things proper names, the interactions between classes become logical analogues of real-world things &#8211; we don&#8217;t need to use technical words or made up words that subsequent readers will need to work to understand or learn, someone familiar with the domain will know what the expected interactions are. This makes it easier to build a mental model of the system.</p>
<p>For example, in an online book store, I might have concepts (classes) such as book, customer, shopping basket, postal address. These are all logical real world things with obvious interactions. If I instead named them PurchasableItem, RegisteredUser, OrderItemList and DeliveryIndicationStringList you&#8217;d probably struggle to understand how one related to the other. Naming things is hard, but incredibly important &#8211; poor naming will make it that much harder to develop a good mental model of how your system works.</p>
<p>Reading code, the necessary precursor to writing code, is all about building a mental model. We&#8217;re trying to visualize something that doesn&#8217;t exist, by reading lines of text.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/987/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/987/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=987&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2013/05/06/visualizing-code/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Choosing a Programming Language</title>
		<link>http://blog.activelylazy.co.uk/2013/04/09/choosing-a-programming-language/</link>
		<comments>http://blog.activelylazy.co.uk/2013/04/09/choosing-a-programming-language/#comments</comments>
		<pubDate>Tue, 09 Apr 2013 19:30:14 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[clojure]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[language]]></category>
		<category><![CDATA[node]]></category>
		<category><![CDATA[scala]]></category>
		<category><![CDATA[software]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=977</guid>
		<description><![CDATA[What programming language to use is probably the single biggest technical decision facing a project. That one decision, affects every one that follows &#8211; from the frameworks and libraries you can use, to the people you hire. So how do you go about choosing what programming language to use? The truth is, you probably do [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=977&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>What programming language to use is probably the single biggest technical decision facing a project. That one decision, affects every one that follows &#8211; from the frameworks and libraries you can use, to the people you hire. So how do you go about choosing what programming language to use?</p>
<p>The truth is, you probably do what most people do and use the same language you used on your last project. Or, if you&#8217;re a hipster, you use the latest super cool language. A couple of years ago all the cool kids were on rails. Now the hipsters are trying to tell me how awesome their nodes are. Or that clojures are where its at. Last time I checked, their turing complete language had the same problem solving capacity as my turing complete language. Really what they&#8217;re arguing is their language gives them better expressive power: it&#8217;s faster to write and/or cheaper to maintain.</p>
<h1>Right tool, right job</h1>
<p>As the old adage goes: always use the right tool for the job. If you need to automate some command line maintenance task &#8211; use a language that&#8217;s good at shell scripting: bash, perl, hell even ruby; don&#8217;t use Java. If the problem you&#8217;re solving needs a desktop client that integrates seamlessly in a Windows environment: use C#, don&#8217;t use Java (be quiet Java on the desktop fanboys, just be quiet). If the problem you&#8217;re solving involves handling lots of XML and you like stack traces: sure, use Java.</p>
<p>The biggest distinction normally comes down to algorithmic complexity. If what you&#8217;re working on has a lot of algorithmic complexity, use something that&#8217;s good at expressing it: a functional language, like haskell or F#. Or if, like 90% of webapps, what you&#8217;re doing is data in, data out you need a language with good OO power to try and model your domain: Java and C# are both good choices here, along with almost every other modern language out there.</p>
<h1>Scala</h1>
<p>Or maybe you really hate yourself and you want a compromise: why choose functional or procedural when you can have both? Why miss out on every language feature thought of over the last 50 years when you can have them all, baked into one mess of a language? Yes, if that sounds like you, you probably think you&#8217;re a hipster but you actually missed the boat by several years: its time to learn you some scalas.</p>
<p>I suspect part of the reason Scala is gaining so much popularity is that it finally gives all the frustrated Java devs the language toys they&#8217;ve always wanted. Java really is an unbelievably retarded language now, it&#8217;s incredibly frustrating to work in. As someone that&#8217;s just switched to C#, I&#8217;ve relished all the new language gadgets and geegaws I&#8217;ve got to play with. Have they made the code any better? With lots of toys comes lots of complexity and variety, making code hard to understand and hard to maintain.</p>
<p>The thing is, Java is a toy language: any idiot can write decent idiomatic Java. The trouble is, Java is a toy language: everyone is forced to write screeds of noddy idiomatic, idiotic Java, no matter how much of a ninja rockstar they are. The best thing with Java, is it stops all the ninja rockstars from showing how ninja they are by writing undecipherable crap. I fear the impact lambdas will have on the maintainability of the average Java codebase as everyone starts finding new and confusing ways to express everything.<i><br />
</i></p>
<h1>Hiring</h1>
<p>Another reason to choose the right programming language, is it affects the developers you can hire. But does it really? I work in a C# shop now, do I turn down Java developers? Hell no. A good developer is a good developer, regardless of the language. To dismiss potential recruits because of the language they know is retarded.</p>
<p>And the trouble is, if you think that hiring only python or node developers will get you a better standard of developer: you&#8217;re wrong. The pool will simply be much smaller. Maybe the average quality of that pool will be higher, who knows, who cares? I only need one developer, I want her to be the best I can hire &#8211; it makes no difference where the average is.</p>
<p>Language has no correlation with ability: I&#8217;ve met some very smart Java developers, and some truly terrible hipster developers. I&#8217;d rather cast the widest possible net and hire <em>good developers</em> who are happy to use the technologies we use. To do anything else is to limit the pool of talent I can draw from; which, lets be honest, is pretty limited already.</p>
<p>Another argument I&#8217;ve heard is that the technologies you use will limit candidates willing to work for you &#8211; some developers only want to work in, say, clojure. Well, they&#8217;re retarded then. I&#8217;d rather have people who want to work on interesting problems, <em>regardless of the language</em>, than people who would rather solve shit problems in the latest hipster language. Now if you work for a bank, and all you have are shit problems? Sure, go ahead and use a hipster language if it helps you hire your quota of morons. If nothing else it keeps them away from me.</p>
<h1>Lingua Franca</h1>
<p>Take a room full of hipster language programmers and ask them to form teams. What happens? Magically, you&#8217;ve now got a room full of C# and Java developers. Almost every developer will know at least one of these two languages &#8211; they are the lingua franca. Everything else is frankly varying degrees of hipster.</p>
<p>The truth is the most important thing when choosing a language is how many developers on your team, and those you plan on hiring, already know the language. If everyone on the team has to retrain into say, smalltalk; and everyone you hire needs hand holding while they learn the new language &#8211; that&#8217;s a <em>cost</em> you have to factor in. What&#8217;s the <em>benefit</em> you&#8217;re getting from it?</p>
<p>Secondly, how easy is it to get support when you hit problems? The open source community around Java is awesome &#8211; if you&#8217;ve got a problem, there will already be 15 different solutions, some of which even work. If you work in C#, your choices are more limited &#8211; but there will be choices, some of which aren&#8217;t even from Microsoft. If you&#8217;re working in the latest hipster language, guess what? You&#8217;re on your own. For some people that&#8217;s the draw of hipster languages. For those of us wanting to get work done, it&#8217;s just a pain.</p>
<p>In the end, the best advice is probably to use the same language you used on your last project: everybody already knows it and your tooling is already setup around it. This is why Java has quickly become the new cobol.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/977/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/977/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=977&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2013/04/09/choosing-a-programming-language/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>The Economics of Car Rental</title>
		<link>http://blog.activelylazy.co.uk/2013/04/02/the-economics-of-car-rental/</link>
		<comments>http://blog.activelylazy.co.uk/2013/04/02/the-economics-of-car-rental/#comments</comments>
		<pubDate>Tue, 02 Apr 2013 19:20:29 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[car rental]]></category>
		<category><![CDATA[cars]]></category>
		<category><![CDATA[driving]]></category>
		<category><![CDATA[self driving]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=967</guid>
		<description><![CDATA[We&#8217;re flying back to the UK for a week later this month, so once again we&#8217;re forced to rent a car. Both sets of parents live too far from public transport for it to be a realistic option, even assuming the trains in the UK break the habit of a lifetime and work for a change. [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=967&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>We&#8217;re flying back to the UK for a week later this month, so once again we&#8217;re forced to rent a car. Both sets of parents live too far from public transport for it to be a realistic option, even assuming the trains in the UK break the habit of a lifetime and <em>work</em> for a change. (Rail replacement bus service? What sadistic bastard thought of that?)</p>
<p>It got me thinking about the outrageous cost of hiring a car for the week. To get a car large enough for the three of us and all our luggage (who knew we needed to take a kitchen sink for a 1 week trip?), it will cost us over <strong>£200</strong><strong> </strong>for the week. I could practically <em>buy</em> a car more cost effectively than that&#8230; if only there was some way of everyone clubbing together to buy a car that you can drive when you need it. Scaled up, you&#8217;d have&#8230; a car rental company. Are they just ripping us off? Or does it plausibly cost that much to hire cars out? I made up some numbers to see if it would shed any light on the situation.</p>
<table border="0" rules="NONE" cellspacing="0">
<col width="147" />
<col width="86" />
<tbody>
<tr>
<td align="LEFT" width="147" height="17">New price</td>
<td align="RIGHT" width="86">£24,000.00</td>
</tr>
<tr>
<td align="LEFT" height="18">Price @ 3 yrs</td>
<td align="RIGHT">£12,000.00</td>
</tr>
<tr>
<td align="LEFT" height="17">Annual running costs</td>
<td align="RIGHT">£2,000.00</td>
</tr>
<tr>
<td align="LEFT" height="18">Cost over 3 yrs</td>
<td align="RIGHT">£18,000.00</td>
</tr>
</tbody>
</table>
<p>A fairly low-spec, family sized car would cost about £24,000 to buy brand new. Assuming you kept it for 3 years, and allowing for insurance and up-keep etc, I reckon you&#8217;d need to make about £6,000 a year to cover it. Is that a lot?</p>
<table border="0" rules="NONE" cellspacing="0">
<col width="147" />
<col width="86" />
<tbody>
<tr>
<td align="LEFT" width="147" height="17">Annual cost</td>
<td align="RIGHT" width="86">£6,000.00</td>
</tr>
<tr>
<td align="LEFT" height="17">Average utilisation</td>
<td align="RIGHT">50%</td>
</tr>
<tr>
<td align="LEFT" height="17">Min daily cost</td>
<td align="RIGHT">£32.97</td>
</tr>
</tbody>
</table>
<p>Assuming the car is being used 50% of the time, you&#8217;d need to charge about £30/day to make your £6,000 a year back. Which works out about the same as I&#8217;m actually paying &#8211; so it&#8217;s probably not a million miles wide of the mark. Which is slightly depressing &#8211; unless you buy an older car, and risk spending more money on maintaining it and repairing it&#8230; it&#8217;s difficult to see how you could rent a car for less than they currently charge.</p>
<p>Although I&#8217;m hiring a car for the week, I don&#8217;t actually <em>need</em> the car for 7 full days of 24 hours. Maximum, I&#8217;ll probably be in the car for 12 hours across that week. If only there was a way that I could rent a car for an hour at a time? (Zipcar and the like only serve big cities, which is useless when you&#8217;re visiting the sticks)</p>
<h1>Self-Driving Cars</h1>
<p>Well, maybe this is where self-driving cars could massively change things. With a self-driving car, it wouldn&#8217;t matter that I&#8217;m parking up in the middle of nowhere. It can scoot itself off into the nearest city to continue ferrying people about. I&#8217;d only need to pay for the time I actually use it.</p>
<table border="0" rules="NONE" cellspacing="0">
<col width="147" />
<col width="86" />
<tbody>
<tr>
<td align="LEFT" width="147" height="17">Annual cost</td>
<td align="RIGHT" width="86">£6,000.00</td>
</tr>
<tr>
<td align="LEFT" height="17">Average utilisation</td>
<td align="RIGHT">25%</td>
</tr>
<tr>
<td align="LEFT" height="17">Min hourly cost</td>
<td align="RIGHT">£2.75</td>
</tr>
</tbody>
</table>
<p>Obviously the utilisation would be lower (I can&#8217;t imagine many people will need carrying about in the middle of the night). But instead of paying <strong>£230</strong> for a week&#8217;s car parking, I could instead pay <strong>£33</strong> for 12 hours of driving. In theory, the car would still be paid for over three years &#8211; but the cost to individual users would be <em>massively lower</em>.</p>
<h1>Not Just for Holidays</h1>
<p>At those prices, could it even replace my <em>main</em> car?</p>
<table border="0" rules="NONE" cellspacing="0">
<col width="173" />
<col width="86" />
<col width="86" />
<tbody>
<tr>
<td align="LEFT" width="173" height="17">Annual mileage</td>
<td align="RIGHT" width="86">12000</td>
<td align="LEFT" width="86"> miles</td>
</tr>
<tr>
<td align="LEFT" height="17">Average monthly mileage</td>
<td align="RIGHT">1000</td>
<td align="LEFT"> miles</td>
</tr>
<tr>
<td align="LEFT" height="17">Average speed</td>
<td align="RIGHT">40</td>
<td align="LEFT"> mph</td>
</tr>
<tr>
<td align="LEFT" height="17">Average monthly time</td>
<td align="RIGHT">25</td>
<td align="LEFT"> hours</td>
</tr>
<tr>
<td align="LEFT" height="17">Average monthly cost</td>
<td align="RIGHT">£68.68</td>
<td align="LEFT"></td>
</tr>
</tbody>
</table>
<p>If I was paying for the exact same car, to spend the bulk of it&#8217;s time parked outside my house, it would cost <strong>£500</strong> per month. But renting it by the hour is a fraction of that. Of course, if everyone did this, you&#8217;d need a massive number of cars to cover the peak demand at rush hour &#8211; but the utilisation could drop to 5% and it would <em>still</em> be cheaper than owning the car outright. That&#8217;s each car in use for just over 1 hour each day, given that&#8217;s the average UK daily commute that seems easily achievable.</p>
<p>So, it&#8217;s 2013, I only have one question:</p>
<blockquote><p>Where&#8217;s my goddamned self driving car?</p></blockquote>
<p>&nbsp;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/967/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/967/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=967&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2013/04/02/the-economics-of-car-rental/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Short Commit Cycles</title>
		<link>http://blog.activelylazy.co.uk/2013/02/27/short-commit-cycles/</link>
		<comments>http://blog.activelylazy.co.uk/2013/02/27/short-commit-cycles/#comments</comments>
		<pubDate>Wed, 27 Feb 2013 19:27:01 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[brain fade]]></category>
		<category><![CDATA[commit often]]></category>
		<category><![CDATA[cycle time]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=950</guid>
		<description><![CDATA[How often do you commit? Once a week? Once a day? Once an hour? Every few minutes? The more often you commit, the less likely you are to make a mistake. I used to work with a guy who reckoned you should commit at least every 15 minutes. I thought he was mad. Maybe he [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=950&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>How often do you commit? Once a week? Once a day? Once an hour? Every few minutes? The more often you commit, the less likely you are to make a mistake.</p>
<p>I used to work with <a href="https://twitter.com/scarytom">a guy</a> who reckoned you should commit at least every 15 minutes. I thought he was mad. Maybe he is. But he&#8217;s also damned right. I didn&#8217;t believe it was possible: what can you actually get done in 15 minutes? At best, maybe you can write a test and make it pass. Well good! That&#8217;s enough. If you <strong>can</strong> write a test and make it pass in 15 minutes, check that sucker in! If you can&#8217;t: back it the hell out.</p>
<blockquote><p>But I&#8217;ll never get anything done!</p></blockquote>
<p>Sure you will, you just need to <strong>think</strong> more. Writing software isn&#8217;t about typing, it&#8217;s about thinking. If you can&#8217;t see a way to make a step in 15 minutes, think harder.</p>
<h1>Chase the Red</h1>
<p>One of my oft-used anti-patterns is to &#8220;chase the red&#8221;. You make one change, delete a method or class you don&#8217;t want &#8211; and then hack away, error by error, until the compiler is happy. It might take 5 minutes. It might take a week.</p>
<p>It&#8217;s very easy to get sucked into this pattern &#8211; you think you know where you want to get to: I have a method that takes a string &#8211; maybe it&#8217;s a product SKU from the warehouse; I want to replace it with a StockUnit which has useful functionality on it. Simples: change the signature of the method to accept StockUnit instead of string and follow the red, when the compiler&#8217;s happy: I&#8217;m done.</p>
<p>Trouble is &#8211; how do I know that every calling method <em>can</em> change? Maybe I think I know the code base and can make a reasonable guess. Maybe I&#8217;m even <em>right</em>. But it&#8217;s unbelievably easy to be wrong. I might even check all references methodically first, but until the code&#8217;s written &#8211; it&#8217;s just a theory. And you know what they say about the difference between theory and practice.</p>
<p>Is there a different way? What if I add a new method that accepts a StockUnit and delegates to the original method? I can test drive adding the new method, commit! I can go through each reference, one by one: write a failing test, make it pass by calling the new method, commit! Step-by-step, the code compiles and the tests pass <em>every step of the way</em>.</p>
<p>What happens if I hit something insurmountable half way? Where I am is a mess, but it&#8217;s a compiling, green mess. If I decide to back out I can revert those commits. Or refactoring tools can inline the method and automatically remove half the mess for me. But the critical thing is, every step of the way I can integrate with the rest of the team, and all the tests pass in case I hit something unexpected.</p>
<h1>Merge Hell</h1>
<p>The trouble with long running branches (and I include in that your local &#8220;branch&#8221; that you haven&#8217;t committed for two weeks!) is that the longer they run the harder they are to integrate. Now sure, git makes it easier to manage branching &amp; merging &#8211; but you still have to do it. You still have to push &amp; pull changes regularly &#8211; let others integrate with you and integrate with others <em>as often as you can</em>.</p>
<p>The likelihood of you having merge problems increases rapidly the longer your branch is open. If it&#8217;s 15 minutes and one test, you know what? If you have a merge problem, you can throw it away and redo the work &#8211; its only 15 minutes!</p>
<blockquote><p>Just keep swimming!</p></blockquote>
<p>But if you&#8217;ve been working for days and you hit merge hell, what do you do? You&#8217;re <strong>forced</strong> to wade through it. What you&#8217;re doing is chasing the red in your version control system. You&#8217;ve adopted an approach that gives you no choice but to keep on hacking until all the red merge conflict markers are gone from your workspace. If it takes 5 minutes or 5 days, you&#8217;ve got to keep going because you can&#8217;t afford to lose your work.</p>
<p>The kicker is by the time you&#8217;re done merging and everything compiles and works again, what&#8217;s the betting some other bugger has jumped in with another epic commit? Off we go again. You&#8217;re now in a race to try and merge your steaming pile before anyone else gets in. This is a ridiculous race &#8211; and who wins? Nobody, you&#8217;re still a loser.</p>
<p>Instead, if you adopt the 15 minute rule, you write a test, make it pass, check it in <em>and push to share with everyone else</em>. Little and often means you lose little time to merge conflicts and instead let your version control system do what it&#8217;s good at*: merging changes!</p>
<p>*<em> doesn&#8217;t apply to those poor suckers using TFS, sorry</em></p>
<h1>Brain Fade</h1>
<p>An interesting side effect of a short cycle time is that you limit the damage periods of brain fade can do. I dunno about you, but there are times when I really shouldn&#8217;t be allowed near a keyboard. The hour after lunch can be pretty bad &#8211; a full belly is not good for my thinking. The morning after the night before: it&#8217;s best if you keep me away from anything mission critical.</p>
<p>The trouble is, if I have a multi-day branch open I&#8217;m <em>almost guaranteed</em> to hit a period of brain fade. Because I&#8217;m not committing, when my head clears and I realise I&#8217;ve screwed up I can&#8217;t just revert those commits or throw my branch away entirely &#8211; I have to try and unpick the mess I just made from the mess I already had. It&#8217;s incredibly hard to be disciplined and tidy when you&#8217;re wading in excrement.</p>
<p>We all make mistakes &#8211; but version control gives me an overview of what I did, without relying on my flaky memory. Maybe I&#8217;ve gone completely the wrong way and can unpick parts of what I&#8217;ve done, maybe I got lucky and some commits were half-way decent &#8211; I can cherry pick those and start a new branch. Without version control I&#8217;d be flapping around in an ungodly mess trying to figure out how to keep the good bits without just binning everything. All the time trying to explain to the project manager how I&#8217;m 90% done! No, really! Nearly there now!</p>
<p><strong>Practice!</strong></p>
<p>Version control is an invaluable tool that we must learn to use properly. It takes discipline. It doesn&#8217;t come naturally. If you&#8217;ve never worked in such short cycles, work through a kata committing regularly. Our natural instinct is to type first and think later. <strong>Stop!</strong> Think about how you can make an increment in 15 minutes and do that. If you can&#8217;t: <strong>revert!</strong></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/950/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/950/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=950&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2013/02/27/short-commit-cycles/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Measuring Software</title>
		<link>http://blog.activelylazy.co.uk/2012/11/20/measuring-software/</link>
		<comments>http://blog.activelylazy.co.uk/2012/11/20/measuring-software/#comments</comments>
		<pubDate>Tue, 20 Nov 2012 20:58:57 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[making software]]></category>
		<category><![CDATA[measuring software]]></category>
		<category><![CDATA[metrics]]></category>
		<category><![CDATA[productivity]]></category>
		<category><![CDATA[quality]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=939</guid>
		<description><![CDATA[A while back I read Making Software &#8211; it made me disappointed at the state of academic research into the practice of developing software. I just read Leprechauns of Software Engineering which made me angry about the state of academic research. Laurent provides a great critique of some of the leprechauns of our industry and why we [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=939&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>A while back I read <a href="http://shop.oreilly.com/product/9780596808303.do">Making Software</a> &#8211; it made me disappointed at the state of academic research into the practice of developing software. I just read <a href="https://leanpub.com/leprechauns">Leprechauns of Software Engineering</a> which made me <strong>angry</strong> about the state of academic research.</p>
<p>Laurent provides a great critique of some of the leprechauns of our industry and why we believe in them. But it just highlighted to me how little we really know about what works in software development. Our industry is driven by fashion because nobody has any objective measure on what works and what doesn&#8217;t. Some people love comparing software to the medical profession, to torture the analogy a bit &#8211; I think today we&#8217;re in the blood letting and leeches phase of medical science. We don&#8217;t really know what works, but we have all sorts of strange rituals to do it better.</p>
<h1>Rituals</h1>
<p>Rituals? What rituals? We&#8217;re professional software developers!</p>
<p>But of course, we all get together every morning for a quick status update. Naturally we answer the three questions strictly, any deviations are off-topic. We stand up to keep the meeting short, obviously. And we all stand round the hallowed <del>scrum</del> kanban board.</p>
<p>But rituals? What rituals?</p>
<p>Do we know if stand ups are effective? Do we know if scrum is effective? Do we even know if TDD works?</p>
<h1>Measuring is Hard</h1>
<blockquote><p>Not everything that can be measured matters; not everything that matters can be measured</p></blockquote>
<p>I think we have a fundamental problem when it comes to analysing what works and what doesn&#8217;t. As a developer there are two things I ultimately need to know about any practice/tool/methodology:</p>
<ol>
<li>Does it get the job done faster?</li>
<li>Does it result in less bugs / lower maintenance cost?</li>
</ol>
<p>This boils down to measuring productivity and defects.</p>
<h1>Productivity</h1>
<p>Does TDD make developers more productive? Are developers more productive in Ruby or Java? Is pairing productive?</p>
<p>These are some fascinating questions that, if we had objective, repeatable answers to would have a <strong>massive</strong> impact on our industry. Imagine being able to dismiss all the non-TDD doing, non-pairing Java developers as being an unproductive waste of space! Imagine if there was <em>scientific proof</em>! We could finally end the language wars once and for all.</p>
<p>But how can you measure productivity? By lines of code? Don&#8217;t make me laugh. By story points? Not likely. Function points? Now I know you&#8217;re smoking crack. As Ben argues, there&#8217;s <a href="http://www.benrady.com/2012/11/theres-no-such-thing-as-software-productivity.html">no such thing as productivity</a>.</p>
<p>The trouble is, if we can&#8217;t measure productivity &#8211; it&#8217;s <em>impossible</em> to compare whether doing something has an impact on whether you get the job done faster or not. This isn&#8217;t just an idle problem &#8211; I think it fundamentally makes research into software engineering practices <strong>impossible</strong>.</p>
<p>It makes it impossible to answer these basic questions. It leaves us open to fashion, to whimsy and to consultants.</p>
<h1>Quality</h1>
<p>Does TDD help increase quality? What about code reviews? Just how much should you invest in quality?</p>
<p>Again, there are some fundamental questions that we cannot answer without measuring quality. But how can you measure quality? Is it a bug or a feature? Is it a user error or a requirements error? How many bugs? Is an error in a third party library that breaks several pages of your website one bug or dozens? If we can&#8217;t agree what a defect is or even how to count them how can we ever measure quality?</p>
<h1>Subjective Measures</h1>
<p>Maybe there are some subjective measures we could adopt. For example, perhaps I could monitor the number of emails to support. That&#8217;s a measure of software quality. It&#8217;s rather broad, but if software quality increases, the number of emails should decrease. However, social factors could so easily dwarf any actual improvement. For example, if users keep reporting software crashes and are told by the developers &#8220;yeah, we know&#8221;. Do you keep reporting it? Or just accept it and get on with your life? The trouble is, the lack of customer complaints doesn&#8217;t indicate the presence of quality.</p>
<h1>What To Do?</h1>
<p>What do we do? Do we just give up and adopt the latest fashion hoping that this time it will solve all our problems?</p>
<p>I think we need to gather data. We need to gather <strong>lots</strong> of data. I&#8217;d like to see thousands of dev teams across the world gathering statistics on their development process. Maybe out of a mass of data we can start to see some general patterns and begin to have some scientific basis for what we do.</p>
<p>What to measure? <strong>Everything!</strong> Anything and everything. The only constraint is we have to agree on <em>how</em> to measure it. Since everything in life is fundamentally a problem of lack of code, maybe we need a tool to help measure our development process? E.g. a tool to measure how long I spend in my IDE, how long I spend testing. How many tests I write; how often I run them; how often I commit to version control etc etc. These all provide detailed telemetry on our development process &#8211; perhaps out of this mass of data we can find some interesting patterns to help guide us all towards building software better.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/939/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/939/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=939&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2012/11/20/measuring-software/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Knowledge vs Superstition</title>
		<link>http://blog.activelylazy.co.uk/2012/10/09/knowledge-vs-superstition/</link>
		<comments>http://blog.activelylazy.co.uk/2012/10/09/knowledge-vs-superstition/#comments</comments>
		<pubDate>Tue, 09 Oct 2012 20:15:57 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[superstition]]></category>
		<category><![CDATA[understanding]]></category>
		<category><![CDATA[voodoo]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=914</guid>
		<description><![CDATA[How much of what we do is based on sound understanding? And how often do we do things without really understanding why? Everything we do: from walking down the street to writing software &#8211; sometimes we understand why we do things, other times we follow superstition. We&#8217;re trained to associate cause with effect, even if we don&#8217;t [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=914&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>How much of what we do is based on sound understanding? And how often do we do things without <em>really</em> understanding why? Everything we do: from walking down the street to writing software &#8211; sometimes we understand why we do things, other times we follow superstition.</p>
<p>We&#8217;re trained to associate cause with effect, even if we don&#8217;t understand the connection:</p>
<blockquote><p>Press button: get food. Hungry. Press button. Food.</p></blockquote>
<p>At an animal level, the <em>reason</em> is irrelevant. But as rational human beings, we&#8217;re able to understand the relationship between cause and effect; but that doesn&#8217;t mean we always behave rationally. Ever <a href="http://library.thinkquest.org/J0111801/inside/Superstitions/Ladders.html">walked around a set of ladders</a> rather than under them? My wife makes me laugh by <a href="http://www.timelessmyths.co.uk/saulting-magpies.html">saluting magpies</a>. These superstitions are entirely irrational behaviours, but are mostly just amusing and harmless.</p>
<p>But when it comes to computers, this ability for us to not worry about <em>why</em> things work is pervasive. For example, ever had a conversation like the following:</p>
<blockquote><p>Wife: I need to email someone this word document I just wrote</p>
<p>Me: ok, where did you save it?</p>
<p>Wife: in word</p>
<p>Me: ok, but is it in your documents folder or on your desktop?</p>
<p>Wife: I clicked File then Save.</p>
<p>Me: ooookaaaay, but what folder did you save it in?</p>
<p>Wife:</p>
<p>Me:</p>
<p>Wife:</p>
<p>Me: *sigh*</p></blockquote>
<p>Now, this isn&#8217;t an uncommon problem &#8211; people use computers all the time without really understanding what&#8217;s happening underneath. We learn a set of behaviours that do what we want. <em>Why</em> that set of behaviours work is irrelevant. We have a mental model that describes the world as we see it, our model is only called into question when we need to do something new or different.</p>
<h1>Mental Models</h1>
<p>The trouble is, from the outside, it can be very difficult to tell the difference between superstition and understanding. For example, how many Windows users actually understand <em>shortcuts</em>? Ever tried explaining the idea to your Dad? But yet, I bet he can click links on his desktop or in his start menu without any problem. His mental model of the world is sufficient to let him work, but insufficient to let him understand <em>why</em> it works. As soon as you step outside the normal behaviour &#8211; for example, trying to explain the difference between deleting the desktop icon and deleting the application &#8211; your mental model is challenged and superstitions exposed.<em><br />
</em></p>
<p>For users to not question things and adopt computer superstitions is understandable. But for software developers, it&#8217;s frightening. If you don&#8217;t understand something someone is explaining, you have to challenge it &#8211; either their model of the world is wrong or yours is. Either way, you&#8217;re not going to understand and agree until you can agree a consistent model.</p>
<h1>Voodoo Programmers</h1>
<p>But I&#8217;ve worked with developers who effectively become superstitious programmers. They don&#8217;t really know <em>why</em> something works, they just know that clicking these buttons does the right thing. Who needs to know how Hibernate works, as long as I know the magic incantations (or can copy&amp;paste from somewhere else) &#8211; I can get the job done! But as another developer on the team, without looking closely &#8211; can I tell whether you&#8217;ve setup the Hibernate mappings because you know how they work, or just copy&amp;pasted it from somewhere else without understanding?</p>
<p>The trouble is, almost all programmers resort to copy&amp;paste&amp;change from time-to-time. There are some incantations that are just too complex and too rarely used to memorise, so we quite reasonably borrow from somewhere else. But the difference between a developer that uses the incantations to aide his memory and the developer who just blindly copies without thinking is incredibly subtle. It&#8217;s easy to be one while thinking you&#8217;re the other &#8211; especially if it&#8217;s something you don&#8217;t do all the time.</p>
<h1>Understanding</h1>
<p>How many times have you found a fix for something but not understood <em>why</em>? Do you keep investigating or move on? For example, I was investigating a race condition recently and I&#8217;d spotted an incorrect implementation of <a href="http://en.wikipedia.org/wiki/Double-checked_locking">double-checked locking</a> - but I found that fixing it didn&#8217;t actually fix the bug. I wasn&#8217;t convinced I&#8217;d implemented the double-checked lock correctly either, so I replaced it with a method that always locked. What do you know: problem fixed!</p>
<p>Now, given what I know of the bug &#8211; that&#8217;s not right. Double-checked locking is a performance tweak, it shouldn&#8217;t impact the thread-safety of the solution. The fact that locking in all cases has fixed the bug gives me a hint that there must be something else that isn&#8217;t thread safe. By introducing the lock, the code that runs just after ends up <em>effectively</em> locked &#8211; it&#8217;s unlikely to get interrupted by the scheduler with another thread in the same critical section.</p>
<p>After another couple of hours investigation, I found the code in question &#8211; there was a singleton that was being given a reference to a non-thread safe object. I <em>could</em> have left my lock in place, since it &#8220;fixed&#8221; the bug &#8211; but by following my intuition that I didn&#8217;t understand the reason I found a much more damaging bug.</p>
<p>Understanding is key, be wary of superstitions. If you don&#8217;t understand <em>why</em> something works, keep digging. If this means you slow down: good! Going fast when you don&#8217;t understand what you&#8217;re doing is a recipe for disaster.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/914/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/914/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=914&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2012/10/09/knowledge-vs-superstition/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Fast Feedback</title>
		<link>http://blog.activelylazy.co.uk/2012/09/27/fast-feedback/</link>
		<comments>http://blog.activelylazy.co.uk/2012/09/27/fast-feedback/#comments</comments>
		<pubDate>Thu, 27 Sep 2012 19:10:22 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[pairing]]></category>
		<category><![CDATA[feedback]]></category>
		<category><![CDATA[code review]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=895</guid>
		<description><![CDATA[Writing good software is all about getting feedback, quickly. Does it compile? Does it function? Does it build? Does it deploy? Does it do what the customer wanted? Does it actually work? Every step of the way we have feedback loops, to improve the software. The faster these feedback loops are, the faster the software [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=895&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Writing good software is all about getting feedback, quickly. Does it compile? Does it function? Does it build? Does it deploy? Does it do what the customer wanted? Does it actually work? Every step of the way we have feedback loops, to improve the software. The faster these feedback loops are, the faster the software improves.</p>
<h1>Builds</h1>
<p>Don&#8217;t you hate waiting for your code to compile? Or, if you use a language from this century: do you remember back in the olden days when you had to wait for the compiler? Until recently, I&#8217;d actually forgotten that incremental compilers are a relatively new invention. I remember when JBuilder (my IDE of choice back in those distant times) first introduced me to incremental compilation &#8211; it was something of a revelation! You mean, I don&#8217;t have to hit compile? It just <em>does it</em>? In the <em>background</em>? Like <em>magic?!</em></p>
<p>A few years ago I joined a company who had something of a byzantine build process. As was the fashion at the time, they used ant for their build. Unfortunately, nobody had told them that Eclipse could also compile code. So all code was built with ant. Made a change? Run the ant build to build the relevant library (may require guesswork). Copy it (by hand) to the app server. Quickly restart WebSphere (note: not quick). Test. Lather. Rinse. Repeat. Die of boredom.</p>
<p>Eventually, I replaced this with an Eclipse workspace that could run the application. No more build step. No more copying things by hand. No more mistakes. No more long delays in getting feedback.</p>
<p>Just recently I started working with C++ again after nearly a decade in byte code / interpreted languages. I&#8217;d actually forgotten what it was like to wait for code to compile. I&#8217;d got so used to working in Eclipse where you press Go and Things Happen(tm). Now instead I have to wait for a build before I can do anything. Every little change involves minutes of my life waiting for Visual Studio.</p>
<p>Then, if I&#8217;m <em>really</em> lucky &#8211; it will even compile! Remember when your IDE didn&#8217;t give you little red squiggles or highlight broken code? How fast is that feedback loop now? Before I&#8217;ve even finished typing the IDE is telling me I&#8217;m a moron and suggesting how to fix it. Assuming my code compiles, next I run the gauntlet of <em>linking</em>. Normally that means some godawful error message that googling just gives decade old answers and stack overflow posts that might as well be discussing religion.</p>
<h1>TDD</h1>
<p>I suspect this is why TDD is less common in the C++ world. Not only does the language feel ill-suited to doing TDD (to be honest, it feels ill-suited to writing software at all), but if you have to wait minutes after each change &#8211; TDD just doesn&#8217;t work.</p>
<ul>
<li>Write a failing test</li>
<li>Wait minutes for the compiler to check your work, maybe go for a cuppa</li>
<li>Write code to make the test pass</li>
<li>Wait minutes for the compiler to check your work, perhaps its lunchtime?</li>
<li>Refactor</li>
</ul>
<p>Actually, scrap the last step &#8211; since C++ is basically entirely devoid of automated refactoring tools &#8211; just leave whatever mess you&#8217;ve created because it&#8217;s about as good as it will get.</p>
<p>But with a red, green, refactor cycle that takes approximately 2.6 hours &#8211; it would be impossibly slow. No wonder TDD happens less.</p>
<h1>Pairing</h1>
<p>I&#8217;ve been arguing recently about whether pairing or code review is the best way to improve code quality. I always used to be a huge believer in code review &#8211; I&#8217;d seen it have a massive impact on code quality and really help the team learn both the code and how to code better.</p>
<p>But now, after spending months pairing day in day out &#8211; I think pairing is better in every conceivable way than code review. Why? Because it&#8217;s so much more <em>immediate</em>. How many times have you heard feedback from code review getting left because &#8220;we don&#8217;t have time right now&#8221; or &#8220;we&#8217;ll come back to that just as soon as we&#8217;ve got this release out&#8221;.</p>
<p>But with pairing, you have your reviewer right there offering feedback, before you&#8217;ve even finished writing the line of code. Just like your modern IDE &#8211; giving you feedback before you&#8217;ve even had chance to get it wrong. And, just like the IDE, if the smart ass sitting next to you thinks he knows better, pass over the keyboard and let him show you.</p>
<p>This is just impossible with code review. The feedback cycle is necessarily much slower and, worse, it&#8217;s too easy to ignore. You can add a story to the backlog to fix code review comments. You can&#8217;t so easily add a story to the backlog to make the argumentative bloke next to you shut up! (More&#8217;s the pity, sometimes)</p>
<p>But either way &#8211; whether you get feedback from code review or pairing, the important thing is <em>to get feedback</em>. If you&#8217;re not getting feedback: you&#8217;re not learning and neither you nor your code are improving.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/895/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/895/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=895&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2012/09/27/fast-feedback/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>Pattern oriented programming</title>
		<link>http://blog.activelylazy.co.uk/2012/09/04/pattern-oriented-programming/</link>
		<comments>http://blog.activelylazy.co.uk/2012/09/04/pattern-oriented-programming/#comments</comments>
		<pubDate>Tue, 04 Sep 2012 19:16:32 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[design patterns]]></category>
		<category><![CDATA[frameworks]]></category>
		<category><![CDATA[gang of four]]></category>
		<category><![CDATA[patterns]]></category>
		<category><![CDATA[refactoring]]></category>
		<category><![CDATA[spring]]></category>
		<category><![CDATA[struts]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=866</guid>
		<description><![CDATA[Ever since the &#8220;Gang of Four&#8221; book, everyone and their uncle is an expert in patterns. Software is all about patterns &#8211; the trouble is, it seems very little of note has happened in the intervening 20 years. Why patterns are good Patterns help because they let us talk about code using a consistent language. [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=866&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>Ever since the &#8220;<a href="http://www.amazon.co.uk/Design-patterns-elements-reusable-object-oriented/dp/0201633612/ref=sr_1_1?ie=UTF8&amp;qid=1346350658&amp;sr=8-1">Gang of Four</a>&#8221; book, everyone and their uncle is an expert in patterns. Software is all about patterns &#8211; the trouble is, it seems very little of note has happened in the intervening 20 years.</p>
<h1>Why patterns are good</h1>
<p>Patterns help because they let us talk about code using a consistent language. Patterns make it easier to read code. Ultimately, reading code is all about being able to <em>reason</em> about it.</p>
<blockquote><p>If I change <em>this</em>, what&#8217;s going to break?</p>
<p><em>This</em> bug got reported in production, how the hell did it happen?</p></blockquote>
<p>If I can see the patterns the code implements, it lets me reason about the code more easily, without having to carefully analyse exactly what it does. Without them, I have to carefully understand every single line of code and try and reverse engineer the patterns.</p>
<p>The trouble is, the patterns often get mixed up with the implementation. This makes it hard to discern what the pattern is, and whether it&#8217;s actually being followed. Just because a class is called TradeManagerVisitorFactory doesn&#8217;t mean I actually know what it does. And when you open up the rats nest, you realise it&#8217;s going to take a <em>long</em> time to know what on earth it&#8217;s doing.</p>
<h1>Patterns Exist</h1>
<p>Patterns exist in our code, whether we explicitly call them out or not &#8211; there are hundreds, probably <em>thousands</em> of patterns that we&#8217;re all familiar with. Wouldn&#8217;t it be great if these patterns, at least within a single code base, were <em>consistent</em>? Wouldn&#8217;t it be great if we could help keep developers on the straight and narrow so that when they instantiate a second instance of my &#8220;singleton&#8221; we can break the build because it&#8217;s <em>obviously</em> changed something that might break all sorts of assumptions.</p>
<p>If we could start identifying the patterns in our code, and (somehow) separate that from how they&#8217;re <em>implemented</em>, we might actually be able to change how certain things are implemented, consistently, mechanically, across an entire enterprise-scale code base. Let me guess, an example would help?</p>
<h1>The Builder Pattern</h1>
<p>Ok, it&#8217;s a really simple pattern &#8211; but it makes a nice example. I have a class, that I need to be able to create, so I use the builder pattern. However, really, a builder is a type of <em>object construction pattern</em>. If I start thinking about different ways objects can be instantiated I can quickly come up with a handful of alternatives:</p>
<ul>
<li>A constructor, with a long parameter list</li>
<li>A builder, with a lot of setXxx methods</li>
<li>A builder, with a lot of withXxx methods, that each return the builder for method chaining</li>
<li>A builder with a list of properties for object initialisation (C#)</li>
</ul>
<p>Now, this means I have four ways of implementing &#8220;the builder pattern&#8221;. And you know, it makes <em>precisely zero</em> difference, functionality-wise, which I choose. It&#8217;s an entirely stylistic choice. However, I probably want it to be <em>consistent</em> across my codebase.</p>
<p>When it boils down to it, my pattern has three elements:</p>
<ul>
<li>The actual pattern &#8211; e.g. a builder with method chaining</li>
<li>The logic &amp; configuration for the pattern &#8211; the list of fields, the types, any type conversions or parsing etc</li>
<li>The actual rendering of the first two &#8211; this is <em>all</em> we have today: source code</li>
</ul>
<p>I don&#8217;t want to get rid of the last (code generation is great, until you have to, you know, actually <em>use</em> the generated code). This should all work from existing, real code. But maybe we could mark up the code with annotations or attributes to describe what pattern we&#8217;re following and how it&#8217;s configured. Some of the logic and configuration would have to be inferred &#8211; but that&#8217;s ok, once we know it&#8217;s a builder pattern we can take entire method bodies as &#8220;logic&#8221;.</p>
<h1>Pattern Migration</h1>
<p>But you know what would be <em>really awesome</em>? If I could <em>change</em> how the pattern is implemented. Maybe today I&#8217;m happy with all my objects being constructed from a long parameter list. But maybe tomorrow I decide to change my mind and use builders and withXxx method names. Wouldn&#8217;t it be awesome if I could simply change the global config and have all my code automagically refactored to match? If all my builders are annotated and identified, and all enforced to be written the same way &#8211; I can extract the configuration &amp; logic from the implementation and re-render the pattern differently. I could programmatically replace a constructor call with a builder or vice versa.</p>
<p>Ok, the builder is a trivial example that probably isn&#8217;t of much use. But how many more patterns are there? Say today I have classes with lots of static methods. Well, really, they&#8217;re singletons in disguise. But none of the cool kids create singletons nowadays, they use IoC frameworks like spring to create singleton beans. Wouldn&#8217;t it be nice if I could mass-migrate a legacy codebase from static methods, to singletons, to spring beans (and back again when I realise that&#8217;s made things worse!)</p>
<h1>Controllers</h1>
<p>What about a more complex example &#8211; let&#8217;s compare spring-mvc and struts. Two frameworks to accomplish <em>basically</em> the same thing &#8211; but both with a very different philosophy. The answer isn&#8217;t to build a framework to capture the common parts of both &#8211; trust me, been there, done that: you get the worst of both worlds.</p>
<p><strong>But</strong>, could you describe a pattern (probably several) that struts actions and spring-mvc controllers follow? Ultimately, both spring-mvc and struts let you respond to web requests with <em>some code</em>. Both give you access to the HTTP request and the session. Both give you a way of rendering a view. I wonder if you could describe how to extract the <em>pattern-specific</em> parts of a struts action and a spring-mvc controller? The config comes from different places, how to render views is different, how the view is selected is different, even the number of actions-per-class can be different. But, could you extract all that <em>functionally irrelevant detail</em> and separate the <em>pattern configuration</em> from the <em>underlying source code</em>.</p>
<p>If you could, maybe then you could describe a transformation between the two (sets of) patterns. This would give you a purely mechanical way of migrating a struts application to spring-mvc or vice versa.</p>
<h1>Pattern Database</h1>
<p>Now, the cost for me to describe, in great detail, all of the patterns for spring-mvc and struts in order to automatically migrate from one to the other is probably more than the effort to just get on and do it by hand. I could probably tackle a bunch with regexes and shell scripts, then hand finish the rest. However, what if we could define these patterns and <em>share them</em>? If there was some kind of open source pattern database? Then, the cost for the community is spread out &#8211; the cost for me is minimal.</p>
<p>Could we get to a point where our patterns are documented and <em>codified</em>? Where we can migrate between frameworks and even architectures with a manageable cost? An impossible dream? Or a better way of crafting software?</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/866/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/866/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=866&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2012/09/04/pattern-oriented-programming/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
		<item>
		<title>I can haz dependencies?</title>
		<link>http://blog.activelylazy.co.uk/2012/08/30/i-can-haz-dependencies/</link>
		<comments>http://blog.activelylazy.co.uk/2012/08/30/i-can-haz-dependencies/#comments</comments>
		<pubDate>Thu, 30 Aug 2012 18:15:18 +0000</pubDate>
		<dc:creator>David Green</dc:creator>
				<category><![CDATA[Software development]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[guice]]></category>
		<category><![CDATA[inversion of control]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[spring]]></category>

		<guid isPermaLink="false">http://blog.activelylazy.co.uk/?p=859</guid>
		<description><![CDATA[I hate IoC containers. Spring? Evil. Guice? The devil&#8217;s own work. Why? Because it leads to such slack, lazy, thoughtless programming. Why the hate? Ok, perhaps I better explain myself a bit. IoC is a great idea. What annoys me, is the way IoC frameworks end up getting used by normal people. I&#8217;ve ranted previously about [&#8230;]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=859&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>I hate IoC containers. Spring? Evil. Guice? The devil&#8217;s own work. Why? Because it leads to such slack, lazy, thoughtless programming.</p>
<h1>Why the hate?</h1>
<p>Ok, perhaps I better explain myself a bit. IoC is a <em>great idea</em>. What annoys me, is the way IoC frameworks end up getting used by normal people. I&#8217;ve ranted previously about how <a title="Implementing a rich domain model with Guice" href="http://blog.activelylazy.co.uk/2011/10/04/implementing-a-rich-domain-model-with-guice/">IoC containers lead us to implement anaemic domain models</a>. The trouble is, once you have a hammer, everything starts to look like a nail. Especially those pesky fingers. Once you have a dependency injection framework, everything starts to look like a dependency that needs to be injected. Need to implement some business logic? First create a new class, test drive it, then make it injectable, inject it into the class where the calling code needs it, test driving it natch, then bingo &#8211; you just hit yourself on the finger.</p>
<p>Now I&#8217;ve got two classes, basically closely coupled, but the IoC container hides that fact from me. I see a nice, clean interface being injected in. Aren&#8217;t I a good little OO developer? No, you&#8217;re stupid and you&#8217;re lazy.</p>
<p>Before you know it, your class has a dozen or more dependencies, each of which have a dozen dependencies, each of which have a dozen dependencies, each of which&#8230; you get the picture. You&#8217;ve managed to build a rats nest of a dependency graph, little by little. What you&#8217;ve TDD&#8217;d isn&#8217;t a design. The technical name for it is <a href="http://www.codinghorror.com/blog/2007/11/the-big-ball-of-mud-and-other-architectural-disasters.html">The Big Ball of Mud</a>.</p>
<h1>An Alternative</h1>
<p>Instead, I think dependency injection works best at application seams, at architectural boundaries. Say, for example, you&#8217;re building a web app. You&#8217;ve created a TradeEntryController that allows users to, well, enter trades. The TradeEntryController naturally has loads of dependencies on the rest of the system. It needs to fetch valid assets to invest in and prices, it needs to know what your balance is so you can&#8217;t buy more shares than money in the bank etc etc. A perfect example where life without an IoC container could become really cumbersome.</p>
<p>But, I don&#8217;t think you need one. I think what your controller needs is a few, specific dependencies &#8211; that define the architectural boundary the controller lives within. Above the controller is a HTTP request, a session and all that blah blah. Within it, is business logic. Below it is the database. So, the dependencies we inject should represent <strong>only</strong> the architectural context in which the controller operates. For the most part, this will be common to <em>all</em> my controllers &#8211; not just trade entry. Controllers for managing balances, lists of assets, user accounts &#8211; these all depend on knowing stuff about their session, and to be able to talk to the next layer down: the database (or in an n-tier setup, perhaps some web services).</p>
<p>So, why not just inject those dependencies?</p>
<pre class="brush: java; title: ; notranslate">
public class TradeEntryController {
    public void setSessionManager(ISessionManager sessionManager) { ... }
    public void setTradeDatabase(ITradeDatabase tradeDatabase) { ... }
    public void setAccountDatabase(IAccountDatabase accountDatabase) { ... }
    public void setAssetDatabase(IAssetDatabase assetDatabase) { ... }
}
</pre>
<p>Then in my controller, I can fetch user information from the SessionManager; I can get the list of assets from the AssetDatabase; I can check the user&#8217;s balance via the AccountDatabase; and I can record the trade via the TradeDatabase. So far, so much the same as a normal IoC container.</p>
<h1>So what&#8217;s different?</h1>
<p>Rather than manage these dependencies via an IoC container. I think you should push them in manually. Yes, I&#8217;m suggesting you write your own dead simple dependency injection framework. What? Am I mad? Quite probably, but bear with me.</p>
<pre class="brush: java; title: ; notranslate">
public interface ICanHazTradeDatabase {
    void setTradeDatabase(ITradeDatabase tradeDatabase);
}

public class TradeEntryController
    implements ICanHazTradeDatabase, ICanHazAssetDatabase...
{
    ...
}

public class ControllerFactory {
    public Controller createController(Class clazz) {
        Controller c = clazz.newInstance();
        if (c instanceof ICanHazTradeDatabase)
            ((ICanHazTradeDatabase) c).setTradeDatabase(tradeDatabase);
        if (c instanceof ICanHazAssetDatabase)
            ((ICanHazAssetDatabase) c).setAssetDatabase(assetDatabase);
        if ...

        return c;
    }
}
</pre>
<p>The exact mechanics of ControllerFactory of course depend on your MVC framework, but hopefully the idea is clear: when we instantiate a controller, we check it against a known set of interfaces and push in very specific dependencies. Is it pretty? Not really. Is it easy to write? Of course. Does it push dependencies into your controller? Well, yes. Where do they come from? Well, that&#8217;s an exercise for the reader. But I&#8217;m sure you can find a way to make ControllerFactory a singleton and instantiate all your dependencies in one place.</p>
<h1>The Point</h1>
<p>What, exactly, is the point of all this? Well, as a developer writing a controller &#8211; I can get easy access to all the dependencies that represent the architectural context I&#8217;m running within. The databases, services, message brokers, email server, blah blah blah that the application as a whole depends on. They&#8217;re right there &#8211; I just add the interface, one method and bang &#8211; ICanHazCheeseburger.</p>
<p>More interesting, is what I <strong>can&#8217;t</strong> do. I can&#8217;t decide that my TradeEntryController needs a TradePricingCalculator and inject that as a dependency. Well, I could, but I&#8217;d be making TradePricingCalculator available everywhere, and I&#8217;ve got a little more work to do than I would if I was using plain old Spring or Guice &#8211; I&#8217;ve an interface to create, a couple of lines to add to some scarily named GlobalControllerFactory. Why is this important? It adds some <strong>friction</strong>. It makes something bad hard to do. I&#8217;m forced instead to think about creating a TradePrices object and adding some functionality to it. I&#8217;m forced to have a rich domain, because I can&#8217;t just move all my functionality off into a TradePriceCalculatorVisitorFactoryManagerBuilder.<em><br />
</em></p>
<p>The choices we make and the technologies we choose make some things easy and other things hard. We need to think carefully about whether the things we make easy <em>should</em> be easy. It&#8217;s always <em>possible</em> to do the right thing, but sometimes we need to make it <em>easier</em> than doing the wrong thing.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/activelylazy.wordpress.com/859/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/activelylazy.wordpress.com/859/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.activelylazy.co.uk&#038;blog=5298473&#038;post=859&#038;subd=activelylazy&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://blog.activelylazy.co.uk/2012/08/30/i-can-haz-dependencies/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/00e555332332a9cd82924ac2571a0bad?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">activelylazy</media:title>
		</media:content>
	</item>
	</channel>
</rss>
