<?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>matt burns</title>
	<atom:link href="http://www.mattburns.co.uk/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mattburns.co.uk/blog</link>
	<description></description>
	<lastBuildDate>Wed, 11 Apr 2012 20:12:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Do you know Sarah who just turned 21? (Windsor, UK)</title>
		<link>http://www.mattburns.co.uk/blog/2012/04/11/found-21-year-old-sarahs-camera-with-birthday-presents/</link>
		<comments>http://www.mattburns.co.uk/blog/2012/04/11/found-21-year-old-sarahs-camera-with-birthday-presents/#comments</comments>
		<pubDate>Wed, 11 Apr 2012 20:11:49 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=407</guid>
		<description><![CDATA[This is an appeal to anyone who may know a 21 year old Sarah (born April 6th, 1991) in Windsor, UK. Her camera and other precious items have been found and we want to get them back to her.
Sarah ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>This is an appeal to anyone who may know a 21 year old Sarah (born April 6th, 1991) in Windsor, UK. Her camera and other precious items have been found and we want to get them back to her.</p>
<blockquote><p>Sarah a celebrated her 21st birthday on friday 6th april. she got picked up by a taxi in windsor on sat morning. a bag containing a pink floral photo album celebrating her life upto her 21st birthday, camera, scarf and other things were left. please help me locate this young lady. precious photos, im sure she would want back</p></blockquote>
<p>People are losing cameras all the time and thankfully there are plenty of nice people out there that find them and are happy to give them back. There are many more stories like these on the lost and found map over on <a title="stolen camera finder" href="http://www.stolencamerafinder.com/lostandfound.jsp">stolencamerafinder.com</a>.</p>
<p>Cheers, Matt</p>
<div id="attachment_408" class="wp-caption alignnone" style="width: 870px"><a href="http://www.stolencamerafinder.com/lostandfound.jsp"><img class="size-full wp-image-408" title="lost and found map" src="http://www.mattburns.co.uk/blog/wp-content/uploads/2012/04/lostandfoundmap.png" alt="" width="860" height="399" /></a><p class="wp-caption-text">There are so many reports, you can barely see the map underneath!</p></div>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=407&amp;md5=78fc4b2f93691708940f3fbb6b83105c" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2012/04/11/found-21-year-old-sarahs-camera-with-birthday-presents/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>&#8220;F&#8221; (The Movie) &#8211; Is everyone stupid or is it just me?</title>
		<link>http://www.mattburns.co.uk/blog/2012/03/04/f-the-movie-is-everyone-stupid-or-is-it-just-me/</link>
		<comments>http://www.mattburns.co.uk/blog/2012/03/04/f-the-movie-is-everyone-stupid-or-is-it-just-me/#comments</comments>
		<pubDate>Sun, 04 Mar 2012 11:52:15 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=393</guid>
		<description><![CDATA[Spoiler Alert - This will ruin the film if you haven't seen it.

F



This film started great, a teacher tangled in red tape, falls into depression and alcohol etc etc. But then these supernatural hooded psychos spring into the film and ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p><strong>Spoiler Alert</strong> - This will ruin the film if you haven&#8217;t seen it.</p>
<p><a href="http://www.imdb.com/title/tt1486670/">F</a></p>
<p><a href="http://www.imdb.com/title/tt1486670/"><img class="alignleft" title="F the movie" src="http://i.imgur.com/C0ncg.jpg" alt="" width="214" height="317" /></a></p>
<p>This film started great, a teacher tangled in red tape, falls into depression and alcohol etc etc. But then these supernatural hooded psychos spring into the film and start killing everyone. If that is all the film is then, well, let&#8217;s just say it&#8217;s not my kind of film.</p>
<p>However, I didn&#8217;t think that was what the story was about. I googled around to see if others had come to the same conclusion as me, but no-one had so I figured I&#8217;d post my interpretation here.</p>
<p>I thought at the end you were supposed to realise that the main protagonist, Robert, was the one who had killed everyone. There never were any crazed ASBO ninjas.</p>
<p>My reasons:</p>
<ol>
<li>The hoodies have no motivation for their killing spree.</li>
<li>The start of the film is all about his crumbling mental state. His paranoia about unstoppable violent youths. He hits his daughter, he&#8217;s losing it.</li>
<li>People get killed just after he leaves (like the librarian).</li>
<li>When he was with the security guard and they see a hoody, I assume Robert was going mental, schizophrenic style. The guard says something like &#8220;leave us alone&#8221; which could have referred to him and the daughter, not him and Robert. The guard then locks the door against him. Robert isn&#8217;t killed at this point even though he&#8217;s looking through the door for ages and they&#8217;re uber-fast freaking ninjas.</li>
<li>At the end I assumed Robert thinks he&#8217;s stabbing a hoody, but actually went a bit nuts again and stabbed his daughter.</li>
<li>At the very end, and his daughter sees her mum&#8217;s car, she wants to get out and find her mum. Perhaps she meant that they should stop her seeing the bodies, or that she wanted her mum to take her to the hospital.</li>
</ol>
<p>Obviously I&#8217;m probably completely wrong since no-one else has come to this conclusion and I&#8217;m rubbish at understanding films. Heck, when I saw the 6th sense I was practically in the cinema car park before I twigged what it was about. Anyway, I don&#8217;t really care. That&#8217;s what I think it was about and that helps make the film better for me!</p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=393&amp;md5=1f316802d635ba58addeb7cd349001a7" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2012/03/04/f-the-movie-is-everyone-stupid-or-is-it-just-me/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My first &#8220;parkrun&#8221;</title>
		<link>http://www.mattburns.co.uk/blog/2012/03/03/my-first-parkrun/</link>
		<comments>http://www.mattburns.co.uk/blog/2012/03/03/my-first-parkrun/#comments</comments>
		<pubDate>Sat, 03 Mar 2012 10:58:10 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[running]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=390</guid>
		<description><![CDATA[Today I ran my first parkrun. If like me you've never heard of them:
parkrun organise free, weekly, 5km timed runs around the world. They are open to everyone, free, and are safe and easy to take part in.
Pretty simple ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>Today I ran my first parkrun. If like me you&#8217;ve never heard of them:</p>
<blockquote><p>parkrun organise free, weekly, 5km timed runs around the world. They are open to everyone, free, and are safe and easy to take part in.</p></blockquote>
<p>Pretty simple really. You just register for free on the website for a personal barcode, print it out then turn up and race. You just register as a runner, not for individual races, it&#8217;s up to you which races you attend.</p>
<p>The <a title="Bristol parkrun" href="http://www.parkrun.org.uk/ashton-court/home">parkrun in Bristol</a> is held in Ashton Court, a pretty simple <a href="http://www.endomondo.com/workouts/sDVNzvo-IEE">out-and-back course</a> that takes you up a hill then back down it.</p>
<p>The races starts at 9am so I left the house a little late at 8:40 but thought I&#8217;d be ok. I underestimated how rubbish my bike is, how strong the wind was and how slow I am. It too me 22 minutes of flat-out cycling to get to the start line. Luckily the race started 5 minutes late so I was able to join in (heart still beating like mad!).</p>
<p>As usual, I started near the front over-filled with optimism. Half way up the climb my pace slows to a crawl and I realise I left all my optimism at the start line. I plod on.</p>
<p>At the half way point of the course you&#8217;re at the top of the park and turn back on yourself. Panoramic views of Bristol spread before you and you realise it&#8217;s all downhill from here. The optimism has caught me up and I smile. I probably look like a complete idiot when I run downhill, bouncing with huge lanky strides. I don&#8217;t care, it feels great, I love running downhill. The wind is also on my back and it just feels like flying. I start picking off the people that overtook me on the climb. Clap clap, my feet pound the path picking up dangerous speeds. This can&#8217;t be good for my bones. It doesn&#8217;t even feel like hard work, I can feel my heart rate dropping. Did I mention I love running downhill?</p>
<p>If you&#8217;re expecting me to say I won the thing, well, I was nowhere near. I guess I finished about 30th and I forgot to stop my watch so don&#8217;t really know what my time was (although it&#8217;ll be on <a href="http://www.parkrun.org.uk/ashton-court/results/weeklyresults?runSeqNumber=44">the website</a> later). That doesn&#8217;t matter though, it was a good, fun race. Well, I say it doesn&#8217;t matter but I&#8217;m far too competitive to leave it there. I wonder if I can get into the top 20 before the end of the month&#8230; <img src='http://www.mattburns.co.uk/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=390&amp;md5=cab6ef9bd599f8cfe38cd402506e966c" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2012/03/03/my-first-parkrun/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My recommendation for your first SLR in 2012</title>
		<link>http://www.mattburns.co.uk/blog/2012/02/27/my-recommendation-for-your-first-slr-in-2012/</link>
		<comments>http://www.mattburns.co.uk/blog/2012/02/27/my-recommendation-for-your-first-slr-in-2012/#comments</comments>
		<pubDate>Mon, 27 Feb 2012 11:17:13 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=380</guid>
		<description><![CDATA[Want better photos?
As I've mentioned before, I get asked what camera to buy a lot. I mean loads, it's silly. Generally, I get asked by people who are fed up with the blurry, grainy photos they are currently taking ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><h2>Want better photos?</h2>
<p>As I&#8217;ve mentioned before, I get asked what camera to buy a lot. I mean loads, it&#8217;s silly. Generally, I get asked by people who are fed up with the blurry, grainy photos they are currently taking and think a new camera will solve everything. If this sounds like you, then go <a title="Buying Your First SLR" href="http://www.mattburns.co.uk/blog/2010/05/22/buying-your-first-slr/">read my previous post</a> about whether or not an SLR is for you.</p>
<p>Done? Still interested? Excellent&#8230;</p>
<h2>For entry-level, buy new</h2>
<p>In that post I suggested that buying second hand may be a good way to go. Well, I just had a rummage around eBay, and although I would recommend it for buying more expensive second hand pro stuff, the entry level stuff seems to hold its price a lot better. So much so that most of what I saw is now better specced brand new for the same money. When buying entry-level equipment, I suggest you buy new. Sleep easy knowing that you&#8217;ll probably be able to sell it for a decent price should you choose to upgrade in a few years.</p>
<h2>Manufacturer lock-in</h2>
<p>The first choice to make is between Canon and Nikon (some argue Sony but I wouldn’t). Lenses and flashes are generally not interchangeable between brands, so whichever one you pick, you’re kinda stuck with forever. (I’m on team Canon, but Nikon also make awesome stuff). Don&#8217;t stress about it too much, it doesn&#8217;t matter, flip a coin.</p>
<h2>My favourite</h2>
<p>After looking around, my recommendation is the <a href="http://www.amazon.co.uk/gp/product/B004MPQXZA/ref=as_li_ss_tl?ie=UTF8&amp;tag=mattburnscouk-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B004MPQXZA" target="_blank">Canon 1100D</a>. It is a cracking little camera. Packing great bang for buck, it also shoots HD video. It&#8217;s just dropped in price on Amazon for some reason, so I think it&#8217;s an absolute bargain.</p>
<p>£352 &#8211; <a href="http://www.amazon.co.uk/gp/product/B004MPQXZA/ref=as_li_ss_tl?ie=UTF8&amp;tag=mattburnscouk-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B004MPQXZA" target="_blank">Camera body + kit lens (18-55mm)</a><br />
The kit lens is a great all-rounder and worth a good £100 on it&#8217;s own.</p>
<h2>Extra lens</h2>
<p>If you&#8217;re feeling flush, the first lens you should buy is a no-brainer (in my humble opinion).</p>
<p>£81 &#8211; <a href="http://www.amazon.co.uk/gp/product/B00005K47X/ref=as_li_ss_tl?ie=UTF8&amp;tag=mattburnscouk-21&amp;linkCode=as2&amp;camp=1634&amp;creative=19450&amp;creativeASIN=B00005K47X" target="_blank">50mm lens. The &#8220;nifty-fifty&#8221;</a></p>
<p>This lens is amazing and dirt cheap. In my short experience, you normally have to spend £300 before you can get a lens that is worth having. This one bucks that trend by producing the best photos you&#8217;ve ever taken.<br />
<em>Warning</em>: It has no zoom at all. None. Nada. Zip. If you want to zoom in or out you have to walk. It sounds pretty crazy but it&#8217;s worth it for the picture quality. It&#8217;s f1.8 which means it practically sees in the dark and takes prints that look like they belong in a magazine. Bear in mind this lens is perfect for taking portraits, baby photos etc. but no good for anything wider like landscapes. I find landscapes boring anyway. Being a &#8220;fast&#8221; lens means you&#8217;ll be able to take sharper images (same bright image in faster shutter time) which is handy for fast moving kids.</p>
<h2><del>Film</del> Memory</h2>
<p>You&#8217;ll need a memory card, I always choose memory cards in this order:<br />
Brand &#8211; for reliability<br />
Speed &#8211; don&#8217;t buy a slow one<br />
Size &#8211; your budget will decide this</p>
<p>There&#8217;s no point putting a link for this, prices change by the minute, just have a shop around. Perhaps you already have one lying around in an old camera/phone/wii&#8230;</p>
<h2>Good luck</h2>
<p>Even though this equipment is described as &#8220;entry-level&#8221; don&#8217;t let that put you off. Seriously, you&#8217;ll take photos so good you&#8217;ll grin from ear to ear. You&#8217;ll show your friends and they&#8217;ll compliment you on what a great photographer you are. Six months later you&#8217;ll look back at those photos with a harsh and critical eye and be surprised at how amateur they were. Congratulations, you&#8217;re on your slippery way to an expensive but rewarding hobby.</p>
<p>If you take this advice, be sure to post a link to your flickr / Google+ photos page in the comments below. <img src='http://www.mattburns.co.uk/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=380&amp;md5=c1dd4ae0b999cc409e06ab8768018e55" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2012/02/27/my-recommendation-for-your-first-slr-in-2012/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Testing JavaScript with QUnit for for Dummies, sorry, Java developers</title>
		<link>http://www.mattburns.co.uk/blog/2012/01/11/testing-javascript-with-quni/</link>
		<comments>http://www.mattburns.co.uk/blog/2012/01/11/testing-javascript-with-quni/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 13:03:50 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=365</guid>
		<description><![CDATA[Disclaimer: I'm no javascript expert so I may be am almost certainly talking a load of rubbish here.

I was just looking for a unit testing framework for some javascript I'm writing  (rather the the home-rolled framework I've out-grown) ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>Disclaimer: I&#8217;m no javascript expert so I <del datetime="2012-01-11T12:23:57+00:00">may be</del> am almost certainly talking a load of rubbish here.</p>
<p>I was just looking for a unit testing framework for some javascript I&#8217;m writing  (rather the the home-rolled framework I&#8217;ve out-grown) and came across <a href="http://docs.jquery.com/QUnit">QUnit</a>. I&#8217;ve not tried any others so feel free to suggest alternatives. So far, it&#8217;s great and does everything I want and took me almost no time to learn. Easy.</p>
<p>The one thing that bugs me though is that they&#8217;ve swapped &#8220;expected&#8221; and &#8220;actual&#8221; parameter arguments around for the equality test. Technically it&#8217;s not that important since it won&#8217;t affect the result of the test, but in practice I think it&#8217;s very important. Your tests form part of your documentation of how the code should behave. If you get them the wrong way around and a test fails with &#8220;expected 10 but got 20&#8243; the developer may well go off and try to make the code return 10. *shudder*.</p>
<p>Java method signature in JUnit:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw4">void</span> assertEquals<span class="br0">&#40;</span><span class="kw3">Object</span> expected, <span class="kw3">Object</span> actual<span class="br0">&#41;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">public static void assertEquals(Object expected, Object actual)</pre></div></div>

<p>The <a href="http://kentbeck.github.com/junit/javadoc/latest/org/junit/Assert.html">class</a> offers overloaded implementations with primitives or with message etc. There are also ways of writing your tests in a type-safe fashion to prevent this whole problem in Java, but in my experience, this is more common. Another post maybe&#8230;</p>
<p>Javascript function signature in QUnit:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1">equal<span class="br0">&#40;</span> actual<span class="sy0">,</span> expected<span class="sy0">,</span> <span class="br0">&#91;</span>message<span class="br0">&#93;</span> <span class="br0">&#41;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">equal( actual, expected, [message] )</pre></div></div>

<p>I can only assume they reversed the order of the arguments because of the way that javascript allows optional arguments.</p>
<p>I flip between writing Java and JavaScript quite a lot which would be a disaster waiting to happen so I&#8217;ve just wrapped it in my own function:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
</pre></td><td class="de1"><pre class="de1"><span class="kw2">function</span> assertEquals<span class="br0">&#40;</span>expected<span class="sy0">,</span> actual<span class="sy0">,</span> message<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; equal<span class="br0">&#40;</span>actual<span class="sy0">,</span> expected<span class="sy0">,</span> message<span class="br0">&#41;</span><span class="sy0">;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">function assertEquals(expected, actual, message) {
    equal(actual, expected, message);
}</pre></div></div>

<p>This all feels wrong and stupid. What do you think?</p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=365&amp;md5=31705cc2153eb031d1ed8c615c3f7f5b" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2012/01/11/testing-javascript-with-quni/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The cheapest way to get a Samsung Galaxy S2 in the UK</title>
		<link>http://www.mattburns.co.uk/blog/2011/12/07/the-cheapest-way-to-get-a-samsung-galaxy-s2-in-the-uk/</link>
		<comments>http://www.mattburns.co.uk/blog/2011/12/07/the-cheapest-way-to-get-a-samsung-galaxy-s2-in-the-uk/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 12:46:45 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=354</guid>
		<description><![CDATA[If you're a materialistic idiot like me, you'll be interested in how you can get your hands on a disgustingly extravagant smartphone while parting with the least amount of cash possible.

The best deal I found for the Galaxy S2 ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>If you&#8217;re a materialistic idiot like me, you&#8217;ll be interested in how you can get your hands on a <a href="http://www.samsung.com/uk/galaxys2/">disgustingly extravagant smartphone</a> while parting with the least amount of cash possible.</p>
<p>The best deal I found for the Galaxy S2 (by far) has been through <a href="http://clkuk.tradedoubler.com/click?p=898&#038;a=2046553&#038;g=14074016">Tesco</a>:</p>
<ul>
<li>Free handset</li>
<li>T-Mobile network</li>
<li>300 mins/300 texts</li>
<li>24 month contract</li>
<li>Free delivery</li>
<li>500MB Data Booster + Unlimited Internet</li>
<li>£20 of free apps available (through some T&amp;Cs)</li>
<li><strong>£20.42</strong> per month</li>
</ul>
<div><a href="http://phone-shop.tesco.com/mobile-phones-and-sim-cards/pay-monthly-phones/pay-monthly-phones-listing.aspx?manufacturer=Samsung&amp;model=Galaxy%20S%20II&amp;networkProvider=&amp;contractLength=&amp;price=0&amp;colour=&amp;group=&amp;tmcampid=7&amp;tmad=c" target="_blank">Here&#8217;s the link.</a></div>
<div>At time of writing, that is the best deal I could find and is even better than anything I could find through the (usually excellent) <a href="http://www.billmonitor.com/">billmonitor</a> website.</div>
<div>Chances are that deal should work out just fine for you. If so, I hope this post helped you out.</div>
<p>&nbsp;</p>
<h1>Current T-Mobile customers:</h1>
<div>If (like me) you are already a T-Mobile customer then the checkout procedure will fail right at the end with an error code &#8220;<span style="color: #800000;">existing customer</span>&#8220;. I went into the tesco mobile shop and was told that the only way around it was to switch to a PAYG contract, then try again. This was a bit of a pain and I won&#8217;t bore you with the series of contradicting advice I got from T-Mobile on the matter. If you&#8217;re a T-Mobile customer, you have to do the following:</div>
<div>
<ol>
<li>Buy a PAYG sim card (I got one for £11.99 with £10 credit from <a href="http://www.three.co.uk/">Three</a> but you can get cheaper).</li>
<li>Ring T-Mobile. Tell them you wish to cancel. Also request a Porting Authorisation Code (<a href="http://en.wikipedia.org/wiki/Porting_Authorisation_Code">PAC</a>) so that you can keep my number. Your account isn&#8217;t actually closed until the number is ported.</li>
<li>Contact your PAYG sim network to port your number. For Three there is an <a href="http://www.three.co.uk/Support/Welcome_to_Three">online form</a> under &#8220;Bringing your number to Three&#8221;.</li>
<li>Once your number has been ported onto your PAYG sim (mine took 1 day) you can order your phone from Tesco.</li>
</ol>
<div>There are a few quirks with the tesco order form. For example, entering a landline number is mandatory and a mobile number is not accepted. I just made up a number and it still worked. Also, it asked me to enter my name as it appears on the card (MR M J BURNS) but then complained that my first name was too short.  I entered both my initials in the firstname box and that worked.</div>
</div>
<p>&nbsp;</p>
<h1>Alternatives</h1>
<div>The <a href="http://www.google.co.uk/nexus/">Google Nexus</a> is the new kid on the block but costs big bucks at the moment. There&#8217;s also an upgraded Galaxy S2 in the form of the Galaxy S2 HD LTE floating around Japan. Don&#8217;t get too excited though, this isn&#8217;t coming to the UK for ages and there&#8217;s no foreseeable plans for a decent rollout of a 4G network in the UK for quite a while anyway. You should also consider if you can afford to commit to 24 months for a phone that won&#8217;t make your life any better/easier/happier. It&#8217;s just a phone. Pah, who am I kidding, it&#8217;s a work of art and object of pure desire!</div>
<p>&nbsp;</p>
<h1>Conclusion</h1>
<div>Getting your hands on this Tesco deal can be a bit of hassle, but when you look at the savings over 24 months, completely worth it.</div>
<div>I hope this helps you if you&#8217;re in the market for a top smartphone.</div>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=354&amp;md5=04bd84a46a694c3003dae17c60565762" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2011/12/07/the-cheapest-way-to-get-a-samsung-galaxy-s2-in-the-uk/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Simplify your API &#8211; Can Singletons be used for Good, not Evil?</title>
		<link>http://www.mattburns.co.uk/blog/2011/11/14/simplify-your-api/</link>
		<comments>http://www.mattburns.co.uk/blog/2011/11/14/simplify-your-api/#comments</comments>
		<pubDate>Mon, 14 Nov 2011 15:55:53 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=304</guid>
		<description><![CDATA[I recently wrote an article about singletons in java. The only thing I wanted to cover was that if you really want a singleton, I recommend you use the enum pattern. This post was motivated after more interesting comments ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>I recently wrote <a href="http://www.mattburns.co.uk/blog/2011/10/26/how-to-write-singletons-in-java/">an article about singletons</a> in java. The only thing I wanted to cover was that if you really want a singleton, I recommend you use the enum pattern. This post was motivated after more interesting comments were raised about testability when you see the &#8220;static&#8221; keyword.</p>
<p>When you type &#8220;static&#8221; a little alarm bell should ring in your head to warn you that there could be trouble ahead. As <a href="http://dantwining.co.uk">Dan</a> correctly pointed out, a reference to the static member INSTANCE will tightly couple the caller to Elvis. This is not good if testing with Elvis will cause you problems. For example, if Elvis is slow, or accesses a database or something like that which would be better tested with a mock implementation.</p>
<p>However, sometimes the static keyword makes sense because it is an implementation detail that you are not concerned with. By you I mean a client of the code. Why muddy an API so that you can pass around objects that will never change. To illustrate my point, I wrote a very simple bit of code that hopefully isn&#8217;t too contrived. </p>
<p>Imagine you have to write a computer system for a Blackpool nightclub called &#8220;Elvis Live!&#8221;. This club has a different Elvis impersonator on every night. The system has to manage the bookings of the different Elvis impersonators and print the posters which list which impersonators are performing each night.</p>
<p>In my very simple implementation I wrote a class to represent the club:<br />
<strong>ElvisClub.java</strong></p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 252px;"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
</pre></td><td class="de1"><pre class="de1"><span class="kw1">package</span> <span class="co2">uk.co.mattburns.elvis</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">java.util.Map</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.joda.time.LocalDate</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">com.google.common.collect.Maps</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">public</span> <span class="kw1">class</span> ElvisClub <span class="br0">&#123;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">final</span> Map<span class="sy0">&lt;</span>LocalDate, ElvisImpersonator<span class="sy0">&gt;</span> bookings <span class="sy0">=</span> Maps
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .<span class="me1">newTreeMap</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">boolean</span> bookImpersonator<span class="br0">&#40;</span>LocalDate date,
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElvisImpersonator impersonator<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">if</span> <span class="br0">&#40;</span>bookings.<span class="me1">containsKey</span><span class="br0">&#40;</span>date<span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">false</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span> <span class="kw1">else</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bookings.<span class="me1">put</span><span class="br0">&#40;</span>date, impersonator<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="kw2">true</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> ElvisImpersonator getImpersonatorOnDate<span class="br0">&#40;</span>LocalDate date<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> bookings.<span class="me1">get</span><span class="br0">&#40;</span>date<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw3">String</span> getPosterTitle<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> <span class="st0">&quot;Keeping The King Alive since &quot;</span> <span class="sy0">+</span> Elvis.<span class="me1">INSTANCE</span>.<span class="me1">died</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw3">String</span> getPosterBody<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; StringBuilder stringBuilder <span class="sy0">=</span> <span class="kw1">new</span> StringBuilder<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">for</span> <span class="br0">&#40;</span>LocalDate date <span class="sy0">:</span> bookings.<span class="me1">keySet</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ElvisImpersonator act <span class="sy0">=</span> bookings.<span class="me1">get</span><span class="br0">&#40;</span>date<span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stringBuilder.<span class="me1">append</span><span class="br0">&#40;</span>date.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">+</span> <span class="st0">&quot; : See &quot;</span> <span class="sy0">+</span> act.<span class="me1">name</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stringBuilder.<span class="me1">append</span><span class="br0">&#40;</span><span class="st0">&quot; who was born &quot;</span> <span class="sy0">+</span> act.<span class="me1">yearsBornAfterElvis</span><span class="br0">&#40;</span><span class="br0">&#41;</span>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span class="sy0">+</span> <span class="st0">&quot; years after Elvis&quot;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> stringBuilder.<span class="me1">toString</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package uk.co.mattburns.elvis;
import java.util.Map;
import org.joda.time.LocalDate;
import com.google.common.collect.Maps;

public class ElvisClub {

    private final Map&lt;LocalDate, ElvisImpersonator&gt; bookings = Maps
            .newTreeMap();

    public boolean bookImpersonator(LocalDate date,
            ElvisImpersonator impersonator) {
        if (bookings.containsKey(date)) {
            return false;
        } else {
            bookings.put(date, impersonator);
            return true;
        }
    }

    public ElvisImpersonator getImpersonatorOnDate(LocalDate date) {
        return bookings.get(date);
    }

    public String getPosterTitle() {
        return "Keeping The King Alive since " + Elvis.INSTANCE.died();
    }

    public String getPosterBody() {
        StringBuilder stringBuilder = new StringBuilder();
        for (LocalDate date : bookings.keySet()) {
            ElvisImpersonator act = bookings.get(date);
            stringBuilder.append(date.toString() + " : See " + act.name());
            stringBuilder.append(" who was born " + act.yearsBornAfterElvis()
                    + " years after Elvis");
        }
        return stringBuilder.toString();
    }
}</pre></div></div>

<p>A simple pojo to represent a performer at the club:<br />
<strong>ElvisImpersonator.java</strong></p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 252px;"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
</pre></td><td class="de1"><pre class="de1"><span class="kw1">package</span> <span class="co2">uk.co.mattburns.elvis</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.joda.time.LocalDate</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">public</span> <span class="kw1">class</span> ElvisImpersonator <span class="br0">&#123;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">final</span> <span class="kw3">String</span> name<span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">final</span> LocalDate birthdate<span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> ElvisImpersonator<span class="br0">&#40;</span><span class="kw3">String</span> name, LocalDate birthdate<span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">name</span> <span class="sy0">=</span> name<span class="sy0">;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">this</span>.<span class="me1">birthdate</span> <span class="sy0">=</span> birthdate<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw3">String</span> name<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> name<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> LocalDate birthdate<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> birthdate<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">int</span> yearsBornAfterElvis<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> birthdate<span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getYear</span><span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="sy0">-</span> Elvis.<span class="me1">INSTANCE</span>.<span class="me1">born</span><span class="br0">&#40;</span><span class="br0">&#41;</span>.<span class="me1">getYear</span><span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package uk.co.mattburns.elvis;
import org.joda.time.LocalDate;

public class ElvisImpersonator {

    private final String name;
    private final LocalDate birthdate;

    public ElvisImpersonator(String name, LocalDate birthdate) {
        this.name = name;
        this.birthdate = birthdate;
    }

    public String name() {
        return name;
    }

    public LocalDate birthdate() {
        return birthdate;
    }

    public int yearsBornAfterElvis() {
        return birthdate().getYear() - Elvis.INSTANCE.born().getYear();
    }
}</pre></div></div>

<p>Crucially, both of these classes have a dependency on Elvis. I decided to make Elvis a singleton:<br />
<strong>Elvis.java</strong></p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar" style="right: 15px;" ><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"style=" height: 252px;"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="de1"><pre class="de1"><span class="kw1">package</span> <span class="co2">uk.co.mattburns.elvis</span><span class="sy0">;</span>
<span class="kw1">import</span> <span class="co2">org.joda.time.LocalDate</span><span class="sy0">;</span>
&nbsp;
<span class="kw1">public</span> <span class="kw1">enum</span> Elvis <span class="br0">&#123;</span>
&nbsp; &nbsp; INSTANCE<span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">final</span> LocalDate born <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1935</span>, <span class="nu0">1</span>, <span class="nu0">8</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw1">private</span> <span class="kw1">final</span> LocalDate died <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1977</span>, <span class="nu0">8</span>, <span class="nu0">16</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> LocalDate born<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> born<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
&nbsp;
&nbsp; &nbsp; <span class="kw1">public</span> LocalDate died<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; &nbsp; &nbsp; <span class="kw1">return</span> died<span class="sy0">;</span>
&nbsp; &nbsp; <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">package uk.co.mattburns.elvis;
import org.joda.time.LocalDate;

public enum Elvis {
    INSTANCE;
    private final LocalDate born = new LocalDate(1935, 1, 8);
    private final LocalDate died = new LocalDate(1977, 8, 16);

    public LocalDate born() {
        return born;
    }

    public LocalDate died() {
        return died;
    }
}</pre></div></div>

<p>You can browse all the source code <a href="http://code.google.com/p/elvis-club/source/browse/trunk/">here</a>. Or better still, checkout the code and simply import the project into eclipse:</p>
<code class="bwp-syntax-inline"><span style="color: #c20cb9; font-weight: bold;">svn</span> checkout http:<span style="color: #000000; font-weight: bold;">//</span>elvis-club.googlecode.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>trunk<span style="color: #000000; font-weight: bold;">/</span> elvis-club-read-only</code>
<p>&nbsp;</p>
<p>I already know what you&#8217;re thinking:</p>
<blockquote><p>Elvis.java should be an interface: Celebrity.java. Then I could have a concrete Elvis to pass around which implements Celebrity.</p></blockquote>
<blockquote><p>ElvisImpersonator.java should be an interface: Impersonator.java. Then I could write a CelebrityImpersonator.java which would take a Celebrity on construction.</p></blockquote>
<p>That is one way of solving it, and it&#8217;s not a bad way. I agree that you should expect change, embrace it, marry it, have its babies, but don&#8217;t start writing code for it before it&#8217;s happened. One day the club may have a Marilyn Monroe night and in that case you anticipated change <del datetime="2011-11-14T12:39:43+00:00">beautifully</del> luckily. What if it changes into a comedy club? How about a restaurant?</p>
<p>What&#8217;s really important is writing code that&#8217;s easy for programmers to read, and therefore, easy for programmers to change.</p>
<p>Here is a snippet from some of my test code which gives you an idea of what I mean:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
</pre></td><td class="de1"><pre class="de1">ElvisClub theClub <span class="sy0">=</span> <span class="kw1">new</span> ElvisClub<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
LocalDate today <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
LocalDate brianBorn <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1970</span>, <span class="nu0">1</span>, <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
ElvisImpersonator brian <span class="sy0">=</span> <span class="kw1">new</span> ElvisImpersonator<span class="br0">&#40;</span><span class="st0">&quot;Brian&quot;</span>, brianBorn<span class="br0">&#41;</span><span class="sy0">;</span>
theClub.<span class="me1">bookImpersonator</span><span class="br0">&#40;</span>today, brian<span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">ElvisClub theClub = new ElvisClub();
LocalDate today = new LocalDate();
LocalDate brianBorn = new LocalDate(1970, 1, 1);
ElvisImpersonator brian = new ElvisImpersonator("Brian", brianBorn);
theClub.bookImpersonator(today, brian);</pre></div></div>

<p>A similar snippet, without using the Elvis singleton would look something like this:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
6
7
8
</pre></td><td class="de1"><pre class="de1">LocalDate brianBorn <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1970</span>, <span class="nu0">1</span>, <span class="nu0">1</span><span class="br0">&#41;</span><span class="sy0">;</span>
LocalDate elvisBorn <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1935</span>, <span class="nu0">1</span>, <span class="nu0">8</span><span class="br0">&#41;</span><span class="sy0">;</span>
LocalDate elvisDied <span class="sy0">=</span> <span class="kw1">new</span> LocalDate<span class="br0">&#40;</span><span class="nu0">1977</span>, <span class="nu0">8</span>, <span class="nu0">16</span><span class="br0">&#41;</span><span class="sy0">;</span>
&nbsp;
Celebrity realElvis <span class="sy0">=</span> <span class="kw1">new</span> CelebrityImpl<span class="br0">&#40;</span><span class="st0">&quot;Elvis&quot;</span>, elvisBorn, elvisDied<span class="br0">&#41;</span><span class="sy0">;</span>
Impersonator brian <span class="sy0">=</span> <span class="kw1">new</span> CelebrityImpersonator<span class="br0">&#40;</span><span class="st0">&quot;Brian&quot;</span>, realElvis, brianBorn<span class="br0">&#41;</span><span class="sy0">;</span>
Club theClub <span class="sy0">=</span> <span class="kw1">new</span> Club<span class="br0">&#40;</span>realElvis<span class="br0">&#41;</span><span class="sy0">;</span>
theClub.<span class="me1">bookImpersonator</span><span class="br0">&#40;</span>today, brian<span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">LocalDate brianBorn = new LocalDate(1970, 1, 1);
LocalDate elvisBorn = new LocalDate(1935, 1, 8);
LocalDate elvisDied = new LocalDate(1977, 8, 16);

Celebrity realElvis = new CelebrityImpl("Elvis", elvisBorn, elvisDied);
Impersonator brian = new CelebrityImpersonator("Brian", realElvis, brianBorn);
Club theClub = new Club(realElvis);
theClub.bookImpersonator(today, brian);</pre></div></div>

<p>There&#8217;s not a massive difference but I still think the constructors are a bit &#8220;noisy&#8221;. In a real-world application, you would probably expect references to a more complex set of collaborating objects.</p>
<p>I haven&#8217;t sacrificed any testibility of my code. If anything, I&#8217;ve reduced the amount of code I <em>need</em> to test. My way, there can only be Elvis and so I only need to test that the club handles things to do with Elvis. If I wrote a more generic version I would have to test that it handles Celebrities that are still alive, that they were born before they died, and so on.</p>
<p>I think I&#8217;m right but I&#8217;ve changed software design views pretty frequently over the last 10 years. If you think I&#8217;m wrong, I challenge you to convince me why&#8230;</p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=304&amp;md5=f2a5b2cf52c67328c1ae717b0b4bb704" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2011/11/14/simplify-your-api/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Bug with JQuery validation error messages showing tooltip text</title>
		<link>http://www.mattburns.co.uk/blog/2011/10/28/bug-with-jquery-validation-error-messages-showing-tooltip-text/</link>
		<comments>http://www.mattburns.co.uk/blog/2011/10/28/bug-with-jquery-validation-error-messages-showing-tooltip-text/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 13:50:45 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=295</guid>
		<description><![CDATA[I had the following html in my form:

Email


Nothing complicated there I hope.
I had the help text set in the title attribute of the input which I styled with the lovely qTip to make it look nice. I validated my ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>I had the following html in my form:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="html4strict"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
</pre></td><td class="de1"><pre class="de1"><span class="sc2">&lt;<span class="kw2">label</span> <span class="kw3">for</span><span class="sy0">=</span><span class="st0">&quot;email-input&quot;</span>&gt;</span>Email<span class="sc2">&lt;<span class="sy0">/</span><span class="kw2">label</span>&gt;</span>
<span class="sc2">&lt;<span class="kw2">input</span> <span class="kw3">id</span><span class="sy0">=</span><span class="st0">&quot;email-input&quot;</span></span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; <span class="kw3">type</span><span class="sy0">=</span><span class="st0">&quot;text&quot;</span></span>
<span class="sc2"> &nbsp; &nbsp; &nbsp; <span class="kw3">title</span><span class="sy0">=</span><span class="st0">&quot;Don't worry, your email will not be displayed on the website or given to anyone else. We hate spam too.&quot;</span> <span class="sy0">/</span>&gt;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">&lt;label for="email-input"&gt;Email&lt;/label&gt;
&lt;input id="email-input"
       type="text"
       title="Don't worry, your email will not be displayed on the website or given to anyone else. We hate spam too." /&gt;</pre></div></div>

<p>Nothing complicated there I hope.<br />
I had the help text set in the title attribute of the input which I styled with the lovely <a href="http://craigsworks.com/projects/qtip/">qTip</a> to make it look nice. I validated my entry using the jQuery <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/">validation plugin</a> which also works well. The problem is that if an attempt is made to submit the form before any attempt at editing the value or showing the tooltip, the error message would show the value of the tooltip (&#8220;<span style="color: #ff0000;">Don&#8217;t worry&#8230;</span>&#8220;) instead of the validation error message (&#8220;<span style="color: #ff0000;">This field is required</span>&#8220;).</p>
<p>It&#8217;s taken me a while to find the cause, but the fix is easy. When invoking the validator, throw in the option to <a href="http://rocketsquared.com/wiki/Plugins/Validation/validate#options">ignore title attributes</a>.</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="javascript"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
</pre></td><td class="de1"><pre class="de1">$<span class="br0">&#40;</span><span class="st0">&quot;#your-form&quot;</span><span class="br0">&#41;</span>.<span class="me1">validate</span><span class="br0">&#40;</span><span class="br0">&#123;</span>
ignoreTitle<span class="sy0">:</span> <span class="kw2">true</span>
<span class="br0">&#125;</span><span class="br0">&#41;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">$("#your-form").validate({
ignoreTitle: true
})</pre></div></div>

 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=295&amp;md5=12bf23d22e444e96543bad1b5d3196db" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2011/10/28/bug-with-jquery-validation-error-messages-showing-tooltip-text/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to enable Offline Google Docs for Google Apps users</title>
		<link>http://www.mattburns.co.uk/blog/2011/10/26/how-to-enable-offline-google-docs-for-google-apps-users/</link>
		<comments>http://www.mattburns.co.uk/blog/2011/10/26/how-to-enable-offline-google-docs-for-google-apps-users/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 14:27:03 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=274</guid>
		<description><![CDATA[Do you still not have the offline option for Google Docs?

If you're a Google Apps user, then your apps administrator has to enable it first:

	Log in to the Google Apps control panel at https://www.google.com/a/your_domain.com (replace your_domain.comwith your actual domain name).
	From the ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>Do you still not have the offline option for Google Docs?</p>
<p>If you&#8217;re a Google Apps user, then your apps administrator has to <a href="http://www.google.com/support/a/bin/answer.py?hl=en&amp;answer=1642623">enable it</a> first:</p>
<ol>
<li>Log in to the Google Apps control panel at <strong>https://www.google.com/a/your_domain.com</strong> (replace <em>your_domain.com</em>with your actual domain name).</li>
<li>From the menu bar at the top of the page, click <strong>Settings</strong>.</li>
<li>In the left menu, click <strong>Docs</strong>.</li>
<li>Select the <strong>Allow users to enable offline docs</strong> check box.</li>
<li>Click <strong>Save changes</strong>.</li>
</ol>
<p>Then your users can choose to set it up in <a href="https://docs.google.com/support/bin/answer.py?hl=en&amp;answer=1628469&amp;topic=1628465">the same way</a> normal gmailers can with the docs cog in the corner:</p>
<p><a href="http://www.mattburns.co.uk/blog/wp-content/uploads/2011/10/offlinedocs.png"><img class="alignnone size-full wp-image-292" title="offlinedocs" src="http://www.mattburns.co.uk/blog/wp-content/uploads/2011/10/offlinedocs.png" alt="set up offline docs" width="214" height="259" /></a></p>
<p>Hope this helps you out.</p>
<p>Matt</p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=274&amp;md5=047ee4d3601b664a257118c55b4aafb2" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2011/10/26/how-to-enable-offline-google-docs-for-google-apps-users/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to write Singletons in java</title>
		<link>http://www.mattburns.co.uk/blog/2011/10/26/how-to-write-singletons-in-java/</link>
		<comments>http://www.mattburns.co.uk/blog/2011/10/26/how-to-write-singletons-in-java/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 11:30:37 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.mattburns.co.uk/blog/?p=276</guid>
		<description><![CDATA[Singletons get a pretty bad press. Often described as an "anti-pattern". I think it's a little unfair since I find them pretty useful in several situations. However, the reason they can be bad is important to understand:


Making a class ...]]></description>
			<content:encoded><![CDATA[<p class="wp-flattr-button"></p><p>Singletons get a pretty bad press. Often described as an &#8220;anti-pattern&#8221;. I think it&#8217;s a little unfair since I find them pretty useful in several situations. However, the reason they can be bad is important to understand:</p>
<blockquote><p><em>Making a class a singleton can make it difficult to test its clients, as it’s impossible to substitute a mock implementation for a singleton unless it implements an interface that serves as its type.</em></p></blockquote>
<p>That quote, and most of what I am about to write are completely stolen from Josh Bloch&#8217;s excellent book, Effective Java (highly recommended in <a href="http://amzn.to/sxX8l4">paperback</a> or <a href="http://amzn.to/vVgXVU">kindle</a> editions).  Those are affiliate links, but I still recommend you buy it no matter where you get it from.</p>
<p>Anyway, it raises an important point about testability, but one that I think doesn&#8217;t matter. The way I see it, if you&#8217;re writing a singleton that represents something you want to swap with a mock, such as a database connection or network resource etc then your design will change as your tests evolve. You practice <a href="http://en.wikipedia.org/wiki/Test-driven_development">TDD</a> right? You&#8217;ll soon realise that a singleton doesn&#8217;t make sense or you need an interface of some kind. This post is about how to write a good singleton.</p>
<p>In the bad old days before java 1.5 there were 2 common ways to implement a singleton. A public final field:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
</pre></td><td class="de1"><pre class="de1"><span class="kw1">public</span> <span class="kw1">static</span> <span class="kw1">final</span> Elvis INSTANCE <span class="sy0">=</span> <span class="kw1">new</span> Elvis<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">public static final Elvis INSTANCE = new Elvis();</pre></div></div>

<p>or a static factory:</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
</pre></td><td class="de1"><pre class="de1"><span class="kw1">private</span> <span class="kw1">static</span> <span class="kw1">final</span> Elvis INSTANCE <span class="sy0">=</span> <span class="kw1">new</span> Elvis<span class="br0">&#40;</span><span class="br0">&#41;</span><span class="sy0">;</span>
<span class="kw1">public</span> <span class="kw1">static</span> Elvis getInstance<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span>
&nbsp; &nbsp; <span class="kw1">return</span> INSTANCE<span class="sy0">;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">private static final Elvis INSTANCE = new Elvis();
public static Elvis getInstance() {
    return INSTANCE;
}</pre></div></div>

<p>The static factory version is slightly better in that the you have a bit more flexibility to change your implementation details at a later date. In my two examples there is no performance benefit of either technique in modern JVMs. This is all well and good. There is only one Elvis in the world. There is the possibility a privileged client can invoke the private constructor reflectively but I&#8217;m not going to dwell on that.</p>
<p>Bloch raises another problem:</p>
<blockquote><p><em>To make a singleton class that is implemented using either of the previous approaches serializable, it is not sufficient merely to add implements Serializable to its declaration. To maintain the singleton guarantee, you have to declare all instance fields transient and provide a readResolve method. Otherwise, each time a serialized instance is deserialized, a new instance will be created, leading, in the case of our example, to spurious Elvis sightings.</em></p></blockquote>
<p>Oo-er, this sounds messy. You implied in java 1.5 there&#8217;s a better way, please, what is it, I&#8217;m desperate!</p>

<div class="bwp-syntax-block clearfix">
<div class="bwp-syntax-toolbar"><div class="bwp-syntax-control"><a href="javascript:;" class="bwp-syntax-source-switch" title="View Source Code"></a></div></div>
<div class="bwp-syntax-wrapper clearfix bwp-syntax-simple"><table class="java"><tbody><tr class="li1"><td class="ln"><pre class="de1">1
2
3
4
5
</pre></td><td class="de1"><pre class="de1"><span class="co1">// Enum singleton - the preferred approach</span>
<span class="kw1">public</span> <span class="sy0">&lt;</span>strong<span class="sy0">&gt;</span>enum<span class="sy0">&lt;/</span>strong<span class="sy0">&gt;</span> Elvis <span class="br0">&#123;</span>
&nbsp; &nbsp; INSTANCE<span class="sy0">;</span>
&nbsp; &nbsp; <span class="kw1">public</span> <span class="kw4">void</span> leaveTheBuilding<span class="br0">&#40;</span><span class="br0">&#41;</span> <span class="br0">&#123;</span> ... <span class="br0">&#125;</span>
<span class="br0">&#125;</span></pre></td></tr></tbody></table></div>
<div class="bwp-syntax-source"><pre class="no-parse">// Enum singleton - the preferred approach
public &lt;strong&gt;enum&lt;/strong&gt; Elvis {
    INSTANCE;
    public void leaveTheBuilding() { ... }
}</pre></div></div>

<p>TADA!</p>
<blockquote><p><em>This approach is functionally equivalent to the public field approach, except that it is more concise, provides the serialization machinery for free, and provides an ironclad guarantee against multiple instantiation, even in the face of sophisticated serialization or reflection attacks. While this approach has yet to be widely adopted, a single-element enum type is the best way to implement a singleton.</em></p></blockquote>
<p>Have a little think about it, let it sink in, then run off and replace any singletons in any projects you can get your hands on.</p>
 <p><a href="http://www.mattburns.co.uk/blog/?flattrss_redirect&amp;id=276&amp;md5=c02ad42e6880f6966e0b0c3b19ec0777" title="Flattr" target="_blank"><img src="http://www.mattburns.co.uk/blog/wp-content/plugins/flattr/img/flattr-badge-large.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.mattburns.co.uk/blog/2011/10/26/how-to-write-singletons-in-java/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

