<?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>alecmce.com</title>
	<atom:link href="http://alecmce.com/feed" rel="self" type="application/rss+xml" />
	<link>http://alecmce.com</link>
	<description></description>
	<lastBuildDate>Fri, 18 May 2012 02:54:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Future Of Flash</title>
		<link>http://alecmce.com/uncategorized/future-of-flash-2</link>
		<comments>http://alecmce.com/uncategorized/future-of-flash-2#comments</comments>
		<pubDate>Thu, 10 Nov 2011 21:09:17 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1301</guid>
		<description><![CDATA[Flash Is Dead! Or so you&#8217;d think. It&#8217;s been a fascinating couple of days in the Flash community. Everyone has had their say. ZDNet are telling everyone that Without Mobile, Adobe Flash is irrelevant. CNN talks about the Beginning of the End for Adobe Flash. Adobe Shrinks! This week, Adobe laid off 750 jobs. We [...]]]></description>
			<content:encoded><![CDATA[<h2>Flash Is Dead!</h2>
<p>Or so you&#8217;d think. It&#8217;s been a fascinating couple of days in the Flash community. Everyone has had their say. ZDNet are telling everyone that <a href="http://www.zdnet.com/blog/perlow/without-mobile-adobe-flash-is-irrelevant/19247">Without Mobile, Adobe Flash is irrelevant</a>. CNN talks about the <a href="http://money.cnn.com/2011/11/10/technology/adobe_flash/">Beginning of the End for Adobe Flash</a>.</p>
<h2>Adobe Shrinks!</h2>
<p>This week, Adobe laid off 750 jobs. We should remember that 1950 jobs have been lost at Adobe in  the last three years now (600 in <a href="http://techcrunch.com/2009/11/10/layoffs-reported-at-adobe/" title="600 in 2009">2009</a> and 600 in <a href="http://techcrunch.com/2008/12/03/in-the-face-of-weakening-demand-adobe-sheds-600-workers/" title="600 in 2008">2008</a> &#8211; from <a href="daringfireball.net">daringfireball.net</a>).</p>
<p>Part of this was belt-tightening was the entire US-based Flash Authoring team. <a href=http://www.junglecode.net/?p=57">This article</a> blithely jumps from this premise to the conclusion that &#8220;offering a free Flash Player runtime subsidized by selling tools is no longer a business Adobe is interested in&#8221;. Does it? Had Adobe said that they no longer have that business interest, then things would be a lot clearer. They haven&#8217;t said that at all. The media and the community is jumping to apocalyptic conclusions. (The community should know better)</p>
<h2>Tired Communities</h2>
<p>Last night I watched a chunk of an online meeting about the Flash Platform of about 80 developers, that notably included <a href="https://twitter.com/#!/seantheflexguy">@seantheflexguy</a>, <a href="https://twitter.com/#!/j0eflash">@j0eflash</a>, <a href="https://twitter.com/#!/leebrimelow">Lee Brimelow</a> and <a href="https://twitter.com/#!/thibault_imbert">Thibault Imbert</a>.</p>
<p>The most noticeable thing about that conversation for me was the exasperation and ill-feeling in the room directed towards Adobe. The Flash Platform Community feels that it has been ill-treated by Adobe.</p>
<p>On one level, that&#8217;s absurd. Without Adobe the community would be fragmented across myriad other communities. Adobe&#8217;s investment into the platform is a primary reason the community exists. For many years now, Adobe has given us tools that allow us to make best-in-class products (or bad, buggy products as per our abilities) and display them on the web, desktop and mobile.</p>
<h2>Diluting Juice</h2>
<p>There has definitely been a dilution of Adobe&#8217;s lead in the interactive experience space. HTML5 has taken a lot of the wind out of Flash&#8217;s sails. The player performance on Apple products has been frustrating. The gradual loss of Flash&#8217;s performance advantage against other platforms has been demoralizing. But it is hardly surprising that other platforms and developers have looked at what Flash did right and have tried to implement similar functionality targetting other platforms and other languages. What would we have Adobe do about this? Somehow continually out-compete all other vendors? If they don&#8217;t, should we consider it a betrayal?</p>
<h2>Buoyant Communities</h2>
<p>Right now, if you attend a JavaScript developer meetup there are a hundred kids in their 20s inventing the stuff we invented over the last decade (a lot of which was invented before us for other platforms, of course). They&#8217;re excited and young and vibrant.</p>
<p>At the equivalent Flash developer meetup down the street the picture is very different. There&#8217;s a mash of artists, Flex developers, game developers, developers who make banner ads for platforms, developers who use Flash to produce graphics for massive stadium gigs for rock stars. Meetup after meetup fewer developers attend, they are older, less enthusiastic, jaded.</p>
<p>So the apocalyptic conclusions are understandable, if misguided. You can understand why developers might be angry with Adobe, having watched the platform lose out to the new kids on the block over several years. Now it feels that Adobe have finally admitted as much, they are venting that frustration.</p>
<h2>Flash Is Alive!</h2>
<p>Could it be that the Flash Player has tried to be all things to all people? That the banner ad guy, the RIA guy building data grids and the game developer are all targetting the same platform could be a problem. Add into that mix a requirement that these games, RIAs and ads display on every browser on every desktop, but also on every browser on every mobile, and you can see what a headache Adobe has been contending with over years.</p>
<p>The rise of HTML5 simplifies this issue: gradually, banner ads and simple RIAs will be doable in pure JavaScript. That may upset a lot of Flex developers, but seriously, if you can actually do it better on another platform, wouldn&#8217;t you?</p>
<p>But games, and those more powerful RIAs that really juice the Flash Player are not going anywhere. They need not only the current Flash Player, but a beefed-up, more aggressively powerful Flash Player. These apps may remain in the browser for desktops, but will take over the screen on mobiles, wrapped in an AIR wrapper.</p>
<p>Flash Player can still deliver a particular set of experiences across desktop and mobile better than any other platform. The stats about Flash Player are indisputable and compelling. In an attempt to make bolster their business case against the brunt of criticism this week, Adobe <a href="http://www.adobe.com/choice/flash.html" title="Article on the Future of Flash">published some of these stats</a>.</p>
<div style="text-align: center;">
<div style="margin: auto; display: inline-block;"><img src="http://alecmce.com/wp-content/uploads/2011/11/truth-about-flash.png" alt="" title="truth-about-flash" width="551" height="336" class="alignnone size-full wp-image-1281" /></div>
</div>
<p>Everything dies, even the Flash Player. Just because it isn&#8217;t a kid anymore, doesn&#8217;t mean it&#8217;s dead, and these stats demonstrate it pretty convincingly.</p>
<h2>Where Does Flash Go?</h2>
<p><a href="https://twitter.com/#!/thibault_imbert">Thibault Imbert</a> wrote an article yesterday called <a href="http://www.bytearray.org/?p=3744">Focusing</a>, in which he made the case that what has happened this week is a good thing. I broadly agree with this commentary, if this frees up the team to innovate on the current Flash Player.</p>
<p>I have been arguing the case for generics in AS3 so long that it has become a standing joke. AS3 should also adopt inline functions, enums, typedefs and every other good idea that <a href="http://ncannasse.fr/">Nicolas Cannasse</a> has baked into <a href="http://haxe.org/">haXe</a>. In fact, Adobe should have brought Nicolas into the fold long ago, and would be well advised to do so now, if they can. This sort of language innovation would free-up the open-source developers to create better, faster tools and architectures for other people to build their games on.</p>
<p>They should also be working hard to develop better tooling. That FDT remains broadly better than Flash Builder should be a cause of embarrassment. That we have to use a creaky buggy platform like Eclipse in the first place, when we are using tooling from the company that leads the world in creating tools for creative professionals is continually frustrating. It makes you think that they still don&#8217;t really understand what coders want.</p>
<p>They need to continue to improve the performance of the player and the compiler. That people are still doing things like byte-weaving or using Apparat means that Adobe continue to miss really simple tricks in this area.</p>
<h2>Conclusions</h2>
<p>The community has gone nuts, but you can understand why. They&#8217;re mostly wrong, and are probably largely jealous of those JS script kiddies who seem to be having so much fun! But, they also like their not-quite Java, not-quite JS middle-road language, and want to stick with it. They want Adobe to help them stick with it. Adobe are helping! It just doesn&#8217;t feel much like it, because Flash isn&#8217;t new anymore, and like all old things, it has its problems.</p>
<p>After a week or two, calmer heads will prevail, and the pendulum will swing back. People will think to themselves &#8220;when was the last time I used a Flash app in the browser on a mobile?&#8221; and also think &#8220;wasn&#8217;t the Flash IDE mostly junk?&#8221;, and on reflection, may even have something positive to say about Adobe.</p>
<p>Did I miss anything?</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/uncategorized/future-of-flash-2/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>TDD-ing Game Of Life in haXe</title>
		<link>http://alecmce.com/tdd/tdd-ing-game-of-life-in-haxe</link>
		<comments>http://alecmce.com/tdd/tdd-ing-game-of-life-in-haxe#comments</comments>
		<pubDate>Mon, 10 Oct 2011 12:41:52 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[haxe]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1265</guid>
		<description><![CDATA[Last week I attended the inaugural Try Harder collaborative training week with a group of talented and dedicated developers. It was an extraordinary week, my brain is still fizzing with ideas and techniques that I learned there. One afternoon Mike Cann and I put together The Game Of Life following a largely test-driven-development process, using [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I attended the inaugural <a href="http://tryharder.org.uk/">Try Harder</a> collaborative training week with a group of talented and dedicated developers. It was an extraordinary week, my brain is still fizzing with ideas and techniques that I learned there.</p>
<p><img src="http://alecmce.com/wp-content/uploads/2011/10/Screen-Shot-2011-10-10-at-13.53.30.png" alt="Image showing game of life implementation" width="635" height="399"/></p>
<p>One afternoon <a href="http://mikecann.co.uk">Mike Cann</a> and I put together The Game Of Life following a largely test-driven-development process, using <a href="http://twitter.com/mikestead">Mike Stead</a>&#8216;s <a href="https://github.com/massiveinteractive/MassiveUnit">MassiveUnit</a> unit testing implementation for haXe</a>.</p>
<p>This was Mike&#8217;s first time using a TDD approach, and one of the first times I&#8217;ve built in haXe, and it was fun and informative. You can read <a href="http://mikecann.co.uk/personal-project/conways-game-of-life-in-haxe-nme-massiveunit/">Mike&#8217;s post about the project here</a>, and <a href="https://github.com/alecmce/haxe_game_of_life">browse the source-code on Github here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/tdd/tdd-ing-game-of-life-in-haxe/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>(Unfolding) Platonic Solids</title>
		<link>http://alecmce.com/uncategorized/unfolding-platonic-solids</link>
		<comments>http://alecmce.com/uncategorized/unfolding-platonic-solids#comments</comments>
		<pubDate>Sun, 11 Sep 2011 17:34:04 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[math]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1223</guid>
		<description><![CDATA[Before I was an ActionScript coder I was a mathematics teacher. It may have been a giveaway that coding was more my style than teaching when I made this, originally in AS2: (roll-over to activate) Later on I ported it to AS3 for a game that was never published. I made these: Then, I forgot [...]]]></description>
			<content:encoded><![CDATA[<p>Before I was an ActionScript coder I was a mathematics teacher. It may have been a giveaway that coding was more my style than teaching when I made this, originally in AS2: (roll-over to activate)</p>
<div style="text-align:center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_0" width="400" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/09/UnfoldingDodecahedron4.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/09/UnfoldingDodecahedron4.swf" width="400" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>Later on I ported it to AS3 for a game that was never published. I made these:</p>
<div style="text-align:center;">

    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_1" width="400" height="400">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/09/AllJewels.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/09/AllJewels.swf" width="400" height="400">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>

</div>
<p>Then, I forgot about it, for a long time, but I just came across it again! It&#8217;s actually my own 3D library, back in the days before I had heard of Papervision or Away3D, or any of the others. It draws the polygons using Graphics. That part is worthless.</p>
<p>However, I haven&#8217;t seen the dihedral angle structure that allows me to define the solid to open and close in other code. Perhaps this will be useful to someone. If you would like it, then you&#8217;re very welcome!</p>
<p>The code is here: <a href="http://bit.ly/reybnU">https://github.com/alecmce/ptolemy3D/tree/master/src</a>. The unfolding parts <a href="http://bit.ly/otraoa">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/uncategorized/unfolding-platonic-solids/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CommandFlow &#8211; Another Approach to (RobotLegs) Asynchronicity</title>
		<link>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity</link>
		<comments>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity#comments</comments>
		<pubDate>Sun, 11 Sep 2011 11:38:18 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1213</guid>
		<description><![CDATA[In this post I present another first draft of an extension for RobotLegs, my RobotLegs Flow Extension, which seeks to cope with problems surrounding asnychronicity in command-level code. In my last blog post, I argued that Robotlegs is poorly equipped to cope with asynchronous processes, and offered an extension to RobotLegs to seek to solve [...]]]></description>
			<content:encoded><![CDATA[<p>In this post I present another first draft of an extension for RobotLegs, my <a href="http://bit.ly/qF9QqN">RobotLegs Flow Extension</a>, which seeks to cope with problems surrounding asnychronicity in command-level code.</p>
<p>In my last blog post, I argued that Robotlegs is poorly equipped to cope with asynchronous processes, and offered an extension to RobotLegs to seek to solve this problem, &quot;<a href="http://bit.ly/nEtgUZ">Async Processes Extension</a>&quot;. This extension follows in the footsteps of other interesting libraries, such as Shaun Smith&#8217;s <a href="https://github.com/darscan/robotlegs-extensions-Oil">Oil Extension</a> among many others.</p>
<h2>Reflecting about Processes</h2>
<p>Since I wrote that code and blog post, I have been reflecting on my approach. I have a few problems with it:</p>
<ul>
<li>RobotLegs is fundamentally lightweight. It is my framework of choice because it&#8217;s hardly a framework at all. The Processes extension adds a lot of conceptual overhead and does a lot of work under-the-hood.</li>
<li>It separates the concept of a process from the concept of a command, but it can often be the case that previously synchronous code can become asynchronous (for example: when moving from mocked data to live data), or the other way (for example: once data is  pre-loaded that was previously loaded just-in-time). Refactoring between commands and processes seems more trouble than it&#8217;s worth.</li>
<li>The under-the-hood part of the Process class means that it&#8217;s impossible to duck-type a Process. Duck-typing is good insofar as you know a framework that accepts duck-typable object has minimal dependencies.</li>
</ul>
<p>These criticisms of the library led me to think about a more lightweight approach.</p>
<h2>The Central Premise of Process</h2>
<p>The central premise of my critique of asynchronous code is that this sort of code is bad because the Command contains both its own logic and sequencing logic:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	signalCommandMap.map(runSecond, SecondCommand);
	signalCommandMap.execute(FirstCommand);
}

class FirstCommand
{
	[Inject]
	public var runSecond:Signal;

	public function execute():void
	{
		process = new SomeProcess();
		process.run().addOnce(onComplete);
	}

	private function onComplete():void
	{
		runSecond.dispatch();
	}
}
</pre>
<p>It would be preferable to abstract the sequencing logic, so that the FirstCommand can just report that it has completed what it needs to do without having to know what&#8217;s next.</p>
<p>I have often found that you end up drawing diagrams for code written this way with each command in a box with arrows between them. I want a class that encapsulates that diagram, ensuring that the individual commands are truly agnostic with respect to their context in the application.</p>
<h2>A Different Approach</h2>
<p>If we abandon the notion of a Process, then how can we retain this separation? My second approach has been to abstract the sequencing logic into a class, called <a href="http://bit.ly/n46bVs">CommandFlow</a>. The intention is to use it like this:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	injector.mapClass(ComamndFlow, CommandFlow);

	signalCommandMap.execute(InitCommand);
}

class InitCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(FirstCommand);
		flow.push(SecondCommand);
		flow.next();
	}

}

class FirstCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		process = new SomeProcess();
		process.run().addOnce(onComplete);
	}

	private function onComplete():void
	{
		flow.next();
	}
}
</pre>
</p>
<p>The command sequencing is abstracted into InitCommand, so that FirstCommand doesn&#8217;t need to know anything more than that it is part of a sequence. CommandFlow is a helper that allows asnychronous command sequencing to take place with a minimum of impact on the classes&#8217; functionalities themselves.</p>
<p>Each CommandFlow injected into a command is a separate instantiation, so that if nested command logic is required, then it is possible. For example:</p>
<pre class="brush: as3; title: ; notranslate">
// pseudo-code!

class Context
{
	signalCommandMap.execute(InitCommand);
}

class InitCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(FirstCommand);
		flow.push(LastCommand);
		flow.next();
	}
}

class FirstCommand
{
	[Inject]
	public var flow:CommandFlow;

	public function execute():void
	{
		flow.push(SecondCommand);
		flow.push(ThirdCommand);
	}
}
</pre>
<p>In this structure, FirstCommand will trigger SecondCommand and ThirdCommand before LastCommand is executed.</p>
<p>Payloads can be passed in explicitly through the push method, as CommandFlow exposes this method:</p>
<pre class="brush: as3; title: ; notranslate">
public function push(command:Class, ...args):Boolean;
</pre>
<p>A working demo of the code-in-action is provided in the github repository <a href="http://bit.ly/niwypL">here</a>.</p>
<h2>Notes</h2>
<p>At the moment it is not clear how to handle commands being pushed into a CommandFlow once the flow has been started with a next() call.</p>
<p>If the CommandFlow approach is to be useful, I will need to add branching into the CommandFlow class, and it could quickly become very difficult to maintain. Careful thought will be needed to cope with this.</p>
<p>After my previous post, <a href="http://www.creynders.be">Camille Reynders</a> made several good criticisms. One important one is how to handle failures. I think that this might be handled elegantly through branching, or possibly through some CommandFlow.error method that is a general &#8216;abandon-ship&#8217; method. I&#8217;m not sure yet how to implement this, since I&#8217;m not yet committed to using this sort of approach to solving asynchronicity problems.</p>
<p><a href="https://github.com/brianheylin">Brian Heylin</a> also pointed me towards some interesting resources that led me to adjust my Notices classes (my implementation of the Signals concept) to expose what I am calling a &#8216;<a href="http://bit.ly/r1z05O">Future</a>&#8216;; essentially a single-dispatch Signal/Notice, such that if you bind to it post-dispatch, the bound method is immediately called with the data that was originally dispatched.</p>
<h2>Last Thought</h2>
<p>I am keen to emphasise that these ideas are not complete; they need refining, tweaking and using. Perhaps I have gone down another blind-alley? Perhaps the Processes idea is better after-all? Or perhaps I&#8217;m misunderstanding something fundamental about how to wire-up applications with asynchronous functionality that you can enlighten me about?</p>
<p>A blog is for nothing if not shared learning. If you have any comments (positive or negative) then I would really appreciate hearing them!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/commandflow-another-approach-to-robotlegs-asynchronicity/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Asynchronous Processes and RobotLegs</title>
		<link>http://alecmce.com/library/asynchronous-processes-and-robotlegs</link>
		<comments>http://alecmce.com/library/asynchronous-processes-and-robotlegs#comments</comments>
		<pubDate>Tue, 23 Aug 2011 20:15:05 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[library]]></category>
		<category><![CDATA[opinion]]></category>
		<category><![CDATA[robotlegs]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1192</guid>
		<description><![CDATA[Asynchronous processes are a common feature of ActionScript applications: we often need to initiate some asynchronous process, wait for a response and handle it. We have good language tools and design patterns for solving these sorts issues. RobotLegs is an MVCS framework that aims to decrease inter-dependency between different parts of code, so that code [...]]]></description>
			<content:encoded><![CDATA[<p>Asynchronous processes are a common feature of ActionScript applications: we often need to initiate some asynchronous process, wait for a response and handle it. We have good language tools and design patterns for solving these sorts issues.</p>
<p>RobotLegs is an MVCS framework that aims to decrease inter-dependency between different parts of code, so that code is more robust, and more reusable. It does this through a combination of dependency injection and the model-view-controller (+services) design pattern. The &#8216;controller&#8217; portion of RobotLegs&#8217; MVCS implementation is achieved by offering coders a simple way of implementing the Command pattern and binding commands to events that can be called from other areas of the code.</p>
<p>Problematically, commands are stateless and synchronous. They are not wired up to handle asynchronicity under-the-hood. &#8220;Async Commands&#8221; amend the Command structure to attempt to solve this problem, but they still contain architectural limitations that force us to restrict the way we code to the potential of the framework. Using Commands for asynchronous processes often require us to &#8216;double wire&#8217; between different application elements to solve the problem of passing data between classes.</p>
<p>What I am calling Processes are a redesign of the Async Command concept that seek to resolve these issues. They can be used in parallel with Commands to elegantly handle the problems of asynchronous code in RobotLegs.</p>
<h2>The Async Pattern</h2>
<p>The event model exists explicitly because we often need to wire up code to be triggered at an indeterminate future event. Fundamentally, client-side programming is about state and asynchronicity: events handle the asynchronicity. We handle them with this sort of pattern:</p>
<pre class="brush: as3; title: ; notranslate">
public function init():void
{
	var process:AsyncProcess = new MyAsyncProcess();
	process.addEventListener(AsyncProcessEvent.COMPLETE, onProcessComplete);
	process.init();
}

private function onProcessComplete(event:AsyncProcessEvent):void
{
	var processs:AsyncProcess = event.process;
	process.removeEventListener(AsyncProcessEvent.COMPLETE, onProcessComplete);

	parse(process.data);
}
</pre>
<p>Signals improves upon this structure by removing the necessity of event classes and offers some added features like automatically handling the removal of listener functions:</p>
<pre class="brush: as3; title: ; notranslate">
public function init():void
{
	var process:AsyncProcess = new MyAsyncProcess();
	process.completed.addOnce(onProcessComplete);
	process.init();
}

private function onProcessComplete(process:AsyncProcess):void
{
	parse(process.data);
}
</pre>
<p>This pattern is simple but powerful &#8211; create an object to tokenise or act-as-delegate-to the process, bind to some generic event/signal defined on the token, then initialise the process. I take the signal implementation to be a substantial improvement to the original. </p>
<h2>The Async Pattern across different objects</h2>
<p>A more complex case emerges if one class wants to launch a process in another class and retrieve data from its result. Ideally we want to keep the same three-step process.</p>
<pre class="brush: as3; title: ; notranslate">
class Model
{
	public var service:Service;

	public function init():void
	{
		service.completed.addOnce(onServiceComplete);
		service.init();
	}

	private function onServiceComplete(process:AsyncProcess):void
	{
		parse(process.data);
	}
}

interface Service
{
	function get completed:Signal;

	function init():void;
}
</pre>
<p>Unfortunately, this pattern is now insufficient, because it is possible for two different objects to trigger an asynchronous process from the same service at overlapping times (such that the second one is triggered before the first response).</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelsCommand
{
	public var a:Model;
	public var b:Model;

	public function execute():void
	{
		a.init();
		b.init();
	}
}
</pre>
<p>In this scenario, if modelA and modelB both call init() in turn, then modelB will receive the data for modelA, then remove its listener before its own data is retrieved (assuming that modelA&#8217;s data is returned first, otherwise vice-versa).</p>
<p>This problem comes about because the service exposes a single Signal for multiple requests. There are two options to remedy this limitation:</p>
<pre class="brush: as3; title: ; notranslate">
// option A - the calling service tells the response where to go
interface Service
{
	function init(signal:Signal):void;
}

// option B - the service generates a response signal on a per-call basis
interface Service
{
	function init():Signal;
}
</pre>
<p>There&#8217;s not a lot between the two solutions, but I prefer Option B because it keeps together the repsonsibilities for creating and managing delegates to the asynchronous process in the same place as the process itself.</p>
<p>The pattern morphs to this:</p>
<pre class="brush: as3; title: ; notranslate">
class Model
{
	public var service:Service;

	public function init():void
	{
		service.init().addOnce(onServiceComplete);
	}

	private function onServiceComplete(process:AsyncProcess):void
	{
		parse(process.data);
	}
}

interface Service
{
	function init():Signal;
}
</pre>
<p>Here, be aware that if the signal responds within the init() method then it will not be routed to onServiceComplete. This can be handled by defining a signal that once dispatched, will dispatch immediately to any methods that are then added.</p>
<h2>Asynchronous Processes in RobotLegs</h2>
<p>The point of RobotLegs is to keep as few dependencies between different parts of code as possible. Ideally a model and a service shouldn&#8217;t reference each other, so RobotLegs best-practises would suggest you separate their interaction into a Command:</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelCommand
{
	[Inject]
	public var model:Model;

	[Inject]
	public var service:Service;

	public function execute():void
	{
		service.completed.addOnce(onResponse);
		service.init();

		commandMap.detain(this) // if we don't do this for an async command everything could explode
	}

	private function onResponse(process:AsyncProcess):void
	{
		commandMap.release(this) // if we don't do this for an async command commands stay in memory

		model.parse(process.data);
	}
}
</pre>
<p>There several problems with this implementation. Imagine that this command is called as part of an initialisation routine, and once complete, another command should be called:</p>
<pre class="brush: as3; title: ; notranslate">
class Context
{
	public function onStartup():void
	{
		signalCommandMap.mapCommand(InitModel, InitModelCommand);
		signalCommandMap.mapCommand(InitView, InitViewCommand);
	}
}
</pre>
<p>How should InitViewCommand be called? The only place where the InitModelCommand is known to be complete is in its own onResponse command:</p>
<pre class="brush: as3; title: ; notranslate">
class InitModelCommand
{
	[Inject]
	public var initView:InitView;

	...

	private function onResponse(process:AsyncProcess):void
	{
		model.parse(process.data);
		initView.dispatch();
	}
}
</pre>
<p>This is unsatisfactory. Without this, the command is neatly encapsulated and simple to describe and understand. Once this code is added, the command takes on two responsibilities: firstly to initialise the model, and secondarily to kick-off the InitViewCommand.</p>
<p>The stateless command design pattern is ill-suited for asynchronous processes, and the attempt to use them leads to poor code design.</p>
<h2>An asynchronous process for RobotLegs</h2>
<p>The simple cases at the start of this article are instructive if we try to design a preferred architecture from the ground up. While retaining the power of RobotLegs to remove class dependencies, we want to find a way to use the simple asynchronous process pattern to wire up processes.</p>
<p>These design considerations have led me to what I&#8217;ve tentatively called the <a href="https://github.com/alecmce/robotlegs-async-processes-extension">robotlegs-async-process-extension</a>. It&#8217;s very early stages, and as usual I&#8217;m sharing the code more to get feedback than as a polished piece of work, but it functions to provide what I think is a superior alternative to Async Commands.</p>
<p>The structure is roughly like this:</p>
<pre class="brush: as3; title: ; notranslate">
class Context
{
	public function onStartup():void
	{
		// a delegate is a new concept...
		processMap.map(InitModelDelegate, InitModelProcess);
		processMap.map(InitViewDelegate, InitViewProcess);
	}
}

Class InitModelDelegate extends ProcessDelegate {}

Class InitViewDelegate extends ProcessDelegate {}

class InitProcess extends Process
{
	[Inject]
	public var initModel:InitModelDelegate;

	[Inject]
	public var initView:InitViewDelegate;

	public function execute():void
	{
		initModel.execute().addOnce(onModelInited);
	}

	private function onModelInited():void
	{
		initView.execute().addOnce(onViewInited);
	}

	private function onViewInited():void
	{
		complete();
	}
}
</pre>
<p>Note the features here:</p>
<ul>
<li>Like the SignalCommandMap extension, a different core structure, the <a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/ProcessMap.as">ProcessMap</a> is defined that allows Processes to be defined in a way similar to Commands;</li>
<li>Rather than binding an event or signal to a Process, we bind a <a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/ProcessDelegate.as">ProcessDelegate</a>. We need a little bit of extra functionality in the ProcessDelegate for the structure to work satisfactorily, but this is not functionally different from the SignalCommandMap extension;</li>
<li>When a delegate is executed, it passes back a signal that the calling object binds to in order to know when the process completes (it may also send back data through this callback);</li>
<li><a href="https://github.com/alecmce/robotlegs-async-processes-extension/blob/master/src/gaia/lib/robotlegs/process/Process.as">Processes</a> can&#8217;t be duck-typed, because they also need to inherit the functionality from their base class Process. Process exposes a complete() method that is called when the Process completes. If complete() is called inside execute(), then the Process becomes functionally equivalent to a Command.</li>
</ul>
<p>In fact, this is not quite the library as developed, because I have started using <a href="https://github.com/alecmce/gaia-tween/tree/master/src/gaia/lib/notice">Notices</a> rather than Signals, so I have ported this across to Signals since it has a much broader adoption. Notices are pared down, simple implementations of Signals that allow you to expose very simple interfaces like <a href="https://github.com/alecmce/gaia-tween/blob/master/src/gaia/lib/notice/SingularNotice.as">the SingularNotice interface</a>. It&#8217;s a preference thing; if anyone would like the original implementation with Notices, I&#8217;m happy to publish it.</p>
<p>I hope that this gives you some food for thought with respect to asynchronous processes. I&#8217;d love to know what you think about the idea, the implementation, the implied critique of RobotLegs. Let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/library/asynchronous-processes-and-robotlegs/feed</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>gaia-tween</title>
		<link>http://alecmce.com/animation/gaia-tween</link>
		<comments>http://alecmce.com/animation/gaia-tween#comments</comments>
		<pubDate>Sat, 23 Jul 2011 10:52:38 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[animation]]></category>
		<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[tdd]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1141</guid>
		<description><![CDATA[Today I have pushed the first version of a new open-source tween library to github/alecmce/gaia-tween. I have been working on it for some time, to provide a robust, flexible, extensible alternative to the Greensock stable of tween libraries (TweenMax, TweenLite, etc.). I have several reasons for choosing not to use Greensock libraries for tweening: I [...]]]></description>
			<content:encoded><![CDATA[<p>Today I have pushed the first version of a new open-source tween library to <a href="https://github.com/alecmce/gaia-tween">github/alecmce/gaia-tween</a>. I have been working on it for some time, to provide a robust, flexible, extensible alternative to the Greensock stable of tween libraries (TweenMax, TweenLite, etc.).</p>
<p>I have several reasons for choosing not to use Greensock libraries for tweening:</p>
<ul>
<li>I have great respect for TweenLite, but I have rarely used it in anger. Most of the time, the applications that I work on have some element of pay-to-play, and Greensock has <a href="http://www.greensock.com/licensing/">an unusual license</a> that has put-off at least two employers from using it. I do not want to learn a library that I can only use on some of my projects;</li>
<li>For all the clean code we try to write, Tweening libraries often jar with their funky APIs. I didn&#8217;t want my tweening library to be a statically-referenced black-box of almost unreadable code, I wanted it to have elements with well-defined responsibilities, objects that encapsulate concepts of time, tweens and eases. I wanted to be able to <acronym definition="Test Drive Development">TDD</acronym> these elements and offer my tests for public scrutiny. In short, I wanted my tweening library to feel more like the rest of my code and less like dark magic;</li>
<li>Probably most of all, I wanted to write it because I could, and because I hadn&#8217;t yet.</li>
</ul>
<h2>Speed and Memory</h2>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_2" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/SpeedDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/SpeedDemo1.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/SpeedDemo.as">SpeedDemo.as source</a></div>
<p>In the tests that I have done so far, gaia-tween is fractionally behind TweenLite on speed. However, it is ahead in memory consumption! Currently the strategy for gaia-tween is to instantiate the elements that it needs and pool them indefinitely, so there is no garbage collection taking place, but I am looking to add that in as a future iteration. During tweening, no object is constructed nor destroyed by the tweening engine. Compare the memory profile of the two tween engines, from the SpeedDemo test below (<a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/SpeedDemo.as">SpeedDemo source here</a>):</p>
<h3>gaia-tween memory graph</h3>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/gaia-tween-memory.jpg" alt="" title="gaia-tween-memory" width="484" height="282" class="aligncenter size-full wp-image-1146" /></p>
<h3>TweenLite memory graph</h3>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/tweenlite-memory.jpg" alt="" title="tweenlite-memory" width="490" height="281" class="aligncenter size-full wp-image-1147" /></p>
<p>gaia-tween uses considerably less memory to run than TweenLite.</p>
<h2>Structure</h2>
<p>The API challenge was to find the right separation of responsibilities to keep the tween engine extensible without the extender having to do unnecessary work. The key features of this API are:</p>
<ul>
<li>Time is an independent concept from the tweening engine. A Time object is passed into the Tweening engine, which responds to changes in milliseconds-elapsed appropriately;</li>
<li>The ease functions have been simplified so that eases take one parameter &#8211; a proportion between 0 and 1, and return back a proportion between 0 and 1. This should make it easier for custom eases to be implemented;</li>
<li>The duration of a tween, the delay before starting it and any ease that may be applied to it are defined at the moment that a tween is added;</li>
<li>All other definition depends upon the context of the tween, and can be defined in a TweenForm. Currently three different kinds of TweenForms exist: a PropertyTweenForm for performing classic property tweens on objects; a ColorTweenForm for tweening the ColorTranform.color property of a DisplayObject; a MethodTweenForm for defining a method that will take the proportion between 0 and 1.</li>
</ul>
<p>This diagram may help explain the concepts more easily:</p>
<p><img src="http://alecmce.com/wp-content/uploads/2011/07/gaia-tween-explanation.jpg" alt="" title="gaia-tween-explanation" width="500" height="438" class="aligncenter size-full wp-image-1154" /></p>
<p>I have also added a convenience class that does the job of creating the TweenForms for you, <code><a href="https://github.com/alecmce/gaia-tween/blob/master/src/gaia/lib/tween/GaiaTweens.as">GaiaTweens.as</a></code>. This object-pools property tween forms and exposes a simplified API for those who want their tweening engine to keep everything under the hood.</p>
<h2>Examples</h2>
<p>The <code>ColorTweenForm</code> in action (roll-over to trigger):</p>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_3" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/ColorDemo1.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/ColorDemo1.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/ColorDemo.as">ColorDemo.as source</a></div>
<p><br/></p>
<p>By passing in a different <code>Time</code> class, timeline animations are possible:</p>
<div style="text-align: center; margin: auto;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_4" width="500" height="375">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/07/TimelineDemo.swf" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/07/TimelineDemo.swf" width="500" height="375">
      <!--<![endif]-->
        
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
<br/><a href="https://github.com/alecmce/gaia-tween/blob/master/demo/gaia/demo/tween/TimelineDemo.as">TimelineDemo.as source</a></div>
</p>
<p>Some issues with time-lining remain, and will be worked on for future improvements to the engine.</p>
<h2>Notices and Signals</h2>
<p>I am a huge proponent of the <a href="https://github.com/robertpenner/as3-signals/wiki">as3-signals</a> library. When <a href="http://robertpenner.com/">Robert Penner</a> originally introduced Signals, I was working on something similar with my friend <a href="http://blog.vizio360.co.uk/">Simone</a>. Since that time I have used Signals in almost every project I have worked on. However, One thing I really want to be able to do is to define a signal that only exposes an <code>addOnce</code> method. I have advocated this but there is clearly a disagreement about the direction that signals should take. So, I have created my own &#8211; simplified &#8211; implementation of signals. For want of a better name, I&#8217;ve called them <a href="https://github.com/alecmce/gaia-tween/tree/master/src/gaia/lib/notice"><code>Notices</code></a>. However, if you are interested in using or trying-out gaia-tween but are committed to using Signals, there is a <a href="https://github.com/alecmce/gaia-tween/tree/signals">signals branch</a> that replaces the Notices with Signals.</p>
<h2>Feedback</h2>
<p>I have produced this for my work at <a href="http://www.gaiaonline.com/">Gaia Interactive</a>, but Gaia have agreed to it being released because we would greatly appreciate feedback about it so that it can be improved. Please comment on API decisions, code implementations, feature requests, and so on. The more feedback I get, the more likely I can produce a robust, scalable alternative to the Greensock tweening stable. Or of course, you could fork the library and help improve it more directly!</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/animation/gaia-tween/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Reflection on Code Design</title>
		<link>http://alecmce.com/opinion/reflection-on-code-design</link>
		<comments>http://alecmce.com/opinion/reflection-on-code-design#comments</comments>
		<pubDate>Sun, 17 Jul 2011 12:30:08 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[opinion]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1117</guid>
		<description><![CDATA[I recently created a Time class which can cope with two distinct methodologies for pausing. Time will essentially be a wrapper for getTimer() that has a tick signal that fires once-per-frame and can be used as a replacement for Event.ENTER_FRAME listeners. Sometimes, if you&#8217;re making a game like Asteroids, you want to be able to [...]]]></description>
			<content:encoded><![CDATA[<p>I recently created a Time class which can cope with two distinct methodologies for pausing. Time will essentially be a wrapper for getTimer() that has a tick signal that fires once-per-frame and can be used as a replacement for Event.ENTER_FRAME listeners.</p>
<p>Sometimes, if you&#8217;re making a game like Asteroids, you want to be able to pause the game, and on resume, it continues precisely where it left off. Other times, if you&#8217;re making a social game, when you pause time continues. When you resume, your state has to suddenly catch-up.</p>
<p>You can think about this in terms of whether time is an intrinsic property of your game (if your game pauses, time pauses) or an extrinsic property that your game references (when your game pauses, time carries on).</p>
<p>Which leaves me with three possible designs for my Time class. I found it interesting that I actually went through each of these three designs, and am still unclear about whether the second or third strategy is the best.</p>
<h2>Strategy One</h2>
<pre class="brush: as3; title: ; notranslate">
public class Time
{

    public function Time();

    public function get now():uint;

    public function pause(strategy:PauseStrategy):void;

    public function resume():void;

    public function get tick():ISignal;

}

public class PauseStrategy
{
    public static const TIME_IS_EXTRINSIC;
    public static const TIME_IS_INTRINSIC;
}
</pre>
<p>The first strategy offers a great deal of flexibility. Each time you pause, you can decide whether in this case time is intrinsic or extrinsic. This seems flexible, but then it occurred to me that I couldn&#8217;t conceive of a case in which I would need to keep changing the &#8216;pause strategy&#8217;.</p>
<h2>Strategy Two</h2>
<pre class="brush: as3; title: ; notranslate">
public class Time
{

    public function Time(pauseStrategy:PauseStrategy);

    public function get now():uint;

    public function pause():void;

    public function resume():void;

    public function get tick():ISignal;

}

public class PauseStrategy
{
    public static const TIME_IS_EXTRINSIC;
    public static const TIME_IS_INTRINSIC;
}
</pre>
<p>That led me to the second strategy. I have dropped the PauseStrategy from the pause method and the API looks much easier to use, as it has fewer parameters.</p>
<p>I have left the PauseStrategy as stub-code, but the elegance of the whole PauseStrategy approach is that the TIME_IS_EXTRINSIC and TIME_IS_INTRINSIC constants could contain the core behavioural difference themselves, without needing switching inside either strategy one or two, like this:</p>
<h2>PauseStrategy</h2>
<pre class="brush: as3; title: ; notranslate">

public class PauseStrategy
{
    public static const TIME_IS_EXTRINSIC:PauseStrategy = new ExtrinsicPause();
    public static const TIME_IS_INTRINSIC:PauseStrategy = new IntrinsicPause();

    internal function onResume(timeAtPause:uint, timePaused:uint):uint
    {
        return Number.NaN;
    }
}

final internal class ExtrinsicPause extends PauseStrategy
{
    override internal function onResume(timeAtPause:uint, timePaused:uint):uint;
}

final internal class IntrinsicPause extends PauseStrategy
{
    override internal function onResume(timeAtPause:uint, timePaused:uint):uint;
}
</pre>
<p>In this way both the first two strategies can find out what the time after the pause should be by asking the strategy. The different strategies are geniunely encapsulated.</p>
<p>I am a little uncomfortable in enumerating in this way. There are plenty of ways that you can attempt to make this type-safe, but it does upset me that I have broken many a coding law by making the PauseStrategy class itself broken. It should probably be an interface itself&#8230; and then do I need a PauseStrategy factory? bah&#8230;</p>
<p>The neat API of the second strategy presents a third strategy:</p>
<h2>Strategy Three</h2>
<pre class="brush: as3; title: ; notranslate">
public interface Time
{
    function get now():uint;

    function pause():void;

    function resume():void;

    function get tick():ISignal;
}

public class ExtrinsicTime implements Time;
public class IntrinsicTime implements Time;
</pre>
<p>Here the different functionalities of the two different PauseStrategy objects would be shifted into the two different implementations of Time. Unless I ended up having an internal BaseTime class, the third strategy would mean giving up a certain amount of code <acronym definition="Don't Repeat Yourself">DRY</acronym>ness, since there would be a lot of repeated code in the two different Time implementations. I am always a little uncomfortable defining both an interface and a base class, though I have never been able to explicate exactly why.</p>
<p>So I have replaced two PauseStrategy implementations with two Time implementations. What have I gained? It seems unfeasible that there would be a third time strategy that someone could independently develop and satisfy the API for Time, so is there any good justification for interfacing Time?</p>
<h2>What would The Perfect Coder Do?</h2>
<p>The correct decision for the design of this class is that it should satisfy the current use-case. <acronym definition="Test-Driven Development">TDD</acronym> purists might argue that once the current use-case is satisfied, other design decisions are moot. I am sympathetic to this way of thinking, and cannot offer a counter-argument stronger than suggesting that this design thought-process is in-itself valuable; I do not want to minimally satisfy requirements, I want to satisfy them in the most elegant, satisfying way.</p>
<p>But which is more satisfying? While writing this I have drafted arguments that assert that both strategy 2 and strategy 3 are the best, and have found those arguments unconvincing. I am probably going to settle on strategy 2 for the time-being. Not being The Perfect Coder though, I would welcome a bit of wisdom from the community.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/opinion/reflection-on-code-design/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Working remotely and SVN</title>
		<link>http://alecmce.com/opinion/working-remotely-and-svn</link>
		<comments>http://alecmce.com/opinion/working-remotely-and-svn#comments</comments>
		<pubDate>Fri, 27 May 2011 11:48:31 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[opinion]]></category>
		<category><![CDATA[project]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1112</guid>
		<description><![CDATA[I am working remotely with a company in Beijing from Aberdeen, UK. The Beijing team is primary, they have setup an svn server to host code and have a QA team for testing. Whatever other test harnesses are in play, a commit isn&#8217;t solid until it passes QA. This is a diary of events, written [...]]]></description>
			<content:encoded><![CDATA[<p>I am working remotely with a company in Beijing from Aberdeen, UK. The Beijing team is primary, they have setup an svn server to host code and have a QA team for testing. Whatever other test harnesses are in play, a commit isn&#8217;t solid until it passes QA. This is a diary of events, written retrospectively.</p>
<h3>Abereen 9am, Beijing 5pm</h3>
<p>Conference call with Beijing to decide what I&#8217;m working on. All goes well, I start working.</p>
<h3>Aberdeen 2pm, Beijing 10pm (Commit +0 hours)</h3>
<p>I try to commit and discover that the svn server has gone down. I am stuck with a commit that I cannot commit. What do I do? The Beijing team will want this commit first thing their time, but that&#8217;s 11 hours away, at 1am my time. I can&#8217;t sit on it until then, and I don&#8217;t want to do nothing. I decide to create a patch</p>
<pre class="brush: bash; title: ; notranslate">svn diff &gt; mywork.diff</pre>
<p>Now, if I get stuck, I can</p>
<pre class="brush: bash; title: ; notranslate">
svn revert -R *
patch -p0 -i mywork.diff
</pre>
<p>and I&#8217;m back to what would be HEAD if svn wasn&#8217;t down! Essentially I&#8217;ve found a way to store atomic commits before they&#8217;re committed, marvellous. And so I continue&#8230;</p>
<h3>Aberdeen 4pm, Beijing: 12pm (Commit +2 hours)</h3>
<pre class="brush: bash; title: ; notranslate">
svn revert -R *
patch -p0 -i mywork.diff

15 out of 15 hunks failed
8 out of 8 hunks failed
3 out of 3 hunks failed
...
</pre>
<p>What!? The patch failed? How can this be!? It makes no sense! Slowly it dawns on me that the Beijing office is universally PC, whereas I am using a Mac. diff and patch expect unix line-endings, and something in there has confused them. Without any external changes at all, I&#8217;ve screwed myself. My work is gone, and I&#8217;ll have to manually apply my diffs back to the source.</p>
<p>Now, clearly I&#8217;m at fault here. I make no bones about the fact that I should have thought long and hard before I svn reverted, but I didn&#8217;t. More fool me.</p>
<h3>Aberdeen 6pm, Beijing 2am (Commit +4 hours)</h3>
<p>I have manually applied my diffs to the source and now I&#8217;m going to stop working on that and do work on a personal project. The last thing I want to do is to have to do that again!</p>
<h3>Aberdeen 1am,  Beijing 9am (Commit +11 hours)</h3>
<p>I&#8217;m asleep, meanwhile Beijing sort out the svn server and get my emails. They don&#8217;t dare touch the diff, especially after my problems.</p>
<h3>Aberdeen 9am, Beijing 4pm (Commit +19 hours)</h3>
<p>I awake, and commit my code. I do other work&#8230;</p>
<h3>Aberdeen 1am, Beijing 9am (Commit +36 hours)</h3>
<p>This is the first opportunity Beijing has had to test my work.</p>
<h2>If we&#8217;d been using git</h2>
<p>Imagine what would have happened if we&#8217;d been using git. I put it to you that I would have saved maybe 6 hours of my time and my work would have been QAed 25 hours sooner.</p>
<h3>Aberdeen: 2pm, Beijing: 10pm (Commit +0 hours)</h3>
<p>Having git committed incrementally into a local branch in my locally cloned repo, I decide it&#8217;s time to merge back to master and push. Push fails, seems like their repo is down. Oh well. I&#8217;ll keep working.</p>
<h3>Aberdeen: 1am,  Beijing 9am (Commit +11 hours)</h3>
<p>Beijing comes in, sort out the git server and get my emails. Realising what has happened they pull from my repo as a remote, which I have made sure is available for them in as a conscientious guy, not only that commit but also the other work I could have done in the 4-6 extra hours I had during that day to do work. My work can be QAed, 25 hours sooner than it actually was.</p>
<h2>Discussion</h2>
<p>Is git better than svn, or svn better than git? Almost certainly your reaction to this question is that the one that you use most and are most comfortable with is better. Of course it is, and I&#8217;m not going to be able to dissuade you with one anecdote.</p>
<p>Don&#8217;t delude yourself: most people when asked this question don&#8217;t say or even think &#8220;well, I use x more so x is better&#8221;, they think of all the reasons why x is better&#8230; but here&#8217;s the thing, they do so <em>after</em> they make their mind up, and usually their minds are made up by emotion rather than rationality. Think about it; it happens a lot. It happens to me, and to everyone at one time or another.</p>
<p>So I&#8217;m not going to tell you that git is better than svn categorically, I&#8217;m just going to say that in this scenario, I think wouldn&#8217;t git have been much better?</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/opinion/working-remotely-and-svn/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Working with Firefox</title>
		<link>http://alecmce.com/as3/working-with-firefox</link>
		<comments>http://alecmce.com/as3/working-with-firefox#comments</comments>
		<pubDate>Thu, 31 Mar 2011 23:31:04 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1108</guid>
		<description><![CDATA[Just a quickie, that you probably already know. I don&#8217;t think have I updated Firefox in a while, and suddenly when I did I was getting a lot of firefox Flash crashes when I was studying code on a breakpoint. It turns out that recent versions of Firefox run the Flash Player on a separate [...]]]></description>
			<content:encoded><![CDATA[<p>Just a quickie, that you probably already know. I don&#8217;t think have I updated Firefox in a while, and suddenly when I did I was getting a lot of firefox Flash crashes when I was studying code on a breakpoint.</p>
<p>It turns out that recent versions of Firefox run the Flash Player on a separate process that has a timeout of 45 seconds. If the player hangs for that long then the Flash Player will be crashed. That&#8217;s fine for people consuming content, but for developers it is not acceptable.</p>
<p>The solution is to modify <code>about:config</code>, and to amend the value of <code>dom.ipc.plugins.timeoutSecs</code> to the number of seconds before a crash is triggered. You can choose -1 for never, or some sufficiently long period of time.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/working-with-firefox/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple List</title>
		<link>http://alecmce.com/as3/a-simple-list</link>
		<comments>http://alecmce.com/as3/a-simple-list#comments</comments>
		<pubDate>Sat, 22 Jan 2011 04:21:09 +0000</pubDate>
		<dc:creator>alecmce</dc:creator>
				<category><![CDATA[as3]]></category>
		<category><![CDATA[library]]></category>

		<guid isPermaLink="false">http://alecmce.com/?p=1071</guid>
		<description><![CDATA[I have lost count of the number of times I&#8217;ve needed to create a UI list in the years since I started writing ActionScript. Most of the time, most of the lists that need to be created have very narrow, very simple requirements. If you ignore the visual design most lists require elements of the [...]]]></description>
			<content:encoded><![CDATA[<p>I have lost count of the number of times I&#8217;ve needed to create a UI list in the years since I started writing ActionScript. Most of the time, most of the lists that need to be created have very narrow, very simple requirements. If you ignore the visual design most lists require elements of the same size, uniformly positioned to be scrolled so that a subset of the list is visible within a given &#8216;viewing&#8217; area at any one time.</p>
<h2>The design FLA</h2>
<p>There are lots of different ways to approach putting a list together. For a bunch of different reasons I tend to work by loading SWFs that have no code into a code-base and then adding functionality by composition. In that way, artists can manipulate assets unencumbered by the code, and I can reuse code across an application with multiple swfs in a very easy-to-manage way.</p>
<p>To create my list then, I create an &#8216;item&#8217; MovieClip, and iterate it vertically or horizontally in a secondary &#8216;list&#8217; MovieClip. Then, to demarcate the visual limits of the list I apply a mask to it, like this:</p>
<p><img src="http://alecmce.com/wp-content/uploads/2011/01/structure.png" alt="" title="structure" width="530" height="400" class="aligncenter size-full wp-image-1078" /></p>
<p>Notice that there is at least one, but more often two &#8216;overflow&#8217; elements defined on the list; that is, list items that don&#8217;t actually show up initially. These are used later on when the list has to scroll.</p>
<h2>Compositing the FLA into VList</h2>
<p>When this swf is loaded into the application, the <a href="https://github.com/alecmce/SimpleList/blob/master/src/alecmce/list/VList.as">VList class</a> configures it very straightforwardly, creating a vector of ListItem objects that wrap each item MovieClip.</p>
<p>When this swf is loaded into the application, the <a href="https://github.com/alecmce/SimpleList/blob/master/src/alecmce/list/ListItem.as">ListItem</a> objects that wrap each list-item MovieClips.</p>
<p>In order to separate functionality from the scrolling mechanism (which could be scrolling arrows, a scrollbar, drag-fling functionality, or whatever else), the position of the list is defined by the <code>VList.position</code> property. When this property changes, the list updates its position by doing the following:</p>
<ul>
<li>The list container is moved upwards as the position increases;</li>
<li>As the top list items disappear out of the masked area, they are repositioned to the bottom and reassigned different data;</li>
</ul>
<p>In this way, no extra visual items need to be constructed or destructed, and as few objects are moved per change of position as possible. It is fast, clean and efficient.</p>
<h2>VList Code</h2>
<p>The <code>position</code> setter immediately repositions the container clip when a new position is asserted. (The first line merely checks for <code>isNaN(value)</code> in a more efficient way). Then, it checks whether the top-most element visible in the list is the same as it was before. If it is not, then <code>updateItems()</code> is called.</p>
<pre class="brush: as3; title: ; notranslate">
/**
 * baseY is the position that container.y has when _position is 0
 * dy is the distance between the same point on two adjacent ListItems
 * _index retains the integer value of the previous list position
 */
public function set position(value:Number):void
{
	_position = value != value ? 0 : value;
	container.y = baseY - _position * dy;

	var newIndex:int = _position | 0;
	if (_index == newIndex)
		return;

	_index = newIndex;
	updateItems();
}
</pre>
<p><code>updateItems()</code> then iterates through all the ListItems, positions them appropriately within the container clip and asserts data into each item</p>
<pre class="brush: as3; title: ; notranslate">
/**
 * items is a Vector of ListItem, one for each MovieClip list item
 * count is the number of ListItems in items
 * _data is the data that differentiates each item
 */
private function updateItems():void
{
	var i:int = count;
	while (i--)
	{
		var n:int = i + _index;
		var item:ListItem = items[n % count];

		item.mc.y = n * dy;
		item.datum = n &lt; dataLength ? _data[n] : null;
	}
}
</pre>
<p>ListItem will check whether it&#8217;s current datum is the same as the one entered, and if it is it will not update the visual component. If the datum does change, then ListItem passes it&#8217;s MovieClip into <code>ListDatum.apply(mc:MovieClip)</code> to be updated.</p>
<h2>Add A Scrollbar &#8211; Job Done</h2>
<p>And that&#8217;s it really. It needs a few trimmings of course, like a scrollbar or arrows to actually trigger the scrolling. In the example below a scrollbar class is added, and when the scrollbar changes it relays the position back to the list:</p>
<div style="margin: auto; 0px; text-align: center;">
    <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" id="swfobj_5" width="400" height="600" align="center">
      <param name="movie" value="http://alecmce.com/wp-content/uploads/2011/01/Example.swf" />
      <param name="align" value="center" />
      <!--[if !IE]>-->
      <object type="application/x-shockwave-flash" data="http://alecmce.com/wp-content/uploads/2011/01/Example.swf" width="400" height="600" align="center">
      <!--<![endif]-->
        An example of the list that this article discusses
      <!--[if !IE]>-->
      </object>
      <!--<![endif]-->
    </object>
</div>
<p>This sturcture is fairly simple too, and can be found in the <a href="https://github.com/alecmce/SimpleList/blob/master/src/Example.as">Example class</a>.</p>
<pre class="brush: as3; title: ; notranslate">
	...

	list = new VList(content.list);

	scrollbar = new VScrollbar(content.knob, content.groove);
	scrollbar.reposition.add(onReposition);

	...

	list.data = data;
	scrollbar.setup(4, data.length);
	scrollbar.isVisible = data.length &gt; 4;
}

private function onReposition(value:Number):void
{
	list.position = value;
}
</pre>
<h2>Summary</h2>
<p>I am very satisfied with this implementation. It might need a tweak here or there, but it does it&#8217;s job very cleanly.  There are more complex cases where you have could have list data of different sizes, or you could have an absolutely enormous data set. Then, this list may not be appropriate, but for the 99% of cases where this is not the case, I think this serves its purpose well.</p>
<p>The complex problem facing most people making lists is choosing which control functionality to implement: drag-fling, scrollbars, little Apple dots, or arrows. Maybe you also want to add touches like bounce effects when you hit the limits of the list. All of these solutions can be developed separately from the core list class and coupled together in a way similar to my basic VScrollbar.</p>
<p>As ever, this code is available on <a href="https://github.com/alecmce/SimpleList">GitHub</a>. I would welcome any comments, improvements or suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://alecmce.com/as3/a-simple-list/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

