<?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>Crafting software&#187; Javascript</title>
	<atom:link href="http://davidlaing.com/category/platforms/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidlaing.com</link>
	<description>David Laing&#039;s thoughts on software development</description>
	<lastBuildDate>Wed, 01 Feb 2012 11:02:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Functional programming in Javascript and F#</title>
		<link>http://davidlaing.com/2011/06/19/functional-programming-in-javascript-and-f/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=functional-programming-in-javascript-and-f</link>
		<comments>http://davidlaing.com/2011/06/19/functional-programming-in-javascript-and-f/#comments</comments>
		<pubDate>Sun, 19 Jun 2011 09:39:00 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Conferences]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=295</guid>
		<description><![CDATA[During June 2011 I presented a session at the SPA2011 conference in London, UK. My session was a hands on introduction to functional programming techniques with code samples in Javascript and F#. The focus on the session was to get peopling thinking about first class functions; and the techniques they enable to simplify and increase [...]]]></description>
			<content:encoded><![CDATA[<p>During June 2011 I presented a session at the <a href="http://www.spaconference.org/spa2011/index.php?page=programme">SPA2011</a> conference in London, UK. </p>
<p>My session was a hands on introduction to functional programming techniques with code samples in Javascript and F#.  The focus on the session was to get peopling thinking about first class functions; and the techniques they enable to simplify and increase readability of code when solving certain classes of problems.</p>
<p>The code samples can be found at:</p>
<ul>
<li>Javascript &#8211; <a href="https://github.com/mrdavidlaing/functional-javascript">https://github.com/mrdavidlaing/functional-javascript</a> </li>
<li>F# &#8211;  <a href="https://github.com/mrdavidlaing/functional-fsharp">https://github.com/mrdavidlaing/functional-fsharp</a></li>
</ul>
<p>An online/executable version of the Javascript code is at <a href="http://functional-javascript.davidlaing.com">http://functional-javascript.davidlaing.com</a>.</p>
<p>Judging by the feedback I received, the session went very well.  People seemed to like the hands-on format of the session; and just being left alone for a while to learn something at their own pace.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2011/06/19/functional-programming-in-javascript-and-f/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing the strategy pattern without an explosion of classes &#8211; part 3 of ??</title>
		<link>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of</link>
		<comments>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/#comments</comments>
		<pubDate>Sat, 16 Apr 2011 21:51:25 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[Code smells]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Refactoring]]></category>

		<guid isPermaLink="false">http://davidlaing.radweb.co.za/?p=272</guid>
		<description><![CDATA[I feel uncomfortable when I see large switch statements. I appreciate how they break the Open Closed Principle. I have enough experience to know that they seem to attract extra conditions &#38; additional logic during maintenance, and quickly become bug hotspots. A refactoring I use frequently to deal with this is Replace Conditional with Polymorphism; [...]]]></description>
			<content:encoded><![CDATA[<p>I feel uncomfortable when I see large switch statements.  I appreciate how they break the <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principle</a>.  I have enough experience to know that they seem to attract extra conditions &amp; additional logic during maintenance, and quickly become bug hotspots.</p>
<p>A refactoring I use frequently to deal with this is <a href="http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html">Replace Conditional with Polymorphism</a>; but for simple switches, its always seemed like a rather large hammer.</p>
<p>Take the following simple example that performs slightly different processing logic based on the credit card type:</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-switch.js"></script> Its highly likely that the number of credit card types will increase; and that the complexity of processing logic for each will also increase over time.  The traditional application of the <a href="http://www.refactoring.com/catalog/replaceConditionalWithPolymorphism.html">Replace Conditional with Polymorphism</a> refactoring gives the following:  </p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-strategy.js"></script></p>
<p>This explosion of classes containing almost zero logic has always bothered me as quite a lot of boilerplate overhead for a relatively small reduction in complexity.</p>
<p>Consider however, the functional approach to the same refactoring:</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-simple-functional.js"></script> </p>
<p>Here we have obtained the same simplification of the switch statement; but avoided the explosion of simple classes.  Whilst strictly speaking we are still violating the  <a href="http://en.wikipedia.org/wiki/Open/closed_principle">Open Closed Principle</a>; we do have a collection of simple methods that are easy to comprehend and test.  It&#8217;s worth noting that when our logic becomes very complex; converting to the OO Strategy pattern becomes a more compelling option.  Consider the case when we include a collection of validation logic for each credit card:  <script src="https://gist.github.com/923516.js?file=CreditCard-complex-functional.js"></script></p>
<p>In this case the whole file starts to feel too complex to me; and having the logic partitioned into separate strategy classes / files seems more maintainable to me.</p>
<p><script src="https://gist.github.com/923516.js?file=CreditCard-complex-strategy.js"></script></p>
<p>To conclude then, the fact that languages treat functions as first class constructs, gives us the flexibility to use them in a &#8220;polymorphic&#8221; way; where our &#8220;interface&#8221; is the function signature.  </p>
<p>And for some problems, like a refactoring a simple switch statement; I feel this gives us a more elegant solution.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2011/04/16/implementing-the-strategy-pattern-without-an-explosion-of-classes-part-3-of/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Learning functional Javascript through Koans</title>
		<link>http://davidlaing.com/2010/07/19/learning-functional-javascript-through-koans/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=learning-functional-javascript-through-koans</link>
		<comments>http://davidlaing.com/2010/07/19/learning-functional-javascript-through-koans/#comments</comments>
		<pubDate>Sun, 18 Jul 2010 23:37:39 +0000</pubDate>
		<dc:creator>mrdavidlaing</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Software Craftmanship]]></category>
		<category><![CDATA[koans; javascript; functional]]></category>

		<guid isPermaLink="false">http://davidlaing.com/?p=236</guid>
		<description><![CDATA[Given how Javascript interpreters are improving in leaps and bounds; and that it seems to be the only language that will be supported by all web devices; its time to for me to revive my Javascript skilz. Fortunately the tooling has improved greatly; Eclipse 3.6 for Web Developers and JsTestDriver bring a refactoring and a [...]]]></description>
			<content:encoded><![CDATA[<p>Given how Javascript interpreters are improving in leaps and bounds; and that it seems to be the only language that will be supported by all web devices; its time to for me to revive my Javascript skilz.  Fortunately the tooling has improved greatly; Eclipse 3.6 for Web Developers and JsTestDriver bring a refactoring and a unit test runner to Javascript development.</p>
<p>Interestingly, Javascript seems to have more functional than object orientated characteristics; so it seems reasonable to learn it wearing my functional hat.</p>
<p>I&#8217;ve been enjoying learning Ruby syntax via <a href="http://github.com/edgecase/ruby_koans">RubyKoans &#8211; little tests that teach you syntax and convention as you make them pass</a></p>
<p>I though I&#8217;d create a similar set of <a href="https://github.com/mrdavidlaing/javascript-koans">Functional Javascript Koans</a> to help refresh my Javascript skills.</p>
<p>Its a bit rough; so please fork and contibute back improvements.<br />
<a href="https://github.com/mrdavidlaing/javascript-koans">https://github.com/mrdavidlaing/javascript-koans</a></p>
<p><object width="490" height="310"><param name="movie" value="http://www.youtube.com/v/qAoWxXPLB0Q&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/qAoWxXPLB0Q&amp;hl=en_US&amp;fs=1?rel=0&amp;color1=0x3a3a3a&amp;color2=0x999999&amp;border=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="490" height="310"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://davidlaing.com/2010/07/19/learning-functional-javascript-through-koans/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

