<?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>Lab49 Blog &#187; Lab49</title>
	<atom:link href="http://blog.lab49.com/archives/category/lab49/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.lab49.com</link>
	<description>Technology and industry insights from Lab49.</description>
	<lastBuildDate>Wed, 08 Feb 2012 09:02:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Sharing in RX: Publish, Replay, and Multicast</title>
		<link>http://northhorizon.net/2011/sharing-in-rx/</link>
		<comments>http://northhorizon.net/2011/sharing-in-rx/#comments</comments>
		<pubDate>Fri, 11 Nov 2011 03:54:38 +0000</pubDate>
		<dc:creator>Daniel Moore</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://northhorizon.net/?p=482</guid>
		<description><![CDATA[State is a tricky thing in RX, especially when we have more than one subscriber to a stream. Consider a fairly innocuous setup: var interval = Observable.Interval(TimeSpan.FromMilliseconds(500)); interval.Subscribe(i =&#62; Console.WriteLine("First: {0}", i)); interval.Subscribe(i =&#62; Console.WriteLine("Second: {0}", i)); At first glance it might look like I&#8217;m setting up two listeners to a single interval pulse, but [...]]]></description>
			<content:encoded><![CDATA[<p>State is a tricky thing in RX, especially when we have more than one subscriber to a stream. Consider a fairly innocuous setup:</p>
<pre class="brush:csharp">var interval = Observable.Interval(TimeSpan.FromMilliseconds(500)); interval.Subscribe(i => Console.WriteLine("First: {0}", i)); interval.Subscribe(i => Console.WriteLine("Second: {0}", i));</pre>
<p>At first glance it might look like I&#8217;m setting up two listeners to a single interval pulse, but what&#8217;s actually happening is that each time I call <code>Subscribe</code>, I&#8217;ve created a new timer to tick values. Imagine how bad this could be if instead of an interval I was, say, sending a message across the network and waiting for a response. <span id="more-482"></span></p>
<p>There are a few ways to solve this problem, but only one of them is actually correct. The first thing most people latch on to in Intellisense is <code>Publish()</code>. Now <i>that</i> method looks useful. So I might try:</p>
<pre class="brush:csharp">var interval = Observable.Interval(TimeSpan.FromMilliseconds(500)).Publish(); interval.Subscribe(i => Console.WriteLine("First: {0}", i)); interval.Subscribe(i => Console.WriteLine("Second: {0}", i));</pre>
<p>Now I get nothing at all. Great advertising there.</p>
<p>So what is actually happening here? Well, for one you might notice that <code>interval</code> is no longer <code>IObservable&lt;long&gt;</code> but is now an <code>IConnectableObservable&lt;long&gt;</code>, which extends <code>IObservable</code> with a single method: <code>IDisposable Connect()</code>.</p>
<p>As it turns out, <code>Publish</code> is simply a convenience method for <code>Multicast</code> that supplies the parameter for you. Specifically, calling <code>stream.Publish()</code> is exactly the same as calling <code>stream.Multicast(new Subject&lt;T&gt;())</code>. Wait, a subject?</p>
<p>What <code>Multicast</code> does is create a concrete implementation of <code>IConnectableObservable&lt;T&gt;</code> to wrap the subject we give it and forwards the <code>Subscribe</code> method of the <code>IConnectableObservable&lt;T&gt;</code> to <code>Subject&lt;T&gt;.Subscribe</code>, so it looks something like this:</p>
<p><img src="http://northhorizon.net/wp-content/uploads/2011/11/before-connect.png" alt="" title="Before Connecting" width="375" height="106" class="aligncenter size-full wp-image-485" /></p>
<p>You might have noticed that the input doesn&#8217;t go anywhere. That&#8217;s exactly why our simple call to <code>Publish()</code> earlier didn&#8217;t produce any results at all &#8211; <code>IConnectableObservable&lt;T&gt;</code> hadn&#8217;t been fully wired up yet. To do that, we need to make a call to <code>Connect()</code>, which will subscribe our input into our subject.</p>
<p><img src="http://northhorizon.net/wp-content/uploads/2011/11/connect.png" alt="" title="Connect" width="375" height="163" class="aligncenter size-full wp-image-486" /></p>
<p><code>Connect()</code> returns to us an <code>IDisposable</code> which we can use to cut off the input again. Keep in mind the downstream observers <i>have no idea any of this is happening</i>. When we disconnect, <code>OnCompleted</code> will <i>not</i> be fired.</p>
<p><img src="http://northhorizon.net/wp-content/uploads/2011/11/disconnect.png" alt="" title="Disconnect" width="375" height="164" class="aligncenter size-full wp-image-487" /></p>
<p>Getting back to my example, the correct code looks like this:</p>
<pre class="brush:csharp">var interval = Observable.Interval(TimeSpan.FromMilliseconds(500)).Publish(); interval.Subscribe(i => Console.WriteLine("First: {0}", i)); interval.Subscribe(i => Console.WriteLine("Second: {0}", i)); var connection = interval.Connect(); // Later connection.Dispose();</pre>
<p>It is very important to make sure all of your subscribers are setup <i>before</i> you call <code>Connect()</code>. You can think of <code>Publish</code> (or, really, <code>Multicast</code>) like a valve on a pipe. You want to be sure you have all your pipes together and sealed before you open it up, otherwise you&#8217;ll have a mess.</p>
<p>A problem that comes up fairly often is what do you do when you do not control the number or timing of subscriptions? For instance, if I have a stream of USD/EUR market rates, there&#8217;s no need for me to keep that stream open if nobody is listening, but if someone is, I&#8217;d like to share that connection, rather than create a new one.</p>
<p>This is where <code>RefCount()</code> comes in. <code>RefCount()</code> takes an <code>IConnectableObservable&lt;T&gt;</code> and returns an <code>IObservable&lt;Tg&gt;</code>, but with a twist. When <code>RefCount</code> gets its first subscriber, it automatically calls <code>Connect()</code> for you and keeps the connection open as long as anyone is listening; once the last subscriber disconnects, it will call <code>Dispose</code> on its connection token.</p>
<p>So now you might be wondering why I didn&#8217;t use <code>RefCount()</code> in my so-called &#8220;correct&#8221; implementation. I wouldn&#8217;t have had to call either <code>Connect()</code> or <code>Dispose</code>, and less is more, right? All that is true, but it omits the cost of safety. Once I dispose my connection, my source no longer has an object reference to my object, which allows the GC to do what it does best. Often, these streams start to make their way outside of my class, which can create a long dependency chain of object references. That&#8217;s fine, but if I dispose an object in the middle, I want to make sure that that object is now ready for collection, and if I <code>RefCount()</code>, I simply can&#8217;t make that assertion, because I&#8217;d have to ensure every downstream subscriber had also disposed.</p>
<p>Another scenario that comes up is how to keep a record of things you&#8217;ve already received. For instance, I might make a call to find all tweets with the hashtag &#8220;#RxNet&#8221; with live updates. If I subscribe second observer, I might expect that all the previously found data to be sent again without making a new request to the server. Fortunately, we have <code>Replay()</code> for this. It literally has 15 overloads, which cover just about every permutation of windowing by count and/or time, and supplying an optional scheduler and/or selector. The parameterless call, however, just remembers everything. <code>Replay</code> is just like <code>Publish</code> in the sense that it also forwards a call to <code>Multicast</code>, but this time with a <code>ReplaySubject&lt;T&gt;</code>.</p>
<p>Now the temptation is to combine <code>Replay()</code> and <code>RefCount</code> to make caches of things for subscribers when they are needed. Lets look at my Twitter example.</p>
<pre class="brush:csharp;gutter:false">tweetService.FindByHashTag("RxNet").Replay().RefCount()</pre>
<p>When the first observer subscribes, <code>FindByHashTag</code> will make a call (I assume this is deferred) to the network and start streaming data, and all is well. When the second observer subscribes, he gets all the previously found data and updates. Great! Now, let&#8217;s say both unsubscribe and a third observer then subscribes. He&#8217;s going to get all that previous data, and then the deferred call in <code>FindByHashTag</code> is going to be re-triggered and provide results that we might have already received from the replay cache! Instead, we should implement a caching solution that actually does what we expect and wrap it in an <code>Observable.Create</code>, or if we expect only fresh tweets, use <code>Publish().RefCount()</code> instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://northhorizon.net/2011/sharing-in-rx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>My Thoughts on MEF</title>
		<link>http://blingcode.blogspot.com/2011/10/my-thoughts-on-mef.html</link>
		<comments>http://blingcode.blogspot.com/2011/10/my-thoughts-on-mef.html#comments</comments>
		<pubDate>Mon, 31 Oct 2011 22:45:00 +0000</pubDate>
		<dc:creator>Bailey Ling</dc:creator>
				<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Ever since MEF was conceived, despite the authors saying that it is not an IoC container, it has since evolved to become one of the more popular IoC containers.&#160; I’ve always avoided it because I disagree with using attributes, and I’ve had no ...]]></description>
			<content:encoded><![CDATA[<p>Ever since MEF was conceived, despite the authors saying that it is <strong>not<em> </em></strong>an IoC container, it has since evolved to become one of the more popular IoC containers.&nbsp; I’ve always avoided it because I disagree with using attributes, and I’ve had no reason to use it over Autofac or Windsor.</p>
<p>Recently, I found a reason to use it – Metro-style applications only support MEF so far.&nbsp; My Twitter client ping.pong uses Autofac as the IoC container.&nbsp; It uses some very basic functionality like factories and hooks.&nbsp; To my surprise, MEF has no support for either of these.</p>
<p>Coming across these limitations solidifies my opinion that MEF is a plugin container, not an IoC container.</p>
<p>First let’s take a look at automated factories. What I mean is that by registering Foo, like so:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">container.RegisterType&lt;Foo&gt;();</pre>
<p><!--CRLF--></div>
</div>
<p>the container will automatically provide us a Func&lt;Foo&gt; without explicitly having to register it. This can be useful when you want to create an instance of Foo some time in the future rather than at constructor time.&nbsp; You can do this with MEF via an ExportFactory&lt;T&gt;, but it’s limited because you cannot override dependencies at resolve time.</p>
<p>For example, let’s say Foo has a constructor of Foo(Bar1, Bar2, Bar3). With MEF, you have no control at resolution time what the Bars are. A container that has support for automated factories (like Autofac and Castle Windsor), will let you resolve a Func&lt;Bar1, Foo&gt;, which lets you override Bar1 at resolve time. Similarly, you can resolve a Func&lt;Bar1, Bar2, Bar3, Foo&gt; and override all dependencies. Any dependencies not overridden fall back to their configuration in the bootstrapper. This is a <em>very</em> useful feature, and coupled with the scoping features for automatic disposal it opens up many doors for elegant solutions for what otherwise are complicated problems.</p>
<p>On to the second point; MEF has limited extension points. This one sounds odd since MEF is all about designing decoupled plugins so surely it should have extension points! The problem here is that MEF is designed as an explicit API (attributes are required) rather than an implicit API. In Autofac, you can scan an assembly and register every type. In MEF, every class needs to have an [Export] on it.&nbsp; It also baffles my mind why [ImportingConstructor] is required even when there’s only one constructor. All this explicitness means you lose a bunch of “free” extension points that typical IoC containers have, like this:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">b.RegisterAssemblyTypes(GetType().Assembly)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">  .OnActivated(x =&gt; x.Context.Resolve&lt;IEventAggregator&gt;().Subscribe(x.Instance));</pre>
<p><!--CRLF--></div>
</div>
<p>What the code above is saying that every time <em>any</em> component is activated, it will subscribe to the event aggregator. If the component doesn’t IHandle&lt;&gt; any messages, it’s a no-op and continues on. If the instance does IHandle&lt;&gt; messages, this will ensure it’s hooked up.</p>
<p>The closest thing I could find in MEF was IPartImportsSatisfiedNotification (yes, an interface, more explicitness!).&nbsp; It contains a single method OnImportsSatisfied() which gets called when the part is created.&nbsp; Needless to say, the one line of code from Autofac would translate into a method for every implementation of IHandle&lt;&gt;, and since OnImportsSatisfied() contains no contextual information, every component will need IEventAggregator injected just to be able to call Subscribe.</p>
<p>To fully complete this example, Autofac has the following methods when registering a component: <em>OnRegistered, OnPreparing, OnActivating, OnActivated, </em>and<em> OnRelease</em>.&nbsp; Each of these methods gives you complete contextual information at the time it is called like access to the current scope of the container, the instance (if applicable), which component which requested the dependency, etc.&nbsp; This makes it almost too easy to extend the container.</p>
<p>For MEF, the only real extension point is an ExportProvider.&nbsp; It is pretty low level (all it does is parse attributes for you) so to write anything similar for MEF requires a lot more code.&nbsp; To further illustrate this point, compare the interception modules from AutofacContrib and MefContrib.&nbsp; The Autofac implementation is a single file with a couple extension methods.&nbsp; The MEF implementation is an entire namespace, over multiple classes, not the mention that it also relies on other infrastructure code in MefContrib.&nbsp; Basically, the guys that wrote MefContrib had to write a mini-container within MEF.</p>
<p>MEF is great for building <em><strong>extremely</strong> loosely coupled </em>applications.&nbsp; I don’t think it has any business in an application where you know and own all of the dependencies; there are simply better libraries for that.</p>
<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3157881265969801285-4363758329185830711?l=blingcode.blogspot.com' alt='' /></div>
]]></content:encoded>
			<wfw:commentRss>http://blingcode.blogspot.com/2011/10/my-thoughts-on-mef.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adobe: Official Maven support is coming</title>
		<link>http://justinjmoses.wordpress.com/2011/10/11/adobe-official-maven-support-is-coming/</link>
		<comments>http://justinjmoses.wordpress.com/2011/10/11/adobe-official-maven-support-is-coming/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 19:05:21 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=575</guid>
		<description><![CDATA[I recently spent a lot of time at AdobeMAX hassling the Flashbuilder team on what the deal is with Flex and Maven, and we’ve finally been given the word: support is coming &#8211; we just don’t yet know what form it’s going to take. Step One: Hosting the framework artifacts The first step towards Maven [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=575&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I recently spent a lot of time at AdobeMAX hassling the Flashbuilder team on what the deal is with Flex and Maven, and we’ve finally been given the word: support is coming &#8211; we just don’t yet know what form it’s going to take.</p>
<p><strong>Step One: Hosting the framework artifacts</strong></p>
<p>The first step towards Maven support is for Adobe to start hosting their releases in a Maven-friendly way. They have admitted that this is on the cards for them, but steered away from specifics. They have two real options here &#8211; either they submit their artifacts to Maven Central or they set up and deploy to their own public Nexus. Many of us in the community would like to see the former before the latter. Having AS3/Flex/AIR projects build out of the box without requiring any external repository would be a great start (Maven Central is referenced in every execution via the super POM). Currently while the Flexmojos plugin now lives in Maven Central, we’re still reliant on the community (specifically @velobr) to deploy the latest JARs, SWCs and RSLs to Sonatype.</p>
<p>Nevertheless, if Adobe were to host a Flash artifact repository, it could become the central repository for the community to deploy their own open source libraries. This could include tools such as unit testing libraries (FlexUnit, ASUnit), mocking tools (Mockolate, Fluint), micro-architectures (Robotlegs, Parsley), utilities (as3corelib, AS3Signals, RxAS), etc. This would then be the go-to for all Flash developers new to Maven. And, we could finally answer the question plaguing all Maven/Flash newbies: <strong>Where are my dependencies???</strong></p>
<p><strong>Step Two: Either sponsor, fork or replace Flexmojos</strong></p>
<p>The next step is for Adobe to decide what to do with Flexmojos &#8211; the open source Maven plugin that compiles Flash artifacts. Because it’s open source, they don’t want to usurp the hard work of the community and completely take it over as-is. As I see it, they can either fork it in its current state, sponsor it with funding and their own development team, or start again from the ground up and target Spark and above. In its current state, Flexmojos 4 (4.0-RC2 is the latest) is well equipped to deal with the needs of Flash projects up to and including Flash Player 10.3 (albeit with some bugs). Going forward however, we have no assurance that Flex 4.6 or AIR 3 will be supported out of the box, and I have doubts that the community alone will keep the pace.</p>
<p>Moreover, many of us Flash/Maven advocates are in enterprise development and find it hard enough to convince our customers to rely on an open source initiative that isn’t maintained by Adobe, let alone officially supported or sponsored. If Adobe get behind a Maven plug-in and put their stamp on it, we’ll have a much easier time advocating it to our clients.</p>
<p><strong>Step Three: Integrate with Flashbuilder</strong></p>
<p>Last but not least, is Flashbuilder (FB) integration. The current situation is fairly dismal. Flexmojos 3.9 was the last to officially support the flexbuilder/flashbuilder goal &#8211; the process which generated the project structure in Eclipse from your POM (creating and configuring .project and .actionScriptProperties among others). It’s been removed from Flexmojos 4 and there is currently no robust way to keep FB abreast of the latest changes in your POM. You <em>can</em> run the old 3.9 goal for partial results in FB 4.5, but it’s more hassle than it’s worth. Keeping large teams in sync across a complex project is cumbersome at best (and don’t get me started on checking in .project files).</p>
<p>While m2eclipse &#8211; the Maven-Eclipse plugin &#8211; provides the functionality required to run Maven within Flashbuilder, it is not integrated with the Flexmojos plugin. Put simply, m2eclipse is a lot less powerful with Flashbuilder than it is with typical Java projects in Eclipse. Updated your POM with a different Flex SDK, added some dependencies or a new runtime module? Fine, just make sure to tell all the developers to update their workspaces manually &#8211; otherwise either switch to IntelliJ or wait for Flashbuilder 5 (we hope).</p>
<p><strong>Looking forward</strong></p>
<p>The first step in a long process has begun. Adobe are taking the plunge into Maven compatibility and it seems the Flashbuilder team are our best hope for the future of the union. We know support is coming, but how exactly it will pan out is still up for debate. Hopefully we’ll have an answer before the end of the year, but I won’t be holding my breath.</p>
<p><strong>The latest</strong></p>
<p>Want to keep abreast of the latest developments, here’s a list of people to follow:</p>
<ul>
<li>Adam Lehman, PM for Flashbuilder, Adobe <a href="http://twitter.com/adrocknaphobia">@adrocknaphobia</a></li>
<li>Andrew Shorten, GPM of Dev Tools, Adobe <a href="http://twitter.com/ashorten">@ashorten</a></li>
<li>Raghu Thricovil, one of the new PMs of Flex, Adobe <a href="http://twitter.com/rthricov">@rthricov</a></li>
<li>The Flexmojos plugin <a href="http://twitter.com/flexmojos">@flexmojos</a></li>
<li>Marvin Froeder, Flexmojos creator <a href="http://twitter.com/velobr">@velobr</a></li>
<li>Me <a href="http://twitter.com/justinjmoses">@justinjmoses</a></li>
</ul>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/575/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/575/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/575/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=575&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/10/11/adobe-official-maven-support-is-coming/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Push Driven Development with Reactive Extensions</title>
		<link>http://blingcode.blogspot.com/2011/09/push-driven-development-with-reactive.html</link>
		<comments>http://blingcode.blogspot.com/2011/09/push-driven-development-with-reactive.html#comments</comments>
		<pubDate>Fri, 30 Sep 2011 02:04:00 +0000</pubDate>
		<dc:creator>Bailey Ling</dc:creator>
				<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[This is going to be the last post that concludes my series on building a real-time push app with Silverlight.&#160; Any additional posts would likely be outside the context of writing a push app and more about how I’m adding features to ping.pong, my...]]></description>
			<content:encoded><![CDATA[<p>This is going to be the last post that concludes my series on building a real-time push app with Silverlight.&nbsp; Any additional posts would likely be outside the context of writing a push app and more about how I’m adding features to ping.pong, my Twitter app, so I think this is a good place to wrap up and talk generally from a top down overview of building a push-style application.</p>
<p>Here’s a recap of everything discussed so far:</p>
<p><a href="http://blingcode.blogspot.com/2011/08/building-real-time-push-app-with.html">Part 1</a>:&nbsp; Basics – Creating an Observable around a basic HTTP web stream against Twitter’s streaming API</p>
<p><a href="http://blingcode.blogspot.com/2011/08/building-real-time-push-app-with_27.html">Part 2</a>:&nbsp; Subscription and Observation of Observables</p>
<p><a href="http://blingcode.blogspot.com/2011/08/building-real-time-push-app-with_28.html">Part 3</a>:&nbsp; Basics of UX design with a look at shadows and gradients.</p>
<p><a href="http://blingcode.blogspot.com/2011/09/building-real-time-push-app-with.html">Part 4</a>:&nbsp; Integrating with 3rd party libraries, notably Caliburn Micro and Linq2Twitter and how to achieve polling with observables.</p>
<p><a href="http://blingcode.blogspot.com/2011/09/building-real-time-push-app-with_08.html">Part 5</a>:&nbsp; A minor hick up with Linq2Twitter.</p>
<p><a href="http://blingcode.blogspot.com/2011/09/building-real-time-push-app-with_13.html">Part 6</a>:&nbsp; Taking advantage of transparencies to improve the design and reusability of UX.</p>
<p><a href="http://blingcode.blogspot.com/2011/09/building-real-time-push-app-with_16.html">Part 7</a>:&nbsp; A summary of all things encountered so far, replacing Linq2Twitter with Hammock, first release of code to <a href="https://github.com/bling/Ping.Pong">GitHub</a>, and a binary released capable pulling and streaming tweets from Twitter.</p>
<p><a href="http://blingcode.blogspot.com/2011/09/building-real-time-push-app-with_21.html">Part 8</a>:&nbsp; Examples of using Caliburn Micro to easily resolve data bindings that otherwise would be much more effort.</p>
<p>And that leads us to this post…</p>
<h3>PDD (Push Driven Development)</h3>
<p>One of the main goals of this series is to create a performant Silverlight app based on push principles, as opposed to more traditional pull principles.&nbsp; To that effect, ping.pong has performed remarkably well and is limited only by Twitter’s throttling, which currently appears to be maximum of 50 tweets per second via the streaming API.</p>
<p>Writing the application from a push-driven mindset was definitely unintuitive at first, and I had to refactor (actually rewrite is more accurate) the code many times to move closer to a world where the application is simply <em>reacting</em> to events thrown at it (as opposed to asking the world for events).</p>
<p>To be absolutely clear on what I mean on the differences between push and pull, here’s a comparison:</p>
<table border="0" cellspacing="0" cellpadding="2" width="100%">
<tbody>
<tr>
<td valign="top"><strong>Pulling</strong></td>
<td valign="top"><strong>Push</strong></td>
</tr>
<tr>
<td valign="top" width="50%">var e = tweets.GetEnumerator();<br />while (e.MoveNext()) <strong>// is there more?<br /></strong>{<br />&nbsp; e.Current; <strong>// get current<br /></strong>&nbsp; DoSomething(e.Current);<br />}</td>
<td valign="top" width="50%">IObservable&lt;Data&gt; data = /* get source */</p>
<p><strong>// whenever data comes, do something</strong><br />data.Subscribe(DoSometing); </td>
</tr>
</tbody>
</table>
<p>On the pulling side, the caller is much more concerned with the logic on how to process each message.&nbsp; It needs to <em>repeatedly</em> ask the world, “hey, is there more data?”.</p>
<p>On the push side, the caller merely asks the world, “hey, give me data when you get some”.</p>
<p>Twitter is a perfect example because their APIs have both a pulling and pushing models.&nbsp; Traditional clients poll continuously all the time, and many had configurable options to try to stay under the 200 API calls per hour limit.&nbsp; Most of Twitter’s API still consists of pulling, but the user’s home line and searching can be streamed in near real time via the streaming API, aka. push.&nbsp; Streaming tweets effectively removes the API call limit.</p>
<h3></h3>
<h3>Push and Pull with Reactive Extensions</h3>
<p>The beauty of Rx is that regardless of whether it is actually pushing or pulling, the API will look same:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">IObservable&lt;Tweet&gt; tweets = _client.GetHomeTimeline();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">tweets.Subscribe(t =&gt; { <span style="color: #008000">/* do something with the tweet */</span> });</pre>
<p><!--CRLF--></div>
</div>
<p>As far as the caller is concerned, it doesn’t care (or needs to know) whether the <em>GetHomeTimeline</em> method is polling Twitter or streaming from Twitter.&nbsp; All it needs to know is <em>when</em> a tweet comes it will <em>react</em> and do something in the Subscribe action.</p>
<p>In fact, Subscribe simply means “when you have data, call this”, but that could also be immediately, which would be analogous to IEnumerable.</p>
<p>However, if that was the only thing Rx provided it wouldn’t be as popular as it is, because other pub/sub solutions like the EventAggregator already provide a viable asynchronous solution.</p>
<p>Unlocking Rx’s power comes with its multitude of operators.&nbsp; Here’s an example:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> IObservable&lt;Tweet&gt; GetStreamingStatuses(<span style="color: #0000ff">this</span> TwitterClient client)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">{</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">  <span style="color: #0000ff">return</span> client.GetHomeTimeline()</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">      .Merge(client.GetMentions())</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">      .Concat(client.GetStreamingHomeline());</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">}</pre>
<p><!--CRLF--></div>
</div>
<p><em>GetHomeTimeline</em> and <em>GetMentions</em> initiate once-only pull style API calls, while <em>GetStreamingHomeline</em> will initiate a sticky connection and stream subsequent tweets down the pipe.</p>
<p>The <em>Merge</em> operator is defined as this: “Merges an observable sequence of observable sequences into an observable sequence.”</p>
<p>I think a better description would be “whenever there is data from any of the sources, push it through”.&nbsp; In the example above, this would translate to whenever a tweet comes from either the home timeline or the mentions timeline, give me a Tweet (first-come-first-push), followed by anything from the streaming timeline.</p>
<p>And there lies one of the greatest beauties of Rx.&nbsp; <em>All</em> of the complexity lies solely on setting up the stream and operators.&nbsp; And that, also, is its disadvantage.</p>
<h3></h3>
<h3>Rx Complexity</h3>
<p>Let’s take a look at the <em><a href="http://msdn.microsoft.com/en-us/library/hh212146(v=VS.103).aspx">Concat</a></em> operator, defined as: “Concatenates two observable sequences.”&nbsp; In the remarks sections it states this: “The Concat operator runs the first sequence to completion. Then, the second sequence is run to completion effectively concatenating the second sequence to the end of the first sequence.”</p>
<p>Let’s try it out:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var a = Observable.Interval(TimeSpan.FromSeconds(1)).Select(x =&gt; x.ToString());</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var b = Observable.Interval(TimeSpan.FromSeconds(1)).Select(x =&gt; <span style="color: #006080">"s"</span> + x);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">a.Concat(b).Subscribe(Console.WriteLine);</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">// output: 0, 1, 2, 3, 4...</pre>
<p><!--CRLF--></div>
</div>
<p>As expected, only numbers are printed because the first sequence never ends, so it won’t concatenate the second one.&nbsp; Let’s modify it so that it does finish:</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">int</span> count = 0;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var a = Observable.Interval(TimeSpan.FromSeconds(1))</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    .TakeWhile(_ =&gt; ++count &lt; 5)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    .Select(x =&gt; x.ToString());</pre>
<p><!--CRLF--></div>
</div>
<p>Note, that using Observable.Generate is preferred because it doesn’t introduce an external variable, but I stuck with Interval so the code looks similar to the second observable.&nbsp; As expected again, it will print “0, 1, 2, s0, s1, s2”.</p>
<p>OK, let’s spice things up.&nbsp; Let’s make <em>b</em> a ConnectableObservable by using the <em><a href="http://msdn.microsoft.com/en-us/library/hh229126(v=VS.103).aspx">Publish</a></em> operator, and immediately call <em>Connect</em>.</p>
<div id="codeSnippetWrapper">
<div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet">
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #0000ff">int</span> count = 0;</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var a = Observable.Interval(TimeSpan.FromSeconds(1))</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    .TakeWhile(_ =&gt; ++count &lt; 5)</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">    .Select(x =&gt; x.ToString());</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">var b = Observable.Interval(TimeSpan.FromSeconds(1)).Select(_ =&gt; <span style="color: #006080">"s"</span> + _).Publish();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">b.Connect();</pre>
<p><!--CRLF-->
<pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px">a.Concat(b).Subscribe(Console.WriteLine);</pre>
<p><!--CRLF--></div>
</div>
<p>What do you think the output of this will be?&nbsp; The answer is “0, 1, 2, 3, <strong>s5, s6, s7</strong>, …”</p>
<p>Despite using the same <em>Concat</em> operator, the result can be very different depending on the source observables.&nbsp; If you use the <em><a href="http://msdn.microsoft.com/en-us/library/hh229288(v=VS.103).aspx">Replay</a></em> operator, it would have printed “0, 1, 2, 3, s0, s1, s2, …”</p>
<p>Years and years of working in synchronous programming models have trained us to think in synchronous ways, and I picked Concat specifically because Concat also exists in the enumerable world.&nbsp; Observable sequences are asynchronous, so we never know exactly <em>when</em> data comes at us, only what to do when it does.&nbsp; And because streams occur at different times, when you combine them together there are many many ways of doing so (CombineLatest, Merge, Zip, are just a few).</p>
<p>The greatest hurdle to working in Rx is to know what the different combinations do.&nbsp; This takes time and practice.&nbsp; <a href="http://mnajder.blogspot.com/2010/03/rxsandbox-v1.html">RxTools</a> is a great learning tool to test out what all the operators do.</p>
<h3><strong>Unit Testing</strong></h3>
<p>Last but not least, Rx can make it easier to write unit tests.&nbsp; The concept is easy: take some inputs and test the output.&nbsp; In practice this is complicated because applications typically carry a lot of state with them.&nbsp; Even with dependency injection and mocking frameworks I’ve seen a lot of code where for every assert there is 10 lines of mock setup code.</p>
<p>So how does it make it easier to test?&nbsp; It reduces what you need to test to a single method, Subscribe, which takes one input, an IObservable&lt;T&gt;.</p>
<h3>Conclusion</h3>
<p>Rx is a library unlike any other you will use.&nbsp; With other libraries, you will add them to your solution, use a method here or there, and go on with your life.&nbsp; With Rx, it will radically change the way you code and think in general.&nbsp; It’s awesome.</p>
<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/3157881265969801285-3658586159535349540?l=blingcode.blogspot.com' alt='' /></div>
]]></content:encoded>
			<wfw:commentRss>http://blingcode.blogspot.com/2011/09/push-driven-development-with-reactive.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Selective removeAll() addition to as3-signals</title>
		<link>http://justinjmoses.wordpress.com/2011/09/22/selective-removeall-addition-to-as3-signals/</link>
		<comments>http://justinjmoses.wordpress.com/2011/09/22/selective-removeall-addition-to-as3-signals/#comments</comments>
		<pubDate>Thu, 22 Sep 2011 18:03:38 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=527</guid>
		<description><![CDATA[This post and code is related to my fork of as3-signals. The fork is from the latest version of as3-signals 0.9-BETA. Summary of additions ISlot.applyTo(value:*):void ISlot.doesApply(value:*):Boolean SlotList.filterNotAppliesTo(value:*):SlotList SlotList.findNotAppliesTo(value:*):SlotList Summary of modifications IOnceSignal.removeAll(appliesTo:* = null):void Details This backwards compatible addition to as3-signals chiefly allows the removal of all listeners for a given instance or class type. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=527&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>This post and code is related to <a href="https://github.com/justinjmoses/as3-signals">my fork of as3-signals</a>. The fork is from the latest version of as3-signals <em>0.9-BETA</em>.</p>
<p><strong>Summary of additions</strong></p>
<ul>
<li>ISlot.applyTo(value:*):void</li>
<li>ISlot.doesApply(value:*):Boolean</li>
<li>SlotList.filterNotAppliesTo(value:*):SlotList</li>
<li>SlotList.findNotAppliesTo(value:*):SlotList</li>
</ul>
<p><strong>Summary of modifications</strong></p>
<ul>
<li>IOnceSignal.removeAll(appliesTo:* = null):void</li>
</ul>
<p><strong>Details</strong></p>
<p>This backwards compatible addition to as3-signals chiefly allows the removal of all listeners for a given instance or class type. It keeps the convenience of the removeAll function but provides a mechanism to prevent removal of listeners not bound to the current instance or class.</p>
<p>The removeAll() method allows for an optional parameter which will then removeAll slots that applyTo the given parameter, if any.</p>
<p>Essentially, this allows us to asynchronously clean up after a class or instance without affecting any listeners from other classes and without having to define our anonymous functions or closures.</p>
<p><strong>Reasoning</strong></p>
<p>A signal &#8211; as a <a href="http://en.wikipedia.org/wiki/Futures_and_promises">promise</a> &#8211; may be reused across instances and classes. For example, a service that is managed by an IOC container may cache signal calls, or a model may use signals to notify of changes. When the signal is shared across various types (either directly via the IOC container, or indirectly cached within an instance) we don’t want to removeAll() lest we remove functional code in other classes (that may well have been written by other developers).</p>
<p><strong>Example</strong></p>
<p><em>Update Sept 23: Changed the example to use Robotlegs and Mediation</em></p>
<p>Let&#8217;s look at an example to follow this through. This example below illustrates usage when marshalling updates of a model to a view (using covariant mediation to an interface) via a Mediator. Chiefly, the problem arises when an asynchronous cleanup method is called (in this case `onRemove()`), it needs to remove all of the listeners applied to by this instance but not remove listeners that may be used elsewhere.</p>
<p>
<pre class="brush: as3;">
public class LogModel
{
	protected var updateSignal:ISignal;
	protected var logs:Vector.&lt;LogItem&gt;;

	public function get update():ISignal
	{
		return updateSignal ||= new Signal();
	}

	public function set logs(collection:Vector.&lt;LogItem&gt;):void
	{
		logs = collection;
		update.dispatch(logs);
	}
}

public class SomethingMediator extends Mediator
{
     [Inject]
     public var model:LogModel;

	 [Inject]
	 public var view:IDoesSomething;

     override public function onRegister():void
     {
        model.update.add(function(collection:Vector.&lt;LogItem&gt;):void
		{
			view.logs = collection;
		}).applyTo(this);
     }

     override public function onRemove():void
     {
          model.update.removeAll(this); //removes all listeners applied to this instance only
     }
}
</pre>
</p>
<p><strong>Usage (pseudo-code):</strong></p>
<p>
<pre class="brush: as3;">
//setup values
const logModel:LogModel = new LogModel();
injector.mapValue(LogModel, logModel);

//map interfaces to a mediator
mediatorMap.mapMediator(IDoesSomething, SomethingMediator);
const viewA:IDoesSomething = new DoesSomething();
const viewB:IDoesSomething = new DoesSomething();

//register mediators for our views (creates two instances of SomethingMediator)
mediatorMap.registerMediators(viewA);
mediatorMap.registerMediators(viewB);

trace(logModel.update.numListeners); //2 - one listener from viewA.onRegister() and one from viewB.onRegister()

mediatorMap.removeMediators(viewA);

trace(logModel.update.numListeners); //1 - one listener from viewB.onRegister()

mediatorMap.removeMediators(viewB);

trace(logModel.update.numListeners); //0
</pre>
</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/527/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/527/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/527/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=527&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/09/22/selective-removeall-addition-to-as3-signals/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Reactions from Build</title>
		<link>http://northhorizon.net/2011/reactions-from-build/</link>
		<comments>http://northhorizon.net/2011/reactions-from-build/#comments</comments>
		<pubDate>Fri, 16 Sep 2011 21:51:02 +0000</pubDate>
		<dc:creator>Daniel Moore</dc:creator>
				<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://northhorizon.net/?p=476</guid>
		<description><![CDATA[There’s been no shortage of news and non-news coming out of Build Conference this week, and I suspect there will be continue to be no shortage of the same for the next few months. We’ve learned that WPF isn’t quite dead, Silverlight isn’t quite dead, but both are in the process of being “reimagined,” whatever [...]]]></description>
			<content:encoded><![CDATA[<p>There’s been no shortage of news and non-news coming out of Build Conference this week, and I suspect there will be continue to be no shortage of the same for the next few months. We’ve learned that WPF isn’t quite dead, Silverlight isn’t quite dead, but both are in the process of being “reimagined,” whatever that means. Metro is clearly the first step of that process and it provokes a very diametric response from developers.<span id="more-476"></span></p>
<p>I sat down to breakfast this morning with a couple guys I hadn’t met. Since Build Conference was an incorporation of both ISVs and IHVs, I greeted them with, “Software or hardware?” The man across the table told me he was involved with software, while the guy to my right ignored me entirely. Without quite playing <em>20 Questions</em>, I found that the more vocal one was a client side developer in health care. He told me that he was very excited about the new Metro design and especially for the upcoming Windows 8 tablets. “Right now, everything is moving to Electronic Medical Records. So, when a doctor goes into see a patient, the first thing he does is turn his back on that patient and bring up the records on a desktop. A tablet is much more like the clipboards doctors used to use.” And, of course, Metro plays a huge role in the realization of that use case; a friendly, full-screen touch-accelerated app is intrinsic to the paradigm of a tablet. Not only that, but ease of access to peripherals, especially the webcam, make Windows Runtime (WinRT) a compelling API. As an added bonus, he pointed out that he could transition his current ASP.NET development stack and programmers much more easily to use either C# and XAML or even HTML5 and JavaScript to produce a Metro app than to use Coco and Objective-C to make an iPad app. Without a doubt, this is what Microsoft had envisioned.</p>
<p>At the opposite end of the spectrum, I met a couple developers that maintain an institutional client-facing application written in MFC. “There’s over three hundred screens in our application. No way can we fit that into Metro.” He went on further to explain that their application opens direct connections to a SQL Server instances located on both the client and server tiers. “I have to figure out how to go back and tell my boss that there’s just no way we can move over to Metro.”</p>
<p>I don’t know if he was aware or not of the seemingly obvious flaws in his app’s design, or that Microsoft was encouraging developers to forsake that all-too-familiar design of MFC apps that he showed me. “It’d be a complete rewrite;” that much we completely agreed upon.</p>
<p>There is a continuing consensus around the notion that WinRT is by far the most ambitious thing Microsoft has done in decades. Perhaps in a lot of ways, Windows XP is an apt analog of Win32 programming: it’s been around for so long, it’s in use in so many places, and it’s so well known, that it will take a very, very long time to unwind from it. Windows 8 and WinRT have enormous potential to revitalize the failing Windows desktop software market. All that remains to be seen is whether developers choose to capitalize upon it or cut their losses and move on.</p>
]]></content:encoded>
			<wfw:commentRss>http://northhorizon.net/2011/reactions-from-build/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using RequireJS to load UglifyJS’s parser in the browser</title>
		<link>http://blog.davidpadbury.com/2011/08/26/using-requirejs-to-load-uglifyjs-in-the-browser/</link>
		<comments>http://blog.davidpadbury.com/2011/08/26/using-requirejs-to-load-uglifyjs-in-the-browser/#comments</comments>
		<pubDate>Fri, 26 Aug 2011 12:30:00 +0000</pubDate>
		<dc:creator>David Padbury</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://blog.davidpadbury.com/?p=296</guid>
		<description><![CDATA[UglifyJS has a great parser (parse-js) which is written as a CommonJS module. This works great in node but not so great in the browser. The suggested route to use it browser side is to just manually wrap it in a AMD define or just pull out the exports yourself. It&#8217;s easy enough to do &#8230; <span class="more-link"><a href="http://blog.davidpadbury.com/2011/08/26/using-requirejs-to-load-uglifyjs-in-the-browser/">Continue reading &#187;</a></span><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&#38;blog=2979783&#38;post=296&#38;subd=davidpadbury&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/mishoo/UglifyJS">UglifyJS</a> has a great parser (<a href="https://github.com/mishoo/UglifyJS/blob/master/lib/parse-js.js">parse-js</a>) which is written as a CommonJS module. This works great in node but not so great in the browser. The suggested route to use it browser side is to just manually wrap it in a AMD define or just pull out the exports yourself. It&#8217;s easy enough to do but likely a difficulty to maintain going forward.</p>
<p><a href="http://requirejs.org/">RequireJS</a>&nbsp;has support for custom plugins &#8211; effectively code that can process the content of a file before it is passed into RequireJS&#8217;s AMD module system. Ben Hockey has put together a simple CommonJS module loader plugin (<a href="https://github.com/neonstalwart/cjs">cjs</a>) which automatically wraps the content of a CommonJS module with a AMD define.</p>
<p>This makes a great example of why RequireJS is so powerful. For this example I&#8217;ve just <code>git clone</code>&#8216;d the content of the UglifyJS repo into my project and used the following RequireJS configuration to tell it where the CommonJS module is based.</p>
<p>
<pre class="brush: xml;">
&lt;script&gt;
	var require = {
		baseUrl: '/js/requirejs',
		packages: [{
			name: 'uglify-js',
			main: 'uglify-js',
			location: '../UglifyJS'
		}]
	};
&lt;/script&gt;
&lt;script src=&quot;/js/requirejs/require.js&quot;&gt;&lt;/script&gt;
</pre>
</p>
<p>Once that is in place it&#8217;s just a matter of asking for the module and prefixing the module id with the cjs plugin.</p>
<p>
<pre class="brush: jscript;">
require(['cjs!uglify-js/lib/parse-js'], function(parser) {
	var ast = parser.parse('function saySomething() { alert(&quot;Hello!&quot;); }');
	// ...
});
</pre>
</p>
<p>These simple steps are enough to give us the following parse tree.</p>
<p><a href="http://davidpadbury.files.wordpress.com/2011/08/screen-shot-2011-08-26-at-8-24-03-am.png"><img class="aligncenter size-full wp-image-299" title="UglifyJS Parser Output" src="http://davidpadbury.files.wordpress.com/2011/08/screen-shot-2011-08-26-at-8-24-03-am.png?w=580" alt=""   /></a></p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidpadbury.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidpadbury.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidpadbury.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&amp;blog=2979783&amp;post=296&amp;subd=davidpadbury&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davidpadbury.com/2011/08/26/using-requirejs-to-load-uglifyjs-in-the-browser/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>David Padbury speaks at Times Open, HTML5 and Beyond</title>
		<link>http://blog.lab49.com/archives/5517</link>
		<comments>http://blog.lab49.com/archives/5517#comments</comments>
		<pubDate>Mon, 22 Aug 2011 09:24:45 +0000</pubDate>
		<dc:creator>Haidee Clarke</dc:creator>
				<category><![CDATA[Lab49]]></category>
		<category><![CDATA[coffeescript]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://blog.lab49.com/?p=5517</guid>
		<description><![CDATA[The New York Times reviews the Times Open, HTML5 and Beyond seminar where Lab49&#8242;s David Padbury spoke about HTML5 and node.js. To read the article in full visit The New York Times.]]></description>
			<content:encoded><![CDATA[<p>The New York Times reviews the Times Open, HTML5 and Beyond seminar where Lab49&#8242;s David Padbury spoke about HTML5 and node.js. To read the article in full visit <a href="http://open.blogs.nytimes.com/2011/08/19/recapping-times-open-html5-and-beyond/" target="_blank">The New York Times</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lab49.com/archives/5517/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Modules</title>
		<link>http://blog.davidpadbury.com/2011/08/21/javascript-modules/</link>
		<comments>http://blog.davidpadbury.com/2011/08/21/javascript-modules/#comments</comments>
		<pubDate>Sun, 21 Aug 2011 15:25:44 +0000</pubDate>
		<dc:creator>David Padbury</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://blog.davidpadbury.com/?p=274</guid>
		<description><![CDATA[One of the first challenges developers new to JavaScript who are building large applications will have to face is how to go about organizing their code. Most start by embedding hundreds of lines of code between a &#060;script&#062; tag which works but quickly turns into a mess. The difficultly is that JavaScript doesn&#8217;t offer any &#8230; <span class="more-link"><a href="http://blog.davidpadbury.com/2011/08/21/javascript-modules/">Continue reading &#187;</a></span><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&#38;blog=2979783&#38;post=274&#38;subd=davidpadbury&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the first challenges developers new to JavaScript who are building large applications will have to face is how to go about organizing their code. Most start by embedding hundreds of lines of code between a <code>&lt;script&gt;</code> tag which works but quickly turns into a mess. The difficultly is that JavaScript doesn&#8217;t offer any obvious help with organizing our code. Literally where C# has <code>using,</code> Java has <code>import -</code> JavaScript has nothing. This has forced JavaScript authors to experiment with different conventions and to use the language we do have to create practical ways of organizing large JavaScript applications.</p>
<blockquote><p><em>The patterns and tools and practices that will form the foundation of Modern JavaScript are going to have to come from outside implementations of the language itself</em></p>
<p>- <a href="http://blog.rebeccamurphey.com/modern-javascript">Rebecca Murphy</a></p>
</blockquote>
<h1>The Module Pattern</h1>
<p>One of the most widely used approaches to solve this problem is known as the Module Pattern. I&#8217;ve attempted to explain a basic example below and talk about some of it&#8217;s properties. For a much better description and a fantastic run down of different approaches take a look at Ben Cherry&#8217;s post &#8211; <a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth">JavaScript Module Pattern: In-Depth</a>.</p>
<p>
<pre class="brush: jscript;">
(function(lab49) {

	function privateAdder(n1, n2) {
		return n1 + n2;
	}

	lab49.add = function(n1, n2) {
		return privateAdder(n1);
	};

})(window.lab49 = window.lab49 || {});
</pre>
</p>
<p>In the above example we&#8217;ve used a number of basic features from the language to create constructs like what we see in languages like C# and Java.</p>
<h2>Isolation</h2>
<p>You&#8217;ll notice that the code is wrapped inside a function which is invoked immediately (check the last line). By default in the browser JavaScript files are evaluated in the global scope so anything we declared inside our file would be available everywhere. Imagine if in lib1.js we had a <code>var name = '...'</code> statement then in lib2.js we had another <code>var name = '...'</code> statement. The second var statement would replace the value of the first &#8211; not good. However as JavaScript has function scoping, in the above example everything is declared in it&#8217;s own scope away from the global. This means anything in this function will be isolated from whatever else is going on in the system.</p>
<h2>Namespacing</h2>
<p>In the last line you&#8217;ll notice that we&#8217;re assigning <code>window.lab49</code> to either itself or to an empty object literal. It looks a bit odd but let&#8217;s walk through an imaginary system where we have a number of js files all using the above function wrapper.</p>
<p>The first file to get included will evaluate that OR statement and find that the left hand side is undefined. This is a falsely value so the OR statement will go ahead and evaluate the right hand side, in this case an empty object literal. The OR statement is actually an expression that will return it&#8217;s result and go ahead and assign it to the global <code>window.lab49</code>.</p>
<p>Now the next file to use this pattern will get to the OR statement and find that <code>window.lab49</code> is now an instance of an object &#8211; a truthy value. The OR statement will short circuit and return this value that is immediately assigned to itself &#8211; effectively doing nothing.</p>
<p>The result of this is that the first file in will create our lab49 namespace (just a JavaScript object) and every subsequent file using this construct will just reuse the existing instance.</p>
<h2>Private State</h2>
<p>As we just talked about due to being inside a function, everything declared inside it is in the scope of that function and not the global scope. This is great to isolate our code but it also has the effect that no one could call it. Pretty useless.</p>
<p>As we also just talked about we&#8217;re creating a window.lab49 object to effectively namespace our content. This lab49 variable is available globally as it&#8217;s attached to the window object. To expose things outside of our module, publically you may say, all we need to do attach values to that global variable. Much like we&#8217;re doing with our add function in the above example. Now outside of our module our add function can be called with <code>lab49.add(2, 2)</code>.</p>
<p>As another result of declaring our values inside of this function, if a value isn&#8217;t explicitly exposed by attaching it to our global namespace or something outside of the module there is no way for external code to reach it. In practice, we&#8217;ve just created some private values.</p>
<h1>CommonJS Modules</h1>
<p>CommonJS is a group primarily made up of authors of server-side JavaScript runtimes who have attempted to standardize exposing and accessing modules. It&#8217;s worth noting however that their proposed module system is not a standard from the same group that creates the JavaScript standard so it&#8217;s become more of an informal convention between the authors of server-side JavaScript runtimes.</p>
<blockquote><p><em>I generally support the CommonJS idea, but let’s be clear: it’s hardly a specification handed down by the gods (like ES5); it’s just some people discussing ideas on a mailing list. Most of these ideas are without actual implementations.</em></p>
<p>- <a href="http://dailyjs.com/2010/10/18/modules/">Ryan Dahl</a>, creator of node.js</p>
</blockquote>
<p>The core of the <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1">Modules specification</a> is relatively straight forward. Modules are evaluated in their own context and have a global <code>exports</code> variable made available to them. This <code>exports</code> variable is just a plain old JavaScript object which you can attach things too, similar to the namespace object we demonstrated above. To access a module you call a global <code>require</code> function and give an identifier for the package you are requesting. This then evaluates the module and returns whatever was attached to the <code>exports</code>. This module will then be cached for subsequent <code>require</code> calls.</p>
<p>
<pre class="brush: jscript; gutter: false;">
// calculator.js
exports.add = function(n1, n2) {

};

// app.js
var calculator = require('./calculator');

calculator.add(2, 2);
</pre>
</p>
<p>If you&#8217;ve ever played with Node.js you&#8217;ll probably find the above familiar. The way that Node implements CommonJS modules is surprisingly easy, looking at a module inside <a href="https://github.com/dannycoates/node-inspector">node-inspector</a> (a Node debugger) will show its content wrapped inside a function that is being passed values for exports and require. Very similar to the hand rolled modules we showed above.</p>
<p><a href="http://davidpadbury.files.wordpress.com/2011/08/screen-shot-2011-08-09-at-7-58-18-am.png"><img class="aligncenter size-full wp-image-286" title="Node Module Wrapper from node-inspector" src="http://davidpadbury.files.wordpress.com/2011/08/screen-shot-2011-08-09-at-7-58-18-am.png?w=580" alt=""   /></a></p>
<p>There&#8217;s a couple of node projects (<a href="https://github.com/sstephenson/stitch">Stitch</a> and <a href="https://github.com/substack/node-browserify">Browserify</a>) which bring CommonJS Modules to the browser. A server-side component will bundle these individual module js files into a single js file with a generated module wrapper around them.</p>
<p>CommonJS was mainly designed for server-side JavaScript runtimes and due to that there&#8217;s a couple of properties which can make them difficult for organization of client-side code in the browser.</p>
<ul>
<li><code>require</code> must return immediately &#8211; this works great when you already have all the content but makes it difficult to use a script loader to download the script asynchronously.</li>
<li>One module per file &#8211; to combine CommonJS modules they need to be wrapped in a function and then organized in some fashion. This makes them difficult to use without some server component like the ones mentioned above and in many environments (ASP.NET, Java) these don&#8217;t yet exist.</li>
</ul>
<h2>Asynchronous Module Definition</h2>
<p>The Asynchronous Module Definition (commonly known as AMD) has been designed as a module format suitable for the browser. It started life as a proposal from the CommonJS group but has since moved onto <a href="https://github.com/amdjs/amdjs-api/wiki/AMD">GitHub</a> and is now accompanied by a <a href="https://github.com/amdjs/amdjs-tests">suite of tests</a> to verify compliance to the AMD API for module system authors.</p>
<p>The core of AMD is the define function. The most common way to call define accepts three parameters &#8211; the name of the module (meaning that it&#8217;s no longer tied to the name of the file), an array of module identifiers that this module depends on, and a factory function which will return the definition of the module. (There are other ways to call define &#8211; check out the <a href="https://github.com/amdjs/amdjs-api/wiki/AMD">AMD wiki</a> for full details).</p>
<p>
<pre class="brush: jscript;">
define('calculator', ['adder'], function(adder) {
	return {
		add: function(n1, n2) {
			return adder.add(n1, n2);
		}
	};
});
</pre>
</p>
<p>Because of this module definition is wrapped in the define call it means you can happily have multiple modules inside a single js file. Also as the module loader has control over when the define module factory function is invoked it can resolve the dependencies in its own time &#8211; handy if those modules have to first be downloaded asynchronously.</p>
<p>A significant effort has been made to remain compatible with the original CommonJS module proposal. There is special behavior for using <code>require</code> and <code>exports</code> within a module factory function meaning that traditional CommonJS modules can be dropped right in.</p>
<p>AMD looks to be becoming a very popular way to organize client-side JavaScript applications. Whether it be through module resource loaders like <a href="http://requirejs.org/">RequireJS</a> or <a href="https://github.com/unscriptable/curl">curl.js</a>, or JavaScript applications that have recently embraced AMD like <a href="http://dojotoolkit.org/features/1.6/async-modules">Dojo</a>.</p>
<h1>Does this mean JavaScript sucks?</h1>
<p>The lack of any language level constructs for organization of code into modules can be quite jarring for developers coming from other languages. However as this deficiency forced JavaScript developers to come up with their own patterns for how modules were structured we&#8217;ve been able to iterate and improve as JavaScript applications have evolved. Follow the <a href="http://tagneto.blogspot.com/">Tagneto</a> blog for some insight into this.</p>
<p>Imagine if this type of functionality had been included in the language 10 years ago. It&#8217;s unlikely they would have imagined the requirements for running large JavaScript applications on the server, loading resources asynchronously in the browser, or including resources like <a href="http://requirejs.org/docs/api.html#text">text templates</a> that loaders like RequireJS are able to do.</p>
<p>Modules are being considered as a language level feature for <a href="http://wiki.ecmascript.org/doku.php?id=harmony:modules">Harmony/ECMAScript 6</a>. Thanks to the thought and hard work of authors of module systems over the past few years, it&#8217;s much more likely that what we end up getting will be suitable for how modern JavaScript applications are built.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidpadbury.wordpress.com/274/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidpadbury.wordpress.com/274/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidpadbury.wordpress.com/274/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&amp;blog=2979783&amp;post=274&amp;subd=davidpadbury&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davidpadbury.com/2011/08/21/javascript-modules/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Cleaning up after closures in Flash</title>
		<link>http://justinjmoses.wordpress.com/2011/08/19/cleaning-up-after-closures-in-flash/</link>
		<comments>http://justinjmoses.wordpress.com/2011/08/19/cleaning-up-after-closures-in-flash/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 14:45:52 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=468</guid>
		<description><![CDATA[If you haven’t experimented much with closures yet - whether in your Flash/Flex projects, Javascripting or while tinkering with Lua - it’s time to start. In case you’re a little nervous about those pesky memory leaks in Flash, here are some ways to cope.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=468&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you haven’t experimented much with closures yet &#8211; whether in your Flash/Flex projects, Javascripting or while tinkering with Lua &#8211; it’s time to start. In case you’re a little nervous about those pesky memory leaks in Flash, here are some ways to cope.</p>
<p><a href="http://www.flickr.com/photos/lrargerich/2787454868/" title="Pampas Fractal by lrargerich, on Flickr"><img src="http://farm4.static.flickr.com/3062/2787454868_eaa791afd0.jpg" width="500" height="250" alt="Pampas Fractal"></a></p>
<div style="border:1px dotted #ccc;background-color:#eee;padding:.5em;">
<div style="font-size:4em;color:white;float:left;">&raquo;&nbsp;</div>
<p> Much of the following code is bundled into an example Flex project that compares the various closure techniques around a custom Timer class.</p>
<p><a href="https://github.com/justinjmoses/closures-cleaning-example">Check the code on Github</a>.</p>
</div>
<h2 id="what_are_closures" style="font-size:1.3em;margin-top:1.5em;border-bottom:1px solid #AAA;">What are closures?</h2>
<p>Many people think of closures as anonymous functions &#8211; probably because that’s the common form they take &#8211; but they are more than that. They are scoped, inline functions that provide a “closure” over a collection of free variables (within the function scope).</p>
<p><a href="http://en.wikipedia.org/wiki/Closure_(computer_science)" >Check out the Wikipedia entry on closures.</a>.</p>
<h2 id="why_use_them" style="font-size:1.3em;margin-top:1.5em;border-bottom:1px solid #AAA;">Why use them?</h2>
<ul style="margin-top:1em;">
<li>They allow the hiding of state (negating the need for maintaining async state in the class) as each closure defines its own variable scope that are available to all nested closures; and</li>
<li>Because they’re easier to follow than continually jumping to functions defined at a type-level.</li>
</ul>
<h2 id="take_a_peek" style="font-size:1.3em;margin-top:1.5em;border-bottom:1px solid #AAA;">Take a peek</h2>
<p>In the below example, we have two closures &#8211; the first defines the <em>userEvent</em> property and <em>someVariable</em>, the second adds to that with it’s own scope of <em>serviceEvent</em>. You see how the inner closure has access not only to that state within itself, but also to that of the outer closure, as well as that of the <em>init()</em> function AND the class itself. Welcome to the scope chain. <a href="http://help.adobe.com/en_US/ActionScript/3.0_ProgrammingAS3/WS5b3ccc516d4fbf351e63e3d118a9b90204-7f54.html">Read the AS3 docs on Function Scope</a>.</p>
<p>
<pre class="brush: as3; highlight: [10,18]; toolbar: false;">
public class SomeClass
{
	protected var view:ISomeView;

	public function init():void
	{
		var functionSaysSo:Boolean = true;

		userAction.addEventListener(UserEvent.LOGIN,
			function(userEvent:UserEvent):void
			{
				//this is outer closure 

				//define a variable in the outer closure's scope
				var someVariable:String = &quot;something&quot;;

				service.addEventListener(ServiceEvent.RESULT,
					function(serviceEvent:ServiceEvent):void
					{
						//this is the inner closure

						if (functionSaysSo)
						{
							view.notify(userEvent.username, serviceEvent.result, someVariable);
						}
					});

				//async call
				service.start(userEvent.username, userEvent.pass);

			});
	}
}
</pre>
</p>
<blockquote><p><strong>Tip</strong>: If you find yourself contesting the readability assertion from before, don’t fret &#8211; it’s early days.</p>
</blockquote>
<h2 id="cleaning_up_after_yourself" style="font-size:1.3em;margin-top:1.5em;border-bottom:1px solid #AAA;">Cleaning up after yourself</h2>
<p>Like any listener, using a closure as an event listener can create memory leaks if not properly cleaned up. Luckily, we have a few options up our sleeves to avoid this.</p>
<h3 id="1_use_weak_references" style="font-size:1.1em;border-bottom:1px solid #CCC;">Use weak references? [Short answer: no]</h3>
<p>Clean, simple and easy, we could simply add closures as weak references.</p>
<p>
<pre class="brush: as3; highlight: [5]; toolbar: false;">
userAction.addEventListener(UserEvent.LOGIN,
	function():void
	{

	}, false, 0, true);
</pre>
</p>
<p><strong>This keeps the code trim, however it introduces its own problems</strong>. If the variable you are listening to lives (is scoped) within another closure or a function definition, it will get cleaned up after the function completes (and before the event might fire). Without a strong reference to that variable, it is a target for garbage collection and you will end up with unpredictable results.</p>
<p>For example, in the following, there is nothing holding onto the timer instance to ensure after the function ends (and before the timer completes) that the timer will still exist and dispatch the <em>TIMER_COMPLETE</em> event.</p>
<p>
<pre class="brush: as3; highlight: [7]; toolbar: false;">
public class SomethingWeak implements IDoesSomething
{
	public function doSomething():void
	{
		var timer:Timer = new Timer(1000,-1);

		//WARNING! Nothing is holding a reference to timer - GC candidate
		timer.addEventListener(TimerEvent.TIMER_COMPLETE,
			function(evt:TimerEvent):void
			{
				//something happened!
			}, false, 0, true); 

		timer.start();
	}
}
</pre>
</p>
<h3 id="2_name_your_handlers" style="font-size:1.1em;border-bottom:1px solid #DDD;">1. Name your handlers</h3>
<p>To improve on this, simply define your handlers locally, and you can remove them within your listeners:</p>
<p style="font-size:smaller;"><strong>&raquo; Aug 30: Updated to inline definition</strong></p>
<p>
<pre class="brush: as3; highlight: [9,14]; toolbar: false;">
public class SomethingNamed implements IDoesSomething
{
	public function doSomething():void
	{
		var timer:Timer = new Timer(1000,-1);

		var timerHandler:Function;

		timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler = function(evt:TimerEvent):void
		{
			//something happened!

			//cleanup after ourselves
			timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
		});

		timer.start();
	}
}
</pre>
</p>
<h3 id="3_use_argumentscallee_to_remove_them_during_execution" style="font-size:1.1em;border-bottom:1px solid #CCC;">2. Use arguments.callee to remove them during execution</h3>
<p>Even better, we can take advantage of a little known feature in AS3 called <em>arguments.callee</em>, and not even have to name our function:</p>
<p>
<pre class="brush: as3; highlight: [13]; toolbar: false;">
public class SomethingCallee implements IDoesSomething
{
	public function doSomething():void
	{
		var timer:Timer = new Timer(1000,-1);

		timer.addEventListener(TimerEvent.TIMER_COMPLETE,
			function(evt:TimerEvent):void
			{
				//something happened

				//cleanup after ourselves
				timer.removeEventListener(TimerEvent.TIMER_COMPLETE, arguments.callee);
			});

		timer.start();
	}
}
</pre>
</p>
<h3 id="4_use_type_level_handlers_to_remove_from_separate_call" style="font-size:1.1em;border-bottom:1px solid #CCC;">3. Use type-level handlers to remove from separate call</h3>
<p>Alas, what if you need to clean up based on another method or event later in the piece (say when a mediator is disposed)? You’ll need to define your handler at a type-level to retain a reference of it:</p>
<p style="font-size:smaller;"><strong>&raquo; Aug 30: Updated to inline definition</strong></p>
<p>
<pre class="brush: as3; highlight: [4,13]; toolbar: false;">
public class SomethingDisposable implements IDoesSomething, IDisposable
{
	//handler is now defined at a type (class) level
	private var timerHandler:Function;

	//we have to also scope the timer to the type level in order to remove listeners
	private var timer:Timer;

	public function doSomething():void
	{
		timer = new Timer(1000,-1);

		timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler = function(evt:TimerEvent):void
		{
			//something happened!
		});

		timer.start();
	}

	public function dispose():void
	{
		if (!timer) return;

		timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);

		//for completeness sake
		timer.stop();
		timer = null;
	}
}
</pre>
</p>
<blockquote style="border:1px dotted #ccc;background-color:#eee;padding:.5em;"><p>At this point, you may be wondering why bother with a closure, when you could simply define the handler as a private method? In this particular example, there is no difference unless you wanted the handler to access the <em>timer</em> instance itself in the handler.</p>
</blockquote>
<h3 id="5_use_signals" style="font-size:1.1em;border-bottom:1px solid #CCC;">4. Use Signals</h3>
<p>There is a final alternative &#8211; use the <a href="http://justinjmoses.wordpress.com/2011/07/07/whats-the-deal-with-signals/">as3-signals</a> library. AS3 Signals is a library that provides an alternative to using Flash Events within your APIs. Using Signals, there are a handful of alternatives to clean up after your closures. Every signal implements ISignal, and it’s that interface we’ll focus on.</p>
<h4 id="isignaladdonce" style="font-size:1em;font-weight:bold;border-bottom:1px solid #EEE;">ISignal.addOnce()</h4>
<p><em>ISignal.addOnce()</em> prescribes attaching a handler which is called once when the signal dispatches and is removed immediately. Below we use a NativeSignal to wrap the <em>TimerEvent.TIMER_COMPLETE</em>, allowing us to avoid attaching and removing event listeners ourselves. We also now return a <em>Signal</em> which gives the user of the class a strongly-typed signal to what they expect.</p>
<p>
<pre class="brush: as3; highlight: [14]; toolbar: false;">
public class SomethingSignalsAddOnce implements IDoesSomethingWithSignals
{
	public function doSomething(index:int):ISignal
	{
		//create a Signal to return
		const response:ISignal = new Signal(int);

		const timer:Timer = new Timer(index * 100,-1);

		//create a signal from the Timer event
		const signal:NativeSignal = new NativeSignal(timer, TimerEvent.TIMER_COMPLETE, TimerEvent);

		//once TIMER COMPLETE has occurred, we can dispatch our signal - ISignal.addOnce() ensures that any listeners to Timer will be cleaned up
		signal.addOnce(function(evt:TimerEvent):void
		{
			//tell response that something happened (as opposed to dispatching an event, we dispatch the signal)
			response.dispatch(index);
		});

		timer.start();

		return response;
	}
}
</pre>
</p>
<p>This is often very useful, but not always optimal. We may not always want to listen only once &#8211; say if we need to selectively remove the listener based on certain conditions. Sometimes we may only want to remove the listener based on another asynchronous event (as in #4 above).</p>
<h4 id="isignalcallee" style="font-size:1em;font-weight:bold;border-bottom:1px solid #EEE;">Signals and arguments.callee</h4>
<p>Alternatively, we could use the <em>arguments.callee</em> property and do a conditional remove when required (after 5 ticks in the below example):</p>
<p>
<pre class="brush: as3; highlight: [21]; toolbar: false;">
public class SomethingSignalsCallee implements IDoesSomethingWithSignals
{

	public function doSomething(index:int):ISignal
	{
		//create a Signal to return
		const response:ISignal = new Signal(int);

		const timer:Timer = new Timer(100);

		//create a signal from the Timer event
		const signal:NativeSignal = new NativeSignal(timer, TimerEvent.TIMER, TimerEvent);

		var numTicks:int = 0;

		signal.add(function(evt:TimerEvent):void
		{
			if (numTicks++ == 5)
			{
				response.dispatch(index);
				signal.remove(arguments.callee);
				timer.stop();
			}
		});

		timer.start();

		return response;
	}
}
</pre>
</p>
<blockquote style="border:1px dotted #ccc;background-color:#eee;padding:.5em;"><p>You might wonder if you can use <em>arguments.callee</em> within nested closures &#8211; and the answer is yes. Just be aware that each closure has its own definition of the <em>arguments.callee</em>, and it overrides the value from any outer closures.</p>
</blockquote>
<h4 id="isignalremoveall" style="font-size:1em;font-weight:bold;border-bottom:1px solid #EEE;">ISignal.removeAll()</h4>
<p><em>ISignal</em> also expose the convenience method: <em>removeAll()</em>. This can help us when we need to remove listeners in response to another method call.</p>
<p>
<pre class="brush: as3; highlight: [16,29]; toolbar: false;">
public class SomethingSignalsRemoveAll implements IDoesSomethingWithSignals, IDisposable
{
	private var timerSignal:ISignal;
	private var timer:Timer;

	public function doSomething(index:int):ISignal
	{
		//create a Signal to return
		const response:ISignal = new Signal(int);

		timer = new Timer(500);

		//create a signal from the Timer event
		timerSignal = new NativeSignal(timer, TimerEvent.TIMER, TimerEvent);

		timerSignal.add(function():void
		{
			response.dispatch(index);
		});

		timer.start();

		return response;
	}

	public function dispose():void
	{
		timer.stop();
		timerSignal.removeAll();
	}
}
</pre>
</p>
<blockquote style="border:1px dotted #ccc;background-color:#eee;padding:.5em;"><p>Be careful using <em>removeAll()</em> &#8211; if your class aggregates the signal as above, and it never leaves the containing type, fine. However, there may be occasions when you pass a signal around between various classes (as we do with the <em>response</em> signal above). In these classes, using <em>removeAll()</em> could present unwanted results if one developer inadvertently removes listeners that another class attached.</p>
</blockquote>
<h2 id="conclusions" style="font-size:1.3em;border-top:1px solid #CCC;margin-top:1.1em;">Conclusions</h2>
<p>Whichever way you use closures, you need to remember to clean up after yourself, less you end up leaking memory in the Flash player. Asynchronous programming is here to stay (take node.js and Reactive eXtensions for .NET as examples) and we’re lucky that Actionscript &#8211; built on ECMA &#8211; supports it natively. As long as you’re aware of the consequences of attaching inline handlers, you can use closures and the async model in general to design a different approach to solving common asynchronous problems. While it takes a little getting used to, I wholeheartedly recommend giving it a shot &#8211; you might just like it.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/468/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/468/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/468/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=468&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/08/19/cleaning-up-after-closures-in-flash/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Book Review: Too Big to Fail</title>
		<link>http://justinjmoses.wordpress.com/2011/08/12/too-big-to-fail/</link>
		<comments>http://justinjmoses.wordpress.com/2011/08/12/too-big-to-fail/#comments</comments>
		<pubDate>Fri, 12 Aug 2011 13:35:23 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=456</guid>
		<description><![CDATA[Too Big to Fail on Amazon.com An ex-colleague recently told me to safely ignore Andrew Ross Sorkin&#8217;s Too Big To Fail &#8211; &#8220;it&#8217;s little more than propaganda&#8221;, he said. Undeterred, I ploughed through the tome, finding it well-written and informative. While it may have defended certain individuals, it by no means came across as biased; though [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=456&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.amazon.com/Too-Big-Fail-Washington-FinancialSystem--/dp/0143120271/ref=sr_1_1?ie=UTF8&amp;qid=1313120997&amp;sr=8-1" >Too Big to Fail on Amazon.com</a></p>
<p>An ex-colleague recently told me to safely ignore Andrew Ross Sorkin&#8217;s<em> Too Big To Fail</em> &#8211; &#8220;it&#8217;s little more than propaganda&#8221;, he said.</p>
<p>Undeterred, I ploughed through the tome, finding it well-written and informative. While it may have defended certain individuals, it by no means came across as biased; though perhaps I&#8217;m just naive.</p>
<p>Where <em>The Big Short</em> is a fascinating yet brief look at a few key players in the crisis who bet against the market, Too Big to Fail is an exhaustive look at the events that occurred during the credit crisis in 2008. It follows an impressive cast of individuals, from the US Treasury, through the Federal Reserve, and just about every major investment bank in the US.</p>
<p>I confess that getting though the book took some effort. Not because there wasn&#8217;t ample drama and conflict, but chiefly because there was just so many characters to familiarise with.</p>
<p>Much of the book centres around the fall of Lehman Brothers and the attempts of all and sundry to save it. The book makes much of both Dick Fuld, the ex-CEO of Lehman who, by all accounts, tried dearly to save the firm, and Hank Paulson, the US Secretary of the Treasury under Bush, who struggled relentlessly to prevent an economic meltdown (perhaps that&#8217;s the said propaganda?).</p>
<p>Sorkin has evidentially put a lot of work into researching the events of the time, and the book reads surprisingly well; often throwing in well-placed reminders regarding character relationships touched on in the past. I particularly like the occasional inconsequential commentary by those present (eg. he looks fit for his age) or throwaway body-language queues that lead nowhere, immersing the reader in the situation.</p>
<p>While the book focuses primarily on Lehman, it also covers most of the other major events during the crisis. In particular, the buyout of Bear Stearns by JP Morgan for $2 a share with support of the US government (later revised to $10), AIG being propped up by the government shortly letting Lehman fall (by not providing government assistance to any of the buyers) and the eventual takeover of Merrill Lynch by Bank of America.</p>
<p>The question of whether or not the US government were to blame for the depth of the crisis by not saving Lehman remains to be seen. Pick up a copy and make up your own mind. At the very least you&#8217;ll see how they do things on the other side of Wall Street.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/456/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/456/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/456/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=456&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/08/12/too-big-to-fail/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>UI mediation sucks. Mediate behaviours, not views.</title>
		<link>http://justinjmoses.wordpress.com/2011/08/07/ui-mediation-sucks-mediate-behaviours-not-views/</link>
		<comments>http://justinjmoses.wordpress.com/2011/08/07/ui-mediation-sucks-mediate-behaviours-not-views/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 16:05:39 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=415</guid>
		<description><![CDATA[Code for this post can be found on Github. In this post, we’re going to look at how the variance utility for Robotlegs allows mediation against interfaces rather than concrete classes. Apart from the gains in decoupling, we can mediate purely against behaviours, rather than specific implementation. And, as we’re talking interfaces, a UI component [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=415&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p style="background-color:#eee;border:1px dashed #AAA;padding:.5em;">Code for this post can be found on <a title="Github" href="https://github.com/justinjmoses/mediate-behaviours-example" >Github</a>.</p>
<p>In this post, we’re going to look at how the variance utility for Robotlegs allows mediation against interfaces rather than concrete classes. Apart from the gains in decoupling, we can mediate purely against behaviours, rather than specific implementation. And, as we’re talking interfaces, a UI component can implement as many interfaces (behaviours) as it likes!</p>
<ul>
<li>Shout out to <a href="http://twitter.com/guyinthechair">Paul Taylor</a> for the <a href="http://guyinthechair.com/2011/07/design-by-contract-in-robotlegs-1-4/">inspiration of this post</a>.</li>
</ul>
<p>Libraries used in this post:</p>
<ul>
<li><a href="https://github.com/robotlegs/robotlegs-framework/">Robotlegs v1.5.2</a></li>
<li><a href="https://github.com/dnalot/robotlegs-utilities-variance">Robotlegs Variance Utility v1.1</a></li>
<li><a href="https://github.com/robertpenner/as3-signals">As3-Signals v0.9-BETA</a></li>
</ul>
<p style="font-size:larger;font-weight:bold;"><strong>Why use mediation at all?</strong></p>
<p>Mediation is a design pattern that performs the job of managing communication between parts to decouple logic. In terms of modern MVC frameworks, mediators are typically employed to monitor UI pieces from the outside in, so that the UI has no references to the framework whatsoever. The common alternative is the Presentation Model pattern (PM) that typically involves injecting in one or more presentation models to the UI component. As such, the UI component is thus coupled to the particular PMs it uses. That said, when mediating against classes (rather than interfaces, which we’ll get to), we couple the mediator to the UI, which is suboptimal.</p>
<p style="font-size:larger;font-weight:bold;"><strong>Why Robotlegs?</strong></p>
<p>Robotlegs (RL) is a lightweight (50KB) and prescriptive library for MVCS applications. Out of the box it provides us with Mediation, IOC container and Dependency Injection via the familiar [Inject] metadata (thanks to SwiftSuspenders).</p>
<p style="font-size:larger;font-weight:bold;"><strong>Regular (invariant) mediation</strong></p>
<p>Take some UI component: (<strong>SomeComponent.mxml</strong>)</p>
<p>
<pre class="brush: as3;">
&lt;s:VGroup&gt;
    &lt;fx:Script&gt;
        //the mediator will tell me when something happens
        public function asyncReturned():void
        {
            //something happened!
        }

        private function onClick(evt:MouseEvent):void
        {
            //tell whoever's listening to do something
            dispatchEvent(new ControlEvent(ControlEvent.START));
        }
    &lt;/fx:Script&gt;

    &lt;s:Button label=&quot;Start&quot; click=&quot;onClick(event)&quot; /&gt;
&lt;/s:VGroup&gt;
</pre>
</p>
<p>A mediator for this component might look like (<strong>SomeComponentMediator.as</strong>):</p>
<p>
<pre class="brush: as3;">
public class SomeComponentMediator extends Mediator
{
    [Inject]
    public var view:SomeComponent;

    [Inject]
    public var service:ISomeService;

    private var viewHandler:Function;
    private var serviceHandler:Function;

    //called when UI component is added to stage and mediator assigned
    override public function onRegister():void
    {
        //handle control events responding
        viewHandler = function(evt:ControlEvent):void
        {
            serviceHandler = function(evt:ServiceEvent):void
            {
                //some where later on tell the view it is done...
                view.asyncReturned();
            }
            service.addEventListener(ServiceEvent.COMPLETE, serviceHandler);

            service.doSomething();
        }

        //attach the listener
        view.addEventListener(ControlEvent.DO_ASYNC, viewHandler);
    }

    //called when UI component is removed from stage, prior to mediator being destroyed
    override public function onRemove():void
    {
       service.removeEventListener(ServiceEvent.COMPLETE, serviceHandler);
       view.removeEventListener(ControlEvent.DO_ASYNC, viewHandler);
    }
}
</pre>
</p>
<p>Via the ADDED_TO_STAGE event, Robotlegs wires up an instance of a mediator for each UI component it finds. All that it requires is that you map in the mediator:</p>
<p>
<pre class="brush: as3;">
IMediatorMap.mapMediator(SomeComponent, SomeComponentMediator);
</pre>
</p>
<blockquote style="background-color:#eee;border:1px dashed #AAAAAA;padding:1em;"><p>Don’t like extending base classes or want your own implementation of mediation? No problems just implement IMediator instead.</p>
</blockquote>
<p style="font-size:larger;font-weight:bold;"><strong>So why covariance?</strong></p>
<p>Because there are some problems here with mediating directly to views:</p>
<ul>
<li>A UI component can only have one mediator;</li>
<li>The mediator is tightly coupled to the UI control.</li>
</ul>
<p>So, what if we wanted to map to an interface instead? We could include the Robotlegs Variance Utility (as a library to our project), and tweak our mediator mapping call to:</p>
<p>
<pre class="brush: as3;">
IVariantMediatorMap.mapMediator(ISomeComponent, SomeComponentMediator);
</pre>
</p>
<p>The above example becomes:</p>
<p>
<pre class="brush: as3;">
&lt;s:VGroup implements=&quot;ISomeBehaviour&quot;&gt;
	&lt;fx:Script&gt;
		//the mediator will tell me when async returns
		public function asyncReturned():void
		{
			//something happened!
		}

		private function onClick(evt:MouseEvent):void
		{
		     //tell whoever's listening to do something
		     dispatchEvent(new ControlEvent(ControlEvent.START));
		}
        &lt;/fx:Script&gt;

    &lt;s:Button label=&quot;Start&quot; click=&quot;onClick(event)&quot; /&gt;
&lt;/s:VGroup&gt;
</pre>
</p>
<p>Using this interface:</p>
<p>
<pre class="brush: as3;">
[Event(name=&quot;startAsync&quot;,type=&quot;ControlEvent&quot;)]
public interface ISomeBehaviour
{
	function asyncReturned();
}
</pre>
</p>
<p>And the mediator becomes:</p>
<p>
<pre class="brush: as3;">
public class SomeComponentMediator extends Mediator
{
    [Inject]
    public var view:ISomeBehaviour;

    //... (as before)

}
</pre>
</p>
<p>And voila &#8211; we’ve solved both problems in one fell swoop! A UI control can implement as many interfaces as it needs, and our mediates now mediate against a behaviour rather than a concrete UI piece.</p>
<p style="font-size:larger;font-weight:bold;"><strong>So now what?</strong></p>
<p>There’s still room for improvement. Flash has no way to enforce that the class &#8211; SomeComponent &#8211; will actually dispatch the ControlEvent. If we’re writing these interfaces &#8211; these behaviours &#8211; we want a contract that explicitly states which events should be fired. Better yet, we’d like the option to state if these events are a functional level or a type level.</p>
<p style="font-size:larger;font-weight:bold;"><strong>Enter Signals, stage right</strong></p>
<p>Signals provide an alternative to events. They are designed to be used within APIs and class libraries, rather than replacing events altogether (Flash events are well suited to UI hierarchies). Where events fire and are handled at a type (class) level, signals live at the variable level. Not only can we pass them to and return them from methods, we can also enforce their presence in types that implement our interfaces. Check out an earlier post on <a href="http://justinjmoses.wordpress.com/2011/07/07/whats-the-deal-with-signals/">Signals</a>.</p>
<p>By including the lightweight Signals SWC, we have access to the ISignal contract and some common implementations.</p>
<p>Our interface from before now becomes:</p>
<p>
<pre class="brush: as3;">
public interface ISomeBehaviour
{
    function asyncReturned();

    function get start():ISignal;
}
</pre>
</p>
<p>Our view becomes:</p>
<p>
<pre class="brush: as3;">
&lt;s:VGroup implements=&quot;ISomeBehaviour&quot;&gt;
    &lt;fx:Declarations&gt;
        &lt;signals:Signal id=&quot;startSignal&quot; /&gt;
    &lt;/fx:Declarations&gt;

    &lt;fx:Script&gt;
        //the mediator will tell me when something happens
        public function asyncReturned():void
        {
            //something happened!
        }

        //provide access to the type-level signal
        public function get start():ISignal
        {
            return startSignal;
        }
    &lt;/fx:Script&gt;

    &lt;!-- Here we actually send the message to the mediator --&gt;
    &lt;s:Button label=&quot;Start&quot; click=&quot;start.dispatch()&quot; /&gt;
&lt;/s:VGroup&gt;
</pre>
</p>
<p>We actually now have a property <em>start</em>, exposed from the view that implements the interface, that we can attach and remove handlers to in our mediator.</p>
<p>And so our mediator finally becomes:</p>
<p>
<pre class="brush: as3;">
public class SomeComponentMediator extends Mediator
{
    [Inject]
    public var view:ISomeComponent;

    [Inject]
    public var service:ISomeService;

    private var serviceSignal:ISignal;

    override public function onRegister():void
    {
        //handle control events responding
        view.start.add(function():void
        {
            serviceSignal = service.doSomething();

            serviceSignal.add(function():void
            {
                //when the service returns, notify the view
                view.asyncReturned();
            });
        });
    }

    override public function onRemove():void
    {
        serviceSignal.removeAll();
        view.start.removeAll(); //clean up any listeners
    }
}
</pre>
</p>
<p style="font-size:larger;font-weight:bold;"><strong>So what now?</strong></p>
<p>Grab the code on <a title="Github" href="https://github.com/justinjmoses/mediate-behaviours-example" >Github</a> and have a play around. For ease of use, I’ve included the dependencies along with the source.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/415/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/415/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/415/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=415&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/08/07/ui-mediation-sucks-mediate-behaviours-not-views/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Why I Use Powershell</title>
		<link>http://northhorizon.net/2011/why-i-use-powershell/</link>
		<comments>http://northhorizon.net/2011/why-i-use-powershell/#comments</comments>
		<pubDate>Sun, 07 Aug 2011 03:36:11 +0000</pubDate>
		<dc:creator>Daniel Moore</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lab49]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://northhorizon.net/?p=457</guid>
		<description><![CDATA[I&#8217;ve been using Powershell for just over a year now, and its effect on my development workflow has been steadily increasing. Looking back, I have no doubt that it is the most important tool in my belt &#8211; to be perfectly honest, I&#8217;d rather have Powershell than Visual Studio now. Of course, that&#8217;s not to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been using Powershell for just over a year now, and its effect on my development workflow has been steadily increasing. Looking back, I have no doubt that it is the most important tool in my belt &#8211; to be perfectly honest, I&#8217;d rather have Powershell than Visual Studio now. Of course, that&#8217;s not to say Visual Studio isn&#8217;t useful &#8211; it is &#8211; but rather more that Poweshell fills an important role in the development process that isn&#8217;t even approached by other tools on the platform. Visual Studio may be the best IDE on the market, but at the end of the day, there are other tools that can replace it, albeit imperfectly.</p>
<p>To take some shavings off of the top top of the iceberg that is why I use Powershell, I&#8217;d like to share a recent experience of Powershell delivering for me. <span id="more-457"></span></p>
<h2>Setup for Failure</h2>
<p>As a co-orgranizer for the <a href="http://www.meetup.com/NY-Dotnet/">New York .NET Meetup</a> I was tasked with getting the list of attendees off of meetup.com and over to the lovely people at Microsoft who kindly give us space to meet. Now, you might think there&#8217;d be some nifty &#8220;export attendee list to CSV&#8221; function the meetup.com website, but like a lot of software, it doesn&#8217;t do half the things you think it should and this is one of those things. Usually my colleague David assembles the list, but this particular month he was out on vacation. He did, however, point me over to a GitHub repository of a tool that would do the extraction.</p>
<p>Following his advice, I grabbed the repository and brought up the C#/WinForms solution in Visual Studio. Looking at the project structure, I was a bit stunned at the scale of it all. The author had divided his concerns very well into UI, data access, the core infrastructure, and, of course, unit testing. I thought that was pretty peculiar considering all I wanted to do was get a CSV of names and such off of a website. Far be it for me to criticize another developer&#8217;s fastidiousness. Maybe it also launched space shuttles; you never know.</p>
<p>In what I can only now describe as naivety, I hit F5 and expected something to happen. </p>
<p>I was rewarded with 76 errors.</p>
<p>Right off the bat, I realized that the author had botched a commit and forgot a bunch of libraries. I was able to find NHibernate fairly easily with Nuget, but had no luck with &#8220;Rhino.Commons.NHibernate&#8221;. I tried to remove the dependency problem, but didn&#8217;t have much luck. And the whole time I was wondering why the hell you needed all these libraries <b>to extract a damn CSV from the internet</b>.</p>
<h2>The Problem</h2>
<p>Rather than throw more time after the problem, I decided to forge out on my own. Really, how hard could it be to</p>
<ol>
<li>Get an XML doc from the internet</li>
<li>Extract the useful data</li>
<li>Perform some heuristics on the names</li>
<li>Dump a CSV file</li>
</ol>
<p>Being a long-time C# programmer, my knee-jerk reaction was to build a solution in that technology. Forgoing a GUI to spend as little time as possible in building this, I&#8217;d probably build a single file design that ostensibly could consist of a single method. And if that were the case, why not script it?</p>
<p>So if I was going to write a script, what to use? I could write a JavaScript and run it on node.js, but it&#8217;s lacking proper CSV utilities and I&#8217;d have to run it on something other than my main Windows box. Not to mention I don&#8217;t particularly writing in JavaScript, so I&#8217;d probably write it in CoffeeScript and have to compile it, etc, etc. </p>
<p>I briefly considered writing an F# script, but I suspect only about ten people would know what on earth it was, and, at the end of the day, I would like to share my script to others.</p>
<h2>The Solution</h2>
<p>In the end, I concluded what I had known already: Powershell was the tool to use. It had excellent support for dealing with XML (via accelerators) and, as a real scripting language, had no pomp and circumstance.</p>
<p>Here&#8217;s the script I ended up writing:</p>
<pre class="brush:powershell">function Get-MeetupRsvps([string]$eventId, [string]$apiKey) {$nameWord = "[\w-']{2,}" $regex = "^(?'first'$nameWord) ((\w\.?|($nameWord )+) )?(?'last'$nameWord)|(?'last'$nameWord), ?(?'first'$nameWord)( \w\.|( $nameWord)+)?$" function Get-AttendeeInfo {process {$matches = $null $answer = $_.answers.answers_item if(-not ($_.name -match $regex)) { $answer -match $regex | Out-Null }return New-Object PSObject -Property @{ 'FirstName' = $matches.first 'LastName' = $matches.last 'RSVPName' = $_.name 'RSVPAnswer' = $answer 'RSVPGuests' = $_.guests }} }$xml = [Xml](New-Object Net.WebClient).DownloadString("https://api.meetup.com/rsvps.xml?event_id=$eventId`&#038;key=$apiKey") $xml.SelectNodes('/results/items/item[response="yes"]') `| Get-AttendeeInfo `| select FirstName, LastName, RSVPName, RSVPAnswer, RSVPGuests }</pre>
<p>To dump this to a CSV file is then really easy:</p>
<pre class="brush: powershell; gutter: false">Get-MeetupRsvps -EventId 1234 -ApiKey 'MyApiKey' | Export-Csv -Path rsvps.csv -NoTypeInformation</pre>
<p>And because of this design, it&#8217;s really extensible. Potentially, instead of exporting to a CSV, you could pipe the information into another processor that would remove anyone named &#8220;Thorsten.&#8221; Actually, that would look like this:</p>
<pre class="brush: powershell; gutter: false">Get-MeetupRsvps -EventId 1234 -ApiKey 'MyApiKey' `| ? { %_.FirstName -ne 'Thorsten' } ` | Export-Csv -Path rsvps.csv -NoTypeInformation</pre>
<p>It&#8217;d be pretty difficult to do that if I&#8217;d written a C# executable &#8211; you&#8217;d have to go into Excel to do that. Or write a Powershell script. Just saying.</p>
<p>Here&#8217;s the real kicker: I spent all of five minutes writing my Powershell script and then spent minutes tweaking my regex to identify as many names as possible. I didn&#8217;t need to recompile, just F5 again in Poweshell ISE, which you have installed already if you&#8217;re on Windows 7. Since I left the <code>Export-Csv</code> part off during debugging, I could just read the console output and see what I got.</p>
<p>When I was happy with my output, it was dead simple to distribute: throw it in <a href="https://gist.github.com/1091011">a GitHub Gist</a> and move on with my life. If you decide to use it, all you need is Powershell installed (again, are you on Windows 7?) and the ability to copy and paste. No libraries. No worries. If you don&#8217;t like my regex, it couldn&#8217;t be easier to figure out how to replace it. If you want more fields, it&#8217;s easy to see where they should be added.</p>
<p>It&#8217;s really just that easy.</p>
]]></content:encoded>
			<wfw:commentRss>http://northhorizon.net/2011/why-i-use-powershell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lab49&#8242;s David Padbury invited to speak at NYTime&#8217;s TimesOpen</title>
		<link>http://blog.lab49.com/archives/5521</link>
		<comments>http://blog.lab49.com/archives/5521#comments</comments>
		<pubDate>Tue, 02 Aug 2011 13:38:35 +0000</pubDate>
		<dc:creator>Haidee Clarke</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lab49]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[node.js]]></category>

		<guid isPermaLink="false">http://blog.lab49.com/?p=5521</guid>
		<description><![CDATA[David Padbury will present a seminar on node.js on August 16th at the TimesOpen: HTML5 and beyond in NYC. Fellow presenters include Pete LePage from Google and Jeremy Ashkenas from NYtimes.com. To find out more details click here.]]></description>
			<content:encoded><![CDATA[<p>David Padbury will present a seminar on node.js on August 16th at the TimesOpen: HTML5 and beyond in NYC. Fellow presenters include Pete LePage from Google and Jeremy Ashkenas from NYtimes.com. To find out more details click <a href="http://timesopenhtml5.eventbrite.com/">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.lab49.com/archives/5521/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>An introduction to Maven and Flexmojos</title>
		<link>http://justinjmoses.wordpress.com/2011/07/27/an-introduction-to-maven-and-flexmojos/</link>
		<comments>http://justinjmoses.wordpress.com/2011/07/27/an-introduction-to-maven-and-flexmojos/#comments</comments>
		<pubDate>Wed, 27 Jul 2011 14:49:20 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=385</guid>
		<description><![CDATA[I presented an introduction to Maven and Flexmojos last night. The talk is a varient of the one I will be giving at FITC@MAX this year. The talk starts off discussing Maven, the hierarchical structure of projects, POMs and the build life cycle. We then discuss the Flexmojos plugin to build Flex applications. After that, we [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=385&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I presented an introduction to Maven and Flexmojos last night. The talk is a varient of the one I will be giving at <a title="FITC@MAX" href="http://www.fitc.ca/events/about/?event=122" ><strong>FITC@MAX</strong> </a>this year.</p>
<p>The talk starts off discussing Maven, the hierarchical structure of projects, POMs and the build life cycle. We then discuss the Flexmojos plugin to build Flex applications. After that, we talk about repositories &#8211; both local and remote, and discuss how Nexus can perform the role of remote repository within your organisation, proxying to others on the web.</p>
<p>We work through 6 main examples. All code is on <a title="Github" href="https://github.com/justinjmoses/flexmojos-introduction" >Github</a>.</p>
<ol>
<li>The simplest application possible &#8211; a custom Hello World that uses the latest Flexmojos (4.0-RC1) and Flex SDK (4.5.1)</li>
<li>Adding automated unit tests to the build</li>
<li>Installing custom dependencies that aren&#8217;t hosted on the web</li>
<li>Using the Flasbuilder goal to create a Flashbuilder project from a build script</li>
<li>Starting Flex applications from the supported archetypes (templates)</li>
<li>A basic application that has custom dependencies and its own class library.</li>
</ol>
<div id="__ss_8697845" style="width:510px;"><iframe src='http://www.slideshare.net/slideshow/embed_code/8697845' width='510' height='418' scrolling='no'></iframe></div>
<p>Source files: <a title="Source" href="https://github.com/justinjmoses/flexmojos-introduction" >https://github.com/justinjmoses/flexmojos-introduction</a></p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/385/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/385/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/385/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=385&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/07/27/an-introduction-to-maven-and-flexmojos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Book Review: The Big Short</title>
		<link>http://justinjmoses.wordpress.com/2011/07/19/book-review-the-big-short/</link>
		<comments>http://justinjmoses.wordpress.com/2011/07/19/book-review-the-big-short/#comments</comments>
		<pubDate>Tue, 19 Jul 2011 15:29:03 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Finance]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=356</guid>
		<description><![CDATA[The Big Short (on Amazon.com) If you&#8217;re looking for a different perspective on the Credit Crisis of 2008, then look no further. The Big Short follows four of the main players who saw the impending doom of the mortgage bond market and betted against it. Outside finance, the concept of buy low and sell high &#8211; or going [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=356&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a title="The Big Short" href="http://www.amazon.com/Big-Short-Inside-Doomsday-Machine/dp/0393072231" >The Big Short</a> (on Amazon.com)</p>
<p>If you&#8217;re looking for a different perspective on the Credit Crisis of 2008, then look no further. The Big Short follows four of the main players who saw the impending doom of the mortgage bond market and betted against it.</p>
<p>Outside finance, the concept of buy low and sell high &#8211; or <em>going long</em> &#8211; is well understood. Of course, the industry is more than just about investing in growth. The converse to going long &#8211; or <em>selling short </em>- involves selling high and buying lower. In essence, shorting is quite simple. A trader who senses a downward shift in the market, may sell items at the current market price without actually owning them. They do this by selling borrowed securities that they obtain from a third party (paying fees for the privilege) until the market falls enough for them to buy low and replace their borrowed securities. While this may seem great in theory, the downside is that your losses are infinite &#8211; as the final market price you buy at has no ceiling.</p>
<p>Unlike the share market, shorting in the debt market isn&#8217;t always as straight  forward. In order to bet against the market, a new type of Credit Default Swap (essentially insurance against something or someone going bust) was invented to quench the thirst of those desperate to short the subprime bubble. By paying a regular premium, they were assured they&#8217;d receive compensation if a number of loans within the security defaulted. However, in the case of The Big Short, these weren&#8217;t traders hedging their books, this was pure speculation.</p>
<p>As the sub-prime mortgage market took off in the mid-2000s, few people thought it could end. Investments banks were printing their own money, selling off mortgage-backed securities chock-full of subprime (or suboptimal) loans. As the market ballooned, so did these loans, and as anyone living in the US at the time can contest, every man and his dog could get a mortgage for $500K plus with no deposit and no repayments for 2 years. It sounds ludicrous, but it really happened.</p>
<p>The Big Short follows the movements of four separate groups, intertwined and yet operating on their own, that shorted the sub-prime market. On the way, they had to fight off endless criticism from their peers, and eventually made truckloads of money.</p>
<p>The first is Mike Burry, founder of the hedge fund Scion and a brilliant recluse who first cottoned on to the intrinsic flaws within the market back in 2005 &#8211; well before his peers. Next comes Steven Eisman, the cynical money manager who, independent of Burry, saw the signs on the horizon and moved into shorting the market. Following is Greg Lippmann, a Deutsche Bank trader  who cottoned on to the situation fairly early in the piece and had to fight his employer to continue paying those CDS premiums against the movements of the entire market. Finally, there&#8217;s the Wall St success story of Cornwell Capital &#8211; originally a Californian-based outfit that had made its mark scouring for mis-priced securities in the stock market.</p>
<p>This book, by the author of <em>Liar&#8217;s Poker</em>, flows well and is, for the most part, chronological. It&#8217;s easy to follow even with a rudimentary understanding of financial markets. The characters are thorough and detailed; indeed, the sense of empathy he creates towards subjects is so compelling, the book is difficult to put down. The pace picks up around the meltdown itself and both the climax and denouement are well-handled &#8211; especially for a very small subset of a very large, and shockingly all too true, story.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/356/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/356/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/356/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=356&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/07/19/book-review-the-big-short/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>What’s the deal with Signals?</title>
		<link>http://justinjmoses.wordpress.com/2011/07/07/whats-the-deal-with-signals/</link>
		<comments>http://justinjmoses.wordpress.com/2011/07/07/whats-the-deal-with-signals/#comments</comments>
		<pubDate>Fri, 08 Jul 2011 03:06:45 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Adobe Flex]]></category>
		<category><![CDATA[Flex]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=302</guid>
		<description><![CDATA[Signals. Heard of them? What's the big deal you say?

Simple. The event system in AS3 is both limited and antiquated. True, native AS3 events offer a convenient way of messaging (bubbling) withinUI hierarchies. Yet, at an abstract API level, they more often as not restrict the developer than aid them.

Chiefly, what Robert Penner has done with <strong>as3-signals</strong> is create a way to represent events as variables, rather than as magical strings firing off at the type (class) level. It sounds simple. It is. Yet the implications for your architecture is vast.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=302&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a title="Signals Home" href="https://github.com/robertpenner/as3-signals" >Signals</a>. Heard of them? What&#8217;s the big deal you say?</p>
<p>Simple. The event system in AS3 is both limited and antiquated. True, native AS3 events offer a convenient way of messaging (bubbling) withinUI hierarchies. Yet, at an abstract API level, they more often as not restrict the developer than aid them.</p>
<p>Chiefly, what Robert Penner has done with <strong>as3-signals</strong> is create a way to represent events as variables, rather than as magical strings firing off at the type (class) level. It sounds simple. It is. Yet the implications for your architecture is vast.</p>
<p>Consider the following interface of asynchronous methods:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
public interface IServiceStream
{
  function open():void;
  function close():void;
}</pre>
</p>
<p>Now, as the contract is asynchronous, we&#8217;ll need some events to notify us when methods have completed. Let&#8217;s say we have the following events:</p>
<ul>
<li>OPENED</li>
<li>CLOSED</li>
<li>ERROR</li>
<li>TIMEOUT</li>
</ul>
<p>In keeping with the native AS3 model, the best we can hope for is using the following metadata at the type level:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
[Event(name=&quot;streamOpened&quot;,type=&quot;...&quot;)]
[Event(name=&quot;streamClosed&quot;,type=&quot;...&quot;)]
[Event(name=&quot;streamError&quot;,type=&quot;...&quot;)]
[Event(name=&quot;streamTimeout&quot;,type=&quot;...&quot;)]
public interface IServiceStream
{
 //...
}
</pre>
</p>
<p>There are four problems with this approach:</p>
<ol>
<li>Decorating via metadata does not enforce that implementors of the interface actually dispatch these events.</li>
<li>We should, for completeness, define the events somewhere as static constants. This means we can no longer simply write interfaces, and need to write event implementations and deploy them with our API;</li>
<li>We&#8217;re using magic strings, and as there is no compile-time checking of the metadata, we&#8217;re opening ourselves up to illusive runtime errors, if the wrong events are dispatched.</li>
<li>There is nothing to specify which events fire when &#8211; and which events belong to which method, and which belong to the class itself.</li>
</ol>
<div>The first two are fairly straightforward, so let&#8217;s focus on the latter two.</div>
<p style="font-size:larger;"><strong>Magic Strings and No Contract</strong></p>
<div>We have no way of tying the event type to the constant in some Event class it will eventually correspond to. &#8220;streamOpened&#8221; may map to ServiceStreamEvent.OPENED, and yet we cannot know this at the metadata level (not for the interface or even the implementor). From #1, it is evident that although we can put these requirements in, we cannot enforce their usage.</div>
<p style="font-size:larger;"><strong>Method vs Type-level Events </strong></p>
<div>Anyone listening to an implementor of our interface, would listen at the type level for all events, and deal with them as they occurred.</div>
<p>For example:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
var service:IServiceStream = new ServiceStreamImplementation(...);

service.addEventListener(ServiceStreamEvent.OPENED, function(evt:Event):void { ... } );
service.addEventListener(ServiceStreamEvent.CLOSED, function(evt:Event):void { ... } );
service.addEventListener(ServiceStreamEvent.ERROR, function(evt:Event):void { ... } );
service.addEventListener(ServiceStreamEvent.TIMEOUT, function(evt:Event):void { ... } );

//later when required
service.open();
</pre>
</p>
<div>We&#8217;ve been forced to declare all our handlers in one point, early enough to precede the calling of any event-dispatching methods. Anyone reading the code will have no real knowledge at which point the implementing class dispatches which event &#8211; hence why all the listeners need to be adding initially. As the interface writer, all we can do is say &#8220;this interface can dispatch any of these events&#8221; &#8211; we cannot even enforce that they are used. From #1 above, the metadata is not enforced, it&#8217;s just decoration.</div>
<p>Here is where Signals come in. Let&#8217;s rewrite the interface using simple signals.</p>
<div>
<pre class="brush: as3; wrap-lines: false;">
public interface IServiceStream
{
  function open():ISignal;
  function close():ISignal;
}</pre>
</p>
</div>
<div>Now let&#8217;s look at a partial implementation.</div>
<div>
<pre class="brush: as3; wrap-lines: false;">
import mx.rpc.events.ResultEvent;
import mx.rpc.http.HTTPService;

import org.osflash.signals.ISignal;
import org.osflash.signals.Signal;

public class ServiceStream implements IServiceStream
{
	public function open():ISignal
	{
		var signal:Signal = new Signal(Object);

		//do something asynchronously...
		var httpService:HTTPService = new HTTPService();
		httpService.addEventListener(ResultEvent.RESULT,
			function(evt:ResultEvent):void
			{
				//use the closure to access your signal and dispatch it async
				signal.dispatch(evt.result);
			});

		httpService.send();

		return signal;
	}

	//function close();
}
</pre>
</p>
</div>
<p>Now, the usage of this implementation can become:</p>
<div>
<pre class="brush: as3; wrap-lines: false;">
var service:IServiceStream = new ServiceStreamImplementation(...);

service.open().addOnce(function(result:Object):void
{
    //do something with your returned &quot;result&quot;
});
</pre>
</p>
</div>
<p><strong>In one fell swoop we fixed all four of the problems with events.</strong> We even have the convenience methods <em>addOnce()</em> and <em>removeAll()</em> from the ISignal interface. The former ensures your listener is removed after it is first used, the latter is pretty self-explanatory. If you look even closer, you&#8217;ll see we just implemented the <a title="Fluent Interface" href="http://en.wikipedia.org/wiki/Fluent_interface" >Fluent interface</a> for free.</p>
<p style="line-height:1.2;background-color:#eeeeee;border:1px solid #CCCCCC;padding:5px;">Imagine this in your mediator pattern &#8211; your UIs by definition have no reference to their mediator. Now they have a prescribed way of notifying their mediators that something has occurred.</p>
<p style="font-size:larger;"><strong>Wait a second. What about those other events?</strong></p>
<p>How do you return multiple items from a regular method call &#8211; compose a type for your requirements.</p>
<p>You could write the following signal collection:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
public class ServiceSignals
{
	public var open:ISignal = new Signal(Object);
	public var error:ISignal = new Signal(String);
	public var timeout:ISignal = new Signal();
}
</pre>
</p>
<p>and change your interface to:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
public interface IServiceStream
{
  function open():ServiceSignals;
  //...
}
</pre>
</p>
<p>Better yet, you could keep your interface and simply conform your Signal collection into an ISignal with a default listener/dispatcher:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
public class ServiceSignal extends Signal
{
	var open:ISignal = new Signal(Object);
	var error:ISignal = new Signal(String);
	var timeout:ISignal = new Signal();

	override public function add(listener:Function):ISignalBinding
	{
		return open.add(listener);
	}

	override public function addOnce(listener:Function):ISignalBinding
	{
		return open.addOnce(listener);
	}

	override public function dispatch(...parameters):void
	{
		open.dispatch();
	}

	override public function remove(listener:Function):ISignalBinding
	{
		return open.remove(listener);
	}

	override public function removeAll():void
	{
		open.removeAll();
	}
}
</pre>
</p>
<p>Then you could use it as such:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
var service:IServiceStream = new ServiceStreamImplementation(...);

var signal:ServiceSignal = service.open();

signal.addOnce(function(result:Object):void
{
    //do something with your returned &quot;result&quot;
});

signal.error.addOnce(...);

signal.timeout.addOnce(...);
</pre>
</p>
<p>Perhaps you&#8217;re not a huge fan of this solution. You may find that the error &amp; timeout signals are type-level events, and you don&#8217;t want to have to add handlers for both open() and close(). OK &#8211; so what about this implementation?</p>
<p>
<pre class="brush: as3; highlight: [30]; wrap-lines: false;">
public class ServiceStream implements IServiceStream
{
	public var error:ISignal = new Signal(String);
	public var timeout:ISignal = new Signal();

	private var _time:int = 30000;
	private var timer:Timer;

	public function open():ISignal
	{
		var signal:Signal = new Signal(Object);

		//do something asynchronously...
		var httpService:HTTPService = new HTTPService();
		httpService.addEventListener(ResultEvent.RESULT,
			function(evt:ResultEvent):void
			{
				//use the closure to access your signal and dispatch it async
				signal.dispatch(evt.result);
			});

		httpService.addEventListener(FaultEvent.FAULT,
			function(evt:FaultEvent):void
			{
				error.dispatch(evt.fault.faultString);
			});

		timer = new Timer(_time,1);

		var timerHandler:Function = function(evt:TimerEvent):void
			{
				timeout.dispatch();
				timer.removeEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);
			}
		timer.addEventListener(TimerEvent.TIMER_COMPLETE, timerHandler);

		httpService.send();

		timer.start();

		return signal;
	}

	//function close();

}
</pre>
</p>
<p style="line-height:1.2;background-color:#eeeeee;border:1px solid #CCCCCC;padding:5px;">Notice how we define the handler function as a variable so we can remove it in the listener. This is replicating the ISignal.addOnce() functionality. True, we could have used weak event listeners to allow for garbage collection, however this way is closer to our approach with Signals, so we&#8217;ll keep it for consistency.</p>
<p>Your implementor could then be used like this:</p>
<p>
<pre class="brush: as3; wrap-lines: false;">
var service:IServiceStream = new ServiceStreamImplementation(...);

service.open().addOnce(function(result:Object):void
{
    //do something with your returned &quot;result&quot;
});

service.error.addOnce(function(message:String):void
{
    //handle error
});

service.timeout.addOnce(function():void
{
    //handle timeout
});

service.close().addOnce(function():void
{
    //now closed
});
</pre>
</p>
<p>Whichever way you decide, Signals give you the choice you need to make the best decision for your API.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/302/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/302/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/302/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=302&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/07/07/whats-the-deal-with-signals/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Why bother writing unit tests?</title>
		<link>http://justinjmoses.wordpress.com/2011/07/03/why-bother-writing-unit-tests/</link>
		<comments>http://justinjmoses.wordpress.com/2011/07/03/why-bother-writing-unit-tests/#comments</comments>
		<pubDate>Sun, 03 Jul 2011 22:19:05 +0000</pubDate>
		<dc:creator>Justin Moses</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://justinjmoses.wordpress.com/?p=296</guid>
		<description><![CDATA[It&#8217;s funny to me how much of a fait accompli unit tests, continuous integration and agile methodologies have become. And, how those outside the scene understand so little of the intrinsic value. The more I talk with those developers on the outside, it becomes apparent just how wide the gap has become. You see, I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&#38;blog=2539888&#38;post=296&#38;subd=justinjmoses&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s funny to me how much of a fait accompli unit tests, continuous integration and agile methodologies have become. And, how those outside the scene understand so little of the intrinsic value. The more I talk with those developers on the outside, it becomes apparent just how wide the gap has become.</p>
<p>You see, I was never a fan of unit tests. Never.</p>
<p>Like many during the dotcom boom, I cut my teeth as a web developer, surrounding myself with clients and designers. I thought I was the bees knees. Why would I bother writing tests that would have to be refactored along with my code?</p>
<p>Deep down, I knew there was value. I knew it. There was no way that so many talented and capable developers were advocating their use if there wasn&#8217;t some significant value-add. But writing those tests felt like going to the dentist &#8211; and damn it if I was going to go willingly.</p>
<p>Soon enough, I found myself cornered into writing them. I gnashed my teeth, wrote the code, and then pointed and laughed gleefully each time I was forced to refactor. &#8220;See!&#8221; &#8220;See!&#8221; I would shout emphatically, and then blithely announce that the rest of my day was now effectively gone.</p>
<p>Initially, I saw test writing as most newbies do &#8211; as a way to ensure my code still worked as prescribed given an ever-changing system. I had my doubts to the effectiveness of such a principle, but I kept them to myself.</p>
<p>Then I thought &#8211; OK, so the PM wants these tests so they can sell it to the client. Work done, tests done &#8211; acceptance tests passed. &#8220;Done done&#8221;, and all that jazz. Makes sense, right? If you&#8217;re going to go agile, you better be able to ensure you&#8217;re actually building something every sprint, rather than just tinkering away and demoing little POCs.</p>
<p>It soon became apparent however, that I&#8217;d seriously underestimated the practice. Most of the discussions around software development in the post-web world &#8211; such as dependency injection, inversion of control and the problem with global state (ie. statics) &#8211; started to have a lot more meaning. I could no longer use aggregation or static singletons as helpers &#8211; even if I wanted to. Everything had to be injected and mocked, and the dependencies themselves had their own unit tests. Loose coupling became less of a nice-to-have, and more of a must-have.</p>
<p>It all suddenly made a lot of sense. My unit tests were enforcing best-practices on me and were actually helping me create my classes. Encapsulation, separation of concerns &#8211; each class had its purpose and my tests helped ensure that they remained that way.</p>
<p>Of course, I still find myself refactoring. I wouldn&#8217;t be much of a coder if I didn&#8217;t. You know what though - I&#8217;m finding it a lot less painful than it used to be. Everything is a lot more compartmentalised, and the code is self-describing. It&#8217;s no wonder there are scores of developers evangelising test-driven development (and, consequently, a counter-culture warning against over-dependence on test coverage).</p>
<p>If you don&#8217;t write unit tests, do yourself a favour. Start.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/justinjmoses.wordpress.com/296/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/justinjmoses.wordpress.com/296/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/justinjmoses.wordpress.com/296/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=justinjmoses.wordpress.com&amp;blog=2539888&amp;post=296&amp;subd=justinjmoses&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://justinjmoses.wordpress.com/2011/07/03/why-bother-writing-unit-tests/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Patterns with MEF and RX</title>
		<link>http://northhorizon.net/2011/patterns-with-mef-and-rx/</link>
		<comments>http://northhorizon.net/2011/patterns-with-mef-and-rx/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 21:47:57 +0000</pubDate>
		<dc:creator>Daniel Moore</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://northhorizon.net/?p=443</guid>
		<description><![CDATA[Since I started using RX, events have played less and less of a role in my code. It&#8217;s true that in the same way LINQ has relegated for-loops to only niche situations, RX is making events all but obsolete. What does this mean for the EventAggregator? Certainly, you can implement your own version using RX. [...]]]></description>
			<content:encoded><![CDATA[<p>Since I started using RX, events have played less and less of a role in my code. It&#8217;s true that in the same way LINQ has relegated for-loops to only niche situations, RX is making events all but obsolete. What does this mean for the <code>EventAggregator</code>? Certainly, <a href="http://joseoncode.com/2010/04/29/event-aggregator-with-reactive-extensions/" >you can implement your own version using RX</a>. But, if you happen to be using MEF (preferably as your IOC container) you can even get rid of that. <span id="more-443"></span></p>
<h2>Introducing the Streams Pattern</h2>
<p>First we need to create a &#8220;stream provider&#8221;. The purpose of this class is to establish a single place that &#8220;owns&#8221; the stream. I like to use the stream provider to establish default values and behavior:</p>
<pre class="brush:csharp">public static class StreamNames {private const string Prefix = "Streams_"; public const string Accounts = Prefix + "Accounts"; public const string SelectedAccount = Prefix + "SelectedAccount"; }// No need to export this type. An instance will be // shared between the two child exports. public class AccountStreamProvider {[ImportingConstructor] public AccountStreamProvider(IAccountService accountService) {// Defer the query for the list of accounts until the first subscription var publishedAccounts = Observable .Defer(() =&gt; Observable.Return(accountService.GetAccounts())) .Publish(); publishedAccounts.Connect(); Accounts = publishedAccounts; SelectedAccount = new ReplaySubject(1); // Take the first account and set it as the initially selected account. Accounts .Take(1) .Select(Enumerable.FirstOrDefault) .Subscribe(SelectedAccount.OnNext); }[Export(StreamNames.Accounts)] public IObservable&lt;IEnumerable&lt;Account&gt;&gt; Accounts { get; set; }[Export(StreamNames.SelectedAccount)] [Export(StreamNames.SelectedAccount, typeof(IObservable&lt;Account&gt;)] public ISubject&lt;Account&gt; SelectedAccount { get;set; }}</pre>
<p>Already the benefits of RX over the <code>EventAggregator</code> are showing.</p>
<p>Now we just need to get a reference to our exports in a relevant view model:</p>
<pre class="brush:csharp">public static class Extensions {public static void DisposeWith(this IDisposable source, CompositeDisposable disposables) {disposables.Add(source); }} [Export, PartCreationPolicty(CreationPolicy.NotShared)] public class AccountViewModel : BindableBase, IDisposable {private readonly Streams _streams; private readonly CompositeDisposable _disposables; [Export] public class Streams {[Import(StreamNames.Accounts)] public IObservable&lt;IEnumerable&lt;Account&gt;&gt; Accounts { get; set; }[Import(StreamNames.SelectedAccount)] public ISubject&lt;Account&gt; SelectedAccount { get; set; }} [ImportingConstructor] public AccountViewModel(Streams streams) {_streams = streams; _disposables = new CompositeDisposable(); _streams .Accounts .Subscribe(a =&gt; Accounts = a) .DisposeWith(_disposables); _streams .SelectedAccount .Subscribe(a =&gt; SelectedAccount = a) .DisposeWith(_disposables); }private IEnumerable&lt;Account&gt; _accounts; public IEnumerable&lt;Account&gt; Accounts {get { return _accounts; }private set { SetProperty(ref _accounts, value, "Accounts"); }} private Account _selectedAccount; public Account SelectedAccount {get { return _selectedAcccount; }private set { SetProperty(ref _selectedAccount, value, "SelectedAccount", OnSelectedAccountChanged); }} // This method is only called when _selectedAccount // actually changes, so there's no indirect recursion. private void OnSelectedAccountChanged() {_streams.SelectedAccount.OnNext(_selectedAccount); }public void Dispose() {_disposables.Dispose(); }}</pre>
<p>By the way, I&#8217;m using <code>BinableBase</code> from my <a href="https://github.com/danielmoore/InpcTemplate/blob/master/InpcTemplate/BindableBase.cs">INPC template</a>.</p>
<h2>Introducing the Config Pattern</h2>
<p>If you&#8217;ve been using RX for a while, you might have noticed that I forgot to put my setters on the dispatcher. Sure, I could rely on automatic dispatching to fix that problem, but if my queries got any more complicated It&#8217;d be better for me to take care of the dispatch myself.</p>
<p>Of course, the problem with <code>ObserveOnDispatcher</code> is that it makes testing a huge pain. Fortunately, we can use MEF to get around that problem, too.</p>
<pre class="brush:csharp; highlight:[19, 34, 40]">public class AccountViewModel : BindableBase, IDisposable {private readonly Streams _streams; private readonly Config _config; private readonly CompositeDisposable _disposables; [Export] public class Streams {[Import(StreamNames.Accounts)] public IObservable&lt;IEnumerable&lt;Account&gt;&gt; Accounts { get; set; }[Import(StreamNames.SelectedAccount)] public ISubject&lt;Account&gt; SelectedAccount { get; set; }} [Export] public class Config {public virtual IScheduler DispatcherScheduler { get { return Scheduler.Dispatcher; } } }[ImportingConstructor] public AccountViewModel(Streams streams, Config config) {_streams = streams; _config = config; _disposables = new CompositeDisposable(); _streams .Accounts .ObserveOn(_config.DispatcherScheduler) .Subscribe(a =&gt; Accounts = a ).DisposeWith(_disposables); _streams .SelectedAccount .ObserveOn(_config.DispatcherScheduler) .Subscribe(a =&gt; SelectedAccount = a) .DisposeWith(_disposables); }// ... }</pre>
<p>Since the <code>DispatcherScheduler</code> property is virtual, it&#8217;s easy to mock it out. Using Moq, all you need to do is:</p>
<pre class="brush:csharp; gutter:false">Mock.Of&lt;AccountViewModel.Config&gt;(m =&gt; m.DispatcherScheduler == Scheduler.Immediate)</pre>
]]></content:encoded>
			<wfw:commentRss>http://northhorizon.net/2011/patterns-with-mef-and-rx/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Presenter vs. Mediator</title>
		<link>http://www.michelboudreau.com/2011/05/19/presenter-vs-mediator/</link>
		<comments>http://www.michelboudreau.com/2011/05/19/presenter-vs-mediator/#comments</comments>
		<pubDate>Thu, 19 May 2011 21:48:15 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Advanced Visualization]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=693</guid>
		<description><![CDATA[This discussion has raged on for some time. Both are fairly common patterns used for front-end development; it&#8217;s a new take on the classic MVC pattern. Recently, the argument has been re-ignited by the choice between two great application frameworks for Flex: RobotLegs and Parsley. I will say this right away, I&#8217;m biased towards Parsley [...]]]></description>
			<content:encoded><![CDATA[<p>This discussion has raged on for  some time.  Both are fairly common patterns used for front-end development; it&#8217;s a new take on the classic MVC pattern.  Recently, the argument has been re-ignited by the choice between two great application frameworks for Flex: <a href="http://www.robotlegs.org/" >RobotLegs</a> and <a href="http://www.spicefactory.org/parsley/" >Parsley</a>.</p>
<p><span id="more-693"></span></p>
<p>I will say this right away, I&#8217;m biased towards Parsley and have advocated its use for over a year and a half now.  It has time and time again proven itself a reliable, robust and rapid framework for application development.  Its track record is quite impressive;  It was used to build some of the world&#8217;s largest Flex applications.  Jens Halm, the creator of Parsley, has done a wonderful job at making his framework extensible, fast and optimized for both Flash and Flex.  Robotlegs is also a good framework, don&#8217;t get me wrong, it just doesn&#8217;t capture me as much and it&#8217;s not optimized for Flex (pure Actionscript), but  in the end it comes down to your development preference.</p>
<p>Now to ask the question, which pattern we use for our project? <a href="http://en.wikipedia.org/wiki/Model-view-presenter" >Presenter</a> or <a href="http://en.wikipedia.org/wiki/Mediator_pattern" >Mediator</a>?  Parsley is built around the Presenter pattern while RobotLegs uses Mediator.  Simply speaking, the difference between the two is fairly minimal, but can affect your project quite a bit.  Here&#8217;s a quick diagram on how they work:</p>
<p><a href="http://www.michelboudreau.com/wp-content/uploads/2011/05/StandardsDesignPatterns.png"><img class="aligncenter size-full wp-image-733" title="Standards&amp;DesignPatterns" src="http://www.michelboudreau.com/wp-content/uploads/2011/05/StandardsDesignPatterns.png" alt="" width="455" height="325" /></a></p>
<p>If you remember your UML class diagrams, you would see that a Mediator can only have one View, while the View can have many Mediators.  In this case, the Mediator is the &#8216;man-in-the-middle&#8217; since nobody else knows about it; its sole purpose is to listen to the View and give it data.  The View communicates with the Mediator through events to which the Mediator acts upon.  One thing I like about this pattern is that it forces developers to use a proper &#8220;data in, events out&#8221; methodology and separates the concerns of the business from the View.  This also creates decoupled components since there&#8217;s no hard dependency in the View; it could still fully function if it is moved into another project.</p>
<p>For the Presenter, things are a bit different since the View knows about it.  The Presenter is there to just present data which is easily binded within the View, but this is problematic since it&#8217;s coupling your View to that Presenter and even the model (data).  However, you don&#8217;t need to use events within the View to communicate to your Presenter since you can access its public functions directly.  It&#8217;s easier to use this method because it limits the code needed to communicate between the View and the Presenter, but it&#8217;s coupling your View.</p>
<p>In the diagram, you might have noticed that with a Mediator pattern you can have a View with several Mediators and even reuse the Mediators on other Views.  This makes the <em>Mediator more of a View based pattern</em>.  The Presenter however doesn&#8217;t care and a View can have multiple Presenters which can (and should) be reused across multiple Views to display the data they need.  This makes the <em>Presenter more of a data based pattern</em> since it&#8217;s job is to give access to data and manage it.</p>
<p>There you have it.  One thing to remember is that patterns are meant to help you develop, not make it harder.   Since I love Parsley so much and had a need for a Mediator pattern for a project (needed to decouple the component) and Parsley only provides a Presenter pattern, I extended the framework to include a Mediator tag. <a href="https://github.com/mboudreau/Parsley-Mediator" > It&#8217;s completely open source and now on GitHub</a>.  Enjoy.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2011/05/19/presenter-vs-mediator/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New York Flex Meetup Videos</title>
		<link>http://www.michelboudreau.com/2011/05/10/new-york-flex-meetup-videos/</link>
		<comments>http://www.michelboudreau.com/2011/05/10/new-york-flex-meetup-videos/#comments</comments>
		<pubDate>Wed, 11 May 2011 03:18:15 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Advanced Visualization]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=720</guid>
		<description><![CDATA[Last night we had another meetup at the Lab49 hideout. This time around, we had my co-worker and friend Paul Taylor present on Adobe&#8217;s RTE &#038; TLF engine as well as his alternative project, TinyTLF. As an added bonus, we had the founder of GraniteDS, Franck Wolff, come talk to us about what Granite can [...]]]></description>
			<content:encoded><![CDATA[<p>Last night we had another meetup at the Lab49 hideout.  This time around, we had my co-worker and friend <a href="http://guyinthechair.com/" >Paul Taylor</a> present on Adobe&#8217;s RTE &amp; TLF engine as well as his alternative project, <a href="http://www.guyinthechair.com/tag/tinytlf/" >TinyTLF</a>. As an added bonus, we had the founder of <a href="http://www.graniteds.org/" >GraniteDS</a>, Franck Wolff, come talk to us about what Granite can do for us and our project.</p>
<p>Videos for both presentations are available after the break.</p>
<p><span id="more-720"></span></p>
<div class="oembed oembed-video oembed-ustream-tv oembed-video-ustream-tv"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="296" id="utv958092" name="utv_n_418189"><param name="flashvars" value="loc=%2F&amp;autoplay=false&amp;vid=14597709&amp;locale=en_US" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.ustream.tv/flash/viewer.swf" /><embed flashvars="loc=%2F&amp;autoplay=false&amp;vid=14597709&amp;locale=en_US" width="480" height="296" allowfullscreen="true" allowscriptaccess="always" id="utv958092" name="utv_n_418189" src="http://www.ustream.tv/flash/viewer.swf" type="application/x-shockwave-flash" /></object></div>
<div class="oembed oembed-video oembed-ustream-tv oembed-video-ustream-tv"><object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="480" height="296" id="utv908207" name="utv_n_501998"><param name="flashvars" value="loc=%2F&amp;autoplay=false&amp;vid=14598584&amp;locale=en_US" /><param name="allowfullscreen" value="true" /><param name="allowscriptaccess" value="always" /><param name="src" value="http://www.ustream.tv/flash/viewer.swf" /><embed flashvars="loc=%2F&amp;autoplay=false&amp;vid=14598584&amp;locale=en_US" width="480" height="296" allowfullscreen="true" allowscriptaccess="always" id="utv908207" name="utv_n_501998" src="http://www.ustream.tv/flash/viewer.swf" type="application/x-shockwave-flash" /></object></div>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2011/05/10/new-york-flex-meetup-videos/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flex Spoon!</title>
		<link>http://www.michelboudreau.com/2011/05/10/flex-spoon/</link>
		<comments>http://www.michelboudreau.com/2011/05/10/flex-spoon/#comments</comments>
		<pubDate>Tue, 10 May 2011 21:58:07 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Advanced Visualization]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=711</guid>
		<description><![CDATA[Spoon is a new project created by Flex expert Michael Labriola to create a community driven Flex SDK.  It&#8217;s also a play-on word of GitHub&#8217;s &#8216;fork&#8216; since the project doesn&#8217;t diverge off from the Flex SDK, but instead keeps up with it as well as merge in community created patches and enhancements. In a way, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.spoon.as/" >Spoon</a> is a new project created by Flex expert <a href="http://www.twitter.com/mlabriola" >Michael Labriola</a> to create a community driven Flex SDK.  It&#8217;s also a play-on word of GitHub&#8217;s &#8216;<a href="http://help.github.com/fork-a-repo/" >fork</a>&#8216; since the project doesn&#8217;t diverge off from the Flex SDK, but instead keeps up with it as well as merge in community created patches and enhancements.</p>
<p>In a way, this project (once it gets started in full force) will be one step ahead of Adobe because of the sheer number of developer resources out there on the web.  Definitely something to keep an eye on, so please sign up and contribute!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2011/05/10/flex-spoon/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sparklines in WPF and Silverlight</title>
		<link>http://blog.jimmy.schementi.com/2011/05/sparklines-in-wpf-and-silverlight.html</link>
		<comments>http://blog.jimmy.schementi.com/2011/05/sparklines-in-wpf-and-silverlight.html#comments</comments>
		<pubDate>Mon, 09 May 2011 04:15:00 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Advanced Visualization]]></category>
		<category><![CDATA[Finance]]></category>
		<category><![CDATA[Lab49]]></category>
		<category><![CDATA[Silverlight]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[ One seemingly-trivial-yet-recurring problem in financial software is the need for a live-updating line-chart. However, from multiple conversations with Lab49 folks, as well as from experience during my first project, I’ve learned that most WPF/Silve...]]></description>
			<content:encoded><![CDATA[<p><a href="http://lh3.ggpht.com/_OqCZhp9yI0Q/TcdqGOwvLII/AAAAAAAAAXw/kv7ipoVOWWU/s1600-h/image%5B38%5D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; padding-top: 0px" title="image" border="0" alt="image" src="http://lh5.ggpht.com/_OqCZhp9yI0Q/TcdqHYBck1I/AAAAAAAAAX0/TfMiLAp5p9w/image_thumb%5B28%5D.png?imgmax=800" width="480" height="240"></a></p>
<p>One seemingly-trivial-yet-recurring problem in financial software is the need for a live-updating line-chart. However, from multiple conversations with <a href="http://lab49.com" >Lab49</a> folks, as well as from experience during my first project, I’ve learned that most WPF/Silverlight charting packages suck in various ways, especially if you’re updating their data frequently. Seems like everyone just rolls their own line chart and tailors it to each project, but doesn’t share it for some reason. I’d like to break that trend by sharing and early version of <a href="http://github.com/jschementi/sparkline" >my own sparkline control for WPF and Silverlight</a>.</p>
<p align="left"><a href="http://github.com/jschementi/sparkline"><strong><font size="3">http://github.com/jschementi/sparkline</font></strong></a></p>
<p><strong>Sample Usage:</strong> </p>
<p><script src="https://gist.github.com/961143.js"> </script>
<p>It’s implementation is very basic; <a href="https://github.com/jschementi/sparkline/blob/master/Schementi.Controls.Sparkline/Sparkline.xaml.cs#L255" >Sparkline.AddTimeValue</a> constructs a point at the next time interval and adds it to a <a href="http://msdn.microsoft.com/en-us/library/system.windows.shapes.polyline.aspx" >Polyline</a>. You can control the sparkline’s visuals, including adding visible points along the line and showing horizontal lines for the latest/highest/lowest values. The source builds assemblies for both .NET 4.0 and Silverlight 4.</p>
<p>There are obvious features missing like rendered axis or variable x-axis (time) values, but hopefully this provides a simple starting place for anyone else needing a very simple updating line graph. </p>
<p>By the way, <a href="http://decav.com/" >Andre de Cavaignac</a>, a colleague of mine at Lab49, and Daniel Simon shared their own a while back: <a href="http://blog.lab49.com/archives/2028" >Live Updating Line Graph in WPF</a>. Let me know if there are any others out there.</p>
<p>Anyways, <a href="http://en.wikipedia.org/wiki/Mother's_Day" >Happy Mother’s Day</a>!</p>
<div class="blogger-post-footer"><img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/5419182-5879555519916795818?l=blog.jimmy.schementi.com' alt='' /></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.jimmy.schementi.com/2011/05/sparklines-in-wpf-and-silverlight.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Coercing ViewModel Values with INotifyPropertyChanged</title>
		<link>http://northhorizon.net/2011/coercing-viewmodel-values-with-inotifypropertychanged/</link>
		<comments>http://northhorizon.net/2011/coercing-viewmodel-values-with-inotifypropertychanged/#comments</comments>
		<pubDate>Sun, 08 May 2011 21:21:14 +0000</pubDate>
		<dc:creator>Daniel Moore</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Advanced Visualization]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://northhorizon.net/?p=429</guid>
		<description><![CDATA[Perhaps one of the most ambivalent things about putting code on GitHub is that it&#8217;s more or less an open project. It&#8217;s great that people (including yourself) can continue to work on it, but it seems to lack closure so that you can move on with your life. So one of the things that I&#8217;ve [...]]]></description>
			<content:encoded><![CDATA[<p>Perhaps one of the most ambivalent things about putting code on GitHub is that it&#8217;s more or less an open project. It&#8217;s great that people (including yourself) can continue to work on it, but it seems to lack closure so that you can move on with your life.</p>
<p>So one of the things that I&#8217;ve been missing in my <code>BindableBase</code> class is property coercion, a la dependency properties. It&#8217;s a pretty smart idea; you can keep values in a valid state without pushing change notification. Unfortunately, there are some problems that crop up pretty quickly in <code>INotifyPropertyChanged</code> based view models.<span id="more-429"></span></p>
<p>Consider a Foo property that refuses to set a value less than zero.</p>
<pre class="brush:csharp">private int _foo; public int Foo {get { return _foo; }set {if(_foo &gt;= 0) SetProperty(ref _foo, value, "Foo"); }}</pre>
<p>That looks like pretty good coercion, but the problem is that your binding and your property are now out of sync. That is, the binding told your object to set a value and assumed it did; you gave it no notification to the contrary. So while your object retains the old value, the bound <code>TextBox</code> will blissfully report -23.</p>
<p>A more brute force option would raise <code>PropertyChanged</code> in the event of this kind of coercion, but that breaks the code contract for <code>INotifyPropertyChanged</code> in that <em>nothing changed</em>. So how do we get around this problem?</p>
<p>If you take a look at the invocation list of your <code>PropertyChanged</code> event with some bound variables, you&#8217;ll notice that there&#8217;s a <code>PropertyChangedEventManager</code> hooked up.</p>
<p><a href="http://northhorizon.net/wp-content/uploads/2011/05/propertychangedeventmanager-watch.png"><img class="aligncenter size-full wp-image-432" title="PropertyChangedEventManager in the Watch" src="http://northhorizon.net/wp-content/uploads/2011/05/propertychangedeventmanager-watch.png" alt="" width="707" height="330" /></a></p>
<p>Considering that the other item in the list is my default delegate, this object must be responsible for communicating my events to the binding system</p>
<p>Of course, the next thing to do is fire up Reflector and take a look at what&#8217;s there.</p>
<pre class="brush:csharp">public class PropertyChangedEventManager : WeakEventManager {// Fields private WeakEventManager.ListenerList _proposedAllListenersList; private static readonly string AllListenersKey; // Methods static PropertyChangedEventManager(); private PropertyChangedEventManager(); public static void AddListener(INotifyPropertyChanged source, IWeakEventListener listener, string propertyName); private void OnPropertyChanged(object sender, PropertyChangedEventArgs args); private void PrivateAddListener(INotifyPropertyChanged source, IWeakEventListener listener, string propertyName); private void PrivateRemoveListener(INotifyPropertyChanged source, IWeakEventListener listener, string propertyName); protected override bool Purge(object source, object data, bool purgeAll); public static void RemoveListener(INotifyPropertyChanged source, IWeakEventListener listener, string propertyName); protected override void StartListening(object source); protected override void StopListening(object source); // Properties private static PropertyChangedEventManager CurrentManager { get; }}</pre>
<p>Basically, <code>AddListener</code> access the private <code>CurrentManager</code> singleton and subscribes the given listener to <code>OnPropertyChanged</code>. Fortunately for us, there&#8217;s a flaw in th the implementation of <code>OnPropertyChanged</code>. What it does is it gets the list of listeners based on the sender and raises their event with the given sender and args. The problem here is that it doesn&#8217;t verify that the object raising the event is actually the sender! That is to say, we should be able to send a fake PropertyChanged event through another object acting as a surrogate. All we need to do is add that object to the PropertyChangedEvenManager&#8217;s list and start impersonating.</p>
<p>To that end, I added this private class to <code>BindableBase</code> to lazily add the <code>INotifyPropertyChanged</code> proxy object to the <code>PropertyChangedEventManager</code>. Since we&#8217;re not actually interested in the events, I made a stub implementation of <code>IWeakEventListener</code> that returns false constantly to indicate it&#8217;s not handling the event. Finally, I hold onto both of these references to keep them from being garbage collected.</p>
<pre class="brush:csharp">private class PropertyChangedEventManagerProxy {// We need to hold on to these refs to keep it from getting GC'd private readonly NotifyPropertyChangedProxy _notifyPropertyChangedProxy; private readonly IWeakEventListener _weakEventListener; private PropertyChangedEventManagerProxy() {_notifyPropertyChangedProxy = new NotifyPropertyChangedProxy(); _weakEventListener = new WeakListenerStub(); PropertyChangedEventManager.AddListener(_notifyPropertyChangedProxy, _weakEventListener, string.Empty); }public void RaisePropertyChanged(object sender, string propertyName) {_notifyPropertyChangedProxy.Raise(sender, new PropertyChangedEventArgs(propertyName)); }private static PropertyChangedEventManagerProxy _instance; public static PropertyChangedEventManagerProxy Instance { get { return _instance ?? (_instance = new PropertyChangedEventManagerProxy()); } } private class NotifyPropertyChangedProxy : INotifyPropertyChanged {public event PropertyChangedEventHandler PropertyChanged = delegate { }; public void Raise(object sender, PropertyChangedEventArgs e) {PropertyChanged(sender, e); }} private class WeakListenerStub : IWeakEventListener {public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e) { return false; }} }</pre>
<p>The only thing left to do is add the coerce value function as an optional parameter on <code>SetProperty</code> and hook it up:</p>
<pre class="brush:csharp">protected void SetProperty&lt;T&gt;( ref T backingStore, T value, string propertyName, Action onChanged = null, Action&lt;T&gt; onChanging = null, Func&lt;T, T&gt; coerceValue = null) {VerifyCallerIsProperty(propertyName); var effectiveValue = coerceValue != null ? coerceValue(value) : value; if (EqualityComparer&lt;T&gt;.Default.Equals(backingStore, effectiveValue)) {// If we coerced this value and the coerced value is not equal to the original, we need to // send a fake PropertyChanged event to notify WPF that this value isn't what it thinks it is. if (coerceValue != null &amp;&amp; !EqualityComparer&lt;T&gt;.Default.Equals(value, effectiveValue)) PropertyChangedEventManagerProxy.Instance.RaisePropertyChanged(this, propertyName); return; }if (onChanging != null) onChanging(effectiveValue); OnPropertyChanging(propertyName); backingStore = effectiveValue; if (onChanged != null) onChanged(); OnPropertyChanged(propertyName); }</pre>
<p>And there you have it. All the benefits of dependency property coercion, and the same short, sweet <code>SetProperty</code> syntax.</p>
<p>As before, everything is on <a href="https://github.com/danielmoore/InpcTemplate">GitHub</a> so you can take a look at the whole thing and fork it if you see something to be improved.</p>
]]></content:encoded>
			<wfw:commentRss>http://northhorizon.net/2011/coercing-viewmodel-values-with-inotifypropertychanged/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Introducing StitchIt – The CommonJS Module packager for ASP.NET MVC</title>
		<link>http://blog.davidpadbury.com/2011/04/17/introducing-stitchit-the-commonjs-module-packager-for-asp-net-mvc/</link>
		<comments>http://blog.davidpadbury.com/2011/04/17/introducing-stitchit-the-commonjs-module-packager-for-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 02:26:39 +0000</pubDate>
		<dc:creator>David Padbury</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://blog.davidpadbury.com/?p=247</guid>
		<description><![CDATA[Introduction One of the biggest challenges writing large client-side JavaScript single page applications is how you actually manage a large amount of JavaScript. How do you structure the content of the files? Where do you include all the script tags? What order do the script tags have to appear in? It&#8217;s all a bit of &#8230; <span class="more-link"><a href="http://blog.davidpadbury.com/2011/04/17/introducing-stitchit-the-commonjs-module-packager-for-asp-net-mvc/">Continue reading &#187;</a></span><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&#38;blog=2979783&#38;post=247&#38;subd=davidpadbury&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<h1>Introduction</h1>
<p>One of the biggest challenges writing large client-side JavaScript single page applications is how you actually manage a large amount of JavaScript. How do you structure the content of the files? Where do you include all the script tags? What order do the script tags have to appear in? It&#8217;s all a bit of a headache.</p>
<p>The <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1">CommonJS Modules</a> specification proposes a method of structuring JavaScript into self contained modules which specify what they require to run and what they expose externally. At it&#8217;s most basic &#8211; a global require function loads a module by an identifier (which typically looks like a file path), and there&#8217;s a global exports object that the module can attach it&#8217;s API on which is returned by the require call. If you&#8217;ve ever tried out Node.js it&#8217;ll be familiar to you.<br />
<span style="text-decoration:underline;">calc.js</span></p>
<pre class="brush: jscript;">
exports.add = function(n1, n2) {
	return n1 + n2;
};
</pre>
</p>
<p><span style="text-decoration:underline;">app.js</span></p>
<pre class="brush: jscript;">
var calculator = require('calc');

var result = calculator.add(2, 3); // 5
</pre>
</p>
<h1>StitchIt</h1>
<p>StitchIt is based on a great library for Node called <a href="https://github.com/sstephenson/stitch">Stitch</a> which provides a CommonJS Module API in the browser and will automatically package your JavaScript into modules.</p>
<p><strong>Disclaimer: StitchIt is not yet ready for use.</strong> It&#8217;s  the result of only a few hours work on a Sunday afternoon to serve as a prototype for how CommonJS modules could really be the way to go for structuring large JavaScript applications. The code is probably awful, there&#8217;s absolutely no caching so it will rebuild everything on every request and there&#8217;s no minification. I hope to make it production ready in the coming weeks but for the time being it&#8217;s just something to look at.</p>
<p>That said, let&#8217;s dig into a demonstration of how it works. You start by placing all the JavaScript you want packaged into a directory &#8211; in this case I&#8217;ve used ~/Scripts/app. We initialize StitchIt in the application&#8217;s InitializeRoutes method and expose its packaged content on a path.</p>
<p>
<pre class="brush: csharp;">
public static void RegisterRoutes(RouteCollection routes)
{
    ...
    routes.StitchIt()
        .RootedAt(&quot;~/Scripts/app&quot;)
        .PublishAt(&quot;app.js&quot;);
    ...
}
</pre>
</p>
<p>Inside the Scripts/app directory we&#8217;ll make a couple of our JavaScript files which will form a basic application. For this example I&#8217;m using the <a href="http://wiki.commonjs.org/wiki/Modules/1.1.1#Sample_Code">sample code</a> provided in the CommonJS Module specification itself.</p>
<p><span style="text-decoration:underline;">math.js</span></p>
<pre class="brush: jscript;">
exports.add = function() {
    var sum = 0, i = 0, args = arguments, l = args.length;
    while (i &lt; l) {
        sum += args[i++];
    }
    return sum;
};
</pre>
</p>
<p><span style="text-decoration:underline;">increment.js</span></p>
<pre class="brush: jscript;">
var add = require('math').add;

exports.increment = function(val) {
    return add(val, 1);
};
</pre>
</p>
<p><span style="text-decoration:underline;">program.js</span></p>
<pre class="brush: jscript;">
var inc = require('increment').increment;
var a = 1;
var b = inc(a);

console.log(b); // 2
</pre>
</p>
<p>With these in place we can pull down the file generated by StitchIt in a script tag and then use a require function attached to the global stitchIt object to execute our program.</p>
<p><span style="text-decoration:underline;">Index.cshtml</span></p>
<pre class="brush: jscript;">
...
&lt;script src=&quot;/app.js&quot;&gt;&lt;/script&gt;
&lt;script&gt;
    stitchIt.require('program');
&lt;/script&gt;
...
</pre>
</p>
<h1>Wrapping third party JavaScript libraries into Modules</h1>
<p>Very few client-side JavaScript libraries are built as CommonJS Modules, so how do we use them from our Modularized code? Let&#8217;s take jQuery as it&#8217;s probably the first JavaScript library people will want to use. </p>
<p>We&#8217;ll ensure that jQuery is loaded separately via a normal script tag before loading the StitchIt content. Then we&#8217;ll create a wrapper which instead of attaching an API to exports, will completely replace the module exports with the jQuery object itself grabbed from the window.</p>
<p><span style="text-decoration:underline;">jquery.js</span></p>
<pre class="brush: jscript;">
module.exports = window.jQuery;
</pre>
</p>
<p>Using this wrapper module we can just require it like a normal library.</p>
<p><span style="text-decoration:underline;">app.js</span></p>
<pre class="brush: jscript;">
var $ = require('jquery');

$(function () {
    $('body').text('Hi from jQuery');
});
</pre>
</p>
<h1>Beyond JavaScript &#8211; Managing related client-side templates</h1>
<p>If you&#8217;ve done much with KnockOut or jQuery templating you&#8217;ve probably found yourself dumping templates into script blocks in the main page body. Although this works for simple scenarios, I quickly found this practice horribly difficult to manage for large single page apps. Following RequireJS&#8217;s and Stitch&#8217;s example, I added support for adding *.html files to your JavaScript application directory. StitchIt will wrap these into a CommonJS JavaScript module so they can be required like any other JS dependency.</p>
<p><span style="text-decoration:underline;">views/personViewTmpl.html</span></p>
<pre class="brush: xml;">
&lt;div&gt;
    &lt;span&gt;Hi, I'm ${name}&lt;/span&gt;
&lt;/div&gt;
</pre>
</p>
<p><span style="text-decoration:underline;">views/personView.js</span></p>
<pre class="brush: jscript;">
var $ = require('jquery'),
    template = require('./personViewTmpl'); // Just another module

function PersonView(el, name) {
    $.tmpl(template, { name: name }).appendTo(el);
}

exports.PersonView = PersonView;
</pre>
</p>
<p><span style="text-decoration:underline;">app.js</span></p>
<pre class="brush: jscript;">
var $ = require('jquery'),
    PersonView = require('views/personView').PersonView;

$(function () {
    var davidView = new PersonView($('body'), 'David');
});
</pre>
</p>
<p>Also notice the use of global and relative identifiers for the require call &#8211; this allows us to nicely organize our JavaScript into sub-directories that can be as deep as we need. Relative module identifiers are evaluated relative to where that module resides.</p>
<h1>CoffeeScript</h1>
<p>I know what you&#8217;re thinking &#8211; <em>JavaScript is so 2010</em>. Well thanks to <a href="http://jurassic.codeplex.com/">Jurassic</a>, a wonderful JavaScript runtime for .NET, simply drop in .coffee files to your app directory and they&#8217;ll automatically get compiled to JavaScript when the StitchIt package is built.</p>
<p><span style="text-decoration:underline;">person.coffee</span></p>
<pre class="brush: jscript;">
class Person
	constructor: (@name) -&gt;

	sayHi: () -&gt;
		&quot;Hi, I'm #{@name}&quot;

exports.Person = Person
</pre>
</p>
<p><span style="text-decoration:underline;">app.js</span></p>
<pre class="brush: jscript;">
var Person = require('person').Person;

var david = new Person('David');

console.log( david.sayHi() ); // Hi, I'm David
</pre>
</p>
<h1>What needs to be done before it&#8217;s ready?</h1>
<p>So there&#8217;s enough here to show off what I believe are very important concepts, but it&#8217;s still a fair bit off  being usable. Currently all of the modules get packaged into a single .js file. Although some may disagree, I prefer wrapping all the code up into a single file which can be downloaded once and then cached forever in the client. The biggest issue now is that this .js file is getting completely regenerated on every request &#8211; this may work okay for development but ideally I&#8217;ll probably want to compare time stamps or something to only regenerate the package when it&#8217;s source files have changed.</p>
<p>I&#8217;ll also want to integrate some form of js minification into StitchIt. I&#8217;d ideally find a way of using <a href="https://github.com/jetheredge/SquishIt">SquishIt</a> (a great tool which inspired this name). If that&#8217;s not possible I&#8217;ll probably want to integrate Google&#8217;s Closure compiler directly into StitchIt.</p>
<p>There&#8217;s also currently only a fraction of the CommonJS Module specification implemented. The major requirement will be support for require.paths so we can control where modules are loaded from &#8211; although I&#8217;m not sure how much sense this makes in a browser at this point.</p>
<h1>Grand Ideas</h1>
<p>Looking further into the future I&#8217;ve got some fairly grand plans. If I support exposing modules from resources in .NET assemblies I can imagine providing very cool NuGet integration support.</p>
<pre>
Install-Package knockout
...
var knockout = require('knockout');
</pre>
<p>I also wonder how difficult it would be to evaluate these CommonJS modules in Visual Studio itself to go towards providing some kind of AutoComplete/Intellisense support. </p>
<p>Probably very difficult.</p>
<h1>Show me the code</h1>
<p>All the code is up at GitHub &#8211; <a href="https://github.com/davidpadbury/StitchIt">StitchIt</a>. Please go browse and fork. I&#8217;d love to hear your thoughts.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidpadbury.wordpress.com/247/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidpadbury.wordpress.com/247/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidpadbury.wordpress.com/247/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&amp;blog=2979783&amp;post=247&amp;subd=davidpadbury&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davidpadbury.com/2011/04/17/introducing-stitchit-the-commonjs-module-packager-for-asp-net-mvc/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>FITC Ten Year Anniversary</title>
		<link>http://www.michelboudreau.com/2011/04/13/fitc-ten-year-anniversary-2/</link>
		<comments>http://www.michelboudreau.com/2011/04/13/fitc-ten-year-anniversary-2/#comments</comments>
		<pubDate>Wed, 13 Apr 2011 19:24:50 +0000</pubDate>
		<dc:creator>Michel Boudreau</dc:creator>
				<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://www.michelboudreau.com/?p=705</guid>
		<description><![CDATA[Has it really been 10 years since it started? Man does time fly when you&#8217;re having fun. To commemorate this momentous occasion, FITC is pulling all the stops at this massive event starting the 2nd of May. I have some insider information saying that the opening day party will be all 60&#8242;s; like a geeky [...]]]></description>
			<content:encoded><![CDATA[<p>Has it really been 10 years since it started? Man does time fly when you&#8217;re having fun. To commemorate this momentous occasion, FITC is pulling all the stops at this massive event starting the 2nd of May.</p>
<p>I have some insider information saying that the opening day party will be all 60&#8242;s; like a geeky version Mad Men except with less debauchery.  There&#8217;s also some roller-skating and cotton candy involved.  Nuts right?</p>
<p>If you&#8217;re in the industry, you do not want to miss out on this event.<a href="http://www.fitc.ca/events/tickets/?event=116" > Buy your tickets now</a> if you haven&#8217;t done so already.  And while you&#8217;re there, <a href="http://www.fitc.ca/events/presentations/presentation.cfm?event=116&amp;presentation_id=1451" >stop by my presentation</a> for support.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.michelboudreau.com/2011/04/13/fitc-ten-year-anniversary-2/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lab49 at IA Summit in Denver</title>
		<link>http://uxcorner.wordpress.com/2011/04/07/lab49-at-ia-summit-in-denver/</link>
		<comments>http://uxcorner.wordpress.com/2011/04/07/lab49-at-ia-summit-in-denver/#comments</comments>
		<pubDate>Thu, 07 Apr 2011 16:16:22 +0000</pubDate>
		<dc:creator>Melissa Bezar</dc:creator>
				<category><![CDATA[Agile]]></category>
		<category><![CDATA[Events]]></category>
		<category><![CDATA[Lab49]]></category>
		<category><![CDATA[UX]]></category>

		<guid isPermaLink="false">http://uxcorner.wordpress.com/?p=152</guid>
		<description><![CDATA[Lab49&#8242;s Ann McMeekin Carrier ran a workshop about creating an agile UX manifesto at the IA Summit in Denver last week. Check out the slides from her workshop.<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=uxcorner.wordpress.com&#38;blog=12901147&#38;post=152&#38;subd=uxcorner&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Lab49&#8242;s Ann McMeekin Carrier ran a workshop about creating an agile UX manifesto at the <a title="2011 IA Summit in Denver" href="http://2011.iasummit.org/" >IA Summit in Denver</a> last week. Check out <a title="Ann's Agile UX slides on Slideshare.net" href="http://www.slideshare.net/annmcmeekin/creating-an-agile-ux-manifesto-at-ia-summit-2011-7549388" >the slides from her workshop</a>.</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/uxcorner.wordpress.com/152/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/uxcorner.wordpress.com/152/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/uxcorner.wordpress.com/152/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=uxcorner.wordpress.com&amp;blog=12901147&amp;post=152&amp;subd=uxcorner&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://uxcorner.wordpress.com/2011/04/07/lab49-at-ia-summit-in-denver/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Concurrency Pattern: Finding and exploiting areas of latent parallelism</title>
		<link>http://feedproxy.google.com/~r/dhruba/lab49/~3/9glyBR63dAQ/</link>
		<comments>http://feedproxy.google.com/~r/dhruba/lab49/~3/9glyBR63dAQ/#comments</comments>
		<pubDate>Wed, 23 Mar 2011 08:48:49 +0000</pubDate>
		<dc:creator>Dhruba Bandopadhyay</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://dhruba.name/?p=1760</guid>
		<description><![CDATA[With the JDK 7 developer preview out and a final release fast approaching it&#8217;s important to not only to become aware of what the new version offers but also, in certain areas where existing programming paradigms have radically changed, to make a mental shift in the way we think and understand how we can leverage [...]]]></description>
			<content:encoded><![CDATA[</p>
<p>With the JDK 7 developer preview out and a final release fast approaching it&#8217;s important to not only to become aware of what the new version offers but also, in certain areas where existing programming paradigms have radically changed, to make a mental shift in the way we think and understand how we can leverage these new paradigms best to our advantage. One such area is that of finding and exploiting areas of latent parallelism using a coarse grained parallelism approach.</p>
<p>As I mentioned in my previous post about the JDK7 developer preview being released &#8211; we&#8217;ve been using jsr166y and extra166y at work for some time now and this post really stems from an impassioned discussion that took place on finding and exploiting areas of latent parallelism in code so here&#8217;s what I have to say on the matter (inspired obviously by Doug Lea, Brian Goetz and my esteemed colleagues). The traditional and very much outdated mindset has only understood threads and ever since java 5 the executor framework on top. However this mechanism is fundamentally limited in its design in the extent of parallelism it can offer.</p>
<p>Firstly threads are expensive not only in their creation and stack size allocation but also in terms of context switching between them. Deciding on how many threads to have is also always at best an educated guess. A particular service within a process may decide to use all available cores but if every service in the process does the same then you have a disproportionately large number of threads and I have worked with applications with more than 150-200 threads operating at a time. Secondly, the executor framework has helped considerably in taking away some of the decision making from the developer and absorbing that complexity but it still suffers from heavy contention from multiple threads on the internal queue of tasks that it holds again adversely impacting performance. Thirdly, threads and executor frameworks normally do not scale up or down based on the hardware that they&#8217;re running on and certainly do not scale based on load. Their performance is very much constant by way of their underlying design.</p>
<p>Enter the fork join framework and parallel arrays. This is not a paragraph about how to use these new features but, in my opinion, a far more important note on how to rid ourselves of a legacy mindset on parallelism and make room for a new one. The fork join framework and parallel arrays (which are backed by the fork join framework and fork join pool internally) should not be perceived only as threading tools. That&#8217;s very dangerous as it means that we are only likely to use them in those areas where we previously used threads. They can in fact help us find and exploit areas of latent parallelism.</p>
<p>What does that mean? In all applications there are areas of code that operate sequentially. This code may be thread confined or stack confined and we almost never reconsider the way they perform. With FJ/PA we can now start making these areas concurrent. How is this an improvement? Well FJ/PA offer the following key features which makes them an ideal fit for such a use case.</p>
<p>Firstly, they are fundamentally decoupled from the number of threads in the way they add value which is a good thing. They tend to perform well regardless of how many threads they are using. Secondly, instead of using a single work queue for all threads they use one work queue per thread. This means further decoupling between threads and the way tasks are stored. Thirdly, given multiple work queues and multiple threads, FJ/PA perform work stealing. Every queue is a double ended queue and when one thread has completed all its tasks it then starts to process the tasks from the tail of another queue and because it is dequeuing off the tail there is no contention on the head of the queue from which the owner of the queue is dequeuing. Not only that but the largest tasks are placed towards the end of queues so that when another thread does steal work off another queue it gets enough work to effectively reduce the interval at which it steals again thereby again reducing contention. And finally, and most importantly, given a piece of FJ/PA code it will not only scale up but effectively scale down based not only on the hardware it runs but also on the load of the incoming work. When you understand this new paradigm suddenly the legacy paradigm seems so primitive and fundamentally stunted.</p>
<p>So the next time you are browsing your code consider using jsr166y and extra166y to find and exploit latent areas of parallelism. Generally the rule of thumb should be that this approach works best for operations that are cpu intensive and the legacy paradigm is better for io or network bound operations for obvious reasons. If operations are io or network bound there is less contention and the limitations of the legacy paradigm are less exposed. Don&#8217;t forget that the two libraries above can be used in java 6 so there&#8217;s no need to wait for java 7!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fdhruba.name%2F2011%2F03%2F23%2Ffinding-and-exploiting-areas-of-latent-parallelism%2F&amp;title=Concurrency%20Pattern%3A%20Finding%20and%20exploiting%20areas%20of%20latent%20parallelism"><img src="http://dhruba.name/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a> </p>
<p><img src="http://feeds.feedburner.com/~r/dhruba/lab49/~4/9glyBR63dAQ" height="1" width="1"/></p>
]]></content:encoded>
			<wfw:commentRss>http://feedproxy.google.com/~r/dhruba/lab49/~3/9glyBR63dAQ/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Isotope with Knockout.js</title>
		<link>http://blog.davidpadbury.com/2011/03/20/using-isotope-with-knockout-js/</link>
		<comments>http://blog.davidpadbury.com/2011/03/20/using-isotope-with-knockout-js/#comments</comments>
		<pubDate>Sun, 20 Mar 2011 17:36:09 +0000</pubDate>
		<dc:creator>David Padbury</dc:creator>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://blog.davidpadbury.com/?p=241</guid>
		<description><![CDATA[Knockout.js is a JavaScript library for writing MVVM style HTML applications. Isotope is a super cool jQuery plugin for fluid list animation &#8211; go play around with it here, it&#8217;s really impressive. A question from a colleague prompted me to look at the Knockout.js documentation for the first time in a while and I noticed &#8230; <span class="more-link"><a href="http://blog.davidpadbury.com/2011/03/20/using-isotope-with-knockout-js/">Continue reading &#187;</a></span><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&#38;blog=2979783&#38;post=241&#38;subd=davidpadbury&#38;ref=&#38;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://knockoutjs.com/">Knockout.js</a> is a JavaScript library for writing MVVM style HTML applications. <a href="http://isotope.metafizzy.co/">Isotope</a> is a super cool jQuery plugin for fluid list animation &#8211; go play around with it <a href="http://isotope.metafizzy.co/">here</a>, it&#8217;s really impressive. </p>
<p>A question from a colleague prompted me to look at the Knockout.js documentation for the first time in a while and I noticed that there&#8217;s now a &#8216;afterAdd&#8217; option available for the foreach binding. This allows us to hook in some code for manipulating an element once it&#8217;s been added to the list, intended for animation. I wondered if it was possible to insert Isotope into this process and it turns out it&#8217;s really easy &#8211; take a look at it working together <a href="http://jsfiddle.net/davidpadbury/BRP4d/embedded/result/">here</a>.</p>
<p><a href="http://jsfiddle.net/davidpadbury/BRP4d/embedded/result/"><img src="http://davidpadbury.files.wordpress.com/2011/03/screen-shot-2011-03-20-at-1-27-37-pm.png?w=580" alt="" title="Knockout.js and Isotope"   class="aligncenter size-full wp-image-243" /></a></p>
<p>The code to do it was also really simple and demonstrates quite how handy Knockout is. I&#8217;m sure there&#8217;s some debate to have about whether the function for manipulating the element in the view really belongs on the ViewModel, but I&#8217;ll leave that for another day.</p>
<p>
<pre class="brush: jscript;">
var $wordList = $('#word-list'),
    wordsViewModel = {
        words: ko.observableArray([]),
        newWord: ko.observable(''),
        add: function() {
            this.words.push( this.newWord() );
            this.newWord('');
        },
        wordAdded: function(el) {
            $wordList.isotope( 'appended', $(el) );
        }
    };

ko.applyBindings(wordsViewModel);

$wordList.isotope({
    layoutMode: 'fitRows',
    itemSelector: '.word'
});
</pre>
</p>
<p>
<pre class="brush: xml;">
&lt;form data-bind=&quot;submit: add&quot;&gt;
    &lt;input placeholder=&quot;New Word&quot; data-bind=&quot;value: newWord&quot; autofocus /&gt;
&lt;/form&gt;
&lt;ul id=&quot;word-list&quot; data-bind=&quot;template: { name: 'word-item-tmpl', foreach: words, afterAdd: wordAdded }&quot;&gt;
&lt;/ul&gt;
&lt;script id=&quot;word-item-tmpl&quot; type=&quot;text/x-jquery-tmpl&quot;&gt;
    &lt;li class=&quot;word&quot;&gt;${ $data }&lt;/li&gt;
&lt;/script&gt;
</pre>
</p>
<p>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/davidpadbury.wordpress.com/241/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/davidpadbury.wordpress.com/241/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/davidpadbury.wordpress.com/241/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=blog.davidpadbury.com&amp;blog=2979783&amp;post=241&amp;subd=davidpadbury&amp;ref=&amp;feed=1" width="1" height="1" /></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.davidpadbury.com/2011/03/20/using-isotope-with-knockout-js/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
<enclosure url="" length="" type="" />
		</item>
		<item>
		<title>Its Consulting time!</title>
		<link>http://feedproxy.google.com/~r/Pixel-In-Gene/~3/LHaPRjC0qEg/</link>
		<comments>http://feedproxy.google.com/~r/Pixel-In-Gene/~3/LHaPRjC0qEg/#comments</comments>
		<pubDate>Sat, 19 Mar 2011 14:47:17 +0000</pubDate>
		<dc:creator>Administrator</dc:creator>
				<category><![CDATA[Lab49]]></category>

		<guid isPermaLink="false">http://blog.pixelingene.com/?p=556</guid>
		<description><![CDATA[After having worked full-time for several years in the Corporate world, I have decided to make a career change and jump on to Consulting. I have joined my friends at , where I’ll be working in the Financial district of New York building solutions using Microsoft .Net, C#, WPF, Silverlight and others. I have known [...]]]></description>
			<content:encoded><![CDATA[<p>After having worked full-time for several years in the Corporate world, I have decided to make a career change and jump on to <strong><em>Consulting</em></strong>. I have joined my friends at <a href="http://www.lab49.com/" ><img style="background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; border-top: 0px; border-right: 0px; padding-top: 0px" border="0" src="http://blog.lab49.com/wp-content/themes/lab49/images/logo_header.gif" width="76" height="30" /></a>, where I’ll be working in the Financial district of New York building solutions using Microsoft .Net, C#, WPF, Silverlight and others.</p>
<p>I have known some people at <em>“the Lab” </em>for several years, mostly when they were consulting with my earlier company. So it feels nice to go into a familiar crowd. Lab49 works on a variety of technologies and have a rich portfolio of clients. Many of the folks working here are experts on some technologies and also have active blogs. It is surely a great place to learn new things and work on exciting projects.</p>
<p>I think it will be fun.</p>
<p><strong>Similar Posts:</strong></p>
<ul class="similar-posts">
<li><a href="http://blog.pixelingene.com/2008/01/playing-with-wordpress-php-photoshop-css-xhtml/" rel="bookmark" title="January 29, 2008">Playing with WordPress, PHP, Photoshop, CSS, XHTML</a></li>
<li><a href="http://blog.pixelingene.com/2010/02/quick-tip-about-changing-sketchflows-startup-page-name-silverlight/" rel="bookmark" title="February 1, 2010">Quick tip about changing SketchFlow’s startup page name (Silverlight)</a></li>
<li><a href="http://blog.pixelingene.com/2008/01/portfolio-page-added/" rel="bookmark" title="January 29, 2008">Portfolio page added</a></li>
<li><a href="http://blog.pixelingene.com/2009/03/quick-update-on-the-wpf-control-development-unleashed-book/" rel="bookmark" title="March 18, 2009">Quick update on the WPF Control Development Unleashed book</a></li>
<li><a href="http://blog.pixelingene.com/2007/01/wpf-multithreading-with-backgroundworker/" rel="bookmark" title="January 8, 2007">WPF Multithreading with BackgroundWorker</a></li>
</ul>
<p><!-- Similar Posts took 8.638 ms --></p>
<div class="feedflare">
<a href="http://feeds.feedburner.com/~ff/Pixel-In-Gene?a=LHaPRjC0qEg:_f0hT1ymcTg:D7DqB2pKExk"><img src="http://feeds.feedburner.com/~ff/Pixel-In-Gene?i=LHaPRjC0qEg:_f0hT1ymcTg:D7DqB2pKExk" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Pixel-In-Gene?a=LHaPRjC0qEg:_f0hT1ymcTg:yIl2AUoC8zA"><img src="http://feeds.feedburner.com/~ff/Pixel-In-Gene?d=yIl2AUoC8zA" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Pixel-In-Gene?a=LHaPRjC0qEg:_f0hT1ymcTg:gIN9vFwOqvQ"><img src="http://feeds.feedburner.com/~ff/Pixel-In-Gene?i=LHaPRjC0qEg:_f0hT1ymcTg:gIN9vFwOqvQ" border="0"></img></a> <a href="http://feeds.feedburner.com/~ff/Pixel-In-Gene?a=LHaPRjC0qEg:_f0hT1ymcTg:V_sGLiPBpWU"><img src="http://feeds.feedburner.com/~ff/Pixel-In-Gene?i=LHaPRjC0qEg:_f0hT1ymcTg:V_sGLiPBpWU" border="0"></img></a>
</div>
<p><img src="http://feeds.feedburner.com/~r/Pixel-In-Gene/~4/LHaPRjC0qEg" height="1" width="1"/></p>
]]></content:encoded>
			<wfw:commentRss>http://feedproxy.google.com/~r/Pixel-In-Gene/~3/LHaPRjC0qEg/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

