<?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>Platformability &#187; Dev Tips</title>
	<atom:link href="http://blog.caplin.com/tag/dev-tips/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.caplin.com</link>
	<description>Single Dealer Platforms, Industry Expertise</description>
	<lastBuildDate>Fri, 03 Feb 2012 15:38:56 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>CSS Sprites and the Jigosaurus</title>
		<link>http://blog.caplin.com/2011/01/28/css-sprites-and-the-jigosaurus/</link>
		<comments>http://blog.caplin.com/2011/01/28/css-sprites-and-the-jigosaurus/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 12:56:33 +0000</pubDate>
		<dc:creator>Andy Trevorah</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Caplin Graduate Scheme]]></category>
		<category><![CDATA[CSS Sprites]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[Jigosaurus]]></category>
		<category><![CDATA[jigsaw]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=4086</guid>
		<description><![CDATA[As mentioned before, Jigosaurus is a multiplayer jigsaw puzzle that is played through a web browser. When Aleksei, Yasser and I joined as part of the Caplin Graduate Scheme, we were given the task of getting it running and improving it, and today we’ll be looking at the client facing...]]></description>
			<content:encoded><![CDATA[<div id="attachment_4256" class="wp-caption alignright" style="width: 310px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvSGFkcm9uX0ppZ3Nhdy5wbmc="><img class="size-medium wp-image-4256" title="Hadron_Jigsaw" src="http://blog.caplin.com/wp-content/uploads/Hadron_Jigsaw-300x258.png" alt="" width="300" height="258" /></a><p class="wp-caption-text">120 individual PNGs for one jigsaw</p></div>
<p>As mentioned <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEwLzExLzAxL3Jlc3VycmVjdGluZy10aGUtamlnb3NhdXJ1cy8=">before</a>, Jigosaurus is a multiplayer jigsaw puzzle that is played through a web browser. When Aleksei, Yasser and I joined as part of the Caplin Graduate Scheme, we were given the task of getting it running and improving it, and today we’ll be looking at the client facing end.</p>
<p>Following the route of the jigsaw from server to client, we quickly found a limitation. Each jigsaw that we wanted to be played had to be generated from an image with another tool before it was ready to host on the server side. This meant cutting the full image into around 200 individual pieces and saving them as PNG files ready to transfer over the internet. Then with many <code>&lt;img&gt;</code> tags placed in the right position, the clients browser could give Jigosaurus piece elements their correct look.<br />
<span id="more-4086"></span></p>
<h1>Variety is the spice of life</h1>
<div id="attachment_4248" class="wp-caption alignright" style="width: 310px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvcmVzb3VyY2VzX2JlZm9yZS5wbmc="><img class="size-medium wp-image-4248" title="resources_before" src="http://blog.caplin.com/wp-content/uploads/resources_before-300x229.png" alt="" width="300" height="229" /></a><p class="wp-caption-text">Clogging up the network with hundreds of requests</p></div>
<p>This &#8220;chop up once, serve many times&#8221; method may be good in a situation where everyone plays the same kind of jigsaw, but as soon as someone wants to try the same puzzle that has more or fewer pieces not only would we have to run the same image through the chopping tool again, but we would waste space on additional PNG files that represent pieces of the same image.</p>
<p>Even if we were ok having no variety in our puzzles (boo, hiss), we still have the problem of actually sending multiple images over the network. These piece images will rarely be sent over the network in complete parallel and so have to queue behind each other. Combined with the overhead of sending each file, this means more time waiting and less time puzzle solving.</p>
<h1>CSS is more than a pretty face</h1>
<div id="attachment_4252" class="wp-caption alignright" style="width: 190px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvZ21haWxfc3ByaXRlcy5wbmc="><img class="size-full wp-image-4252" title="gmail_sprites" src="http://blog.caplin.com/wp-content/uploads/gmail_sprites.png" alt="" width="180" height="140" /></a><p class="wp-caption-text">Sprites for the Gmail Inbox page are held in one image file</p></div>
<p>The problem seems to be a server side limitation of pre-processing things for an individual, so we could try doing things with a bit of extra code on the client side. We could use Javascript as a work horse to cut up each user&#8217;s jigsaw, but this would be slow and there is a cleaner way.</p>
<p>Browsers are optimised to handle styling through CSS well, so we can take advantage of this and get the browser to cut up our jigsaw natively. This technique is known as <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Nzcy10cmlja3MuY29tL2Nzcy1zcHJpdGVzLw==">CSS Sprites</a>.</p>
<p>This technique is normally used for pages that contain multiple images that are usually used all at once. Icons, logos and other pretty pieces of image could be served up individually like our jigsaw pieces, but are instead mashed together and sent all in one go. Each relevant element references this large mashed together image, but by using the background offset CSS property, the element only shows a window of this one large image. This means only dealing with the resource overhead of one file and taking advantage of a browsers optimisations for CSS styling.</p>
<p>This technique is perfect for Jigosaurus, so we ditch the <code>&lt;img&gt;</code> tags for each jigsaw element and just add an individual background-image style that references a small window of the full image that would normally have to be cut up.</p>
<div id="attachment_4247" class="wp-caption aligncenter" style="width: 582px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvdGltZV9iZWZvcmUucG5n"><img class="size-full wp-image-4247" title="time_before" src="http://blog.caplin.com/wp-content/uploads/time_before.png" alt="" width="572" height="87" /></a><p class="wp-caption-text">Before: 72ms page load - the majority being images</p></div>
<div id="attachment_4250" class="wp-caption aligncenter" style="width: 599px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvdGltZV9hZnRlci5wbmc="><img class="size-full wp-image-4250" title="time_after" src="http://blog.caplin.com/wp-content/uploads/time_after.png" alt="" width="589" height="89" /></a><p class="wp-caption-text">After: 8ms page load - a dramatic improvement</p></div>
<p>Not only do we see a dramatic drop in loading times, but we also pave the way for jigsaws of different shapes and even jigsaws that aren’t just static images…</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=4086" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2011/01/28/css-sprites-and-the-jigosaurus/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Prebake: a recipe for great builds</title>
		<link>http://blog.caplin.com/2010/10/07/prebake-a-recipe-for-great-builds/</link>
		<comments>http://blog.caplin.com/2010/10/07/prebake-a-recipe-for-great-builds/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 13:50:30 +0000</pubDate>
		<dc:creator>Dominic Chambers</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Dev Tips]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=3895</guid>
		<description><![CDATA[In his recent post, Java Build Systems: A Sad State of Affairs, Jess Johnson describes the many problems with both Ant and Maven, and how Maven solves none of Ant’s issues, but instead invents a few new ones of its own. But for me, the real of the gem of...]]></description>
			<content:encoded><![CDATA[<p>In his recent post, <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">Java</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">Build</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">Systems</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">: </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">A</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">Sad</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">State</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">of</a><a href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE="> </a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZncm9rLWNvZGUuY29tJTJGNTM4JTJGamF2YS1idWlsZC1zeXN0ZW1zLWEtc2FkLXN0YXRlLW9mLWFmZmFpcnMlMkYmYW1wO3NhPUQmYW1wO3NudHo9MSZhbXA7dXNnPUFGUWpDTkZ5WkU4VVNrWUJMN084Nk94ZG1neVhhQTY5LVE=">Affairs</a>, Jess Johnson describes the many problems with both Ant and Maven, and how Maven solves none of Ant’s issues, but instead invents a few new ones of its own. But for me, the real of the gem of the post was one of the comments it inspired, that mentions a novel new piece of software called <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3ByZWJha2Uvd2lraS9Qcm9kdWN0">prebake</a>, that could be to build systems what SmallTalk and Simula were to OO programming languages, but more about that later.</p>
<p><strong>Using Ant For Your Build Scripts</strong></p>
<p>First, I’d like to describe where, for me, Ant really goes wrong, over and above the points that Jess makes. With Ant, out of the box, you end up with a build system that is inefficient, and is only reliable provided you correctly define the dependencies of all tasks. Given that requires you have a knowledge of the entire build system, and requires lots of testing, that in itself isn’t a trivial task.</p>
<p>Once you do have all your dependencies defined correctly, and your build has become reliable (but still very slow) the next task you are likely to undertake is to make it perform better. You will likely do this using the <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">&lt;</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">uptodate</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">/&gt;</a> task to only perform targets if the source files have been updated since the output files were last generated, and/or the <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGZmlsZXNldC5odG1sJmFtcDtzYT1EJmFtcDtzbnR6PTEmYW1wO3VzZz1BRlFqQ05Ia2tadzdxZFY0eEJuQ1kzUU9SRENRWkFBS0xn">&lt;</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGZmlsZXNldC5odG1sJmFtcDtzYT1EJmFtcDtzbnR6PTEmYW1wO3VzZz1BRlFqQ05Ia2tadzdxZFY0eEJuQ1kzUU9SRENRWkFBS0xn">fileset</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGZmlsZXNldC5odG1sJmFtcDtzYT1EJmFtcDtzbnR6PTEmYW1wO3VzZz1BRlFqQ05Ia2tadzdxZFY0eEJuQ1kzUU9SRENRWkFBS0xn">/&gt;</a> and <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGc2VsZWN0b3JzLmh0bWwlMjNtb2RpZmllZCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNORXJUTlcwUkNOUU85dzFNSWxTczBOc1puUGx3Zw==">&lt;</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGc2VsZWN0b3JzLmh0bWwlMjNtb2RpZmllZCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNORXJUTlcwUkNOUU85dzFNSWxTczBOc1puUGx3Zw==">modified</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlR5cGVzJTJGc2VsZWN0b3JzLmh0bWwlMjNtb2RpZmllZCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNORXJUTlcwUkNOUU85dzFNSWxTczBOc1puUGx3Zw==">/&gt;</a> tasks to limit the files your target processes to only those files that have been changed since the last time you ran the target.</p>
<p>This works provided you don’t have too many source files (they will all needed to be stat-ted or MD5ed before Ant can determine whether it needs to perform the task or not), and creates two new problems:</p>
<ol>
<li>Your build system becomes much harder to comprehend and much more time consuming to test.</li>
<li>Your build system starts breaking every time you modify it because Ant doesn’t check-sum the targets, and ignores your build restrictions if the targets have changed.</li>
</ol>
<p><span id="more-3895"></span>Every time your developers sync and get a change to scripts, they also get a new build problem to debug &#8230; oh Joy! You can also fix this by treating all Ant build files as inputs to each conditional target, but there are even subtleties here, like the fact that developers may be using the -D flag to pass in properties that change whether things need rebuilding, or that you need to keep an eye out for each new .properties and .xml file that is build related and ensure it’s a matched as being a source file, or that your <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">&lt;</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">uptodate</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">/&gt;</a> tasks will keep breaking as developers change the inputs and outputs to tasks without also updating the <em>from</em> and <em>to</em> patterns, which doesn’t get immediately noticed, but just ends up creating another subtle build bug to debug! You can work around all of these problems, but you’re going to end up with a build system that is unwieldy and unreliable, and will be the constant focus of criticism in your retrospectives.</p>
<p><!--more--></p>
<p><strong>The Maven And Ivy Approach</strong></p>
<p>Maven and Ivy try to avoid these problems entirely by encouraging you to divide your build up into small parts that can be checked into a repository, but ultimately by denying you first class access to your own source code, and by introducing a versioning problem you never previously even had, they just create a bigger problem than they solve in the first place.</p>
<p><strong>Prebake To The Rescue</strong></p>
<p>All of this is what intrigues me about <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2NvZGUuZ29vZ2xlLmNvbS9wL3ByZWJha2Uvd2lraS9Qcm9kdWN0">prebake</a>. At a cursory glance, it seems to solve all of these problems and many more, and it does this while still providing first class access to all source code. It tantalizes by seeming to promise that creating efficient and reliable build systems will become a near trivial operation. An example of this is how explicit dependencies are done away with in preference to what is essentially the parallel of Ant’s <em>from</em> and <em>to</em> properties from it’s <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">&lt;</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">uptodate</a><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5nb29nbGUuY29tL3VybD9xPWh0dHAlM0ElMkYlMkZhbnQuYXBhY2hlLm9yZyUyRm1hbnVhbCUyRlRhc2tzJTJGdXB0b2RhdGUuaHRtbCZhbXA7c2E9RCZhbXA7c250ej0xJmFtcDt1c2c9QUZRakNOR083WU1aT0g4dGxwQzY3UTI2RnNRYm1Sd2JHZw==">/&gt;</a> task. The genius here is that it becomes impossible to forget a dependency, and if you don’t define your <em>from</em> and <em>to</em> properties correctly you’ll know about it immediately. This is coupled with built in check-summing of each target, so that the build doesn’t break when you update it, but only the absolute minimum of targets are rebuilt.</p>
<p>Admittedly, I haven’t even downloaded this still alpha software, nor I have I even read all the documentation, and am still unclear of how well, in reality, prebake will handle dependencies which are not intrinsically file related, but everything I have read to date inspires me with confidence. If this isn’t the build system that ends up winning the battle, then I still have a hunch it will end up being considered a seminal work in that direction.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=3895" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/10/07/prebake-a-recipe-for-great-builds/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>If you can&#8217;t think of a good name, use a bad one</title>
		<link>http://blog.caplin.com/2010/09/09/if-you-cant-think-of-a-good-name-use-a-bad-one/</link>
		<comments>http://blog.caplin.com/2010/09/09/if-you-cant-think-of-a-good-name-use-a-bad-one/#comments</comments>
		<pubDate>Thu, 09 Sep 2010 09:09:02 +0000</pubDate>
		<dc:creator>Ian Alderson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=3660</guid>
		<description><![CDATA[I&#8217;ve just read a great tweet from @KentBeck that provides an interesting solution for something that I have always struggled with. if you don&#8217;t have a good name for it, give it a bad name. a really, really bad name so you&#8217;ll fix it later. Good naming is hard Sometimes...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just read a <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL0tlbnRCZWNrL3N0YXR1c2VzLzIzOTU3ODgwMDY4">great tweet</a> from <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3R3aXR0ZXIuY29tL0tlbnRCZWNr">@KentBeck</a> that provides an interesting solution for something that I have always struggled with.</p>
<blockquote><p>if you don&#8217;t have a good name for it, give it a bad name. a really, really bad name so you&#8217;ll fix it later.</p></blockquote>
<p><strong>Good naming is hard</strong></p>
<p>Sometimes when writing a class, or occasionally even a method, I struggle to find a good name for it. After a while I give up trying to find a good name for it and chose something that is just about &#8220;OK&#8221;, a working title if you like. Unfortunately this tends to create poor generic names, such as &#8220;ConnectionManager&#8221;, that vaguely make sense, but can obfuscate the true purpose of the class. I&#8217;ve lost count of the number of times that I&#8217;ve heard developers say something like, &#8220;Oh, so that&#8217;s what that class does!&#8221;</p>
<p>The problem with these &#8220;OK&#8221; names is that they tend to have a strong inertia to change. Typically I have the intention of going back and renaming it, however the longer I leave it the less likely this is. If the name is adequate, but not great, then why go through the effort of renaming it? Sure, some IDEs, such as Eclipse, do a superb job at refactoring, however a lot of the code we write here at Caplin is in JavaScript and the tool support for this isn&#8217;t as good. Regardless of this, even where there is good tool support, there are time pressures, backward compatibility and other considerations that lead to &#8220;OK&#8221; names sticking.</p>
<p><span id="more-3660"></span></p>
<p><strong>Overcoming renaming inertia</strong></p>
<p>This brings me back to <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9LZW50X0JlY2s=">Kent Beck</a>&#8216;s excellent suggestion. If you provide something with a really bad name the inertia to change it will be non-existent. You will have to change it before it becomes part of your public API or other developers have to use it.</p>
<p>The great thing with this is that it allows you to write your class and see what it responsibilities are before you provide its proper name. This should lead to meaningful names that define exactly what a class does, ensuring no one is surprised when they try to use it.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=3660" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/09/09/if-you-cant-think-of-a-good-name-use-a-bad-one/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Optimise for Portable Devices</title>
		<link>http://blog.caplin.com/2010/06/14/optimise-for-portable-devices-2/</link>
		<comments>http://blog.caplin.com/2010/06/14/optimise-for-portable-devices-2/#comments</comments>
		<pubDate>Mon, 14 Jun 2010 13:41:50 +0000</pubDate>
		<dc:creator>Arthur Smit</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[UX]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Ui]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=2689</guid>
		<description><![CDATA[Platformability is now optimised for Portable Devices. (Give it a go on your mobile!) How to achieve a better User Experience on Portable Devices&#8230; As much as everyone loves big pictures for blog backgrounds or lots of  fancy widgets or flash animations, these tend to not be appropriate on Portable...]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;">Platformability is now optimised for Portable Devices.<br />
<em><strong>(Give it a go on your mobile!)</strong></em></p>
<p><em><strong> </strong></em></p>
<p><img class="size-full wp-image-2671 alignnone" title="Platformability on your Mobile!" src="http://blog.caplin.com/wp-content/uploads/Platfrm_mobiles.png" alt="" width="546" height="486" /><br />
<strong><br />
How to achieve a better User Experience on Portable Devices&#8230;<br />
<span id="more-2689"></span></strong></p>
<p>As much as everyone loves big pictures for blog backgrounds or lots of  fancy<br />
widgets or flash animations, these tend to not be appropriate on Portable Devices<br />
(<em>the ones i&#8217;m thinking of are;  iPhone, iPad, Android or BlackBerry</em>).</p>
<p>These features which are quite neat on a desktop computer can quickly become<br />
irritating on small screens. Yes, we can zoom in &amp; out but that just slows us<br />
down as we wait for the page to increase in size, and then have to scroll left and right<br />
to read sentences that are too long to fit onto the screen. This means that often<br />
we are just waiting for the page to load. Even on a 3G network this can be boring.</p>
<p><img class="size-full wp-image-2688 alignnone" title="load_beard" src="http://blog.caplin.com/wp-content/uploads/load_beard.png" alt="" width="260" height="422" /></p>
<p><strong>What can be done?</strong></p>
<p>As usual, there are a number of solutions. Here are my favourite two:</p>
<p>1.) Optimise your existing site to be more fluid and adapt to users&#8217; resolution<br />
2.) Create an alternative theme for Portable Devices.</p>
<p>We have opted to go for the latter (2). Optimising your existing site to work better<br />
on mobiles can be frustrating as you feel that you are cutting out functionality just<br />
to be able to appease the lowest common denominator.</p>
<p>Other pitfalls include super-compressing your images to have a better load time on mobile networks,<br />
stripping out any flash bits you may have to keep Steve Jobs happy, <em>(I&#8217;m joking<br />
of course, let&#8217;s not get into that debate again</em>) removing drop-downs or any<br />
interaction that works on hover. This can be painful and often leaves everyone<br />
unhappy as lots of  &#8220;nice things&#8221; have been left out.</p>
<p>Having an alternate theme for Mobile Users can be very effective in increasing<br />
the number of eyeballs on your blog. By creating an experience which is relevant<br />
to it&#8217;s environment  (for example someone standing in the train just wants to quickly<br />
scan headlines and get the &#8220;gist of it&#8221; and not spend time waiting for pages to load on<br />
an already flaky connection because of tunnels etc.) you can greatly increase traffic.  An other upshot of this approach is you do not feel the site has been compromised as the &#8220;full experience&#8221; is still available.</p>
<p><strong>Implementation </strong></p>
<p>A great way to achieve this is a plugin called <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy53cHRvdWNoLmNvbS8=" 0="target="_blank"">WpTouch</a>. This plugin can really help<br />
to improve your loading times on mobile networks.</p>
<p><strong><img class="size-full wp-image-2684 alignnone" title="wptouch-loading-stats" src="http://blog.caplin.com/wp-content/uploads/wptouch-loading-stats.jpg" alt="" width="500" height="253" /></strong></p>
<p><strong> </strong></p>
<p><strong>Customising</strong></p>
<p>With WpTouch&#8217;s options a bit of  CSS-ing and designing your own assets<br />
you can customise this plugin, bringing it in line with your existing branding and<br />
&#8220;desktop theme&#8221; and make it work for your needs. It&#8217;s very quick to implement<br />
will make a world of difference to users browsing your posts on their phones by<br />
increasing readability, adding intuitive touch control and keeping important<br />
functions such as search, comments &amp; contact forms.</p>
<p><img class="alignnone size-full wp-image-2693" title="edit_plugin" src="http://blog.caplin.com/wp-content/uploads/edit_plugin.png" alt="" width="639" height="362" /></p>
<p>So why don&#8217;t you go check out this post on your mobile?<br />
Let us know what you think.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=2689" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/06/14/optimise-for-portable-devices-2/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>The beauty of small tests</title>
		<link>http://blog.caplin.com/2010/04/15/the-beauty-of-small-tests/</link>
		<comments>http://blog.caplin.com/2010/04/15/the-beauty-of-small-tests/#comments</comments>
		<pubDate>Thu, 15 Apr 2010 11:53:35 +0000</pubDate>
		<dc:creator>Andrew Darnell</dc:creator>
				<category><![CDATA[QA]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Ajax Testing]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=1342</guid>
		<description><![CDATA[When tests are small, a test failure means just one thing – somewhere in these ten lines of code which are being tested, there is an error.  Ok, sometimes this can mean that there is an error in the test script, or a there is a failure, or change of...]]></description>
			<content:encoded><![CDATA[<p>When tests are small, a test failure means just one thing – somewhere in these ten lines of code which are being tested, there is an error.  Ok, sometimes this can mean that there is an error in the test script, or a there is a failure, or change of expectation, but fundamentally, it pin-points the cause of the failure to a <strong>small</strong> target, which usually means that debugging becomes <strong>trivial</strong>.</p>
<p>When an end to end acceptance test fails, the failure could be due to any one of a large number of source lines or expectations changes across a large body of code.  Debugging may be quick, but often isn&#8217;t.</p>
<p><span id="more-1342"></span></p>
<p>Small tests run faster too! While a typical small test may take 10 milliseconds to run, a large acceptance test may take twenty minutes.</p>
<p>Just a small back of the envelope calculation tells us that if a developer checks in twice a day and saves an hour each time because potential issues had been found before check-in with fast small tests, and the faster feedback, or has reduced their time spent debugging &#8211; that is two hours a day per developer that could be put to better use.</p>
<blockquote><p>2 hours a day * thirty developers * two working weeks = <strong>600 additional hours</strong> per two week iteration available.</p></blockquote>
<p>This is equivalent to adding seven and a half developers to the team!</p>
<p><strong>What value do you get from tests of different sizes?</strong></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1342" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/04/15/the-beauty-of-small-tests/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Agile – Tests = Fragile</title>
		<link>http://blog.caplin.com/2010/04/09/agile-%e2%80%93-tests-fragile/</link>
		<comments>http://blog.caplin.com/2010/04/09/agile-%e2%80%93-tests-fragile/#comments</comments>
		<pubDate>Fri, 09 Apr 2010 14:55:46 +0000</pubDate>
		<dc:creator>Andrew Darnell</dc:creator>
				<category><![CDATA[QA]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[Software Engineering]]></category>
		<category><![CDATA[Test Driven Development]]></category>
		<category><![CDATA[Unit Testing]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=1341</guid>
		<description><![CDATA[The nature of agile projects, with lots of small releases mean that there are a lot of test runs to execute if you want to have any confidence in the code and the product. Ignoring this testing just generates projects which will fail – not may fail &#8211; will fail,...]]></description>
			<content:encoded><![CDATA[<p>The nature of agile projects, with lots of small releases mean that there are a lot of test runs to execute if you want to have any confidence in the code and the product.</p>
<p>Ignoring this testing just generates projects which will fail – not may fail &#8211; will fail, <strong>categorically will fail!</strong></p>
<p>There are two sets of tests that are critical here&#8230;</p>
<p><strong>Good unit test coverage and a TDD approach to development</strong> ensure that the rest of the organisation is supplied with product that works as developers expect it to.</p>
<p><strong>Component tests and functional acceptance test</strong>s ensure that the product does what the product owner expects it to.</p>
<ul>
<li>Practically, the only way to do solid testing on new features is to have a stable product.</li>
<li>Practically, the only way to assure a stable product is to either have solid regression testing on each release or to not make any changes.</li>
<li>Practically, the only way to make sure that adequate regression testing is done is to automate the regression tests (unit, component, functional).</li>
</ul>
<p>Without these tests in place, iterating quickly places an impossible to meet burden of verification demand on the testers and product owners, which just gives you a <strong>fragile</strong> process not an <strong>agile</strong> one.</p>
<p><strong> Is your process Agile or Fragile?</strong></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=1341" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2010/04/09/agile-%e2%80%93-tests-fragile/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding an Observer to an Observable</title>
		<link>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/</link>
		<comments>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 13:00:24 +0000</pubDate>
		<dc:creator>Ian Alderson</dc:creator>
				<category><![CDATA[Coding]]></category>
		<category><![CDATA[Caplin Trader]]></category>
		<category><![CDATA[Dev Tips]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Observer]]></category>
		<category><![CDATA[Software Engineering]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=111</guid>
		<description><![CDATA[The Observer design pattern is used in many applications. If you are unfamiliar with it, or need to remind yourself about the specifics, you can read about it at Wikipedia or MSDN. Caplin Trader even provides a helper class to take care of a lot of the boiler plate code: caplin.core.Observable. The...]]></description>
			<content:encoded><![CDATA[<p>The Observer design pattern is used in many applications. If you are unfamiliar with it, or need to remind yourself about the specifics, you can read about it at <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9PYnNlcnZlcl9wYXR0ZXJu">Wikipedia</a> or <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL21zZG4ubWljcm9zb2Z0LmNvbS9lbi11cy9saWJyYXJ5L21zOTU0NjIxLmFzcHg=">MSDN</a>. Caplin Trader even provides a helper class to take care of a lot of the boiler plate code: <em>caplin.core.Observable</em>.</p>
<p>The purpose of the Observer design pattern is to allow one object to notify other objects of events &#8211; usually to do with changes to its state. One common problem I have encountered however is what to do when an Observer  is first registered, since the object that it is observing may already be in a particular state.</p>
<p><span id="more-111"></span></p>
<p>There are two obvious approaches to this problem.</p>
<ol>
<li>The object registering the Observer must check what the state of the object it wants to Observe is after the registration and handle the implications of this (e.g. enabling/disabling parts of the GUI). The main issue I have with this is that it can mean that I end up with two code paths, one to do something before the Observer has been registered and one for the event notifications. In the case where there are lots of different types of Observers for the same object this will introduce a lot of extra code paths &#8211; and eventually someone is bound to forget to handle the initial state and thus introduce a bug. In a multi-threaded environment this may become more complicated, particularly if you want to ensure that you only receive an event once.</li>
<li>When the Observer is registered it is notified of the current state of the object it is observing. Although this is not a standard part of the design pattern, I have found it useful since you only have one code path within the Observer for handling the events.</li>
</ol>
<p>The following example demonstrates how the second approach can easily be implemented in JavaScript (using caplin.core.Observable).</p>
<pre class="javascript">caplin.namespace("caplinx");

caplin.include("caplin.core.Observable");

caplinx.Trade = function()
{
   this.m_bExecuted = false;
   this.m_oObservable = new caplin.core.Observable();
};

caplinx.Trade.prototype.addTradeListener = function(oListener)
{
   this.m_oObservable.addObserver(oListener);

   // **********************************************
   // if we have already executed the trade notify the newly added
   // listener immediately
   if (this.m_bExecuted)
   {
      oListener.executed();
   }
   // **********************************************
};

caplinx.Trade.prototype.execute = function()
{
   // code to handle trade execution ...

   this.m_bExecuted = true;

   // notify all listeners that the trade has executed
   this.m_oObservable.notifyObservers("executed");
}</pre>
<p>The technique suggested here is not necessarily appropriate for all Observer design pattern implementations, however I have found it useful to consider when I am writing a new class that will be observed by others.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=111" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2009/03/02/adding-an-observer-to-an-observable/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

