<?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>Shaun Smith &#187; Code</title>
	<atom:link href="http://shaun.boyblack.co.za/blog/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://shaun.boyblack.co.za/blog</link>
	<description>Flex, Ruby, Mongo - London, UK</description>
	<lastBuildDate>Sat, 04 Feb 2012 17:39:55 +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>Readme</title>
		<link>http://shaun.boyblack.co.za/blog/2012/02/04/readme/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/02/04/readme/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 17:04:25 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Resources]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[readme]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1069</guid>
		<description><![CDATA[Have I mentioned that I love GitHub? When you put a readme file into a folder that file is formatted and presented nicely through GitHub&#8217;s file browser. For example: https://github.com/visionmedia/uikit Scrolling down a little we can see a nicely formatted readme file. GitHub strongly recommends adding a readme file to the root of your repository, but what I didn&#8217;t realise until recently was that it works for any folder in your repo. GitHub already has the best online file browser &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/02/04/readme/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Have I mentioned that I love <a href="https://github.com/">GitHub</a>?</p>
<p>When you put a readme file into a folder that file is formatted and presented nicely through GitHub&#8217;s file browser. For example:</p>
<p><a href="https://github.com/visionmedia/uikit">https://github.com/visionmedia/uikit</a></p>
<p>Scrolling down a little we can see a nicely formatted readme file.<span id="more-1069"></span></p>
<p>GitHub strongly recommends adding a readme file to the root of your repository, but what I didn&#8217;t realise until recently was that it works for any folder in your repo. GitHub already has the best online file browser out there, but this specific feature can turn your source tree into your documentation.</p>
<p>For <a href="https://github.com/robotlegs/robotlegs-framework">Robotlegs 2</a> I decided to try it out:</p>
<p><a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/core/async">Async</a><br />
<a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/core/messaging">MessageDispatcher</a><br />
<a href="https://github.com/darscan/robotlegs-framework/tree/version2/src/robotlegs/bender/extensions">Extensions</a></p>
<p>Almost every package in the entire repo has a readme file. The best way to learn about Robotlegs 2 is to browse the <a href="https://github.com/robotlegs/robotlegs-framework">source and readme files</a> on GitHub.</p>
<p><img class="alignnone size-full wp-image-1075" title="github-logo" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2012/02/github-logo.png" alt="" width="512" height="512" /></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/02/04/readme/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>RL Reloaded</title>
		<link>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 12:03:13 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[framework]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1023</guid>
		<description><![CDATA[I&#8217;ve been worried for quite a long time. Robotlegs 1 is small and simple but a little difficult to extend. I want Robotlegs 2 to be flexible without becoming overly large or complex. Timing To extend any framework you need to be able to hook into that framework&#8217;s initialization process. That Damned Context The Robotlegs 1 context class was, to be frank, rubbish &#8211; it set defaults, configured dependencies and controlled initialization. Worse, to hook into the initialization process or &#8230; <a href="http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been worried for quite a long time. <a href="http://www.robotlegs.org/">Robotlegs 1</a> is small and simple but a little difficult to extend. I want <a href="https://github.com/robotlegs/robotlegs-framework">Robotlegs 2</a> to be flexible without becoming overly large or complex.</p>
<h2>Timing</h2>
<p>To extend any framework you need to be able to hook into that framework&#8217;s initialization process.</p>
<h2>That Damned Context</h2>
<p>The Robotlegs 1 context class was, to be frank, rubbish &#8211; it set defaults, configured dependencies and controlled initialization. Worse, to hook into the initialization process or change the defaults, users had to extend the class itself resulting in the proliferation of funny looking words like SignalDrivenCovariantlyMediatedModularShellContext.<span id="more-1023"></span></p>
<h2>How Could You Let That Happen?</h2>
<p>Extending the context was a silly idea &#8211; and I knew it at the time. It made me sad, deep down inside, but I knew that if I waited for a better solution to emerge the framework might never ship.</p>
<p>Also, my goals for Robotlegs 1 were:</p>
<p>1. Make it small<br />
2. Make it fast<br />
3. Release it</p>
<p>A ton of compromises were made to keep the number of classes down to an absolute minimum. That&#8217;s not how I usually write code. Besides&#8230;</p>
<h2>Small Only Goes So Far</h2>
<p>I always start by doing the simplest thing possible &#8211; it&#8217;s a good way to feel out a problem space. &#8220;<strong>What</strong> am I trying to do?&#8221;. The &#8220;<strong>how</strong>&#8221; doesn&#8217;t matter yet, but becomes important much later when I ask &#8220;How would I <strong>like</strong> to do this?&#8221;.</p>
<p>When writing actual code, however, I&#8217;m constantly faced with this annoying question: &#8220;Should I break this out?&#8221;. When doing the simplest thing possible I often decide against extraction: I&#8217;ve got a specific task to complete (like getting a test to pass) and I can refactor later if the idea proves itself to be worthwhile. Also, I know that extraction inevitably leads to a new set of design decisions. And I&#8217;ll have to start with a test &#8211; for something whose purpose I am only just discovering. And it ups the class count.</p>
<p>Keeping class count down for it&#8217;s own sake is almost always a bad idea. However, I don&#8217;t think Robotlegs 1 would have experienced the same adoption if it had had hundreds of classes instead of the quite digestible 15 presently in its belly. OK, 24 total if you add the interfaces.</p>
<p>When browsing open source libraries I get happy feelings from projects with a limited number of source files &#8211; it gives me a sense that if I really wanted to I could read through the entire codebase and understand it.</p>
<p>But there&#8217;s a point where that simplicity inverts. Profit becomes debt. Without good abstractions in place every participant in the system ends up doing too much. At that point the question becomes: &#8220;Do I need to introduce a new layer of abstraction?&#8221;.</p>
<h2>Now You Have Two Problems</h2>
<p>The introduction of a system wide abstraction layer fueled by a mid feature code extraction will do one of two things: it will strengthen the system or it will weaken it. A bad abstraction might solve the immediate design issues (like duplication) just fine but end up adding complexity and reducing quality overall.</p>
<h2>Extensions? Timing?</h2>
<p>So anyway, I want Robotlegs to be extensible in a sensible way. Users should be able to install custom extensions easily. Those extensions need a way to hook into the context initialization process:</p>
<p>Some extensions may need to be configured before others. Some may need to pause the initialization process and wait for a resource to become available. Some might directly depend on others and may need to wait for those extensions to be fully configured before self initializing. Some may only come to life after the entire context has been initialized.</p>
<p>It&#8217;s clear that the initialization process needs to be asynchronous. But without a good abstraction in place for dealing with asynchronous processing the context will be burdened with co-ordinating a complex series of events. Event soup is not delicious.</p>
<h2>Events, Signals, Tokens, Tasks, Promises, Futures, Callbacks</h2>
<p>There are a number of patterns for dealing with asynchronous processes. They have wildly different properties.</p>
<p>Some are low level, like the callback pattern. Some are high level, like the promise pattern. Some are guaranteed to be asynchronous, while others have the potential to be synchronous. Some are only good for observing. Some can be terminated, while others can be suspended and resumed. Some can be composed and chained. Some necessitate the instantiation of throw-away objects and put stress on the garbage collector. Some put stress on the stack.</p>
<h2>Take Your Pick</h2>
<p>I wanted something fairly low level that enabled asynchronous processing without adding unnecessary overhead in the cases where things could be synchronous (or skipped entirely).</p>
<p>I tried a number of things. For the most part: floppy, verbose and annoying implementations that moved the core problems around in less-than-useful ways.</p>
<h2>Dispatch</h2>
<p>Slowly it dawned on me. In this case all I wanted was an asynchronous message dispatcher. With a well defined set of callback conventions I could write something resembling an Event Dispatcher but without the overhead of creating throw-away objects (events) and with the ability to suspend and resume the dispatch when desired:</p>
<p><a title="Async Conventions" href="https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/core/async/readme.md">Some Async Conventions</a></p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/blob/version2/src/robotlegs/bender/core/messaging/readme.md">The Message Dispatcher</a></p>
<h2>Initialization, Extension, Please Continue</h2>
<p>Very well. Suppose that context initialization comprises 3 steps: preInitialize, selfInitialize and postInitialize. When told to initialize the context moves through those steps in sequence. Anyone can listen in and halt the process as required at any point. What we end up with is in essence just a simple state machine where the observers have the potential to be guards.</p>
<h2>The End</h2>
<p>Well, that&#8217;s where the re-write started anyway.</p>
<p><a href="https://github.com/robotlegs/robotlegs-framework/tree/version2/src">Robotlegs 2</a></p>
<p>p.s. I dropped a bunch of stuff from the version2 branch. I&#8217;ll be going back to pull out any functionality that might have been lost shortly. If you come across anything that&#8217;s missing feel free to adapt it to the new codebase and send a pull request. Or drop an issue on the tracker. For quick reference, here&#8217;s the old version2 branch: <a href="https://github.com/robotlegs/robotlegs-framework/tree/version2-old">version2-old</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/01/23/rl-reloaded/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Unit Testing: My problem with assertThat()</title>
		<link>http://shaun.boyblack.co.za/blog/2012/01/12/unit-testing-my-problem-with-assertthat/</link>
		<comments>http://shaun.boyblack.co.za/blog/2012/01/12/unit-testing-my-problem-with-assertthat/#comments</comments>
		<pubDate>Thu, 12 Jan 2012 02:35:00 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1017</guid>
		<description><![CDATA[I write &#8220;ass&#8221; a lot while I&#8217;m coding.]]></description>
			<content:encoded><![CDATA[<p>I write &#8220;ass&#8221; a lot while I&#8217;m coding.</p>
<p><img class="size-full wp-image-1018 alignleft" title="ass" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2012/01/ass.png" alt="" width="531" height="421" /></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2012/01/12/unit-testing-my-problem-with-assertthat/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Commit Messages</title>
		<link>http://shaun.boyblack.co.za/blog/2011/11/09/commit-messages/</link>
		<comments>http://shaun.boyblack.co.za/blog/2011/11/09/commit-messages/#comments</comments>
		<pubDate>Wed, 09 Nov 2011 18:29:56 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1009</guid>
		<description><![CDATA[When reviewing a commit I&#8217;m not interested in what you did. A commit is a codebase transformation. I&#8217;m interested in what will happen to my codebase when I apply your commit. Bad &#8220;I did this&#8221; form: I had a cup of coffee, went for a walk, and changed some code. &#160; Better &#8220;This commit does this&#8221; form: Adds unmap() to the command map API. A commit message should describe the commit, not the process you went through to create it &#8230; <a href="http://shaun.boyblack.co.za/blog/2011/11/09/commit-messages/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When reviewing a commit I&#8217;m not interested in what you did. A commit is a codebase transformation. I&#8217;m interested in what will happen to my codebase when I apply your commit.</p>
<h4>Bad &#8220;I did this&#8221; form:</h4>
<pre>I had a cup of coffee, went for a walk, and changed some code.</pre>
<p>&nbsp;</p>
<h4>Better &#8220;This commit does this&#8221; form:</h4>
<pre>Adds unmap() to the command map API.</pre>
<p>A commit message should describe the commit, not the process you went through to create it &#8211; it is not a diary.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2011/11/09/commit-messages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unit Testing: Why I prefer assertThat()</title>
		<link>http://shaun.boyblack.co.za/blog/2011/11/08/unit-testing-why-i-prefer-assertthat/</link>
		<comments>http://shaun.boyblack.co.za/blog/2011/11/08/unit-testing-why-i-prefer-assertthat/#comments</comments>
		<pubDate>Tue, 08 Nov 2011 17:57:41 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[unit-testing]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=1003</guid>
		<description><![CDATA[Consider: [Test] public function null_criteria_should_not_match():void { assertFalse("passing null should return false", instance.match(null)); } When reading the test above I have to do a lot of scanning. First I see the string message in the middle because it jumps out. The message is redundant as it&#8217;s included in the test name. If I change the test I&#8217;ll need to change both the method name and the string description. I can see that the string message would be useful for a test &#8230; <a href="http://shaun.boyblack.co.za/blog/2011/11/08/unit-testing-why-i-prefer-assertthat/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Consider:</p>
<pre>[Test]
public function null_criteria_should_not_match():void
{
  assertFalse("passing null should return false", instance.match(null));
}</pre>
<p>When reading the test above I have to do a lot of scanning.<span id="more-1003"></span></p>
<p>First I see the string message in the middle because it jumps out. The message is redundant as it&#8217;s included in the test name. If I change the test I&#8217;ll need to change both the method name and the string description. I can see that the string message would be useful for a test with multiple asserts, but that&#8217;s generally not a good idea.</p>
<p>After reading the string I look to the right to see what is being tested and mentally try to evaluate it.</p>
<p>Then I look to the left to see what the expectation is, possibly flipping the evaluation I just did to match the expectation.</p>
<p>It&#8217;s disconnected, and it&#8217;s hard work.</p>
<p>Consider this instead:</p>
<pre>[Test]
public function null_criteria_should_not_match():void
{
  assertThat(matcher.match(null), isFalse());
}</pre>
<p>Now I just read normally: top-to-bottom, left-to-right. I read the test name, look at what is being evaluated and see what is expected.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2011/11/08/unit-testing-why-i-prefer-assertthat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Show Me Your Tree!</title>
		<link>http://shaun.boyblack.co.za/blog/2011/08/16/show-me-your-tree/</link>
		<comments>http://shaun.boyblack.co.za/blog/2011/08/16/show-me-your-tree/#comments</comments>
		<pubDate>Tue, 16 Aug 2011 18:26:12 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Questions]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[display list]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=996</guid>
		<description><![CDATA[What does your display list look like? While doing some work on multi-context view auto-wiring I wrote a little utility that iterates through the containers in a given display object container and builds some useful stats. If you have a moment I would love it if you could run it against your Flex or Flash app and post the results in the comments. Please also indicate whether you ran it against a single complex component or an entire app, and &#8230; <a href="http://shaun.boyblack.co.za/blog/2011/08/16/show-me-your-tree/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>What does your display list look like?</p>
<p>While doing some work on multi-context view auto-wiring I wrote a little utility that iterates through the containers in a given display object container and builds some useful stats.<span id="more-996"></span></p>
<p>If you have a moment I would love it if you could run it against your Flex or Flash app and post the results in the comments. Please also indicate whether you ran it against a single complex component or an entire app, and whether it was Flash, Flex or Mobile.</p>
<p>GitHub: <a href="https://github.com/darscan/boyblack-toolkit">https://github.com/darscan/boyblack-toolkit</a></p>
<p>ZIP download: <a href="http://shaun.boyblack.co.za/blog/wp-content/uploads/2011/08/boyblack-toolkit.zip">boyblack-toolkit</a></p>
<p>Usage:</p>
<pre>trace(new DocStats(doc));</pre>
<p>Sample output:</p>
<pre>Display Object Container Stats

All Container Stats
Containers:             521 total
Children per container: 8 max, 1.16 avg
Depths (distance):      29 max, 18.45 avg
Unique container types: 86 total

Unfiltered Container Stats
Containers:             153 total
Children per container: 8 max, 1.69 avg
Depths (distance):      26 max, 16.98 avg
Unique container types: 65 total

Filtered (mx., spark., flash.) Container Stats
Containers:             368 total
Children per container: 8 max, 0.94 avg
Depths (distance):      29 max, 19.07 avg
Unique container types: 21 total</pre>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2011/08/16/show-me-your-tree/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Too Much Of A Good Thing</title>
		<link>http://shaun.boyblack.co.za/blog/2011/07/31/too-much-of-a-good-thing/</link>
		<comments>http://shaun.boyblack.co.za/blog/2011/07/31/too-much-of-a-good-thing/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 13:38:28 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[interfaces]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=981</guid>
		<description><![CDATA[As an enthusiastic programmer I tend to get overly excited when I discover a new technique &#8211; nails, nails everywhere for my shiny new hammer! It&#8217;s not a bad thing. I&#8217;ll abuse my newfound technique until I fully understand where it is and isn&#8217;t appropriate. Sometimes this takes a while.  Injection Everywhere Automated Dependency Injection is a handy way to wire the component parts of a system together. But systems are comprised of components at varying levels of abstraction. Some &#8230; <a href="http://shaun.boyblack.co.za/blog/2011/07/31/too-much-of-a-good-thing/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>As an enthusiastic programmer I tend to get overly excited when I discover a new technique &#8211; nails, nails everywhere for my shiny new hammer! It&#8217;s not a bad thing. I&#8217;ll abuse my newfound technique until I fully understand where it is and isn&#8217;t appropriate. Sometimes this takes a while. <span id="more-981"></span></p>
<h3>Injection Everywhere</h3>
<p>Automated Dependency Injection is a handy way to wire the component parts of a system together. But systems are comprised of components at varying levels of abstraction. Some are high-level, domain specific abstractions, whilst others are low-level implementation details.</p>
<p>If every object in a system is given the same level of importance, thrown into a DI container, and made available to every other object, the layers of abstraction become very hard to see. The container becomes a mixed bag of configuration details, value objects, sub-systems and goodness-knows-what-else.</p>
<p>Does a URL (a very specific, low-level configuration detail) really deserve to be sitting in a flat container right alongside a high-level, domain specific model? Certainly not!</p>
<p>It can be difficult to determine what is and what isn&#8217;t appropriate for automated Dependency Injection. It depends on the system you are building, and is something that comes with time and experience. I&#8217;m certainly still struggling with it on a daily basis.</p>
<p>Here&#8217;s a related post on the matter:</p>
<p><a href="http://www.higherorderlogic.com/blog/2011/07/30/is-dependency-injection-like-facebook/">http://www.higherorderlogic.com/blog/2011/07/30/is-dependency-injection-like-facebook/</a></p>
<h3>Interfaces Everywhere</h3>
<p>Program to interfaces, not implementations. Interfaces decouple us from implementations, they are good, but, as always, there are some subtleties worth considering.</p>
<p>Many languages support explicit interfaces: contracts with absolutely no implementation details. But every object also has an implicit interface &#8211; the public methods and properties exposed by that object.</p>
<p>Creating an explicit interface for an object that will only ever have a single implementation is a violation of the DRY principle as the explicit interface duplicates the implicit one.</p>
<p>This happens most often when the interface is large and acts as a &#8220;stand-in&#8221; describing a class rather than a piece of behaviour. Sure, you *could* swap out the implementation at some point, but honestly, so much of the implementation has already leaked out into the interface that there is very little point in doing so.</p>
<p>Program to interfaces, but remember that sometimes a small implicit interface is better than a large explicit one.</p>
<p>Another related post:</p>
<p><a href="http://lostechies.com/derickbailey/2008/10/20/dependency-inversion-abstraction-does-not-mean-interface/">http://lostechies.com/derickbailey/2008/10/20/dependency-inversion-abstraction-does-not-mean-interface/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2011/07/31/too-much-of-a-good-thing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Why Ruby Is Fun</title>
		<link>http://shaun.boyblack.co.za/blog/2010/08/24/why-ruby-is-fun/</link>
		<comments>http://shaun.boyblack.co.za/blog/2010/08/24/why-ruby-is-fun/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 01:14:55 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=953</guid>
		<description><![CDATA[Some little things I enjoy about Ruby:]]></description>
			<content:encoded><![CDATA[<p>Some little things I enjoy about <a href="http://www.ruby-lang.org/en/">Ruby</a>:<span id="more-953"></span></p>
<p><script src="http://gist.github.com/546533.js"> </script></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2010/08/24/why-ruby-is-fun/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Clean Code</title>
		<link>http://shaun.boyblack.co.za/blog/2010/08/02/clean-code/</link>
		<comments>http://shaun.boyblack.co.za/blog/2010/08/02/clean-code/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 16:06:42 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Inspiration]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=911</guid>
		<description><![CDATA[I recently purchased @unclebobmartin&#8216;s awesome book: Clean Code. What a book! I&#8217;m going to echo a sentiment that often ripples through the Twittersphere: If you are a programmer and you haven&#8217;t read Clean Code you are doing your fellow programmers (and yourself) a great disservice. Seriously. For fun I decided to dig up the worst code I have ever written &#8211; quite a challenge considering how much terrible code I have produced in my life! Have a look at this &#8230; <a href="http://shaun.boyblack.co.za/blog/2010/08/02/clean-code/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I recently purchased <a title="Uncle Bob on Twitter" href="http://twitter.com/unclebobmartin">@unclebobmartin</a>&#8216;s awesome book: <a title="Clean Code on Amazon" href="http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882">Clean Code</a>. What a book! I&#8217;m going to echo a sentiment that often ripples through the Twittersphere: If you are a programmer and you haven&#8217;t read Clean Code you are doing your fellow programmers (and yourself) a great disservice. Seriously.<br />
<span id="more-911"></span><br />
For fun I decided to dig up the worst code I have ever written &#8211; quite a challenge considering how much terrible code I have produced in my life! Have a look at this beauty:</p>
<p><script src="http://gist.github.com/504823.js"></script></p>
<p>Stupid names, useless comments, multiple levels of abstraction, poor error handling, super deep nesting, etc etc etc. It pretty much breaks every rule in the book. <strong>But the best bit has to be this</strong>:</p>
<div class="codecolorer-container php default" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$rows_to_populate</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$foreign_table</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$foreign_id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$module_name</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$db_row</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">id</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$field_name</span><span style="color: #339933;">;</span></div></div>
<p>Yes, that&#8217;s right, <strong>a five dimensional array!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2010/08/02/clean-code/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Another Architectural Framework, But Why?</title>
		<link>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/</link>
		<comments>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/#comments</comments>
		<pubDate>Wed, 29 Apr 2009 14:47:15 +0000</pubDate>
		<dc:creator>shaun</dc:creator>
				<category><![CDATA[Banter]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Robotlegs]]></category>
		<category><![CDATA[actionscript]]></category>
		<category><![CDATA[architecture]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[crybaby]]></category>
		<category><![CDATA[dependency injection]]></category>
		<category><![CDATA[flash]]></category>
		<category><![CDATA[flex]]></category>
		<category><![CDATA[smartypants-ioc]]></category>

		<guid isPermaLink="false">http://shaun.boyblack.co.za/blog/?p=406</guid>
		<description><![CDATA[The State Of The Game There are some great Flash and Flex application frameworks out there right now. Mate, Swiz and PureMVC (update: and Parsley!) stand out. The authors of these frameworks realized that the Flash Platform is different enough to the JVM to warrant a fresh approach to application design. Someone mentioned recently that for such a young language (referring to Action Script 3), it&#8217;s quite surprising how many frameworks have sprung up around it. I&#8217;m not surprised at &#8230; <a href="http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-458" title="robotlegssketchsmall" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/robotlegssketchsmall.gif" alt="robotlegssketchsmall" width="221" height="260" /></p>
<h2>The State Of The Game</h2>
<p>There are some great Flash and Flex application frameworks out there right now. <a title="Mate Flex Framework" href="http://mate.asfusion.com/">Mate</a>, <a title="The Swiz Framework" href="http://code.google.com/p/swizframework/">Swiz</a> and <a title="PureMVC Flash and Flex Framework" href="http://puremvc.org/">PureMVC</a> (update: and <a title="Parsley" href="http://www.spicefactory.org/parsley/">Parsley</a>!) stand out. The authors of these frameworks realized that the Flash Platform is different enough to the <a title="The Java Virtual Machine" href="http://en.wikipedia.org/wiki/Java_Virtual_Machine">JVM</a> to warrant a fresh approach to application design.</p>
<p><span id="more-406"></span>Someone mentioned recently that for such a young language (referring to Action Script 3), it&#8217;s quite surprising how many frameworks have sprung up around it. I&#8217;m not surprised at all: rich internet application development is complicated.. and it&#8217;s a pretty recent field in the grand scheme of things. It brings new (and often subtle) twists to traditional web and desktop software development. Writing elegant, maintainable code is hard enough as it is, but doing so on a rapidly evolving, heavily interactive platform.. well, people are still working on the best way to approach that (unless I missed the big news &#8211; in which case you can stop reading right here).</p>
<p>Hence all the groovy new architectural frameworks popping up. They share some common goals:</p>
<ol>
<li>Help developers write good, clean, understandable, testable, maintainable code</li>
<li>Help them write that code faster</li>
<li>Provide an easy-to-use mechanism for application/context/module subsystem inter-communication</li>
<li>Provide an easy-to-use mechanism for wiring distinct parts of the application together whilst keeping those parts loosely coupled</li>
</ol>
<p>And they succeed. To various degrees. I think they&#8217;re all pretty cool.</p>
<p><img class="alignnone size-full wp-image-439" title="scenery" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/scenery.gif" alt="scenery" width="450" height="370" /></p>
<h2>A Poke In The Back With A Sharp Stick</h2>
<h3>So why build another one?</h3>
<ol>
<li>For fun &#8211; it&#8217;s how I learn stuff</li>
<li>Because I find the other frameworks critically flawed</li>
</ol>
<h3>What kind of &#8220;critical&#8221; flaws?</h3>
<ol>
<li>Singletons (big &#8220;S&#8221;)</li>
<li>Central/Static Event Dispatchers</li>
<li>Using the Display List as an Application Event Bus</li>
<li>Casting</li>
<li>The Service/Model Locator Pattern</li>
<li>The Presenter Pattern</li>
<li>Injecting into View Components</li>
</ol>
<h3>And what&#8217;s wrong with those things?</h3>
<p>They are bad ideas:</p>
<h4>1. The Singleton &#8211; Bad Idea</h4>
<p>The standard <a href="http://misko.hevery.com/2008/08/17/singletons-are-pathological-liars/">Singleton</a> <a href="http://misko.hevery.com/2008/08/21/where-have-all-the-singletons-gone/">implementation</a> (that static getInstance method) <a href="http://misko.hevery.com/2008/08/25/root-cause-of-singletons/">is</a> <a href="http://tech.puredanger.com/2007/07/03/pattern-hate-singleton/">severely</a> <a href="http://c2.com/cgi/wiki?SingletonsAreEvil">flawed</a>. Unless you are writing device drivers, there is almost no excuse to touch a Singleton with a sharp stick.</p>
<p>Singletons bring bags of hurt to frameworks and applications.. suddenly, trying to build a modular application becomes an overly complicated affair, and unit testing becomes a nightmare. Singletons are viruses &#8211; they infect every class they touch.</p>
<p>And Multitons? If Singletons are evil, Multitons are diabolically evil. What makes the Multiton pattern incredible is that it manages to chump the Singleton as the worst Design Pattern Of All Time &#8211; no easy feat, and certainly the work of an evil genius with a wicked sense of humour. Not only do we have all the problems of the classic Singleton, we throw a poorly designed Model Locator into the mix &#8211; to pull out these horrendous Singletons we now need to use String keys.</p>
<p>Contextual singletons (as made possible by Dependency Injection frameworks) are a much nicer solution, they don&#8217;t require any extra (fluffy, nonsense, ill placed) code on the target classes themselves, and they allow identical applications/modules to exist side-by-side in the Virtual Machine without fighting and mass confusion. Which leads me to..</p>
<h4>2. Central/Static Event Dispatchers &#8211; Bad Idea</h4>
<p>As convenient as it is to use, a Central Dispatcher is a really bad idea. Another Singleton effectively. Pop two apps into the same SWF and watch, with excitement and glee, all the cross-talk that occurs &#8211; both apps responding to each other&#8217;s events. Oh noes!</p>
<p>Architectural frameworks generally provide you with an application event bus/channel/dispatcher to &#8220;chat&#8221; on, but this should be localised to the application itself (or some other context). Which leads me to&#8230;</p>
<h4>3. Using the Display List as an Application Event Bus &#8211; Bad Idea</h4>
<p>I find this one fairly disturbing too: dispatching system/application events along the display list. No!</p>
<p>A View is just that: &#8220;<strong>A</strong> view&#8221;, not &#8220;<strong>The</strong> view&#8221;. And don&#8217;t get me started on those innocent looking Event Maps! No, let&#8217;s move along&#8230;</p>
<h4>4. Casting &#8211; Bad Idea</h4>
<p>Besides wasting space and annoying programmers, casting distributes knowledge throughout a system &#8211; casting requires that you look elsewhere in your codebase for the &#8220;real&#8221; type.</p>
<p>And it weakens our lovely compile-time type checking (albeit temporarily), sending us back in time to our unhappy days building complex applications in the Flash IDE. And it&#8217;s boring. And it often occurs because of..</p>
<h4>5. The Service/Model Locator Pattern &#8211; Bad Idea</h4>
<p>Classes should not be responsible for &#8220;fetching&#8221; their dependencies &#8211; this is a separate responsibility that belongs somewhere else entirely &#8211; they should only contain code for doing their job. When classes reach outside to fetch things from the application/context they sneakily hide their dependencies away from the outside world.</p>
<p>Unit testers will despise you (which is a serious problem if you are writing your own tests) because it becomes incredibly hard to figure out how much set up needs to be done to write even the smallest of tests. You have to look inside the class for any calls to the Service Locator to find your direct dependencies, and then you have to look inside each of those classes to find theirs and so on. No no, that&#8217;s just cruel.</p>
<h4>6. The Presenter Pattern &#8211; Bad Idea</h4>
<p>Ok, it&#8217;s going to be tricky to back this one up. But think about it this way: the Presenter pattern requires that you modify your View component (to add a reference to a Presenter). Not a biggie, but once you&#8217;ve done that you&#8217;ve started coupling your View component to your application/context &#8211; a slippery slope.</p>
<p>I think the Mediator pattern is a much better fit for Flash and it&#8217;s Display List, and even more-so when it comes to Flex (and other UI frameworks with complex component life cycles).</p>
<p>It is far easier and cleaner to &#8220;wrap&#8221; around view components and poke their APIs than to have to modify (extend) them to make space for their Presenter references. Leave those components alone, leave them to the component developers, you&#8217;re supposed to be writing an application. While we&#8217;re on the Presenter pattern, let&#8217;s take a look at something dirty one might do in an attempt to salvage it&#8217;s reputation..</p>
<h4>7. Injecting into View Components &#8211; Bad Idea</h4>
<p>Besides being incredibly slow and wasteful (especially for Flex UIComponents), injecting directly into a View component couples it to your application/context.</p>
<p>View components, with any hope for reuse, should be as self-contained as possible. They should expose an API and dispatch Events. They shouldn&#8217;t be dependent on the application they are in or the framework it happens to be using. Give &#8216;em ViewModels (M-V-VM) if you must, but don&#8217;t go and couple those ViewModels to your application, and certainly don&#8217;t inject them.</p>
<p><img class="alignnone size-full wp-image-467" title="ducksaysyuk1" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/ducksaysyuk1.gif" alt="ducksaysyuk1" width="450" height="632" /></p>
<h2>Wrapping Up This Micro-Post</h2>
<h4>Well that&#8217;s just your opinion, dude</h4>
<p>Yeh, but I&#8217;m pretty proud of my little 7 point list there (cos I&#8217;m an OOP noob, and this stuff gets me amped). Using Dependency Injection I was able to avoid all those nasty things when building my own PureMVC-like framework.</p>
<h4>But that just shifts the problem somewhere else</h4>
<p>Yes, somewhere more appropriate.</p>
<p>Besides some convenient implementations (in the mvcs package), and some marker interfaces (in the core package) <a title="RobotLegs AS3 - DI Driven MVCS Framework for Flash and Flex" href="http://shaun.boyblack.co.za/blog/2009/04/16/robotlegs-an-as3-mvcs-framework-for-flash-and-flex-applications-inspired-by-puremvc/">RobotLegs</a> essentially provides two things:</p>
<ol>
<li>A Command Factory &#8211; for binding Commands to Events, and</li>
<li>A Mediator Factory &#8211; for handling automatic Mediator creation and registration</li>
</ol>
<p>Everything else is handled by a Dependency Injection framework and an Event Dispatcher.</p>
<p><img class="alignnone size-full wp-image-459" title="theendissmall" src="http://shaun.boyblack.co.za/blog/wp-content/uploads/2009/04/theendissmall.gif" alt="theendissmall" width="225" height="152" /></p>
<p><strong>Note</strong>: If you&#8217;ve been through all this before, I apologise, it&#8217;s new to me.. I&#8217;m a little slow.</p>
<p><strong>Beware</strong>: the current default implementation of <a title="RobotLegs AS3" href="http://shaun.boyblack.co.za/blog/robotlegs-as3/">RobotLegs</a> makes use of annotated setter injection. This breaks encapsulation, is open to misuse, and runs the risk of leaving objects in partially initialised states, but it&#8217;s very convenient! You can swap out SmartyPants-IOC for a Dependency Injection framework that performs constructor injection if you really want to play it safe.</p>
<p><strong>I&#8217;ll admit straight-up</strong> (albeit as a footnote) that I never really gave Cairngorm much of a chance &#8211; preliminary research led me to demos, documentation and diagrams that screamed poor design and foreshadowed immense struggle. I&#8217;m sure there is a way to build a well designed Cairngorm application, but it looks like it&#8217;d take an awful amount of effort.. and code. And it probably wouldn&#8217;t be very much fun.</p>
<p><strong>UPDATE</strong>: Removed some words that made me sound like a douche bag.</p>
]]></content:encoded>
			<wfw:commentRss>http://shaun.boyblack.co.za/blog/2009/04/29/another-architectural-framework-but-why/feed/</wfw:commentRss>
		<slash:comments>39</slash:comments>
		</item>
	</channel>
</rss>

