<?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>Christopher Bird &#187; Software Development</title>
	<atom:link href="http://www.christopherbird.co.uk/category/software-development/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.christopherbird.co.uk</link>
	<description>Personal and professional blog</description>
	<lastBuildDate>Mon, 21 Jun 2010 15:32:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>JavaScript Multiple Callbacks</title>
		<link>http://www.christopherbird.co.uk/2010/06/javascript-multiple-callbacks/</link>
		<comments>http://www.christopherbird.co.uk/2010/06/javascript-multiple-callbacks/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 15:32:12 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=150</guid>
		<description><![CDATA[On a previous project we were writing a web UI using a lot of javascript. The UI was constructed in an MVP style with many Views, Presenters and Models all active at the same time. One of the problems we had was with having multiple Presenters subscribed to listen for a single callback from a [...]]]></description>
			<content:encoded><![CDATA[<p>On a previous project we were writing a web UI using a lot of javascript. The UI was constructed in an MVP style with many Views, Presenters and Models all active at the same time. One of the problems we had was with having multiple Presenters subscribed to listen for a single callback from a Model.</p>
<p>Initially we had quite an ugly solution which involved chaining functions in a similar fashion as to DOM events were handled in the pre jQuery days. To do this we used the following function&#8230;</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">function</span> addEventHandler<span style="color: #009900;">&#40;</span>event<span style="color: #339933;">,</span> scope<span style="color: #339933;">,</span> method<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> oldEvent <span style="color: #339933;">=</span> event<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> arguments.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; oldEvent.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; method.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span>scope<span style="color: #339933;">,</span> params<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>Example usage&#8230;</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">someObject.<span style="color: #660066;">someEvent</span> <span style="color: #339933;">=</span> addEventHandler<span style="color: #009900;">&#40;</span>someObject.<span style="color: #660066;">someEvent</span><span style="color: #339933;">,</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> doSomething<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
<p>After some refactoring we created an Event class (semi inspired by Node.Js EventEmitter). This seemed like a nice way to allow us to simplify the syntax, make it easier to read and attempt to use a familiar syntax to listeners else where in JavaScript.</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> Event <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> self <span style="color: #339933;">=</span> <span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> handlers <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; self.<span style="color: #660066;">addListener</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; handlers.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>handler<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; self.<span style="color: #660066;">trigger</span> <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> index <span style="color: #000066; font-weight: bold;">in</span> handlers<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; handlers<span style="color: #009900;">&#91;</span>index<span style="color: #009900;">&#93;</span>.<span style="color: #660066;">apply</span><span style="color: #009900;">&#40;</span><span style="color: #000066; font-weight: bold;">this</span><span style="color: #339933;">,</span> getArguments<span style="color: #009900;">&#40;</span>arguments<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> getArguments <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> params <span style="color: #339933;">=</span> <span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">for</span> <span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">var</span> i <span style="color: #339933;">=</span> <span style="color: #CC0000;">0</span><span style="color: #339933;">;</span> i <span style="color: #339933;">&lt;</span> args.<span style="color: #660066;">length</span><span style="color: #339933;">;</span> i<span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; params.<span style="color: #660066;">push</span><span style="color: #009900;">&#40;</span>args<span style="color: #009900;">&#91;</span>i<span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> params<span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #339933;">;</span></div></div>
<p>Example usage&#8230;</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">someObject.<span style="color: #660066;">someEvent</span>.<span style="color: #660066;">addListener</span><span style="color: #009900;">&#40;</span>doSomething<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">function</span> doSomething<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
<span style="color: #009900;">&#125;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2010/06/javascript-multiple-callbacks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NodeJS Testing</title>
		<link>http://www.christopherbird.co.uk/2010/04/nodejs-testing/</link>
		<comments>http://www.christopherbird.co.uk/2010/04/nodejs-testing/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 16:05:14 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[NodeJs]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=120</guid>
		<description><![CDATA[First thing that struck me when i started working with NodeJS was a lack of anything to run my tests with. I wanted to be able to write tests, run them, tell me which one failed and why. I thought this may be usefull for others so here is &#8220;Nest&#8221; my node testing module that [...]]]></description>
			<content:encoded><![CDATA[<p>First thing that struck me when i started working with NodeJS was a lack of anything to run my tests with. I wanted to be able to write tests, run them, tell me which one failed and why. I thought this may be usefull for others so here is &#8220;Nest&#8221; my node testing module that works with the existing assert module.</p>
<p><a href="http://github.com/chrisabird/nest">Nest @ GitHub</a></p>
<h3>Example</h3>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #003366; font-weight: bold;">var</span> nest <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;./nest&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<span style="color: #003366; font-weight: bold;">var</span> assert <span style="color: #339933;">=</span> require<span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;assert&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
<br />
<span style="color: #003366; font-weight: bold;">var</span> testCases <span style="color: #339933;">=</span> <span style="color: #003366; font-weight: bold;">new</span> nest.<span style="color: #660066;">Nest</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
testCases.<span style="color: #660066;">add</span><span style="color: #009900;">&#40;</span><span style="color: #3366CC;">&quot;TestSomething&quot;</span><span style="color: #339933;">,</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; test_true_is_true<span style="color: #339933;">:</span> <span style="color: #003366; font-weight: bold;">function</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; assert.<span style="color: #660066;">equal</span><span style="color: #009900;">&#40;</span><span style="color: #003366; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #003366; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
&nbsp; &nbsp; <span style="color: #009900;">&#125;</span><br />
<span style="color: #009900;">&#125;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><br />
testCases.<span style="color: #660066;">run</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2010/04/nodejs-testing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NodeJS and Scope</title>
		<link>http://www.christopherbird.co.uk/2010/03/nodejs-and-scope/</link>
		<comments>http://www.christopherbird.co.uk/2010/03/nodejs-and-scope/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 18:51:03 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[NodeJs]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=112</guid>
		<description><![CDATA[Scope is a little different in NodeJS but only in a artificial sense. let&#8217;s dive into a quick example of what i mean. Circle.js &#160; var PI = 3.14; &#160; exports.getPi = functon&#40;&#41; &#123; &#160; &#160; return PI; &#160; &#125; If you were to include this file into a browser you would expect to be [...]]]></description>
			<content:encoded><![CDATA[<p>Scope is a little different in NodeJS but only in a artificial sense. let&#8217;s dive into a quick example of what i mean.</p>
<p>Circle.js</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; <span style="color: #003366; font-weight: bold;">var</span> PI <span style="color: #339933;">=</span> <span style="color: #CC0000;">3.14</span><span style="color: #339933;">;</span><br />
&nbsp; exports.<span style="color: #660066;">getPi</span> <span style="color: #339933;">=</span> functon<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span><br />
&nbsp; &nbsp; <span style="color: #000066; font-weight: bold;">return</span> PI<span style="color: #339933;">;</span><br />
&nbsp; <span style="color: #009900;">&#125;</span></div></div>
<p>If you were to include this file into a browser you would expect to be able to access the variable PI from another file (ignoring the syntax error which would be created by assigning to the undefined object &#8220;exports&#8221;). This is not the case in NodeJS, when you call require to include this script the contents of the file is inserted into a function as follows&#8230;</p>
<div class="codecolorer-container javascript vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="javascript codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">&nbsp; &nbsp; <span style="color: #003366; font-weight: bold;">var</span> wrapper <span style="color: #339933;">=</span> <span style="color: #3366CC;">&quot;(function (exports, require, module, __filename, __dirname) { &quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> content<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #339933;">+</span> <span style="color: #3366CC;">&quot;<span style="color: #000099; font-weight: bold;">\n</span>});&quot;</span><span style="color: #339933;">;</span></div></div>
<p>By calling this wrapper function and passing in an object to the exports parameter, your exported variables/functions are added to the exports object which is then returned as a result of a &#8220;require&#8221; call.</p>
<p>Because your exported functions are defined inside another function (the one generated when the script is imported) any variables (like PI) are still accessible by your exported functions due to JavaScripts normal scoping. Take a look at JavaScript closures for more information.</p>
<h3>Conclusion</h3>
<ul>
<li>Each script can access what you &#8220;require&#8221; into it and what you define in it.</li>
<li>Requires are cached so every call to require for the same module should get a reference to the same thing</li>
<li>Finally this is my current understanding, ill update as i learn, if you can enlighten me any further leave me a message</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2010/03/nodejs-and-scope/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New validation rules</title>
		<link>http://www.christopherbird.co.uk/2010/01/new-validation-rules/</link>
		<comments>http://www.christopherbird.co.uk/2010/01/new-validation-rules/#comments</comments>
		<pubDate>Sat, 16 Jan 2010 17:23:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Javascript]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=82</guid>
		<description><![CDATA[Few conversations with colleagues later and a few small changes to the validation framework. Fixed typo in adding custom rules test. Added &#8220;length less than&#8221;, &#8220;length greater than&#8221; and &#8220;is a number&#8221; rules Updated example to include some of the new validation rules What next? Date validation seems to be one that keeps cropping up. [...]]]></description>
			<content:encoded><![CDATA[<p>Few conversations with colleagues later and a few small changes to the validation framework.</p>
<ul>
<li>Fixed typo in adding custom rules test.</li>
<li>Added &#8220;length less than&#8221;, &#8220;length greater than&#8221; and &#8220;is a number&#8221; rules</li>
<li>Updated example to include some of the new validation rules</li>
</ul>
<h3>What next?</h3>
<p>Date validation seems to be one that keeps cropping up. DateJs provides a great library for dealing with all sorts of date formats. Im considering whether this should be an optional set of rules as the sizes of DateJs would negate the bennifit of the small validation core if included with it. I&#8217;m also considering an optional set of patterns for common international problems (e.g.Email address and Uri), if they are small enough perhaps they should be in the core as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2010/01/new-validation-rules/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Javascript validation</title>
		<link>http://www.christopherbird.co.uk/2010/01/javascript-validation/</link>
		<comments>http://www.christopherbird.co.uk/2010/01/javascript-validation/#comments</comments>
		<pubDate>Sun, 10 Jan 2010 20:02:49 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JQuery]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=72</guid>
		<description><![CDATA[To quote Eddie Izzard &#8220;Look, you&#8217;re British, so scale it down a bit, all right?&#8221;, well perhaps i should say &#8220;Look, you&#8217;re a validation framework, so scale it down a bit, all right?&#8221;. Recently i&#8217;ve been working on ALOT of javascript and experiences (reassuringly) from the past have come back to haunt me yet again. [...]]]></description>
			<content:encoded><![CDATA[<p>To quote Eddie Izzard &#8220;Look, you&#8217;re British, so scale it down a bit, all right?&#8221;, well perhaps i should say &#8220;Look, you&#8217;re a validation framework, so scale it down a bit, all right?&#8221;. Recently i&#8217;ve been working on ALOT of javascript and experiences (reassuringly) from the past have come back to haunt me yet again. What am i talking about? Well it would seem that every framework starts out with the good intention trying to avoid repetition, but over time, someone adds a little here, and a little there and before you know it you have a behemoth of a framework which does things well out side the scope of what it should do.</p>
<p>How does this relate to javascript validation? Well after using quite a popular JQuery validation framework i noticed the size of the library minified as 29KB. This doesn&#8217;t sound a great deal but when you include a few frameworks like this, plus JQuery the page weights seem to get pretty big. Yes caching, gziping and content delivery networks will help but the first hit on these pages over mobile networks or on mobile phones and they can take quite a while to load. What i would like to see more of is smaller more directed frameworks/utilities that i can customise into what i want and keep page sizes to a minimum.</p>
<p>To this end i flippantly stated &#8220;It can&#8217;t be that hard&#8221; and embarked on writing a validation framework that will allow me to do most of what i need without the overhead. This is only a first stab that works for what i need, any comments on other validation types that i should support would be good.</p>
<p>Currently it supports&#8230; required (and ability to define a default value to ignore), patterns, less than, greater than, equal to, equal to other field and the ability to add custom rules. On top of this you can all specify rules that enable and disabled validation of a field. Currently the minified size stands at about 2k even tripling the number of rules would only take that up to about 4k.</p>
<p>I got the size down by only putting into the framework what really needed to be there. So what won&#8217;t it do? well it wont manage form click events for you, thats for you to decided how you want the validation to fire. It won&#8217;t do anything clever with the error messages, if you want something fancy write what you want.</p>
<p>Take a look at the code on git hub <a href="http://github.com/chrisabird/validate">http://github.com/chrisabird/validate</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2010/01/javascript-validation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Retlang, some examples and explanations</title>
		<link>http://www.christopherbird.co.uk/2009/12/retlang-some-examples-and-explanations/</link>
		<comments>http://www.christopherbird.co.uk/2009/12/retlang-some-examples-and-explanations/#comments</comments>
		<pubDate>Sun, 13 Dec 2009 22:45:16 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[concurrency]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=52</guid>
		<description><![CDATA[Last week I spent some time trying out the message based concurrency library Retlang in and effort speed up a portion of an application I&#8217;ve been working on. When picking up Retlang I found very few examples/explanations that were relevant to the current release (0.4.3.0). In the beginning Retlang is constructed of various channels that [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I spent some time trying out the message based concurrency library <a href="http://code.google.com/p/retlang/">Retlang</a> in and effort speed up a portion of an application I&#8217;ve been working on. When picking up Retlang I found very few examples/explanations that were relevant to the current release (0.4.3.0).</p>
<h3>In the beginning</h3>
<p>Retlang is constructed of various <strong>channels</strong> that can have messages <strong>published</strong> to them. A <strong>channel</strong> also has <strong>fibers subscribed</strong> to them with a delegate to a function that accept a message as a parameter. So create a channel, subscribe a fiber to it and publish your messages to the channel and the fiber will process them one after another leaving your program free to do other things, Simple yeah? not one thread, mutex, monitor or lock in sight, don&#8217;t believe me how about an example?</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var fiber <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; fiber<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var channel <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Channel<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span>fiber, <br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> WebServiceClient<span style="color: #008000;">.</span><span style="color: #0000FF;">SendString</span><span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;hello&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; channel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;world&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h3>Talk to me!</h3>
<p>Ok so you might have noticed these published messages are asynchronous, you get nothing back. There are two solutions use the RequestReplyChannel instead of Channel which will process your message and wait for a response with each call. That&#8217;s gonna slow things down though, so instead we&#8217;ll publish the result on to another channel and pick them up after. Here goes&#8230;</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var requestFiber <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var responseFiber <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; requestFiber<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; responseFiber<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var requestChannel <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Channel<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var responseChannel <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Channel<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; requestFiber, <br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; responseChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, value<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;world&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var results <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; responseChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; responseFiber,<br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; results<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #666666;">&quot;hello london&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span>, <span style="color: #666666;">&quot;hello world&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h3>You said concurrent</h3>
<p>Ok so the previous example used one fiber to find strings that contained the word &#8220;world&#8221; and another to collate them after. It&#8217;s hardly concurrent, still feels a bit sequential. In the example we can&#8217;t really add any concurrency to the collation of those responses, well not without locking that results list, plus that&#8217;s a very simple/fast operation anyway. What we can do is speed up the finding of the word &#8220;world&#8221; in strings because there is no shared state, that&#8217;s simple to do. The channel will allow you to subscribe as many fibers to it as you wish, only problem is every fiber will be called for each message. This doesn&#8217;t really do what we want, we&#8217;ll end up with many results for each message, what we really want is the first free fiber to process the next published message. Step in the QueueChannel which does just that, so same example but with more &#8220;fiber&#8221;!</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var requestFiber1 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var requestFiber2 <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #0600FF; font-weight: bold;">using</span><span style="color: #008000;">&#40;</span>var responseFiber <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> ThreadFiber<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#123;</span><br />
&nbsp; requestFiber1<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestFiber2<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; responseFiber<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var requestChannel <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> QueueChannel<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var responseChannel <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Channel<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; requestFiber1, <br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; responseChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, value<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;world&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; requestFiber2, <br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; responseChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; value<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, value<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Contains</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;world&quot;</span><span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; var results <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> List<span style="color: #008000;">&lt;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">bool</span><span style="color: #008000;">&gt;&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; responseChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Subscribe</span><span style="color: #008000;">&#40;</span><br />
&nbsp; &nbsp; responseFiber,<br />
&nbsp; &nbsp; value <span style="color: #008000;">=&gt;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; results<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>value<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; &nbsp; <span style="color: #008000;">&#125;</span><br />
&nbsp; <span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1</span>, <span style="color: #666666;">&quot;hello london&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; requestChannel<span style="color: #008000;">.</span><span style="color: #0000FF;">Publish</span><span style="color: #008000;">&#40;</span><a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">int</span>, <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">2</span>, <span style="color: #666666;">&quot;hello world&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<h3>Those threads are a bit heavy</h3>
<p>At the moment i&#8217;m using the ThreadFiber which maps down to a Thread. So for every ThreadFiber we&#8217;re creating new threads which is expensive so instead we might want to use the PoolFiber which uses the .Net ThreadPool to manage creation and reuse. It&#8217;s a very simple change to use the PoolFiber, just replace the ThreadFibers. The only difference between ThreadFiber and PoolFiber is that it will batch up a few messages to be processed in a single thread.</p>
<h3>Pause for breath</h3>
<p>This seems like a good place to stop for now. There are a few more things to cover in more detail like batch execution and some other things like customising execution but those can wait till another day.</p>
<h3>Updated</h3>
<p>I&#8217;ve updated the last to examples to solve a type typo.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/12/retlang-some-examples-and-explanations/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Lessons learnt from acceptance testing&#8230; again</title>
		<link>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/</link>
		<comments>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 22:26:48 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=49</guid>
		<description><![CDATA[After writing my last post i&#8217;ve been thinking more about the question of &#8220;How should i organise my tests?&#8221;. The answer i gave last time seemed to work for fixing existing tests but didn&#8217;t seem to fix the cause of the problem that all the tests were still too much like unit tests. Oh yeah, [...]]]></description>
			<content:encoded><![CDATA[<p>After writing my last post i&#8217;ve been thinking more about the question of &#8220;How should i organise my tests?&#8221;. The answer i gave last time seemed to work for fixing existing tests but didn&#8217;t seem to fix the cause of the problem that all the tests were still too much like unit tests. Oh yeah, at this point i&#8217;d like to point out i reserve the right to contradict myself.</p>
<p>While working on a separate RoR project I&#8217;ve used <a href="http://cukes.info/">Cucumber</a> to drive acceptance tests. If you&#8217;ve not tried it already, it&#8217;s great give it a go! Also on a side note i also discovered the guys who wrote selenium-client put a great deal more thought into the API than the .NET counterpart. Lots of extensions for waits and JQuery/Prototype integration are included by default. Anyway back to the problem at had, Cucumber forces you to write plain text stories (or features) and one or more scenarios for that story. Scenarios are written with each line start with &#8220;Given&#8221;, &#8220;When&#8221; and &#8220;Then&#8221; (and optionally And). Each line of the scenario corresponds to an executable &#8220;Step&#8221; that in my case performed a selenium action (or it could also quite easily perform an action against an API).</p>
<div class="codecolorer-container text vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Feature: Manage blog posts<br />
&nbsp; In order to manage my blog posts<br />
&nbsp; As a writer of poor blog posts<br />
&nbsp; I want to be able to create blog posts<br />
<br />
&nbsp; Scenario: Create a blog post <br />
&nbsp; &nbsp; Given i have clicked add blog post<br />
&nbsp; &nbsp; And i have written &quot;My first post&quot; with content &quot;My first post&quot;<br />
&nbsp; &nbsp; When i click publish<br />
&nbsp; &nbsp; Then i should see the post &quot;My first entry&quot; in the list of posts</div></div>
<p>Anyway this method of writing test with the emphasis on the behaviour of the user (not surprising for a BDD tool) meant i ended up with less focus on one bit of functionality on a single page and more on the overall journey of the users actions through the application. Each scenario taking a different path or journey through that story.</p>
<p>Overall cucumber forced me to stay true to testing behaviour, avoiding the pitfalls of the test written in a plain unit testing framework. So, try cucumber, even if you don&#8217;t use it in your project i hope it makes you think differently about how you write the same tests in your native language.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/12/lessons-learnt-from-acceptance-testing-again/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Lessons learnt from acceptance testing (with Selenium)</title>
		<link>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/</link>
		<comments>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 22:34:32 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[acceptance testing]]></category>
		<category><![CDATA[selenium]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=38</guid>
		<description><![CDATA[While recently working with automated acceptance tests I noticed two major problems. The tests had started to intermittently fail and were taking longer and longer to run. With a loss in confidence of the tests they started to fall into disrepair. This post tries to cover some of the root causes of our problems and [...]]]></description>
			<content:encoded><![CDATA[<p>While recently working with automated acceptance tests I noticed two major problems. The tests had started to intermittently fail and were taking longer and longer to run. With a loss in confidence of the tests they started to fall into disrepair.</p>
<p>This post tries to cover some of the root causes of our problems and try to suggest practices to help avoid these problem in the future. While I talk about Selenium most of these practices in theory could be applied to any automation package&#8230;</p>
<h3>What should I test with Selenium?</h3>
<p>Actually this should really be where are my tests best placed? A lot of acceptance tests seemed to delve too deeply into the functionality of a story which partially leads to the problem of too many/long running acceptance test. Try to keep acceptance tests at a high level. Anything of the story that you can test in unit tests, test it there &#8211; don&#8217;t repeat yourself in the acceptance tests.</p>
<p>Try not to use Selenium as a tool to unit test Javascript, this again dramatically increases the number of tests you have and can become very brittle when waiting for expected DOM changes. Use an appropriate Javascript unit testing tool like JsTestDriver.</p>
<h3>How should I organise my tests?</h3>
<p>One of the key problems to organising tests as if they are single unit tests is they tend to navigate to a page, change something, assert something happened then the close page. Now write 25 tests for one page and for every tests you have to wait for the page to load, which as you many expect seriously increases the time taken to run the tests. This is especially a problem testing functionality based entirely in Javascript which is relatively quick to test.</p>
<p>Where possible group all tests for a page and browse to the page once. This does leave the problem of tests effecting each other but if you remember to follow a pattern of, change something, assert something and then reset the page you shouldn&#8217;t have any problems.</p>
<p>Something else that I came across was when testing functionality on a page that was in a sequence after others, you always ended up completing the first page and then moving to the second before starting your tests. Now think about organising your tests where for each test you are completing the first page to get to the second before performing your test, they start to take a very very long time to run. This leads to organising the tests into journeys through the system (or groups of related stories that can be run in sequence) allowing us to tests each criteria as we navigate through the system.</p>
<h3>How should I organise the code that interacts with my web application?</h3>
<p>Use a page model. Construct classes that represent pages or popup windows in your application that have an interface that reflects the user interface. For example a form page that takes a name may have a page model with properties for title, first name and surname that when set or got perform the relevant selenium actions on the browser to get or set the value. This has a couple of benefits, you can reuse these page models across tests and they can be easily replaced if a better automated testing tool comes along. Another point to note is to make sure your page model interface follows a single semantic, e.g. use properties to get/set values and methods to perform actions like clicking a button. Tests tend to become very confused and actions tend to get repeated if there is no common way of defining the interface.</p>
<h3>How do I know when something has happened on the page?</h3>
<p>It&#8217;s very important to know when something has happened on the page (especially on Javascript heavy pages), if you don&#8217;t, expectations become very brittle when they check to early or to late. Hopefully your first reaction is not to start putting Thread.Sleep()&#8217;s all throughout your tests, what happens when something takes longer than you expected? The best way to solve this problem in Selenium is to use the built-in WaitForCondition(condition, timeout) method. You can give a condition in Javascript which has access to the client side Selenium object. For example you can do things like this&#8230; </p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">selenium<span style="color: #008000;">.</span><span style="color: #0000FF;">WaitForCondition</span><span style="color: #008000;">&#40;</span><br />
&nbsp; <span style="color: #666666;">&quot;selenium.isElementPresent('result-div')&quot;</span>, <br />
&nbsp; <span style="color: #666666;">&quot;1000&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>The important difference between this and Thread.Sleep() is that you can give longer timeout periods. A Thread.Sleep() will always make your tests wait for that period of time where as WaitForCondition will move on once the condition is met. This allow you to account for differences in the speed tests run without making your tests take longer and longer to run when increasing Thread.Sleep times.</p>
<h3>Summary</h3>
<ul>
<li>Test where it is most appropriate.</li>
<li>Group tests into journeys where possible.</li>
<li>Hide selenium browser interactions behind page models.</li>
<li>Don&#8217;t Sleep just WaitForCondition&#8217;s to happen.</li>
<ul>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/11/lessons-learnt-from-acceptance-testing-with-selenium/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Equals Builder for c#</title>
		<link>http://www.christopherbird.co.uk/2009/10/equalsbuilder-for-csharp/</link>
		<comments>http://www.christopherbird.co.uk/2009/10/equalsbuilder-for-csharp/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 14:16:58 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=18</guid>
		<description><![CDATA[I recently did a direct port of the java EqualsBuilder into c#. After some experimenting i&#8217;ve created a new version for c# that takes advantage of some of language features that java doesn&#8217;t have. Usage EqualityCheck.Of&#40; &#160; stringA.And&#40;stringB&#41;, &#160; intA.And&#40;intB&#41;, &#160; decimalA.And&#40;decimalB&#41;, &#160; objectA.AndPropertiesOf&#40;objectB&#41;&#41; Code is available for download from here. Download]]></description>
			<content:encoded><![CDATA[<p>I recently did a direct port of the java <a href="http://commons.apache.org/lang/api/org/apache/commons/lang/builder/EqualsBuilder.html">EqualsBuilder</a> into c#. After some experimenting i&#8217;ve created a new version for c# that takes advantage of some of language features that java doesn&#8217;t have.</p>
<p><strong>Usage</strong></p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">EqualityCheck<span style="color: #008000;">.</span><span style="color: #0000FF;">Of</span><span style="color: #008000;">&#40;</span><br />
&nbsp; stringA<span style="color: #008000;">.</span><span style="color: #0000FF;">And</span><span style="color: #008000;">&#40;</span>stringB<span style="color: #008000;">&#41;</span>, <br />
&nbsp; intA<span style="color: #008000;">.</span><span style="color: #0000FF;">And</span><span style="color: #008000;">&#40;</span>intB<span style="color: #008000;">&#41;</span>, <br />
&nbsp; decimalA<span style="color: #008000;">.</span><span style="color: #0000FF;">And</span><span style="color: #008000;">&#40;</span>decimalB<span style="color: #008000;">&#41;</span>, <br />
&nbsp; objectA<span style="color: #008000;">.</span><span style="color: #0000FF;">AndPropertiesOf</span><span style="color: #008000;">&#40;</span>objectB<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span></div></div>
<p>Code is available for download from here. <a href='http://www.christopherbird.co.uk/wp-content/uploads/2009/10/Tau.zip'>Download</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/10/equalsbuilder-for-csharp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Simple alternative to enums in C#</title>
		<link>http://www.christopherbird.co.uk/2009/10/simple-alternative-to-enums-in-c/</link>
		<comments>http://www.christopherbird.co.uk/2009/10/simple-alternative-to-enums-in-c/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 13:06:13 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Software Development]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://www.christopherbird.co.uk/?p=6</guid>
		<description><![CDATA[I&#8217;ve seen quite a few solutions for extending enum&#8217;s in c#, some of them quite complicated. One of the more common is adding additional attributes to store more information. The solution i prefer for this is not to use enum&#8217;s at all, e.g. public class Title &#123; &#160; public static readonly Title Mr = new [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen quite a few solutions for extending enum&#8217;s in c#, some of them quite complicated. One of the more common is adding additional attributes to store more information. The solution i prefer for this is not to use enum&#8217;s at all, e.g.</p>
<div class="codecolorer-container csharp vibrant" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> Title <span style="color: #008000;">&#123;</span><br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Title Mr <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Title<span style="color: #008000;">&#40;</span>Gender<span style="color: #008000;">.</span><span style="color: #0000FF;">Male</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Title Master <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Title<span style="color: #008000;">&#40;</span>Gender<span style="color: #008000;">.</span><span style="color: #0000FF;">Male</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Title Miss <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Title<span style="color: #008000;">&#40;</span>Gender<span style="color: #008000;">.</span><span style="color: #0000FF;">Female</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #0600FF; font-weight: bold;">readonly</span> Title Mrs <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> Title<span style="color: #008000;">&#40;</span>Gender<span style="color: #008000;">.</span><span style="color: #0000FF;">Female</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">public</span> Gender Gender <span style="color: #008000;">&#123;</span> get<span style="color: #008000;">;</span> <span style="color: #0600FF; font-weight: bold;">private</span> set<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span><br />
<br />
&nbsp; <span style="color: #0600FF; font-weight: bold;">private</span> Title<span style="color: #008000;">&#40;</span>Gender gender<span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Gender <span style="color: #008000;">=</span> gender<span style="color: #008000;">;</span><br />
&nbsp; <span style="color: #008000;">&#125;</span><br />
<span style="color: #008000;">&#125;</span></div></div>
<p>One another bonus is it avoids temptation of using switches to perform different functionality on each item of an enum. Instead it forces you to separate functionality using patterns like chain of responsibility.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.christopherbird.co.uk/2009/10/simple-alternative-to-enums-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
