<?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</title>
	<atom:link href="http://blog.caplin.com/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>Server Scalability &#8211; HTML5 websockets vs Comet</title>
		<link>http://blog.caplin.com/2012/02/03/server-scalability-html5-websockets-vs-comet/</link>
		<comments>http://blog.caplin.com/2012/02/03/server-scalability-html5-websockets-vs-comet/#comments</comments>
		<pubDate>Fri, 03 Feb 2012 11:31:49 +0000</pubDate>
		<dc:creator>Martin Tyler</dc:creator>
				<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Real-time web]]></category>
		<category><![CDATA[Comet]]></category>
		<category><![CDATA[WebSocket]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=8290</guid>
		<description><![CDATA[There&#8217;s an interesting discussion over on stackoverflow about server scalability and HTML5 WebSockets vs Comet. I have blogged in the past on the topic of server performance and about WebSocket and have just contributed to the stackoverflow thread. Anyway, here&#8217;s the link.. http://stackoverflow.com/questions/9107384/server-scalability-html-5-websockets-vs-comet]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s an interesting discussion over on stackoverflow about server scalability and HTML5 WebSockets vs Comet. I have blogged in the past on the topic of <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEwLzA1LzE0L2JlbmNobWFya2luZy1saWJlcmF0b3ItdG8tMTAwMDAwLXVzZXJzLw==" 0="target="_new"">server performance</a> and about <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEwLzAzLzAyL3doeS13ZS1kb250LW5lZWQtaHRtbDUtd2Vic29ja2V0Lw==" 0="target="_new"">WebSocket</a> and have just contributed to the stackoverflow thread. Anyway, here&#8217;s the link..</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3N0YWNrb3ZlcmZsb3cuY29tL3F1ZXN0aW9ucy85MTA3Mzg0L3NlcnZlci1zY2FsYWJpbGl0eS1odG1sLTUtd2Vic29ja2V0cy12cy1jb21ldA==" 0="target="_new"">http://stackoverflow.com/questions/9107384/server-scalability-html-5-websockets-vs-comet</a></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=8290" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/02/03/server-scalability-html5-websockets-vs-comet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Caplin to host an Agile UX Safari!</title>
		<link>http://blog.caplin.com/2012/02/01/caplin-to-host-an-agile-ux-safari/</link>
		<comments>http://blog.caplin.com/2012/02/01/caplin-to-host-an-agile-ux-safari/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 18:41:41 +0000</pubDate>
		<dc:creator>Duncan</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[UX]]></category>
		<category><![CDATA[User Experience]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=8282</guid>
		<description><![CDATA[The Agile UX Meetup Group is heading to Caplin! Wednesday, February 15, 2012, 6:30 PM Caplin will be hosting an “Agile UX Safari” in a couple of weeks. It will be a little different to the last one at MindCandy (we don’t have a tree house in our boardroom!) but...]]></description>
			<content:encoded><![CDATA[<h1>The Agile UX Meetup Group is heading to Caplin!</h1>
<h2>Wednesday, February 15, 2012, 6:30 PM</h2>
<p>Caplin will be hosting an “Agile UX Safari” in a couple of weeks. It will be a little different to the last one at <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3RlY2gubWluZGNhbmR5LmNvbS8yMDExLzA3L2FnaWxlLXNhZmFyaS1jb21lcy10by1taW5kLWNhbmR5Lw==">MindCandy</a> <em>(we don</em><em>’t have a tree house in our boardroom!)</em> but we share their passion for design and development and mixing the perfect Agile/UX cocktail.</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5tZWV0dXAuY29tL2F1eG1lZXR1cC9ldmVudHMvNTA0NjM5NjIv">Check out the event</a> &#8211;  We look forward to hosting a healthy discussion on all things design, UX and agile.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=8282" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/02/01/caplin-to-host-an-agile-ux-safari/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>(r)Evolution: learning from the history of interaction design and GUIs</title>
		<link>http://blog.caplin.com/2012/02/01/revolution-learning-from-the-history-of-interaction-design-and-guis/</link>
		<comments>http://blog.caplin.com/2012/02/01/revolution-learning-from-the-history-of-interaction-design-and-guis/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 12:06:50 +0000</pubDate>
		<dc:creator>Rafael Lüder</dc:creator>
				<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=8222</guid>
		<description><![CDATA[I&#8217;ve always had an interest on the history of design, more especifically, the history of interaction design. This post is the first of a series on the history of interaction design and how designers can build up on the work of great designers of the past. Inspiring feelings of awe...]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve always had an interest on the history of design, more especifically, the history of interaction design. This post is the first of a series on the history of interaction design and how designers can build up on the work of great designers of the past.</p>
<h3>Inspiring feelings of awe</h3>
<p>I remember the buzz created around Google Wave back in 2008/2009, of all the innovative interactions and GUI elements introduced, their scrollbars were the one GUI element that really caught my attention:</p>
<p><img src="http://completewaveguide.com/images/1/14/Fg0602-scrollbar.png" alt="" width="300" height="149" /></p>
<p>I was really surprised to find out that Wave&#8217;s scrollbars were actually first designed for Sun Mycrosystems and AT&amp;T&#8217;s <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2VuLndpa2lwZWRpYS5vcmcvd2lraS9PUEVOX0xPT0s=">Open Look GUI</a>. Yet Google took the credit for innovative interaction, the posts below are an evidence of that:</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2JpdC5seS80RTFlU1Q=" 0="target="_blank"">Google Wave&#8217;s Clever Way Of Saving Scrollbar Space</a><br />
<a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2JpdC5seS9UVlU4Ng==" 0="target="_blank"">Google Wave&#8217;s Scrollbars</a><br />
<a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9naXRodWIuY29tL3Jhc3Rhc2hlZXAvZ29vZ2xlLXdhdmUtc2Nyb2xsYmFy" 0="target="_blank"">Google Wave Scrollbars jQuery plugin</a></p>
<p>More recently Apple (in regards to their application <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5hcHBsZS5jb20vaXBob25lL2ZlYXR1cmVzL3NpcmkuaHRtbA==" 0="target="_blank"">Siri</a>) and <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly93d3cuc2ltcGxlLmNvbS8=" 0="target="_blank"">Simple</a> have shown how powerful natural language interactions can be.</p>
<p>Deborah Mayhew in her 1991 book &#8220;Principles and Guidelines in Software User Interface Design&#8221; describes in great detail the use of Natural Language on interfaces.</p>
<p>Why is it that 20 years later that&#8217;s something that still strikes us as highly innovative, even revolutionary?</p>
<p>    <iframe src="http://player.vimeo.com/video/29339937" width="500" height="313" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></p>
<p>A First Look at BankSimple (skip to 2:45 min for an example of a natural language search)</p>
<h3>Know your history, know thyself</h3>
<p>Turns out the examples above have just recently reached the public and become mainstream thanks to companies like Apple and Google rescuing them from the chest of interaction design history. The fact that these are companies familiar to the general public only helps reinforce the &#8220;oh wow, they&#8217;ve done it again&#8221; feeling. Yet the foundation of these interactions have been developed/implemented a long time ago.</p>
<p>For some of the earliest examples of interaction design take a look at Ivan Shuterland&#8217;s 1962 Sketchpad demo or Douglas Engelbart&#8217;s 1968 &#8220;Mother of All Demos&#8221;, shown below.</p>
<p><iframe width="500" height="375" src="http://www.youtube.com/embed/USyoT_Ha_bA?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p><iframe width="500" height="375" src="http://www.youtube.com/embed/JfIgzSoTMOs?fs=1&#038;feature=oembed" frameborder="0" allowfullscreen></iframe></p>
<p>Mind blowing stuff if you realize that was half a century ago!</p>
<h3>(r)Evolution?</h3>
<p>Companies recognized by great interaction design have certain common traits: a deep understanding of interaction design history, of the technical and/or market constraints that might have hindered the use of certain patterns and their eyes open for opportunities to rescue and reapply those ideas.</p>
<p>Check back soon for more historical interaction design awesomeness!</p>
<h3>Further Reading</h3>
<p>If you&#8217;re interested on the history and evolution of GUIs I recommend you check out the books below. Most of them are available on Amazon for very reasonable prices.</p>
<p>Designing the User Interface: Strategies for Effective Human-computer Interaction (1986) — Ben Shneiderman, Catherine Plaisant</p>
<p>The Art of Human/Computer Interface Design (1990) — Brenda Laurel</p>
<p>Graphic Design for Electronic Documents and User Interfaces (1991) — Aaron Marcus</p>
<p>Principles and Guidelines in Software User Interface Design (1991) — Deborah J. Mayhew</p>
<p>The Cross-GUI Handbook for Multiplatform User Interface Design (1994) — Aaron Marcus, et al</p>
<p>Human Computer Interaction (1994) — Jenny Preece, et al</p>
<p>The <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5ndWlkZWJvb2tnYWxsZXJ5Lm9yZy8=" 0="target="_blank"">Guidebook Gallery</a> is also a great resource for screenshots, magazine articles and ads of historical GUIs.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=8222" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/02/01/revolution-learning-from-the-history-of-interaction-design-and-guis/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript is Hard Part 3: You Can&#8217;t Delete With Delete</title>
		<link>http://blog.caplin.com/2012/01/31/javascript-is-hard-part-3-you-cant-delete-with-delete/</link>
		<comments>http://blog.caplin.com/2012/01/31/javascript-is-hard-part-3-you-cant-delete-with-delete/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 08:30:09 +0000</pubDate>
		<dc:creator>Adam Shone</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=7765</guid>
		<description><![CDATA[A puzzle to start things off &#8211; what is going on here? The intention is to remove the local version of a from scope so that we can reassign the global version of a to &#8220;fish&#8221;. Will it work? What will be printed out? a) fish, fish (success) b) fish,...]]></description>
			<content:encoded><![CDATA[<p>A puzzle to start things off &#8211; what is going on here?</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;cat&quot;;
(function() {
    var a = &quot;dog&quot;;
    delete a;
    a = &quot;fish&quot;;
    console.log(a);
})();
console.log(a);
</pre>
<p>The intention is to remove the local version of <em>a</em> from scope so that we can reassign the global version of <em>a</em> to &#8220;fish&#8221;. Will it work? What will be printed out?</p>
<ol>
<li>a) fish, fish (success)</li>
<li>b) fish, cat (failure)</li>
<li>c) a different combination</li>
<li>d) depends on the browser (always a good option if you&#8217;re guessing)</li>
<li>e) depends on the execution context</li>
</ol>
<p><span id="more-7765"></span></p>
<p>The answer in this specific case is <em>b</em>, the answer to more general questions about this sort of thing is <em>e</em> (we&#8217;ll come back to that later). It doesn&#8217;t work! The value of the global version of <em>a</em> is unchanged. This demonstrates a fundamental point about the <strong>delete</strong> operator:</p>
<p><strong>You cannot delete anything declared with var.</strong></p>
<p>This applies even to variables that you declare within functions; once you declare them they exist forever. Bear this in mind if you want to remove something from scope using the delete operator, because it won&#8217;t work. We can fix the code by explicitly reassigning the global version of <em>a</em> rather than using <strong>delete</strong>:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;cat&quot;;
(function() {
    var a = &quot;dog&quot;;
    this.a = &quot;fish&quot;;
    console.log(a);     // prints &quot;dog&quot;
})();
console.log(a);         // prints &quot;fish&quot;
</pre>
<p>So, what is going on with the <strong>delete</strong> operator?</p>
<h3>First things first</h3>
<p>The <strong>delete</strong> operator returns a boolean value. We can use this to get a better understanding of how it works (and doesn&#8217;t work). However there is one gotcha with the return value &#8211; whether it is true or false depends on <em>whether the object exists afterwards</em>, not whether the delete was successful.</p>
<p>It&#8217;s a subtle difference, but it means that <strong>delete</strong> will return true if you try to delete something that never existed in the first place. You might not expect that. I didn&#8217;t.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;you can't delete me!&quot;;
console.log(delete a);          // prints false
console.log(delete octopus);    // prints true!
</pre>
<h3>Deleting in global scope</h3>
<p>Everything you declare in global scope, with or without the <em>var</em> keyword (which creates the new variable in local scope), also becomes a property of the global object.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;apples&quot;;
b = &quot;oranges&quot;;

console.log(window.a);	// prints &quot;apples&quot;
console.log(window.b);	// prints &quot;oranges&quot;
</pre>
<p>It&#8217;s worth mentioning at this point that declaring a variable without the <em>var</em> keyword is illegal in ECMAScript and will throw an error if you try to do it in <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9kZXZlbG9wZXIubW96aWxsYS5vcmcvZW4vSmF2YVNjcmlwdC9TdHJpY3RfbW9kZQ==">strict mode</a>. This is a good thing because declaring a variable without using <em>var</em> often indicates that the programmer mistyped the name of an existing variable. Strict mode makes this kind of error fail fast. Unfortunately strict mode is not widely used, so for now we will have to pretend it doesn&#8217;t exist.</p>
<p>Going back to the example, let&#8217;s see what happens if we try to delete <em>a</em> and <em>b</em>.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;apples&quot;;
b = &quot;oranges&quot;;

console.log(delete a);	// prints false
console.log(delete b);	// prints true

console.log(window.a);	// prints &quot;apples&quot;
console.log(window.b);	// prints undefined
</pre>
<p>Since it was declared with <em>var</em> the variable <em>a</em> is an object in global space and can never be deleted. However variable <em>b</em> was declared using sneaky shorthand to create a property on the global object, and properties can be deleted. In fact this is the main purpose of the <strong>delete</strong> operator:</p>
<p><strong>The delete operator is for deleting properties, not objects.</strong></p>
<p>So far, so good!</p>
<h3>Deleting in function scope</h3>
<p>The good news is that <strong>delete</strong> in function scope works the same way as in global scope. However it does provide a good demonstration of the point above, which is that failing to use the <em>var</em> keyword causes things to leak into global scope.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
	var a = &quot;apples&quot;;
	b = &quot;oranges&quot;;

	console.log(window.a);	// prints undefined
	console.log(window.b);	// prints &quot;oranges&quot;

	console.log(delete a);	// prints false
	console.log(delete b);	// prints true

	console.log(window.a);	// prints undefined
	console.log(window.b);	// prints undefined

	console.log(a);			// prints &quot;apples&quot;
	console.log(b);			// Error: b is not defined
})();
</pre>
<p>The example shows that the local variable <em>a</em> which was correctly initialised with <em>var</em> can never be deleted, but <em>b</em> (which is actually <em>window.b</em>) can be deleted.</p>
<h3>Deleting in eval scope</h3>
<p>Back at the start of this article I claimed that the answer to the initial puzzle depends on the &#8220;execution context&#8221;. JavaScript has three execution contexts, and the good news is that we have already covered two of them:</p>
<ol>
<li>1. Global code</li>
<li>2. Function code</li>
<li>3. Eval code</li>
</ol>
<p>The bad news is that the third case causes the <strong>delete</strong> operator to behave differently to what we have seen so far. The worse news is that it causes us to throw out what has so far been a golden rule &#8211; you can&#8217;t delete anything created with the <em>var</em> keyword.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
eval('var a = &quot;cat&quot;;' +
'console.log(window.a);' +	// prints &quot;cat&quot;
'console.log(delete a);' +	// prints true (?!)
'console.log(window.a);' +	// prints undefined
'console.log(a);');			// Error: a is not defined
</pre>
<p>In this case we declare <em>var a</em> and see that <em>a</em> has found its way on to the <em>window</em> object, which is familiar behaviour implying that we are in global scope. However things then take a twist when we discover that inside an <em>eval</em> statement it is possible to delete <em>a</em>.</p>
<p>You might be thinking &#8220;who cares, I never use eval&#8221;, but just remember that browser developer tools such as the Firefox Scratchpad work by putting whatever code you enter into an <em>eval</em> statement. That&#8217;s why you might not have come across some of the behaviour in this article before, and why you can&#8217;t test it using browser tools. You need to actually create an HTML page with a script if you want to see how <strong>delete</strong> really works.</p>
<h3>A few other things you can&#8217;t delete</h3>
<p>Some objects and properties are specifically flagged with a property indicating that they cannot be deleted, such as the <em>length</em> property of arrays and functions or the <em>window</em> object.</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
console.log(delete window);					// prints false
console.log(delete undefined);				// prints false
console.log(delete [].length);				// prints false
console.log(delete function() {}.length);	// prints false
</pre>
<p>These restrictions are designed to stop you from getting into a mess. This is a pleasant surprise coming from a language that allows you to redefine <em>undefined</em>.</p>
<p>The precise way that these things become undeleteable relates to a feature of JavaScript called &#8220;property attributes&#8221;, which may be the subject of a future blog in this series.</p>
<h3>Final points</h3>
<p>We now know that you can&#8217;t delete anything declared with <em>var</em> unless you are in eval execution. Given that we also know that declaring variables without <em>var</em> is illegal, and we also know from <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=d3d3Lmdvb2dsZS5jby51ay9zZWFyY2g/cT1ldmFsK2lzK2V2aWw=">various blog posts</a> that using <em>eval</em> is generally a bad idea, we can come to the slightly surprising conclusion:</p>
<p><strong>You can never delete objects in JavaScript.</strong></p>
<p>If that sounds like a memory leak waiting to happen then don&#8217;t worry, it shouldn&#8217;t be the case. Objects declared in functions will be eligible for garbage collection when they go out of scope, and you should avoid polluting the global namespace with objects in the first place. This also doesn&#8217;t really mean that <strong>delete</strong> is useless &#8211; it&#8217;s designed for deleting properties rather than objects, and that&#8217;s what you should use it for.</p>
<p><em>This is part three of a series of posts about JavaScript quirks. For part two, click <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEyLzAxLzE4L2phdmFzY3JpcHQtaXMtaGFyZC1wYXJ0LTItdGhlLWhpZGRlbi13b3JsZC1vZi1ob2lzdGluZw==">here</a>.</em></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=7765" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/01/31/javascript-is-hard-part-3-you-cant-delete-with-delete/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stories and Story Maps (Story Maps part 1)</title>
		<link>http://blog.caplin.com/2012/01/30/stories-and-story-maps-story-maps-part-1/</link>
		<comments>http://blog.caplin.com/2012/01/30/stories-and-story-maps-story-maps-part-1/#comments</comments>
		<pubDate>Mon, 30 Jan 2012 13:24:28 +0000</pubDate>
		<dc:creator>Mike Salsbury</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[QA]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=7896</guid>
		<description><![CDATA[Here at Caplin we use and are constantly evaluating Agile practices and techniques that make software development and maintenance as efficient as possible. In particular to the practice of BDD, which ‘utilises stories as it&#8217;s basic unit of functionality’ according to Dan North (]]></description>
			<content:encoded><![CDATA[<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvMjg1NTkxMy1vbGQtbWFwLWFuZC1jb21wYXNzLmpwZw=="><img class="alignleft  wp-image-8154" style="margin: 20px;" title="Map" src="http://blog.caplin.com/wp-content/uploads/2855913-old-map-and-compass-150x116.jpg" alt="Map and Compass" width="150" height="116" /></a></p>
<p>Here at Caplin we use and are constantly evaluating Agile practices and techniques that make software development and maintenance as efficient as possible. In particular to the practice of BDD, which ‘utilises stories as it&#8217;s basic unit of functionality’ according to <strong>Dan North</strong> (<a  0="title="Dan" 1="North" 2="What's" 3="in" 4="a" 5="Story"" href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Rhbm5vcnRoLm5ldC93aGF0cy1pbi1hLXN0b3J5Lw==" 6="target="_blank"">http://dannorth.net/whats-in-a-story/</a>). Even if there is an existing body of requirements assets available at the inception of a customer engagement the first challenge is to &#8216;storify&#8217; those assets. That is to assess each of the assets and ensure that it meets both Dan North&#8217;s assessment of what makes a good story, and also so that it passes our own 4 criteria for a good story:</p>
<p><strong>1. Testable</strong><br />
<strong> 2. Valuable</strong><br />
<strong> 3. Estimable</strong><br />
<strong> 4. Tradeable</strong></p>
<p>Passing on all of these criteria ensures that stories are suitably sized and that there is enough information to add the stories to an initial backlog for categorisation. This categorisation process will then provide the basis for dividing the stories up into groups as iterations and releases.</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvc3RvcnlNYXAuanBn"><img class="alignleft  wp-image-8236" title="storyMap" src="http://blog.caplin.com/wp-content/uploads/storyMap-225x300.jpg" alt="Story Maps" width="170" height="226" hspace="20" /></a>About 5 years ago two of our number who regularly manage customer engagements were at a conference where <strong>Jeff Patton</strong> was speaking. He was describing <strong>Story Maps</strong> (<a  0="title="Jeff" 1="Patton" 2="Story" 3="Maps"" href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Rhbm5vcnRoLm5ldC93aGF0cy1pbi1hLXN0b3J5Lw==" 4="target="_blank"">http://www.agileproductdesign.com/writing/how_you_slice_it.pdf</a>) and the thoughts that the talk elicited were that this was a &#8216;brilliant&#8217; idea, and something that would really help with the process of categorising and prioritising the initial story backlog produced at the inception stage of a project.</p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvODc5NDYxNC1hbmF0b21pY2FsLWNvcnJlY3QtbWFsZS1za2VsZXRvbi0zZC1yZW5kZXJpbmctd2l0aC1zaGFkb3ctb3Zlci13aGl0ZS5qcGc="><img class="size-thumbnail wp-image-8153 alignright" title="Walking skeleton" src="http://blog.caplin.com/wp-content/uploads/8794614-anatomical-correct-male-skeleton-3d-rendering-with-shadow-over-white-150x150.jpg" alt="Walking skeleton" width="150" height="150" /></a></p>
<p>Since that time we have regularly used Story Maps as part of the Inception phase to facilitate categorising the initial stories and producing the iteration and release plans. Stories can be arranged into functional areas, and then ranked by criticality. This allows a &#8216;walking skeleton&#8217; (http://alistair.cockburn.us/Walking+skeleton) to be built, providing a &#8216;steel thread&#8217; or &#8216;barebones&#8217; implementation to be built in the earliest iteration. Then the ribs can be fleshed out and slowly the application will be built around this skeleton.</p>
<p><strong>In part 2 we&#8217;ll look at some issues we have had with using Story Maps.</strong></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=7896" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/01/30/stories-and-story-maps-story-maps-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The WHY of WAT</title>
		<link>http://blog.caplin.com/2012/01/27/the-why-of-wat/</link>
		<comments>http://blog.caplin.com/2012/01/27/the-why-of-wat/#comments</comments>
		<pubDate>Fri, 27 Jan 2012 10:25:17 +0000</pubDate>
		<dc:creator>Adam Iley</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=8184</guid>
		<description><![CDATA[Recently a talk given by Gary Bernhardt at CodeMash has been doing the rounds.  In it, he pokes fun at some apparently crazy behaviours in Ruby and Javascript. While I might not be able to persuade you that all of the things he complains about make sense, I hope I&#8217;ll be...]]></description>
			<content:encoded><![CDATA[<p>Recently <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly93d3cuZGVzdHJveWFsbHNvZnR3YXJlLmNvbS90YWxrcy93YXQ=" 0="target="_blank"">a talk given by Gary Bernhardt at CodeMash</a> has been doing the rounds.  In it, he pokes fun at some apparently crazy behaviours in Ruby and Javascript.</p>
<p>While I might not be able to persuade you that all of the things he com<a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvd2F0LmpwZw=="><img class="alignright  wp-image-8216" title="Gary Bernhardt The WHY of WAT" src="http://blog.caplin.com/wp-content/uploads/wat-300x170.jpg" alt="Gary Bernhardt The WHY of WAT" width="300" height="170" /></a>plains about make sense, I hope I&#8217;ll be able to show you some of the reasons that javascript behaves as it does.</p>
<h2>The + symbol</h2>
<p>The + symbol in javascript can mean one of three things.</p>
<ul>
<li>It can be an infix addition operator where it operates on two numbers.</li>
<li>It can be an infix string concatenation operator where it operates on two strings.</li>
<li>It can be a prefix &#8216;this number is positive&#8217; operator where it operates on a single number.</li>
</ul>
<p>What makes all of this slightly more complicated is that javascript has automatic type coercion, so if you use something that isn&#8217;t a number or a string before or after your + symbol, then javascript is going to automatically convert whatever you did use to be either a string or a number.</p>
<ul>
<li>boolean, null, undefined coerce to a <em>number</em> (true = 1, false = 0, null = 0, undefined = NaN)</li>
<li>object, array, function all coerce to a <em>string</em>.</li>
</ul>
<p>So when you see</p>
<pre class="brush: jscript; title: ; notranslate">
[] + []
</pre>
<p>You know that javascript is going to coerce both of those empty arrays to a string and do a string concatenation on them.</p>
<p>When an array is coerced to a string, you get a comma separated list of its contents, so the result will be an empty string.</p>
<pre class="brush: jscript; title: ; notranslate">
[] + {}
</pre>
<p>In this case, the empty object on the right hand side is again going to be coerced to a string.  Since it doesn&#8217;t implement a toString method, it&#8217;ll pick up the toString method of the default Object by inheritance which returns the string <tt>[object Object]</tt> for objects, so we&#8217;re concatenating the empty string with the string <tt>"[object Object]"</tt>.</p>
<h2>Empty Code Blocks</h2>
<p>Now we come to a parsing weirdness in javascript.  You might have spotted that we use curly braces for two distinct things in javascript.  One of them is to indicate code blocks (like after an if statement or as part of a function definition), and the other is to write object literals (JSON as it&#8217;s often called).  In some languages code blocks can appear in most places within the code and indicate a new scope.  Javascript doesn&#8217;t use block scoping (yet), but it still allows code blocks to appear inside normal code.  Which means that sometimes when you write <tt>{}</tt> the javascript parser understands that as an empty code block and sometimes when you write <tt>{}</tt> it understands that as an empty object literal.  Generally speaking, if the { appears at the beginning of a statement it&#8217;s going to be interpreted as a code block. You can force the object literal understanding by wrapping the literal in normal brackets.</p>
<pre class="brush: jscript; title: ; notranslate">
{} + []
</pre>
<p>In this case the empty curly braces are interpreted as an empty code block, which means that the <tt>+</tt> appears at the beginning of the next statement, meaning that here the <tt>+</tt> is a prefix operator that indicates a number is positive.  The + prefix operator can only accept a single number argument, so it will always coerce its argument to a number.</p>
<p>In an extra wrinkle, the way javascript coerces an object, a function or an array to a number is via first coercing it to a string. An empty string coerces to 0.  So for example:</p>
<pre class="brush: jscript; title: ; notranslate">
+ [] === 0 // because the empty array becomes an empty string which becomes 0
+ [1] === 1 // because the array with 1 in it becomes a string with 1 in it which becomes 1
isNaN(+[1, 2] ) // because the array with 1, 2 in it becomes a string &quot;1,2&quot; which is not a number.
+({toString: function() {return &quot;3&quot;}}) === 3
</pre>
<p>So an empty object coerces to a string <tt>[object Object]</tt> which then coerces to <tt>NaN</tt>when it has to become a number for the prefix + operator in the following statement:</p>
<pre class="brush: jscript; title: ; notranslate">
{} + {}
</pre>
<h2>The &#8211; Symbol</h2>
<div>Unlike +, the symbol &#8211; is comparatively simple.  It has only two meanings, an infix meaning which requires two numbers and a prefix meaning which requires one number.  You already know that strings that don&#8217;t represent numbers get coerced to NaN when they are required to turn into numbers, so it should be no surprise that</div>
<pre class="brush: jscript; title: ; notranslate">
isNaN(&quot;wat&quot; - 1)
</pre>
<h2>Why does this matter?</h2>
<p>There are a few aspects of this that can and do come up in &#8216;real life&#8217;.  Back in the bad old days when people used &#8216;eval&#8217; to parse JSON, they used to have to wrap their JSON in brackets to ensure that the parser didn&#8217;t treat it as a code block.  It&#8217;s often important to bear type in mind and turn your strings into numbers, because otherwise people will be confused when <tt>3 + 1 = 31</tt>.  Knowing how coercion happens can make a lot of the rules around what == false much less confusing.  And perhaps most importantly of course it&#8217;ll let you sit in the audience of a &#8216;javascript is crazy&#8217; talk (of which there seem to be a few) and act as if it all makes perfect sense to you.</p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=8184" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/01/27/the-why-of-wat/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Caplin Thrower &#8211; Mobile Hackday Project</title>
		<link>http://blog.caplin.com/2012/01/19/caplin-thrower-mobile-hackday-project/</link>
		<comments>http://blog.caplin.com/2012/01/19/caplin-thrower-mobile-hackday-project/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 11:32:29 +0000</pubDate>
		<dc:creator>Kane Gregory</dc:creator>
				<category><![CDATA[Mobile]]></category>
		<category><![CDATA[Trading Technology]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=7905</guid>
		<description><![CDATA[While the rise of internet-capable mobile devices has solved a lot of problems, it has also brought a host of new problems with it. One problem you may encounter is that as your customers are now using multiple devices to access your service, they are having to continuously switch context...]]></description>
			<content:encoded><![CDATA[<p>While the rise of internet-capable mobile devices has solved a lot of problems, it has also brought a host of new problems with it. One problem you may encounter is that as your customers are now using multiple devices to access your service, they are having to continuously switch context between them.</p>
<p>Context switching can lead to both frustration and lost time. So what can make this context switching easier?<br />
<span id="more-7905"></span></p>
<p><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5mbGlja3IuY29tL3Bob3Rvcy93aGF0bGV5ZHVkZS82MjMxMTA3MTQwLw=="><img src="http://blog.caplin.com/wp-content/uploads/6231107140_1a60a595fe.jpg" alt="Context Switching" width="500" height="500" class="alignnone size-full wp-image-7991" /></a></p>
<p>This is the question that Priyank Vyas, Yasser Fadl, and myself (aka Team Hack&#8217;N'Slash) set out to answer for our <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDExLzA5LzI4L3RoZS0lRTIlODAlOUNtb2JpbGUlRTIlODAlOUQtaGFja2F0aG9uLw==">Caplin mobile hackday</a> project. Our use case was of a trader who uses his phone/tablet to view some data for a set of financial instruments while traveling, and then wants to view a more detailed analysis when he logs into his desktop at the office.</p>
<h2>Caplin Thrower</h2>
<p>Team Hack&#8217;N'Slash dubbed our project &#8220;Caplin Thrower&#8221;. Caplin Thrower is not an application in itself, but a mechanism to transfer context data between applications. This meant we had to make two web applications; one that was intended to run on a mobile device and one for a desktop computer.</p>
<p>For the desktop application we used the reference implementation of Caplin Trader. This allowed us to focus purely on how we injected context data into the application without having to write a fully fledged trading application from scratch. For the mobile application we created a very simple page that displayed a set of trade tiles.</p>
<h2>Keep it simple</h2>
<p>The reason context switching is a problem is that it pulls the user  out of their current workflow in order to facilitate the context switch.  If your solution requires the user to stop thinking about what they are doing to think about the context switch, then I would argue that it is not a good solution.</p>
<p>Taking this into account, we opted for a simple &#8220;flick&#8221; gesture to initiate the context switch. We chose this gesture as it felt like the user was literally flicking the tile from one device to the other! This action felt very natural, and gave an intuitive experience to the user.</p>
<h2>Don&#8217;t re-invent the wheel</h2>
<p>The next question we had to answer was &#8220;how do we get the context data from one device to the other?&#8221;. For us, there was only one answer to this question: Caplin Xaqua. If you have a world leading streaming server at your disposal, why look elsewhere?</p>
<p>We used SL4B to send small snippets of context data from the mobile application to our Xaqua server. We then listened for this data in our modified Caplin Trader.</p>
<h2>Remember, your contexts are different!</h2>
<p>The last part of the puzzle was to determine how to inject the context into our desktop application. As one of the key features of Caplin Trader is its content management, this turned out to be very easy from a technical standpoint. However, there was still the question of what should be displayed to the user after the context switch.</p>
<p>It is important to keep in mind that your two contexts will be different. If they are not, why would your user make the context switch in the first place? The key is finding how the two contexts differ, and why the user wants to put in the effort required to move from one to the other.</p>
<p>In our case the biggest difference was screen size. A mobile device cannot be expected to display the same amount of data as a desktop computer. This suggests that the primary reason a user would switch from their mobile to their desktop is to see more data.</p>
<p>To take advantage of the extra screen size we decided that instead of just transferring the tile, we would launch an entire new page with multiple components relating to the context of the flicked tile (ie, its currency pair).</p>
<h2>The power of simplicity</h2>
<p>When we demonstrated Caplin Thrower, it received a large round of applause. I believe this was due to how it made the context switch seem completely effortless. What seemed like a complex problem was disposed of with a simple flick of the finger.</p>
<p><em>Team Hack&#8217;N'Slash was a runner-up in the Caplin mobile hackday (you can read about the Caplin mobile hackday <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDExLzA5LzI4L3RoZS0lRTIlODAlOUNtb2JpbGUlRTIlODAlOUQtaGFja2F0aG9uLw==">here</a>, and the winning team&#8217;s project <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDExLzEwLzA2L2NhcGxpbi1yZWF2ZXItaGFja2RheS1wcm9qZWN0Lw==">here</a>).</em></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=7905" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/01/19/caplin-thrower-mobile-hackday-project/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript is Hard Part 2: The Hidden World of Hoisting</title>
		<link>http://blog.caplin.com/2012/01/18/javascript-is-hard-part-2-the-hidden-world-of-hoisting/</link>
		<comments>http://blog.caplin.com/2012/01/18/javascript-is-hard-part-2-the-hidden-world-of-hoisting/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 16:05:53 +0000</pubDate>
		<dc:creator>Adam Shone</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://blog.caplin.com/?p=7581</guid>
		<description><![CDATA[If you are interviewing prospective JavaScript developers and you feel like being a little bit mean then you could do worse than ask this question: In JavaScript, is it possible to call a function before it has been declared? It&#8217;s easy enough to demonstrate that it is indeed possible, as...]]></description>
			<content:encoded><![CDATA[<p>If you are interviewing prospective JavaScript developers and you feel like being a little bit mean then you could do worse than ask this question:</p>
<blockquote><p>In JavaScript, is it possible to call a function before it has been declared?</p></blockquote>
<p><span id="more-7581"></span></p>
<p>It&#8217;s easy enough to demonstrate that it is indeed possible, as this self-executing function proves:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
    console.log(typeof greet);    // prints &quot;function&quot;
    greet();                      // alerts &quot;hello&quot;

    function greet() {
        alert(&quot;hello!&quot;);
    }
})();
</pre>
<p>Unfortunately for the hypothetical interview candidate it&#8217;s just as easy to demonstrate that it&#8217;s <em>not</em> possible:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
    console.log(typeof greet);    // prints &quot;undefined&quot;
    greet();                      // Error: greet is not a function

    var greet = function() {
        alert(&quot;hello!&quot;);
    }
})();
</pre>
<p>In the first case we declared a named function and in the second case we declared a variable and assigned an anonymous function as the value. Although they seem very similar, the first case allows us to call the function before it is declared and the second case does not. This doesn&#8217;t seem very intuitive unless you understand the mechanism at work behind the scenes.</p>
<h3>Hoisting</h3>
<p>Javascript interpreters employ a slightly mysterious process called <em>declaration hoisting</em>, in which all function and variable declarations are moved to the top of their containing scope. If a variable is declared and assigned in one statement then the statement is split into two, with only the declaration getting hoisted. For example, here is a block of code as written by a developer:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
    console.log(a);     // prints &quot;undefined&quot;
    b();                // prints &quot;b&quot;
    console.log(c);     // prints &quot;undefined&quot;
    d();                // Error: d is not a function
    e();                // Error: e is not a function

    var a = &quot;myValue&quot;;
    function b() { console.log(&quot;b&quot;); };
    var c;
    var d = function namedFunc() { console.log(&quot;d&quot;); };
    var e = function() { console.log(&quot;e&quot;); }
})();
</pre>
<p>And here is how that block of code would be interpreted after the hoisting process has taken place:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
    // hoisted section
    var a;
    function b() { console.log(&quot;b&quot;); };
    var c;
    var d;
    function namedFunc() { console.log(&quot;d&quot;); };
    var e;
    function __anon() { console.log(&quot;e&quot;); }

    // user code
    console.log(a);     // prints &quot;undefined&quot;
    b();                // prints &quot;b&quot;
    console.log(c);     // prints &quot;undefined&quot;
    d();                // Error: d is not a function
    e();                // Error: e is not a function

    a = &quot;myValue&quot;;
    d = namedFunc;
    e = __anon;
})();
</pre>
<p>Suddenly it makes more sense. Notice that variables and their assignments are split up with only the declaration getting hoisted, while functions declarations are hoisted along with their bodies. That&#8217;s why we&#8217;re able to call <em>b()</em>.</p>
<p>Now that we know how hoisting works we can see why it wasn&#8217;t possible to call <em>greet()</em> before it was declared in the second code example. The variable <em>greet</em> would have been hoisted, but the assignment of that variable to the function does not happen until after <em>greet()</em> is called.</p>
<h3>Why should we care?</h3>
<p>Besides the fact that you can impress friends at parties with your esoteric JavaScript knowledge, you should be aware of hoisting because not knowing about it can lead to nasty bugs, and before you know it you will be <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3NoYWtlc3BlYXJlLm1pdC5lZHUvaGFtbGV0L2hhbWxldC4zLjQuaHRtbA==">hoist by your own petard</a>, whatever that means.</p>
<div id="attachment_7654" class="wp-caption aligncenter" style="width: 310px"><a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS93cC1jb250ZW50L3VwbG9hZHMvcGV0YXJkLmpwZw=="><img class="size-full wp-image-7654" title="petard" src="http://blog.caplin.com/wp-content/uploads/petard.jpg" alt="petard" width="300" height="408" /></a><p class="wp-caption-text">A petard: some kind of medieval bomb apparently</p></div>
<p>Take this slightly contrived example adapted from <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5hZGVxdWF0ZWx5Z29vZC5jb20vMjAxMC8yL0phdmFTY3JpcHQtU2NvcGluZy1hbmQtSG9pc3Rpbmc=">Ben Cherry&#8217;s blog about hoisting</a>:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
var a = &quot;old value&quot;;
function changeTheValueOfA() {
	a = &quot;new value&quot;;
	return;

	function a() {}
}
changeTheValueOfA();
console.log(a);
</pre>
<p>If you execute this code you will find that it prints &#8220;old value&#8221;, indicating that the <em>changeTheValueOfA</em> function doesn&#8217;t work. To someone unacquainted with hoisting this may seem bizarre.</p>
<p>The reason it doesn&#8217;t work is that the local function <em>a()</em> will be hoisted to the top of <em>changeTheValueOfA</em>, and since declarations are function-scoped the assignment of &#8220;new value&#8221; will apply to the local <em>a</em> rather than the <em>a</em> outside the function.</p>
<p>This shows another facet of hoisting &#8211; all declarations are hoisted whether they are relevant or not, even declarations that are in unreachable code blocks.</p>
<p>Here&#8217;s another one:</p>
<pre class="brush: jscript; gutter: true; title: ; toolbar: false; notranslate">
(function() {
    var a = &quot;initial&quot;;
    if(a) {
        function f() { console.log(&quot;1&quot;); };
    } else {
        function f() { console.log(&quot;2&quot;); };
    }
    f();
})();
</pre>
<p>Since we are now wise to the tricks of hoisting we know that function <em>f</em> will be hoisted. But in this case there are two functions with the same name. You might expect the first instance of <em>f</em> to be hoisted because <em>a</em> is defined, so the declaration in the <em>if</em> block will execute rather than the <em>else</em> block.</p>
<p>Unfortunately the hoisting process does not care in the slightest about which branch executes, and even more unfortunately there is no defined behaviour regarding which function declaration &#8220;wins&#8221; by overwriting the other.</p>
<p>If you run this code in Firefox it will print <em>1</em>. If you run it in Internet Explorer it prints <em>2</em>. Ouch &#8211; try tracking that one down if it was buried in a large code base!</p>
<h3>What should we do about all this?</h3>
<p>It&#8217;s worth pointing out that the last example is actually illegal in ECMAScript, although no browser will complain about it (unless you use the ECMAScript 5 <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cHM6Ly9kZXZlbG9wZXIubW96aWxsYS5vcmcvZW4vSmF2YVNjcmlwdC9TdHJpY3RfbW9kZQ==">strict mode</a>). Hoisting generally won&#8217;t trip you up unless you are already doing something a little bit dubious, such as declaring a variable twice.</p>
<p>The static analysis tool <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL3d3dy5qc2xpbnQuY29t">JS Lint</a> will recommend that all variable and function declarations should be placed at the top of their containing scope, in other words write your code as it would be interpreted after hoisting has taken place. In most cases I think this is overkill, just take a bit of care with your declarations and you&#8217;ll be fine.</p>
<p>Next time: some esoterica about deleting objects.</p>
<p><em>This is part two of a series of posts about JavaScript quirks. For part one, click <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEyLzAxLzEzL2phdmFzY3JpcHQtaXMtaGFyZC1wYXJ0LTEteW91LWNhbnQtdHJ1c3QtYXJyYXlz">here</a>. For part three, click <a  href="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?url=aHR0cDovL2Jsb2cuY2FwbGluLmNvbS8yMDEyLzAxLzMxL2phdmFzY3JpcHQtaXMtaGFyZC1wYXJ0LTMteW91LWNhbnQtZGVsZXRlLXdpdGgtZGVsZXRl">here</a>.</em></p>
 <img src="http://blog.caplin.com/wp-content/plugins/wordpress-feed-statistics/feed-statistics.php?view=1&post_id=7581" width="1" height="1" style="display: none;" />]]></content:encoded>
			<wfw:commentRss>http://blog.caplin.com/2012/01/18/javascript-is-hard-part-2-the-hidden-world-of-hoisting/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

