<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[CodeBrief]]></title>
  <link href="http://codebrief.com/atom.xml" rel="self"/>
  <link href="http://codebrief.com/"/>
  <updated>2012-03-31T17:34:04-07:00</updated>
  <id>http://codebrief.com/</id>
  <author>
    <name><![CDATA[Gordon Leland Hempton]]></name>
    <email><![CDATA[ghempton@gmail.com]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Make the Most of Your Routes]]></title>
    <link href="http://codebrief.com/2012/03/make-the-most-of-your-routes/"/>
    <updated>2012-03-31T11:18:00-07:00</updated>
    <id>http://codebrief.com/2012/03/make-the-most-of-your-routes</id>
    <content type="html"><![CDATA[<p>At the core of any web application is a mapping between urls and application logic; a mapping between what is in the browser&#8217;s address bar and what should be displayed on the screen. Rails has routes.rb, Django has URLconf, Backbone.js has <del>controllers</del>Backbone.Router, and Sammy.js has Sammy.js.</p>

<p>We also aren&#8217;t talking about arbitrary URLs here. Modern well-designed applications use clean, semantic, and probably RESTful urls. These are urls which are human-readable, have a natural hierarchy to them, and intuitively reflect the underlying data to which they relate.</p>

<p>So, what&#8217;s the problem?</p>

<h3>Problem: Routers Are Designed for Stateless Servers</h3>

<p>Historically, url routing systems are designed for web servers which maintain little to no state about the client which is making the request<sup><a href="#footnote-1">1</a></sup>. A typical request/response lifecycle would look something like the following:</p>

<ol>
<li>A url is requested.</li>
<li>The server loads all resources corresponding to the url.</li>
<li>A response is rendered and sent back to the client.</li>
<li>All server-side resources are released.</li>
</ol>


<p>By not maintaining state, the server is able to drastically reduce its memory-footprint. With this scheme in mind, it makes sense for routing systems to be nothing more than a mapping from url patterns to actions, an example of which is represented in the diagram below:</p>

<p><img src="http://codebrief.com/images/posts/routes_stateless.png" alt="Stateless routes" class="centered" /></p>

<p>Here there are four different actions: <code>index</code>, <code>show</code>, <code>edit</code>, and <code>comments</code>, with corresponding url patterns. When a url for one of these actions is requested, the application must load the resource or collection, ensure that the current user has the required permissions to view the page, and render one or more templates.</p>

<p>These days, however, many applications are moving away from the server and into the realm of the client-side single page javascript application. Views are no longer being rendered on the server, pages are no longer being refreshed on each request, and urls are being manipulated through hashes and HTML5&#8217;s <a href="https://developer.mozilla.org/en/DOM/Manipulating_the_browser_history">pushState method</a>. Javascript MVC frameworks such as Backbone and Ember have also arrisen to make these types of applications more pallatable to develop.</p>

<h3>State is Ridiculously Cheap on the Client</h3>

<p>Most client-side javascript applications probably have access to more memory than the virtual machines that serve them. Much like programming for the desktop, one of the great benefits of single-page javascript apps is that you can freely maintain as much state as you want.</p>

<p>Despite this, javascript routing system are still beholden to the same approach used by stateless servers. Routes are still nothing more than a primitive map from patterns to functions, and the above diagram still applies. <em>This is barbaric.</em> In the context of a client-side application, the url-triggered actions of loading models, checking permissions, and rendering shared layout have become extremely redundant.</p>

<h3>Solution: Stateful Routes</h3>

<p>A solution for this is to incorporate a more stateful approach to routing. Common state between actions can be extracted into additional states. Consider the following re-factorization:</p>

<p><img src="http://codebrief.com/images/posts/routes_stateful.png" alt="Stateful routes" class="centered" /></p>

<p>The above diagram still captures that same url structure as the first diagram, but an intermediate state has been created which encapsulates some common logic. The <code>show</code>, <code>edit</code>, and <code>comments</code> actions all share a parent <code>item</code> state. The <code>item</code> state has some common concerns inside of it that are shared by all its children. Namely, the loading of the resource corresponding to the id, checking read permissions, and loading a common layout.</p>

<p>The idea here is that each leaf state corresponds to a route and as a route is loaded, each state along its path from the root is entered. Edges between states correspond to optional url fragments. Thus, when the url is changed to <code>items/1</code>, both the <code>item</code> and the <code>show</code> states are loaded. Similary, when the url is changed to <code>items/1/comments</code>, the <code>item</code> and <code>comments</code> states are loaded.</p>

<p>So far you might be relatively unimpressed. Sure this is a nice declarative approach to moving some cross-cutting concerns into a better location, but it could be argued that something like controller inheritance could accomplish the same thing. Bear with me.</p>

<h3>Stateful Transitions Are Awesome</h3>

<p>This becomes really cool when you take into account transitioning from one state to another. For instance, consider the transition on the client from the url <code>items/1</code> to <code>items/1/edit</code>. This corresponds to a transition from the <code>show</code> state to the <code>edit</code> state. This is captured in the diagram below:</p>

<p><img src="http://codebrief.com/images/posts/routes_stateful_transition.png" alt="Stateful route transition" class="centered" /></p>

<p>Since both the <code>show</code> and <code>edit</code> states share a common parent state, there is no need for it to be re-entered. All of the concerns inside the <code>item</code> state have already been addressed and it is trivial for the client to know to just change the view.</p>

<p>Transitions between states can also be dicated by more than url fragments. States can be defined by whether a user is logged in, if a post has been published, if the user is an admin, etc. This makes it extremely easy to turn off or provide alternate behavior for entire groups of routes based on application state. Just for fun, here is a diagram for such a case:</p>

<p><img src="http://codebrief.com/images/posts/routes_complex.png" alt="Complex routes" class="centered" /></p>

<p>Here, there are different routing trees depending on whether the user is logged in or not.</p>

<h3>Ember.js RouteManager Plug</h3>

<p>This is the part of the blog post where I shamelessly plug a project, <a href="https://github.com/ghempton/ember-routemanager">Ember RouteManager</a>, which is routing system for <a href="http://emberjs.com">Ember.js</a> built with the design I have given in this post. I&#8217;m not going to include any code samples here, but I recommend you check it out!</p>

<div class="footnotes">
<p id="footnote-1">1. There do exist plenty of stateful server-side web frameworks (continuations are cool), but they could also benefit from stateful routing.</p>
</div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Eight Ember.js Gotchas With Workarounds]]></title>
    <link href="http://codebrief.com/2012/03/eight-ember-dot-js-gotchas-with-workarounds/"/>
    <updated>2012-03-11T12:31:00-07:00</updated>
    <id>http://codebrief.com/2012/03/eight-ember-dot-js-gotchas-with-workarounds</id>
    <content type="html"><![CDATA[<p>Having used <a href="http://emberjs.com">Ember.js</a> for a few months now, I have compiled a list of gotchas that I have encountered. Many of these will change/be fixed as Ember matures, but until then I hope these will serve as pre-emptive time savers for other developers.</p>

<h3>1. Computed Properties and .cacheable()</h3>

<p>This one has actually been fixed in the lastest build of Ember, but I&#8217;m putting it here since it is still present in the latest 0.9.5 release. Consider the following object:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">object</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">tags</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[];</span>
</span><span class='line'>  <span class="p">}.</span><span class="nx">property</span><span class="p">()</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>It turns out that if you try and bind to the <code>tags</code> property of the above object, you will encounter an infinite run loop. Any computed property which does not return a primitive value will suffer from this, the underlying cause being due to failing equivalence tests. This fix is to add a call to cacheable() to the end of the computed property:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">object</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nb">Object</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">tags</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[];</span>
</span><span class='line'>  <span class="p">}.</span><span class="nx">property</span><span class="p">().</span><span class="nx">cacheable</span><span class="p">()</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>Even though the infinite loop issue has been fixed, making computed properties cacheable is generally a good idea and will be more the rule than the exception.</p>

<h3>2. firstObject and lastObject</h3>

<p>These properties of enumerables are not bindable. Although this was intentional for performance reasons, this is quite unexpected and I hope this to be fixed in the future. For now, you can create a custom computed property as a substitute:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">myController</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nx">ArrayController</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="p">...</span>
</span><span class='line'>  <span class="nx">firstItem</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">getPath</span><span class="p">(</span><span class="s1">&#39;content.firstObject&#39;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}.</span><span class="nx">property</span><span class="p">(</span><span class="s1">&#39;content.@each&#39;</span><span class="p">).</span><span class="nx">cacheable</span><span class="p">()</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<h3>3. Combining Static and Dynamic CSS Class Names</h3>

<p>It will often be the case that you want an element inside a handlebars template to have <em>both</em> a static css class name as well as class name that is the result of binding to a property. In order to do this in version 0.9.5, use the code below:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="err">{{</span><span class="na">bindAttr</span> <span class="na">class=</span><span class="s">&quot;myProperty:dynamicClass alwaysTrue:staticClass&quot;</span><span class="err">}}</span><span class="nt">&gt;&lt;/div&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>This code will add the <code>dynamicClass</code> class to the div when <code>myProperty</code> is true. The <code>alwaysTrue</code> property is a property you define that always evaluates to true; this will ensure that the div <em>always</em> has the <code>staticClass</code> class.</p>

<p>In the latest build of ember, a shorthand has been created for this:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="err">{{</span><span class="na">bindAttr</span> <span class="na">class=</span><span class="s">&quot;myProperty:dynamicClass :staticClass&quot;</span><span class="err">}}</span><span class="nt">&gt;&lt;/div&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Specifying just <code>:staticClass</code> (without the <code>alwaysTrue</code> property) will have this same effect.</p>

<h3>4. Bound Handlebars Helpers</h3>

<p>As it currently stands, handlebars helpers inside of Ember are just normal helpers. They do not have any of the secret sauce which makes them automatically update when the properties they depend on change. In order to make helpers bound to properties, you must add the magic in yourself.</p>

<p>Fortunately, I have created a <a href="https://gist.github.com/2018185">gist</a> which packages this functionality up into a convenient syntax that is similar to computed properties:</p>

<p>To define a bound helper this way, do something like the following:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">Ember</span><span class="p">.</span><span class="nx">registerBoundHelper</span><span class="p">(</span><span class="s1">&#39;currency&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">value</span><span class="p">,</span> <span class="nx">options</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span><span class="p">(</span><span class="o">!</span><span class="nx">value</span><span class="p">)</span> <span class="k">return</span> <span class="s2">&quot;&quot;</span>
</span><span class='line'>  <span class="k">return</span> <span class="s2">&quot;$&quot;</span> <span class="o">+</span> <span class="nx">value</span><span class="p">.</span><span class="nx">toString</span><span class="p">().</span><span class="nx">replace</span><span class="p">(</span><span class="sr">/(\d)(?=(\d\d\d)+(?!\d))/g</span><span class="p">,</span> <span class="s2">&quot;$1,&quot;</span><span class="p">)</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now you can use this inside of any of your handlebars templates:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;span&gt;</span>{{currency myProperty}}<span class="nt">&lt;/span&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>The helper output will auto-magically update when the value of <code>myProperty</code> changes.</p>

<h3>5. Each Blocks, Indices, and Metamorph</h3>

<p>This one can be very inconvenient at times. Ember&#8217;s <code>{{#each}}</code> helper does not provide access to an <code>index</code> property. This can make things such as styling cumbersome. The situation is also compounded by the fact that the DOM-binding library that Ember uses, Metamorph, also adds html metadata (in the form of <code>script</code> tags) to the dom that can break certain CSS selectors.</p>

<p>Consider the following handlebars template:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;ul&gt;</span>
</span><span class='line'>{{#each myArray}}
</span><span class='line'>  <span class="nt">&lt;li&gt;</span>{{this}}<span class="nt">&lt;/li&gt;</span>
</span><span class='line'>{{/#each}}
</span><span class='line'><span class="nt">&lt;/ul&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>This template loops over the enumerable <code>myArray</code> and outputs its contents into list item elements. One would intuitively expect to be able to use the <code>:first-child</code> CSS pseudo-selector to give the first element in the list a particular style, but this is not the case. Upon inspecting the DOM, it will be noticed that there is a <code>&lt;script&gt;</code> tag before the first element. In order to work around this, use the <a href="http://www.w3.org/TR/selectors/#nth-of-type-pseudo">nth-of-type pseudo selector</a>.</p>

<p>In some cases, however, using a CSS workaround will not be sufficient and having access to the item array indices will be required. Ultimately, I hope an <code>eachWithIndex</code> helper makes it into Ember&#8217;s core, but for now the underlying data must be altered to contain the indices. One easy way of doing this is to create a computed property to this end:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'>  <span class="nx">myArrayWithIndices</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="nx">myArray</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">i</span><span class="p">,</span> <span class="nx">idx</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="k">return</span> <span class="p">{</span><span class="nx">item</span><span class="o">:</span> <span class="nx">i</span><span class="p">,</span> <span class="nx">index</span><span class="o">:</span> <span class="nx">idx</span><span class="p">};</span>
</span><span class='line'>    <span class="p">});</span>
</span><span class='line'>  <span class="p">}.</span><span class="nx">property</span><span class="p">(</span><span class="s1">&#39;myArray.@each&#39;</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>The above template could now be rewritten to include indices:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;ul&gt;</span>
</span><span class='line'>{{#each myArrayWithIndices}}
</span><span class='line'>  <span class="nt">&lt;li&gt;</span>{{this.index}}. {{this.item}}<span class="nt">&lt;/li&gt;</span>
</span><span class='line'>{{/#each}}
</span><span class='line'><span class="nt">&lt;/ul&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<h3>6. Object Default Value Initialization</h3>

<p>The way default values for properties work in Ember is somewhat different from many other languages/frameworks. This will be especially unintuitive for people coming from more traditional object oriented languages such as Java.</p>

<p>Consider the following snippet:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">Category</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nb">Object</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">tags</span><span class="o">:</span> <span class="p">[]</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">animals</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">();</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">reptiles</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="nx">animals</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">).</span><span class="nx">pushObject</span><span class="p">(</span><span class="s1">&#39;warm-blooded&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">reptiles</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">));</span> <span class="c1">// unexpectedly outputs [&#39;warm-blooded&#39;]</span>
</span></code></pre></td></tr></table></div></figure>


<p>In the above example both <code>animals</code> and <code>reptiles</code> share the same tags array. In Ember, object property initialization only runs once per class definition. To get around this, you must either move default value initialization into the <code>init</code> method or just re-define the entire array for each instance:</p>

<p>Fix #1:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">Category</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nb">Object</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">init</span><span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">this</span><span class="p">.</span><span class="nx">_super</span><span class="p">();</span>
</span><span class='line'>    <span class="k">this</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">,</span> <span class="p">[]);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">animals</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">();</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">reptiles</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'><span class="nx">animals</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">).</span><span class="nx">pushObject</span><span class="p">(</span><span class="s1">&#39;warm-blooded&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">reptiles</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">));</span> <span class="c1">// outputs []</span>
</span></code></pre></td></tr></table></div></figure>


<p>Fix #2:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">Category</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nb">Object</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">animals</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">tags</span><span class="o">:</span> <span class="p">[</span><span class="s1">&#39;warm-blooded&#39;</span><span class="p">]</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">reptiles</span> <span class="o">=</span> <span class="nx">Category</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">tags</span><span class="o">:</span> <span class="p">[]</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="nx">reptiles</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;tags&#39;</span><span class="p">));</span> <span class="c1">// outputs []</span>
</span></code></pre></td></tr></table></div></figure>


<p>Everything I just said also applies to any non-primitive property, such as objects.</p>

<h3>7. Metamorph Metadata</h3>

<p>Ember <a href="http://yehudakatz.com/2011/06/11/using-sproutcore-2-0-with-jquery-ui/">plays nicely with other frameworks</a>. <em>For the most part</em>. Sometimes Metamorph gets in the way. For instance, any framework which reliess on cloning DOM elements will probably have some issues (such as jQuery UI&#8217;s draggable).</p>

<p>A workaround for this is to clone the element with all of the Metamorph metadata removed. Fortunately, once again I have a gist for this:</p>

<div><script src='https://gist.github.com/2018290.js?file='></script>
<noscript><pre><code># Small extension to create a clone of the element without
# metamorph binding tags and ember metadata

$.fn.extend
  safeClone: -&gt;
    clone = $(@).clone()
    
    # remove content bindings
    clone.find('script[id^=metamorph]').remove()
    
    # remove attr bindings
    clone.find('*').each -&gt;
      $this = $(@)
      $.each $this[0].attributes, (index, attr) -&gt;
        return if attr.name.indexOf('data-bindattr') == -1
        $this.removeAttr(attr.name)
        
    # remove ember IDs
    clone.removeAttr('id') if clone.attr('id') &amp;&amp; clone.attr('id').indexOf('ember') != -1
    clone.find('[id^=ember]').removeAttr('id')
    clone
    </code></pre></noscript></div>


<h3>8. Run Loop Debugging With Chrome</h3>

<p>This one is somewhat more obscure and particular only to Chrome. Ember has the concept of a run loop which batches bindings and does some other neat stuff. Generally speaking, you won&#8217;t have to know much about it, except when you do.</p>

<p>When inside the run loop, Ember wraps everything in a <code>try/finally</code> statement (with no catch). In theory this should not affect anything, but Chrome has a particularly <a href="http://code.google.com/p/chromium/issues/detail?can=2&amp;start=0&amp;num=100&amp;q=finally%20uncaught&amp;colspec=ID%20Pri%20Mstone%20ReleaseBlock%20Area%20Feature%20Status%20Owner%20Summary&amp;groupby=&amp;sort=&amp;id=79989">nasty bug</a> where the console will swallow uncaught exceptions if they go through a finally (and will also not call <code>window.onerror</code>).</p>

<p>The easy workaround for this is to set Chrome to automatically break on uncaught exceptions, but worth mentioning since there is nothing worse than having to discover exceptions through side effects.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Productivity Versus Performance: Fighting The Good Fight]]></title>
    <link href="http://codebrief.com/2012/02/productivity-versus-performance-fighting-the-good-fight/"/>
    <updated>2012-02-22T10:38:00-08:00</updated>
    <id>http://codebrief.com/2012/02/productivity-versus-performance-fighting-the-good-fight</id>
    <content type="html"><![CDATA[<p>If you&#8217;ve been following the Javascript MVC landscape lately, you might have noticed a growing tension between <a href="http://documentcloud.github.com/backbone/">Backbone.js</a> and <a href="http://emberjs.com/">Ember.js</a>. Being championed by Jeremy Ashkenas and Yehuda Katz respectively, both frameworks reside in decidely different camps. Ember.js favors deep abstraction and sensible defaults, whereas Backbone.js embraces the micro-framework mentality of providing a minimalist set of features whilst encouraging integration with a wide variety of other frameworks.</p>

<p>The most recent evolution of the debate, however, has resided around performance. An <a href="http://news.ycombinator.com/item?id=3616820">animation benchmark</a> comparing the two frameworks was posted on Hacker News yesterday. Despite being a contrived example, the results of the benchmark are undisputable: Backbone.js is significantly faster than Ember.js - and by a visible margin. The reason for this is the computational overhead incurred by Ember&#8217;s view binding system. A core feature of Ember is a rich, bindable and composable view system which has been designed to simplify common programming tasks. Simply put: Ember.js has been built to make development easier.</p>

<p>Of course Ember.js could be optimized and the gap in the benchmark could be narrowed, but that is moot. What is really happening here is the age old dispute of developer productivity versus application performance. New technologies are constantly being introduced which make the lives of developers easier and encumbent technologies will always defend their trenches. The easiest thing for existing technologies to point at is performance - as grander abstractions naturally incur larger overheads. These might be a little more stark than the Ember vs. Backbone debate, but here are some examples that immediately come to mind:</p>

<ol>
<li><p>Assemby vs. C: When I was younger, our family computer had a great operating system installed called <a href="http://en.wikipedia.org/wiki/GEOS_(16-bit_operating_system">GEOS</a>). It was a really nice piece of software. Only later in life did I learn that it was written almost entirely in <em>8086 assembly language</em>. Despite being written in the ultimate low-level language, it ultimately became a slower product than its competitors and part of its demise was due to system complexity.</p></li>
<li><p>Java vs. C++: When Java was first introduced, it was ridiculed for being extremely slow. Over time, especially in the post-JIT era, it has gained the opposite reputation. In today&#8217;s landscape, the JVM is considered one of the faster platform choices, even exceeding C++ in some benchmarks.</p></li>
<li><p>Static vs Dynamic: Among other things, dynamic language skeptics have always pointed a finger at performance. <a href="http://shootout.alioth.debian.org/u32/which-programming-languages-are-fastest.php">Even today</a>, lanuages like Ruby and Python are still an order of magnitude slower than some of their static counterparts. Despite this, frameworks like ROR and Django are industry norms. Javascript itself has also defied people&#8217;s beliefs and expectations as projects like V8 have taken it to the next level.</p></li>
</ol>


<p>There are two things going on here:</p>

<p>The first is <a href="http://steve-yegge.blogspot.com/2008/05/dynamic-languages-strike-back.html">summarized succintly</a> by Steve Yegge: &#8220;Global optimizations always trump benchmarks.&#8221; Even if a framework/language is slower at a granular level, a system with an overall reduced complexity will still run faster. I would much rather live a world where I can do more faster while at the same time benefitting from global optimizations introduced transparently by the framework itself than one where I consciously chose to sacrifice convenience for performance.</p>

<p>Second, slow is relative. It is important to know when performance matters and when it doesn&#8217;t. Databases, real-time systems, and heavily trafficked servers clearly benefit from saved cycles. Apparently it makes sense for CouchDB to <a href="http://damienkatz.net/2012/01/the_future_of_couchdb.html">move to C/C++ from Erlang</a>, but there are also a lot of situations where performance just simply doesn&#8217;t matter that much.</p>

<p>The realm of client-side development is a perfect example of this. Where else do you have essentially unbounded access to a modern CPU in order to scale an application to all of a <em>single user</em>? If anything, in most cases there is a <em>glut</em> of CPU resources that are under-utilized. In the case where you absolutely need to ensure a complex animation runs smoothly, any good framework will allow you to break away from its shackles and apply some manual optimization (you should probably be exploring something like WebGL in this case anyways). There are very few reasons to prematurely optimize for performance in client-side web developement.</p>

<p>In all fairness, Ember.js still <em>does</em> have work do to in the performance area and is actively being developed. Backbone.js is also a great framework and a good choice for a number of applications. At the end of the day, however, to fundamentally criticize a javascript framework for being slow is really to suggest that we have reached the limits of front-end web development. I sincerely hope that is not the case. We should all be striving as developers to make our lives as easy as possible. I personally hope that Ember is just the tip of an iceberg and that even more feature-rich, abstracted, and <em>*gasp*</em> possibly slower frameworks are on the horizon.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Anatomy of a Complex Ember.js App Part I: States and Routes]]></title>
    <link href="http://codebrief.com/2012/02/anatomy-of-a-complex-ember-js-app-part-i-states-and-routes/"/>
    <updated>2012-02-14T13:24:00-08:00</updated>
    <id>http://codebrief.com/2012/02/anatomy-of-a-complex-ember-js-app-part-i-states-and-routes</id>
    <content type="html"><![CDATA[<p>I am long on <a href="http://emberjs.com/">Ember.js</a>. I previously wrote a <a href="http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/">brief comparison</a> of some of the more popular javascript frameworks, and Ember came out on top. I am now in the process of incorporating it into <a href="http://grouptalent.com">GroupTalent</a> in a big way.</p>

<p>Due to the recent origins of Ember, one of its biggest shortcomings is a serious lack of documentation. Its website and some related <a href="http://www.cerebris.com/blog/2012/01/24/beginning-ember-js-on-rails-part-1/">blog posts</a> focus only on the basics and hello world type examples (read <a href="https://github.com/addyosmani/todomvc">todo</a> in the js mvc world). A major reason for this is that the patterns required for a complex application have not yet been added to the core Ember.js codebase. That is not to say, however, that complex Ember.js applications are not already being built.</p>

<p>With that in mind, I have decided to write a series of posts detailing some of the libraries and patterns I have been using for Ember development. In this post, I cover creating a multi-page application: all that is required to swap out different pages and sub-pages as well as tieing everything in to the browser location and the HTML5 history API. Specifically I discuss two libraries that I have written, <a href="https://github.com/ghempton/ember-layout">Ember Layout</a> and <a href="https://github.com/ghempton/ember-routemanager">Ember RouteManager</a>. You can also skip ahead and see an <a href="http://ghempton.github.com/ember-layout-example/">example application</a> in action.</p>

<h2>Meet The State Manager</h2>

<p>A core construct inside of Ember is the notion of states managed by a state manager. This is used in many places inside the Ember.js codebase, including managing view render states. Thus, it is only natural for this construct to be used to manage the composition of views as well.</p>

<p>In fact, Ember already has primitive support for managing views inside it&#8217;s core. You can do the following:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">stateManager</span> <span class="o">=</span> <span class="nx">Ember</span><span class="p">.</span><span class="nx">StateManager</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">rootElement</span><span class="o">:</span> <span class="s1">&#39;#content&#39;</span><span class="p">,</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">section1</span><span class="o">:</span> <span class="nx">Ember</span><span class="p">.</span><span class="nx">ViewState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="nx">view</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">section1</span>
</span><span class='line'>  <span class="p">}),</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">section2</span><span class="o">:</span> <span class="nx">Ember</span><span class="p">.</span><span class="nx">ViewState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="nx">view</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">section2</span>
</span><span class='line'>  <span class="p">})</span>
</span><span class='line'>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>Setting the stateManager&#8217;s state to <code>section1</code> will automatically append the <code>App.section1</code> view to the element selected by <code>#content</code>. If the state is then set to <code>section2</code> the old view will be removed and replaced by <code>App.section2</code>.</p>

<p>This is sufficient for extremely basic applications, but breaks down when the demands are more complex. This method is restricted to view hierarchies that are only a single level deep - most often not the case. The canonical example of this is a page with a primary navigation and a sub-page that has its own tabbing system. What is really needed here is a way to dynamically nest views arbitrarily deep.</p>

<h2>Layouts</h2>

<p><a href="https://github.com/ghempton/ember-layout">Ember Layout</a> adds an intuitive layout mechanism on top of Ember.js. You can see it in action <a href="http://ghempton.github.com/ember-layout-example/">here</a>. It adds the concept of a handlebars <code>{{yield}}</code> helper which can be used to indicate insertion points of dynamically replaceable content. This should be extremely familiar to anyone with a rails background, but with the added notion of being dynamically replaceable.</p>

<p>Here is a code snippet extracted from the example:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">main</span> <span class="o">=</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">LayoutView</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">templateName</span><span class="o">:</span> <span class="s1">&#39;main&#39;</span>
</span><span class='line'><span class="p">});</span>
</span><span class='line'>
</span><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">routeManager</span> <span class="o">=</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">RouteManager</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">rootLayout</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">main</span><span class="p">,</span>
</span><span class='line'>  <span class="p">...</span>
</span><span class='line'>  <span class="nx">layoutNesting</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">NavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>    <span class="nx">viewClass</span><span class="o">:</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">LayoutView</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
</span><span class='line'>      <span class="nx">templateName</span><span class="o">:</span> <span class="s1">&#39;layout-nesting&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="p">}),</span>
</span><span class='line'>    <span class="nx">section1</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">SubNavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>      <span class="p">...</span>
</span><span class='line'>      <span class="nx">viewClass</span><span class="o">:</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">View</span><span class="p">.</span><span class="nx">extend</span><span class="p">({</span>
</span><span class='line'>        <span class="nx">title</span><span class="o">:</span> <span class="s1">&#39;Section 1&#39;</span><span class="p">,</span>
</span><span class='line'>        <span class="nx">templateName</span><span class="o">:</span> <span class="s1">&#39;section&#39;</span>
</span><span class='line'>      <span class="p">})</span>
</span><span class='line'>    <span class="p">}),</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>  <span class="p">})</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>And the corresponding template code:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/x-handlebars&quot;</span> <span class="na">data-template-name=</span><span class="s">&quot;main&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>  <span class="p">...</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;container&quot;</span><span class="o">&gt;</span>
</span><span class='line'>    <span class="p">{{</span><span class="nx">yield</span><span class="p">}}</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'><span class="nt">&lt;/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;script </span><span class="na">type=</span><span class="s">&quot;text/x-handlebars&quot;</span> <span class="na">data-template-name=</span><span class="s">&quot;layout-nesting&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>  <span class="p">...</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="nx">div</span> <span class="kr">class</span><span class="o">=</span><span class="s2">&quot;sub-container&quot;</span><span class="o">&gt;</span>
</span><span class='line'>    <span class="p">{{</span><span class="nx">yield</span><span class="p">}}</span>
</span><span class='line'>  <span class="o">&lt;</span><span class="err">/div&gt;</span>
</span><span class='line'><span class="nt">&lt;/script&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>When the routeManager (i.e. StateManager) goes to the <code>layoutNesting.section1</code> state, a view instance specified by the <code>viewClass</code> property of the <code>layoutNesting</code> state is inserted into the <code>{{yield}}</code> location in the main template. This newly inserted view also has <em>its own</em> <code>{{yield}}</code> location, which is replaced by the view from the <code>section1</code> state. Switching to a different state will then automatically reconstruct this view hierarchy.</p>

<h2>Routing</h2>

<p>At the crux of any single-page web application is a routing system. Although Ember doesn&#8217;t natively include/endorse any particular routing system, it plays well with almost anything out there. Options include <a href="https://github.com/emberjs-addons/sproutcore-routing">SprouteCore Routing</a> and <a href="http://sammyjs.org/">Sammy.js</a>.</p>

<p>Ideally, however, due to Ember&#8217;s proclivity towards states, a state-based routing solution seems like the most natural fit. This makes even more sense when taken in the context of the view composition system already being state-based.</p>

<p><a href="https://github.com/ghempton/ember-routemanager">Ember RouteManager</a> is exactly that, a state-based routing solution. It introduces an extension of StateManager called RouteManager. Consider the following code (irrelevant parts snipped) from the <a href="http://ghempton.github.com/ember-layout-example/">example</a>:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">routeManager</span> <span class="o">=</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">RouteManager</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>  <span class="nx">rootLayout</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">main</span><span class="p">,</span>
</span><span class='line'>  <span class="nx">home</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">NavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>  <span class="p">}),</span>
</span><span class='line'>  <span class="nx">layoutNesting</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">NavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;layout-nesting&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>    <span class="nx">section1</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">SubNavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>      <span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;section1&#39;</span><span class="p">,</span>
</span><span class='line'>      <span class="p">...</span>
</span><span class='line'>    <span class="p">}),</span>
</span><span class='line'>    <span class="nx">section2</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">SubNavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>      <span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;section2&#39;</span><span class="p">,</span>
</span><span class='line'>      <span class="p">...</span>
</span><span class='line'>    <span class="p">}),</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>  <span class="p">}),</span>
</span><span class='line'>  <span class="nx">routeParameters</span><span class="o">:</span> <span class="nx">App</span><span class="p">.</span><span class="nx">NavState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>    <span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;route-parameters&#39;</span><span class="p">,</span>
</span><span class='line'>    <span class="p">...</span>
</span><span class='line'>    <span class="nx">items</span><span class="o">:</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">LayoutState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>      <span class="p">...</span>
</span><span class='line'>    <span class="p">}),</span>
</span><span class='line'>    <span class="nx">item</span><span class="o">:</span> <span class="nx">Em</span><span class="p">.</span><span class="nx">LayoutState</span><span class="p">.</span><span class="nx">create</span><span class="p">({</span>
</span><span class='line'>      <span class="nx">path</span><span class="o">:</span> <span class="s1">&#39;:itemId&#39;</span><span class="p">,</span> <span class="c1">// specify the path to take a parameter</span>
</span><span class='line'>      <span class="p">...</span>
</span><span class='line'>    <span class="p">})</span>
</span><span class='line'>  <span class="p">})</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>I&#8217;m not going to go into detail here, but suffice it to say that each possible route is captured as a leaf node in the state tree. State&#8217;s can have an optional <code>path</code> property which dictates how the routes map to states in the routeManager. Paths can consist of dynamic parameters (<code>:parameterName</code>), wildcards (<code>*</code>), regular expressions, and static paths. For example, from the above code: setting the browser location to <code>#/routeParameters/5</code> would map to the <code>routeParameters.item</code> state with the <code>:itemId</code> parameter being populated by <code>5</code>. Since these states are also layout states, this will also automatically update the view hierarchy as well.</p>

<p>The beauty of this approach is the de-coupling of application state from <em>absolute</em> routes. For some reason, many frameworks enforce a holistic view of the routing system, treating it as a list of mappings from routes to actions. With RouteManager&#8217;s approach, state definitions are agnostic to the parts of the route corresponding to their parent, and instead only focus on their local part.</p>

<p>Much of the code inside RouteManager is originally based on SproutCore routing. Thus, it can also use the HTML 5 history api by setting the <code>wantsHistory</code> property.</p>

<h2>Caveat</h2>

<p>The caveat here is that what I am describing is likely to change as Ember.js evolves. The libraries I have presented are still immature and more conceptual than fully formed. Ultimately Ember&#8217;s core will have a solution for this and I will update this post when that is the case.</p>

<p>Stay tuned for the next post in this series where I cover data persistence.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[25 Reasons to Switch From WordPress To Octopress]]></title>
    <link href="http://codebrief.com/2012/01/25-reasons-to-switch-from-wordpress-to-octopress/"/>
    <updated>2012-01-20T19:41:00-08:00</updated>
    <id>http://codebrief.com/2012/01/25-reasons-to-switch-from-wordpress-to-octopress</id>
    <content type="html"><![CDATA[<ol>
<li>Static content should be served statically</li>
<li>Disqus rocks</li>
<li>Ruby</li>
<li>Google rewards fast loading times</li>
<li>Markdown</li>
<li>Flat files are awesome</li>
<li>Sass</li>
<li>Compass</li>
<li>HAML</li>
<li>GitHub Pages</li>
<li><a href="http://mattgemmell.com/2011/09/12/blogging-with-octopress/">This guy</a> did it</li>
<li>Linode disk alerts are annoying</li>
<li>No more caching plugins</li>
<li>Hacker cred</li>
<li>Security</li>
<li><a href="http://wynnnetherland.com/journal/octopress-classic-is-the-new-kubrick">Octopress Classic is the new Kubrick</a></li>
<li>Built on top of <a href="https://github.com/mojombo/jekyll">Jekyll</a></li>
<li>Web interfaces suck at content creation</li>
<li>Easily preview locally</li>
<li>Version with GIT</li>
<li>Compose in VIM</li>
<li>Wordpress has <a href="http://www.tonywright.com/2007/interaction-with-wordpress-customer-service-not-so-fun/">customer service</a></li>
<li>Score 93/100 instead of 55/100 on <a href="https://developers.google.com/pagespeed/">PageSpeed</a></li>
<li>Happiness as a developer</li>
<li>This Graph:</li>
</ol>


<p><img src="http://codebrief.com/images/posts/linode_cpu_after_octopress.png" alt="linode CPU" /></p>

<p>In case it&#8217;s not obvious, I spent some time migrating this site over to <a href="http://octopress.org/">Octopress</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Top 10 Javascript MVC Frameworks Reviewed]]></title>
    <link href="http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed/"/>
    <updated>2012-01-13T00:00:00-08:00</updated>
    <id>http://codebrief.com/2012/01/the-top-10-javascript-mvc-frameworks-reviewed</id>
    <content type="html"><![CDATA[<p><strong>UPDATE 1/14/2012:</strong> <em>Added Batman.js and Angular.js due to popular demand and because they looked impressive.</em></p>

<p>Over the last several months I have been in a constant search for the perfect javascript MVC framework. Driven by a dire need for the right level of abstraction and features, I have tried out - some more cursorily than others - every framework I could get my hands on. Here lies a brief synopsis of each framework. Lastly, I share the framework which I ultimately decided on.</p>

<p>Specifically, the following four features are very important to me:</p>

<ul>
<li><strong>UI Bindings</strong> - I&#8217;m not just talking about templates, I&#8217;m talking about a declarative approach to automatically updating the view layer when the underlying model changes. Once you have used a framework (such as Flex) that supports UI bindings, you can never go back.</li>
<li><strong>Composed Views</strong> - Like all software developers, I enjoy creating modular reusable code. For this reason, when programming UI, I would like to be able to compose views (preferably at the template layer). This should also entail the potential for a rich view component hierarchy. An example of this would be a reusable pagination widget.</li>
<li><strong>Web Presentation Layer</strong> - We are programming for the web here people, the last thing I want are native-style widgets. There is also no reason for a web framework to create it&#8217;s own layout manager. HTML and CSS are already the richest way to do style and layout in existence, and should be used as such. The framework should be centered around this concept.</li>
<li><strong>Plays Nicely With Others</strong> - Let&#8217;s face it, jQuery is pretty amazing. I don&#8217;t want a framework which comes bundled with a sub-par jQuery clone, I want a framework which recommends using jQuery itself.</li>
</ul>


<h2>The Contenders</h2>

<p>Here is a table showing all of the frameworks support for the above features. Click through the title for more detail.</p>

<table>
<tr>
<th>Framework</th>
<th>UI Bindings</th>
<th>Composed Views</th>
<th>Web Presentation Layer</th>
<th>Plays Nicely With Others</th>
</tr>

<tr>
<td><a href="#backbone">Backbone.js</a></td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#sproutcore">SproutCore 1.x</a></td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
</tr>

<tr>
<td><a href="#sammy">Sammy.js</a></td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#spine">Spine.js</a></td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#cappuccino">Cappuccino</a></td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
</tr>

<tr>
<td><a href="#knockout">Knockout.js</a></td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#javascript-mvc">Javascript MVC</a></td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#gwt">Google Web Toolkit</a></td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="fail">&#x2717;</td>
</tr>

<tr>
<td><a href="#closure">Google Closure</a></td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
</tr>

<tr>
<td><a href="#ember">Ember.js</a></td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#angular">Angular.js</a></td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

<tr>
<td><a href="#batman">Batman.js</a></td>
<td class="pass">&#x2713;</td>
<td class="fail">&#x2717;</td>
<td class="pass">&#x2713;</td>
<td class="pass">&#x2713;</td>
</tr>

</table>




<h3 id="backbone">1. Backbone.js</h3>


<p><a href="http://documentcloud.github.com/backbone/">Backbone.js</a> is the web&#8217;s darling framework. You can&#8217;t go anywhere without hearing about it and they have an impressive list of brands using it. This was naturally one of the first frameworks I tried. I used it to build some of our internal administrative features at <a href="http://grouptalent.com">GroupTalent</a>.</p>

<p><strong>Pros:</strong> Strong community and lots of momentum. Underscore.js (which it uses heavily) is also a great framework.</p>

<p><strong>Cons:</strong> Lacks strong abstractions and leaves something to be desired. The entire framework is surprisingly lightweight and results in lots of boilerplate. The larger an application becomes, the more this becomes apparent.</p>

<h3 id="sproutcore">2. SproutCore 1.x</h3>


<p><a href="http://sproutcore.com/">SproutCore</a> is what Apple used on its iCloud initiative. Despite having a horrible name, it is actually an extremely well thought out framework. It is also one of the largest frameworks.</p>

<p><strong>Pros:</strong> Bindings support. Solid community. Tons of features.</p>

<p><strong>Cons:</strong> Overly prescriptive. Hard to decouple from unneeded features. Forces a native-like paradigm. I have a serious problem with any framework which discourages using html for layout.</p>

<h3 id="sammy">3. Sammy.js</h3>


<p><a href="http://sammyjs.org/">Sammy.js</a> was a smaller framework that I stumbled upon. Due to its simplicity, it almost didn&#8217;t make this list. It&#8217;s core feature is a routing system to swap out areas of an application with AJAX.</p>

<p><strong>Pros:</strong> Simple learning curve. Easier to integrate with an existing server side app.</p>

<p><strong>Cons:</strong> Too simple. Not sufficient for larger applications.</p>

<h3 id="spine">4. Spine.js</h3>


<p>Based on the name, <a href="http://spinejs.com/">Spine.js</a> is obviously heavily influenced by backbone. Like backbone, it is very lightweight and follows a similar model.</p>

<p><strong>Pros:</strong> Lightweight with good documentation.</p>

<p><strong>Cons:</strong> Fundamentally flawed. A core concept of spine is &#8220;is asynchronous UIs. In a nutshell, this means that UIs should ideally never block&#8221;. Having built a serious non-blocking realtime application in the past, I can say this is entirely unrealistic unless the backend has something like <a href="http://en.wikipedia.org/wiki/Operational_transformation">operational transformation</a>.</p>

<h3 id="cappuccino">5. Cappuccino</h3>


<p><a href="http://cappuccino.org/">Cappuccino</a> is one of the more unique frameworks, coming with its own language Objective-J. Cappuccino tries to emulate Cocoa in the browser.</p>

<p><strong>Pros:</strong> Large thought-out framework. Good community. Great inheritance model.</p>

<p><strong>Cons:</strong> Out of all the languages you could emulate in javascript, Objective-C would be my last choice. This is coming from an iOS developer. I simply can&#8217;t get past the idea of programming Objective-J in the browser.</p>

<h3 id="knockout">6. Knockout.js</h3>


<p><a href="http://knockoutjs.com/">Knockout.js</a> is an MVVM framework that receives lots of praise from its supporters. It stresses declarative UI bindings and automatic UI refresh.</p>

<p><strong>Pros:</strong> Binding support. Great documentation and amazing tutorial system.</p>

<p><strong>Cons:</strong> Awkward binding syntax and lacks a solid view component hierarchy. I want to be able to reuse components easily. I also feel like identifying as an MVVM framework is deleterious. Hardly any of these frameworks are MVC, but are of the MV* variety (MVP, MVVM, etc).</p>

<h3 id="javascript-mvc">7. Javascript MVC</h3>


<p><a href="http://javascriptmvc.com/">Javascript MVC</a>, in the interest of full disclosure, is a framework that I didn&#8217;t spend very much time evaluating.</p>

<p><strong>Pros:</strong> Solid community and legacy.</p>

<p><strong>Cons:</strong> Awkward inheritance model based on strings. Controllers are too intimate with views and lack bindings. The name is way too generic - the equivalent would be if RoR was called &#8220;Ruby Web Framework&#8221;.</p>

<h3 id="gwt">8. Google Web Toolkit</h3>


<p><a href="http://code.google.com/webtoolkit/">GWT</a> is a serious client-side toolkit that includes more than just a framework. It compiles Java to Javascript, supporting a subset of the standard java library. Google used it internally for Wave.</p>

<p><strong>Pros:</strong> Comprehensive framework with great community. Solid Java-based component inheritance model. Great for behemoth client-side applications.</p>

<p><strong>Cons:</strong> Despite what Google says, GWT is not going to stand the test of time. With initiatives like <a href="http://www.dartlang.org/">DART</a> its clear that Java is not the future of the web. Furthermore, the abstraction of Java on the client is slightly awkward.</p>

<h3 id="closure">9. Google Closure</h3>


<p><a href="http://code.google.com/closure/">Google Closure</a> is more of a toolkit than simply a javascript framework. It comes bundled with a compiler and optimizer.</p>

<p><strong>Pros:</strong> Use by Google for many of their major apps. Nice component-based ui composition system.</p>

<p><strong>Cons:</strong> Lack of UI-binding support.</p>

<h3 id="ember">10. Ember.js</h3>


<p><a href="http://emberjs.com/">Ember.js</a> (formerly <s>Amber.js</s> SproutCore 2.0) is one of the newest contenders. It is an attempt to extricate the core features from SproutCore 2.0 into a more compact modular framework suited for the web.</p>

<p><strong>Pros:</strong> Extremely rich templating system with composed views and UI bindings.</p>

<p><strong>Cons:</strong> Relatively new. Documentation leaves lots to be desired.</p>

<h3 id="angular">11. Angular.js</h3>


<p><a href="http://docs.angularjs.org">Angular.js</a> is a very nice framework I discovered after I originally posted this review. Developed by Googler&#8217;s, it has some very interesting design choices.</p>

<p><strong>Pros:</strong> Very well thought out with respect to template scoping and controller design. Has a dependency injection system (I am a big fan of IOC). Supports a rich UI-Binding syntax to make things like filtering and transforming values a breeze.</p>

<p><strong>Cons:</strong> Codebase appears to be fairly sprawling and not very modular. Views are not modular enough (will address this in more detail in the cons of <a href="#batman">Batman.js</a>).</p>

<h3 id="batman">12. Batman.js</h3>


<p><a href="http://batmanjs.org/">Batman.js</a>, created by Shopify, is another framework in a similar vein to Knockout and Angular. Has a nice UI binding system based on html attributes. The only framework written in idiomatic coffeescript, it is also tightly integrated with Node.js and even goes to the extent of having its own (optional) Node.js server.</p>

<p><strong>Pros:</strong> Very clean codebase. Has a nice simple approach to binding, persistence, and routing.</p>

<p><strong>Cons:</strong> I very much dislike singletons, let alone the idea of enforcing singleton controllers. Suffers from the same ailments as Knockout and Angular with regards to nested components. I want to be able to declaratively reuse more than just templates. What Ember has over these frameworks is a way to declaratively re-use entire components that are backed by their own (possibly controller-level) logic.</p>

<h2>The Winner</h2>

<p>At the end of the day, Ember.js is the <em>only</em> framework which has everything I desire. I recently ported a relatively small Backbone.js application over to Ember.js and, despite some small performance issues, I am much happier with the resulting code base. Being championed by <a href="http://yehudakatz.com/">Yehuda Katz</a>, the community around Ember.js is also amazing. This is definitely the framework to watch out for.</p>

<p>Of course this list is far from comprehensive. Almost all of these frameworks here were discovered by sheer notoriety, word of mouth, or by being mentioned on <a href="http://news.ycombinator.com">Hacker News</a>. I am also not reviewing proprietary frameworks (or frameworks with disagreeable licenses - ExtJS anyone?).</p>

<p>What MVC framework do you use?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Javascript Frameworks Are Too Small]]></title>
    <link href="http://codebrief.com/2012/01/javascript-frameworks-are-too-small/"/>
    <updated>2012-01-09T00:00:00-08:00</updated>
    <id>http://codebrief.com/2012/01/javascript-frameworks-are-too-small</id>
    <content type="html"><![CDATA[<p>A while back I stumbled upon a <a href="https://plus.google.com/112218872649456413744/posts/dfydM2Cnepe">great post</a> by Jean-Baptiste Queru. It describes the incredible depth of the modern technology stack. Layers upon layers of complex science, hardware, and software, each layer creating a simpler abstraction around the previous. This ultimately enables our paltry human brains to create amazing things that would otherwise be impossible (or really difficult). This is, in my opinion, the lifeblood of modern software development.</p>

<p><a href="http://codebrief.com/old/uploads/2012/01/microjs-sizes.png"><img src="http://codebrief.com/old/uploads/2012/01/microjs-sizes.png" alt="" title="microjs-sizes" width="180" height="231" class="alignleft size-full wp-image-481" /></a></p>

<p>For some reason, however, when it comes to front-end web development - meaning javascript - the stack is extremely shallow. Most websites are built on top of native browser functionality with a sprinkling of jQuery and little else. Moreover, this is true even to the extent that it is embedded in the developer culture itself. Javascript frameworks are lauded for their small sizes and even smaller feature sets. <a href="http://microjs.com/">Sites exist</a> exclusively to categorize and compile lists of these &#8220;micro-frameworks&#8221;, exacting requirements of less than five kilobytes.</p>

<p>This is not to say that significant value <em>can&#8217;t</em> be created by a framework with a small codebase. However, given the choice between two frameworks with equally well-written code, I would probably opt for the larger framework<sup><a href="#footnote-1">1</a></sup>. Choosing a framework for its small size is a premature optimization. Taking this a step further, given a choice between tying together two unrelated &#8220;micro-frameworks&#8221; and one larger framework, I would definitely opt for the latter.</p>

<p>Tom Dale begins a <a href="http://tomdale.net/2011/05/an-uphill-battle/">similar post</a> with the following:</p>

<blockquote><p>Why does it take big teams, big budgets, and long timelines to deliver web apps that have functionality and UI that approaches that of an iPhone app put together by one or two people?</p></blockquote>

<p>Although I&#8217;m not going to comment on the number of people required in either case, I completely agree with the implicit assertion that mobile development is more efficient. As a developer who has been building desktop, web, and mobile applications for years, I have always felt that, specific to web development, a larger amount of energy goes towards dealing with the frameworks involved, rather than the problem being solved. There is also an uncomfortable, almost nauseating, feeling that my code is not as modular and reusable as I would like and have come to expect from other development stacks.</p>

<p>The reason for this is that javascript frameworks are simply too small and unstructured. Client-side web developers are not building atop strong enough abstractions to bring their efficiency up to par. Even <a href="http://documentcloud.github.com/backbone/">backbone.js</a>, the web&#8217;s darling client side javascript framework, weighs in at a mere 4.6kb. Having built an application against backbone, I can attest to the fact that it more closely resembles a philosophy or set of guidelines to develop against rather than a full fledged UI framework.</p>

<p>Yes, I know larger javascript web frameworks exist. <a href="http://sproutcore.com/">SproutCore</a>, <a href="http://cappuccino.org/">Cappuccino</a>, and <a href="http://code.google.com/webtoolkit/">Google Web Toolkit</a> come to mind. I hear good things about all of these frameworks. However, none of them have come to the level of ubiquity that one would hope. They all suffer from similar ailments: being constraining and forcing a particular native-like paradigm. For instance, there is no reason for a web framework to implement it&#8217;s own layout manager. HTML 5 is probably the richest layout system in existence and most modern heavily-designed web applications prefer direct access.</p>

<p>I am constantly searching for a modern client-side javascript framework that has the right level of abstraction. Today, I am extremely excited about <a href="http://emberjs.com/">Ember JS</a> (formerly SproutCore 2.0). It adds some deep layers of functionality without the constraints and bloat of the original SproutCore. I think it will continue to evolve into an amazing framework. For the future, I am excited about initiatives such as <a href="http://www.dartlang.org/">DART</a>. Despite receiving a lot of negative criticism, DART looks promising as a new language for the web (although I would have preferred a raw VM). Particularly, I feel that the awkwardness around implementing packages and re-usable code in Javascript is partly to blame for the current state.</p>

<p>In any case, as web applications continue to become increasingly complex, the emergence of larger and richer frameworks is inevitable - and it&#8217;s about time.</p>

<div class="footnotes">
<p id="footnote-1">1. It is important to clarify this choice with respect to size and horizontal bloat. Here I am using the term larger to denote a framework which has a stronger abstraction/more utility for what I am actually using it for (as opposed to a bunch of unnecessary features).</p>
</div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The 25 Toughest Vocabulary Words Based On 1,000,000 Answers]]></title>
    <link href="http://codebrief.com/2011/12/the-25-toughest-vocabulary-words-based-on-1000000-answers/"/>
    <updated>2011-12-22T00:00:00-08:00</updated>
    <id>http://codebrief.com/2011/12/the-25-toughest-vocabulary-words-based-on-1000000-answers</id>
    <content type="html"><![CDATA[<p><a href="http://codebrief.com/old/uploads/2011/12/feature.jpg"><img src="http://codebrief.com/old/uploads/2011/12/feature-300x146.jpg" alt="" title="feature" width="300" height="146" class="alignleft size-medium wp-image-420" /></a></p>

<p>My first Android creation was a game called <a href="https://market.android.com/details?id=com.hempton.vocab&amp;hl=en">Vocabulary Builder</a>. The gameplay is simple: match words with definitions and vice versa. It has multiple skill levels, tracks your progress, and has a built-in dictionary.</p>

<p>Today, it is the number one Google search result for Android Vocabulary Builder, has a 4/5 star rating, and has around 100k installs. It is monetized with ads and a 99 cent ad-free pro version. Being as this is Android, this translates into me having made roughly $100 dollars from it throughout its entire lifetime. No, seriously. Despite cleverly sneaking ads in between definitions, it&#8217;s CPM is practically nothing (an order of magnitude less than some of my iOS games) and of the 100k installs, a whopping 82 have converted to pro users.</p>

<p>But that is neither here nor there. What <em>is</em> interesting (and hopefully worth sharing), is the analytics data that has been collected. Using a free Google App Engine account, I have collected the anonymized result of every single question (within the free account quota). This equates to over a million data points. Ironically, due to the size of the data set, in order to bulk download all of this data in a timely fashion, I had to temporarily upgrade to a paid account. Here I share the toughest and the easiest vocabulary words.</p>

<h2>The 25 Toughest Words</h2>

<p>To qualify this data, the dictionary used in the game is based on a well known list of difficult GRE-style words. It is <em>not</em> based on the entire English dictionary.</p>

<table>
<tr>
<th>Rank</th>
<th>Word</th>
<th>Definition</th>
<th>Correct Ratio</th>
</tr>
<TR>
<td>1</td>
<TD>transport</TD>
<TD>strong emotion; rapture</TD>
<TD>0.1078838174</TD>
</TR>
<TR>
<td>2</td>
<TD>husband</TD>
<TD>use sparingly; conserve; save</TD>
<TD>0.1198156682</TD>
</TR>
<TR>
<td>3</td>
<TD>career</TD>
<TD>rush wildly; go at full speed</TD>
<TD>0.1380952381</TD>
</TR>
<TR>
<td>4</td>
<TD>disport</TD>
<TD>amuse</TD>
<TD>0.1697247706</TD>
</TR>
<TR>
<td>5</td>
<TD>nicety</TD>
<TD>precision; accuracy; minute distinction or difference</TD>
<TD>0.1991150442</TD>
</TR>
<TR>
<td>6</td>
<TD>cupidity</TD>
<TD>greed (for wealth)</TD>
<TD>0.2042553191</TD>
</TR>
<TR>
<td>7</td>
<TD>cow</TD>
<TD>terrorize; intimidate</TD>
<TD>0.2044444444</TD>
</TR>
<TR>
<td>8</td>
<TD>dint</TD>
<TD>means; effort</TD>
<TD>0.2064220183</TD>
</TR>
<TR>
<td>9</td>
<TD>affected</TD>
<TD>artificial; pretended</TD>
<TD>0.2127659574</TD>
</TR>
<TR>
<td>10</td>
<TD>exceptionable</TD>
<TD>objectionable; likely to cause dislike; offensive</TD>
<TD>0.224137931</TD>
</TR>
<TR>
<td>11</td>
<TD>base</TD>
<TD>contemptible; morally bad; inferior in value or quality</TD>
<TD>0.2282157676</TD>
</TR>
<TR>
<td>12</td>
<TD>brook</TD>
<TD>tolerate; endure</TD>
<TD>0.2307692308</TD>
</TR>
<TR>
<td>13</td>
<TD>qualified</TD>
<TD>limited; restricted</TD>
<TD>0.2322274882</TD>
</TR>
<TR>
<td>14</td>
<TD>guy</TD>
<TD>cable or chain attached to something that needs to be braced or steadied</TD>
<TD>0.2339449541</TD>
</TR>
<TR>
<td>15</td>
<TD>gloss</TD>
<TD>brief explanation note or translation of a difficult expression</TD>
<TD>0.2355769231</TD>
</TR>
<TR>
<td>16</td>
<TD>enjoin</TD>
<TD>command; order; forbid</TD>
<TD>0.2358974359</TD>
</TR>
<TR>
<td>17</td>
<TD>mountebank</TD>
<TD>charlatan; boastful pretender</TD>
<TD>0.2380952381</TD>
</TR>
<TR>
<td>18</td>
<TD>pluck</TD>
<TD>courage</TD>
<TD>0.2476190476</TD>
</TR>
<TR>
<td>19</td>
<TD>bearing</TD>
<TD>deportment; connection</TD>
<TD>0.2511210762</TD>
</TR>
<TR>
<td>20</td>
<TD>flag</TD>
<TD>droop; grow feeble; decline in vigor or strength</TD>
<TD>0.2525252525</TD>
</TR>
<TR>
<td>21</td>
<TD>wont</TD>
<TD>(the stated person&#39;s) habit or custom; habitual procedure</TD>
<TD>0.2525773196</TD>
</TR>
<TR>
<td>22</td>
<TD>pan</TD>
<TD>criticize harshly</TD>
<TD>0.2526315789</TD>
</TR>
<TR>
<td>23</td>
<TD>waffle</TD>
<TD>speak equivocally about an issue</TD>
<TD>0.2565445026</TD>
</TR>
<TR>
<td>24</td>
<TD>ferment</TD>
<TD>agitation; commotion(noisy and excited activity); unrest (of a political kind)</TD>
<TD>0.2566371681</TD>
</TR>
<TR>
<td>25</td>
<TD>mettle</TD>
<TD>courage (to continue bravely in spite of difficulties); spirit</TD>
<TD>0.2581967213</TD>
</TR>
</table>


<p>Interestingly, most of these words are not that uncommon, but are clearly used in the context of their 2nd or 3rd definition.</p>

<h2>The 25 Easiest Words</h2>

<p>For contrast, here is the other end of the spectrum:</p>

<table>
<tr>
<th>Rank</th>
<th>Word</th>
<th>Definition</th>
<th>Correct Ratio</th>
</tr>
<TR>
<td>1</td>
<TD>psychiatrist</TD>
<TD>doctor who treats mental diseases</TD>
<TD>0.9957264957</TD>
</TR>
<TR>
<td>2</td>
<TD>healthy</TD>
<TD>possessing good health; healthful</TD>
<TD>0.9911894273</TD>
</TR>
<TR>
<td>3</td>
<TD>vaporize</TD>
<TD>turn into vapor (steam, gas, fog, etc.)</TD>
<TD>0.9868421053</TD>
</TR>
<TR>
<td>4</td>
<TD>sibling</TD>
<TD>brother or sister</TD>
<TD>0.9855769231</TD>
</TR>
<TR>
<td>5</td>
<TD>optician</TD>
<TD>maker and seller of eyeglasses</TD>
<TD>0.9821428571</TD>
</TR>
<TR>
<td>6</td>
<TD>judiciary</TD>
<TD>judicial branch of government</TD>
<TD>0.981981982</TD>
</TR>
<TR>
<td>7</td>
<TD>plumber</TD>
<TD>one who installs and repairs pipes and plumbing(pipes)</TD>
<TD>0.9815668203</TD>
</TR>
<TR>
<td>8</td>
<TD>exhale</TD>
<TD>breathe out</TD>
<TD>0.9814814815</TD>
</TR>
<TR>
<td>9</td>
<TD>renovate</TD>
<TD>restore to good condition; renew</TD>
<TD>0.981042654</TD>
</TR>
<TR>
<td>10</td>
<TD>lubricate</TD>
<TD>apply a lubricant to</TD>
<TD>0.9807692308</TD>
</TR>
<TR>
<td>11</td>
<TD>replicate</TD>
<TD>reproduce; duplicate</TD>
<TD>0.9787234043</TD>
</TR>
<TR>
<td>12</td>
<TD>reminiscent</TD>
<TD>suggestive of something (in the past); of reminiscence</TD>
<TD>0.9782608696</TD>
</TR>
<TR>
<td>13</td>
<TD>artery</TD>
<TD>blood-vessel</TD>
<TD>0.9779735683</TD>
</TR>
<TR>
<td>14</td>
<TD>morgue</TD>
<TD>mortuary; place where bodies are kept before burial or cremation</TD>
<TD>0.9779735683</TD>
</TR>
<TR>
<td>15</td>
<TD>negligence</TD>
<TD>neglect; failure to take reasonable care</TD>
<TD>0.9777777778</TD>
</TR>
<TR>
<td>16</td>
<TD>nauseous</TD>
<TD>causing nausea; feeling nausea</TD>
<TD>0.9774774775</TD>
</TR>
<TR>
<td>17</td>
<TD>cardiologist</TD>
<TD>doctor specializing in ailments of the heart</TD>
<TD>0.9771689498</TD>
</TR>
<TR>
<td>18</td>
<TD>mentor</TD>
<TD>counselor; teacher</TD>
<TD>0.9770642202</TD>
</TR>
<TR>
<td>19</td>
<TD>oversee</TD>
<TD>watch over and direct; supervise</TD>
<TD>0.9768518519</TD>
</TR>
<TR>
<td>20</td>
<TD>nectar</TD>
<TD>drink of the gods; sweet liquid collected by bees</TD>
<TD>0.976744186</TD>
</TR>
<TR>
<td>21</td>
<TD>amphibian</TD>
<TD>able to live both on land and in water</TD>
<TD>0.9764150943</TD>
</TR>
<TR>
<td>22</td>
<TD>dermatologist</TD>
<TD>one who studies the skin and its diseases</TD>
<TD>0.9763033175</TD>
</TR>
<TR>
<td>23</td>
<TD>kneel</TD>
<TD>go down on one&#39;s knee(s)</TD>
<TD>0.9759615385</TD>
</TR>
<TR>
<td>24</td>
<TD>toxic</TD>
<TD>poisonous</TD>
<TD>0.9758454106</TD>
</TR>
<TR>
<td>25</td>
<TD>hibernate</TD>
<TD>sleep throughout the winter</TD>
<TD>0.9757281553</TD>
</TR>
</table>




<p class="promotion">If you are reading this and you are interested in word games, check out some of my other titles: Beworded (<a href="https://market.android.com/details?id=com.hempton.beworded.pro&hl=en">Android Market</a>, <a href="http://itunes.apple.com/us/app/beworded/id415661926?mt=8">App Store</a>) and Word Topple (<a href="http://itunes.apple.com/us/app/word-topple/id424710773?mt=8">App Store</a>).</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Introducing Misunderstood Pigs]]></title>
    <link href="http://codebrief.com/2011/12/introducing-misunderstood-pigs/"/>
    <updated>2011-12-20T00:00:00-08:00</updated>
    <id>http://codebrief.com/2011/12/introducing-misunderstood-pigs</id>
    <content type="html"><![CDATA[<p><a href="http://codebrief.com/old/uploads/2011/12/action_ipad.png"><img src="http://codebrief.com/old/uploads/2011/12/action_ipad-300x225.png" alt="Miunderstood Pigs Gameplay" title="action_ipad" width="300" height="225" class="alignleft size-medium wp-image-391" /></a></p>

<p>Today I am launching Misunderstood Pigs (<a href="http://itunes.apple.com/us/app/misunderstood-pigs/id431451004?ls=1&amp;mt=8">iTunes Link</a>). The gameplay is simple: place objects to save the pigs from an impending onslaught of projectiles.</p>

<p>I had been sitting on this game at 90% completion for at least 5 months, and decided to bite the bullet and spend a few days finishing the last 10%.</p>

<p>The game shares a lot of code from my previous release, <a href="http://itunes.apple.com/us/app/word-topple/id424710773?mt=8">Word Topple</a>, including a level editor/framework which is tightly integrated with Adobe Fireworks (which I am debating open sourcing).</p>

<p>Enjoy!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Two Game Changing CSS 3 Features]]></title>
    <link href="http://codebrief.com/2011/11/two-game-changing-css-3-features/"/>
    <updated>2011-11-14T00:00:00-08:00</updated>
    <id>http://codebrief.com/2011/11/two-game-changing-css-3-features</id>
    <content type="html"><![CDATA[<p><a href="http://codebrief.com/old/uploads/2011/11/css3.jpg"><img src="http://codebrief.com/old/uploads/2011/11/css3-150x150.jpg" alt="" title="CSS3 Logo" width="150" height="150" class="alignleft size-thumbnail wp-image-368" /></a></p>

<p>HTML and CSS has always been filled with frustration when it comes to being able to intuitively create layouts and designs. Web developers have long since sacrificed ease of implementation for accessibility and semantic purity. Basic layouts and simple aesthetics frequently require very non-trivial implementations. This is especially apparent to developers who have tasted the forbidden fruit of other platforms such as Flex, Android, et al.</p>

<p>Until the near future. Two CSS 3 features in particular are finally solving this in a major way, making web design palatable to the code minimalist in all of us.</p>

<h2>Flexible Box Layouts</h2>

<p>The CSS 3 spec has introduced a new module which is supported by all major non-IE browsers as well as the IE 10 preview. This module is the <a href="http://www.w3.org/TR/css3-flexbox/">Flexible Box Layout</a>.</p>

<p>Gone are the days of forcing a layout into a float-based implementation. No more <a href="http://www.alistapart.com/articles/negativemargins/">negative margins</a>, excessive floating, and clear fixes. This also eliminates the added complexity of having to take into account margins, padding, and border when creating layout styling.</p>

<p>Anyone coming from a Flex or Android background will immediately see the value of this. In Flex and Android, vertical and horizontal box layouts are the backbone of any application. For layouts which aren&#8217;t flow based, this is much more intuitive.</p>

<p>For example, consider the following layout:</p>

<div style="display:box; display: -moz-box; display: -webkit-box; color: #fff; margin: 1.5em 0;">
<div style="padding: 12px; background: #002F32">Child One</div>
<div style="padding: 12px; background: #42826C; box-flex: 1; -webkit-box-flex: 1; -moz-box-flex: 1;">Child Two</div>
<div style="padding: 12px; background: #A5C77F">Child Three</div>
<div style="padding: 12px; background: #FFC861">Child Four</div>
</div>


<p>With the associated markup (styling and browser-specific markup removed):</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="na">style=</span><span class="s">&quot;display:box;&quot;</span><span class="nt">&gt;</span>
</span><span class='line'>  <span class="nt">&lt;div&gt;</span>Child One<span class="nt">&lt;/div&gt;</span>
</span><span class='line'>  <span class="nt">&lt;div</span> <span class="na">style=</span><span class="s">&quot;box-flex: 1;&quot;</span><span class="nt">&gt;</span>Child Two<span class="nt">&lt;/div&gt;</span>
</span><span class='line'>  <span class="nt">&lt;div&gt;</span>Child Three<span class="nt">&lt;/div&gt;</span>
</span><span class='line'>  <span class="nt">&lt;div&gt;</span>Child Four<span class="nt">&lt;/div&gt;</span>
</span><span class='line'><span class="nt">&lt;/div&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>I&#8217;m not going to go into detail as to what the code for this layout would look like today, but suffice it to say that any web developer should be intimately acquainted with such code.</p>

<p>There are other new layout modules as well (such as <a href="http://www.w3.org/TR/css3-grid-layout/">Grid Layout</a>), but none that will play as big of a role in the micro-layout of small items on any website as the flexible box layout.</p>

<h2>Nine Grid Backgrounds</h2>

<p>I had previously <a href="http://codebrief.com/2008/11/9-grid-scaling-support-in-javascriptcss/">created a jQuery plugin</a> which enables 9-grid scaling support for javascript/css. This plugin has been made obsolete by the <a href="http://www.w3.org/TR/css3-background/#the-border-image">border-image</a> style that is finally gaining widespread browser support. Similarly, 9-grid backgrounds have also been supported by frameworks such as Flex and Android for years.</p>

<p>Consider the following image:</p>

<p><img src="http://codebrief.com/old/uploads/2011/11/aqua_bg.png" alt="Aqua Background" title="aqua_bg" width="112" height="112" class="alignnone size-full wp-image-370" /></p>

<p>Using the border-image style, the following background can be created:</p>

<div style="border-width: 25px; border-image: url('/old/uploads/2011/11/aqua_bg.png') 25 25 25 25 repeat; -webkit-border-image: url('/old/uploads/2011/11/aqua_bg.png') 25 25 25 25 repeat; -moz-border-image: url('/old/uploads/2011/11/aqua_bg.png') 25 25 25 25 repeat; width: 500px; height: 100px;"></div>


<p>With the associated markup:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='html'><span class='line'><span class="nt">&lt;div</span> <span class="na">style=</span><span class="s">&quot;border-width: 25px; border-image: url(&#39;/old/uploads/2011/11/aqua_bg.png&#39;) 25 25 25 25 repeat;</span>
</span><span class='line'><span class="s">  width: 500px;</span>
</span><span class='line'><span class="s">  height: 100px;&quot;</span><span class="nt">&gt;</span>
</span><span class='line'><span class="nt">&lt;/div&gt;</span>
</span></code></pre></td></tr></table></div></figure>


<p>This allows for beautiful raster based backgrounds to be easily applied to fluid width elements. The one caveat here is that additional calculations will be required to take into account the additional border widths (which will be eventually mitigated by the <a href="http://www.w3.org/TR/css3-background/#the-border-image-outset">border-image-outset property</a>). In fact, the grid background (only visible on higher resolution screens) on the current theme for this blog is styled using border-image.</p>

<h2>Game Changing</h2>

<p>Having developed on platforms where these two features are standard, I can say that having these available as tools for web design will enable a new class of beautiful designs. Although nothing here was previously unrealizable with a lot of complex markup and styling, this will go a long way towards HTML becoming a much richer language for user interface.</p>

<p>Having lived through the era of table-based layouts, the era of accessibility driven div hell, and now the onset of CSS 3, I envy the next generation of programmers who take these types of tools for granted.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Design Tools Are Broken]]></title>
    <link href="http://codebrief.com/2011/07/design-tools-are-broken/"/>
    <updated>2011-07-14T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/07/design-tools-are-broken</id>
    <content type="html"><![CDATA[<p><img src="http://codebrief.com/old/uploads/2011/07/design_broken.png" alt="" title="design_broken" width="196" height="71" class="alignleft size-full wp-image-300" /></p>

<p>Spending lots of time both coding and designing has given me an acute awareness of how poor design tools are. Design itself has come a long way, but the design process has not. As a disclaimer, most of what is about to be said applies to user interface and graphic design, as opposed to illustration and the creative process.</p>

<p>The culture around design is primarily focused on the end product and not the process behind it. Photoshop, the industry standard for user interface design, is pixel-centric (limited vector support being a later addition). Trivial things such as rounding corners or changing resolutions are often non-trivial to accomplish. Re-usable assets, such as those found on <a href="http://www.smashingmagazine.com/category/freebies/">Smashing Magazine</a>, often consist of static images, hopefully in multiple resolutions. Cascading stylesheets, the lifeblood of web design, are exceedingly repetitive and usually degrade into an unmaintainable soup.</p>

<p>For comparison, the culture of software development largely evolves around getting things done cleanly, efficiently, and maintainably. Entire programming frameworks and communities arise around the idea of making the process of doing something developers are already able to do (e.g build websites) simpler. Existing bodies of code are re-factored entirely to be cleaner, despite having less features. New languages emerge with the goal of making software easier to develop. Re-usable libraries exist for almost every language and programming task imaginable.</p>

<p>The stereotypical developer is horrible at graphic design, but much of this is due to an impedance mismatch between software development and design practices. From the perspective of a good developer, many of the techniques that are required to create good design are appalling and contrary to their core philosophy.</p>

<h3>Massive Violation of DRY</h3>

<p>From Wikipedia:</p>

<blockquote><p>Don&#8217;t Repeat Yourself (DRY) or Duplication is Evil (DIE) is a principle of software development aimed at reducing repetition of information of all kinds&#8230;</p></blockquote>

<p>A rule of thumb for this is if you find yourself doing the same thing often, there is probably/should be a better way to do it. Whether I am writing CSS or creating layouts and graphics in Fireworks or Photoshop, I repeat myself <em>all</em> the time. As a response to this for CSS, developers have created tools such as <a href="http://sass-lang.com/">SASS</a> and <a href="http://lesscss.org/">LESS</a>. The elephant in the room, however, is graphic design. Accomplishing commonplace visual effects such as <a href="http://graphicdesign.stackexchange.com/questions/1441/photoshop-curved-shadow">curved drop shadows</a> and <a href="http://www.hongkiat.com/blog/create-cool-glossy-button-for-web/">glossy buttons</a> usually requires following multi-step rote processes every time they are needed.</p>

<h3>Poor Extensibility and Reusability</h3>

<p>Perhaps causally related with the violation of DRY principles is the lack of ways to extend graphics design tools and reuse existing graphical designs.</p>

<p>In the case of software development, common design patterns and features can easily be modularized and re-used in various projects and components. Existing frameworks are also designed with plugin architecture&#8217;s in mind. The prevalence of rails extensions, for example, has made creating web applications with Ruby on Rails amazingly easy, far beyond what the original framework intended.</p>

<p>Graphic design tools are quite the opposite. One could imagine things like glossy buttons, advanced shadows, and other effects being easily scripted or packaged into custom filters, but it&#8217;s not so in reality. Despite having limited scripting support, the <a href="http://www.alienskin.com/">really useful</a> plugins for tools like Photoshop and Fireworks were all built years ago in native code. These tools are used by thousands of programmers and designers, but the ecosystem around extending and contributing to these products is almost non-existant. I have personally put immense amounts of effort towards scripting Adobe Fireworks, but this has simply made the limitations more apparent.</p>

<p>CSS3 has actually made great strides in this area, but it will never be a complete substitute for graphics design. I can imagine a future ecosystem consisting of a robust open source graphics editing program(s) accompanied by a plethora of plugins, filters and assets freely distributed and written in a modern scripting language.</p>

<h3>Immutability</h3>

<p>Finished designs are often immutable and hard to change (and this has nothing to do with the <a href="http://en.wikipedia.org/wiki/Immutable_object">good type</a> of immutability). Source .psd files often consist of layers of flattened pixels, the exact combination of actions which created the layer lost forever. In many cases, this starkly contrasts with the underlying software being designed, which is in a constant state of flux and improvement.</p>

<p>The software equivalent of this would be software development tools which produce raw binaries without source code, the only possibility of change through a finite number of parameters. The natural solution would be to have graphics software which preserves the entire process by which an image was created. For this reason, I personally tend towards Adobe Fireworks, which is slightly better at this, dealing with items at the object level rather than the layer level.</p>

<p>Another solution would be to have the underlying format for the source of an image be an imperative graphics description language, e.g. <a href="http://www.degrafa.org/">Degrafa</a>. <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics">SVG</a> is theoretically nice, but is poorly implemented and monolithic, but still might ultimately be the answer.</p>

<h3>Lack of Version Control</h3>

<p>Binary source files don&#8217;t mesh well with version control. Merging conflicts is near impossible. Viewing and understanding the history of a file is not easy. I have seen workflows where all the design assets are passed around in shared folders with no version control at all. In the developer world, this would be almost unheard of. This also translates to the web, where design assets are clumsily distributed and the techniques used to create the asset are usually lost.</p>

<h3>Reliance on Proprietary Tools</h3>

<p>Almost no one would argue with the fact that Adobe Photoshop is the industry standard for graphic design, supplemented by Illustrator and sometimes Fireworks. Other open source tools such as <a href="http://www.gimp.org/">GIMP</a> and <a href="http://inkscape.org/">Inkscape</a> are slightly sub par and suffer from the same lack of innovation. This state of affairs has been relatively the same for the last decade or more.</p>

<p>Not only does this restrict innovation, but it also restricts the platforms able to do graphics design. This prevents many developers and designers from using operating systems like Ubuntu as their primary OS. Moreover, I would argue that this has contributed to poor design in many OSS applications. Witnessing open-source software transforming the landscape of software development, one can only hope that the same will eventually happen to design.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Living Untethered]]></title>
    <link href="http://codebrief.com/2011/06/living-untethered/"/>
    <updated>2011-06-17T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/06/living-untethered</id>
    <content type="html"><![CDATA[<p>For roughly two and a half months I have been without a mobile phone of any kind. Two months might not sound like much, but this is coming from a software developer who is entrenched in technology and has even built multiple Android and iOS apps.  Before this, I <em>always</em> carried a phone and was in a constant state of sync. The event which prompted this experiment was the loss of my Nexus One during a trip to Las Vegas&#8211;the exact details of which aren&#8217;t important, but suffice it to say the trip was a success.</p>

<p>My hope throughout this was that I might be able to come to some insight or achieve a revelation about the significance of always being connected. Perhaps by depriving myself of something I had grown to take for granted, having a powerful computer in my pocket, could inspire me as a (mobile) developer. Unfortunately, the best I could come up with is this: <strong>having a phone doesn&#8217;t really fucking matter</strong>. For people who work in front of computers, in this day and age, your phone is a luxury device, and not having one is no big deal.</p>

<p>Sure, I definitely did miss out on a few candid photos of my friends, some of my amazing lunches went undocumented, and I definitely could have benefited from Google Maps from time to time, but fundamentally nothing about my life changed for the better or for the worse. I am still wired to a computer majority of the day, my brain is still synced to my GMail inbox, and aside from short periods of commute, the internet is still readily accessible if needed.</p>

<p>I was also hoping that I could write about how not having a phone could reduce stress. The physical constraint of not being able to check your email several hours a day does relax your attitude, but I still felt no perceptible difference in my stress level. Instead, for the rest of this post I will share some random tidbits I gained from this experience:</p>

<h3>Google Voice is the Shit</h3>

<p>For <strong>$0.00 dollars a month</strong> I have the <em>same mobile phone number</em> I had before as well as unlimited calls and domestic texts. This is all done through Google Voice after <a href="http://www.google.com/support/voice/bin/answer.py?hl=en&amp;answer=1065667">porting my phone number</a>. From the perspective of all of my contacts, I still have a phone and nothing has changed. Of course, I need access to a computer to return calls, but this is not a problem for me, especially with a MacBook Air slung over my shoulder for most of the day. It really is only a matter of time before mobile VOIP clients usurp voice and text plans entirely.</p>

<p>Moreover, using Google Voice for calls and texts is actually a lot better than the traditional phone counterparts. Voicemail transcription definitely helped <a href="http://codebrief.com/2011/06/what-its-like-to-be-recruited/">screen recruiters</a>. I am also doing myself a favor by typing out texts in an instant message-like interface rather than constantly using a touch keyboard. In retrospect, it is actually slightly amusing to think of myself responding to texts on my phone while sitting in front of a full keyboard, as I often did. The same goes for email. Even if you have a phone, it is worthwhile to go through the cumbersome porting process, effectively making your phone and computer interchangeable.</p>

<h3>Touch Interfaces Are Sexy and Easily Forgotten</h3>

<p>While not having a phone, there wasn&#8217;t a single app that I longed to use over it&#8217;s desktop equivalent. Desktop apps aren&#8217;t quite as sexy, but they definitely work. I might be singing a different tune if I were really into the mobile gaming scene or consuming certain types of content as thats where I feel most of the innovation is taking place (even though <a href="http://chrome.angrybirds.com/">Angry Birds</a> is now in the browser).</p>

<p>Phones and computers are converging, and phones are starting to feel like shitty computers. (Although, I really hope I eat these words when <a href="http://en.wikipedia.org/wiki/Near_field_communication">NFC</a> becomes prevalent). This is especially apparent when my Macbook Air is sitting next to my iPad 2 on my coffee table. It is only slightly larger, an order of magnitude more useful, and usually the first to be picked up when someone wants to browse the web. That said, just to be clear, I still do believe that a properly done native iOS or Android app focused on consuming content can still rival anything out there and can appeal to a wide(r) audience.</p>

<h3>I Just Bought a Phone</h3>

<p>I&#8217;m sure I slipped throughout this post and referred to my not having a phone in past tense. That is because yesterday I finally bought myself a replacement phone, an HTC Sensation, not because I needed it, but because I wanted it. I&#8217;m looking forward to being able to tether my air again.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Retroactively Open-Sourced Project #1: Paperblocks]]></title>
    <link href="http://codebrief.com/2011/06/retroactively-open-sourced-project-1-paperblocks/"/>
    <updated>2011-06-06T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/06/retroactively-open-sourced-project-1-paperblocks</id>
    <content type="html"><![CDATA[<p><a href="http://codebrief.com/old/uploads/2008/06/pblocks1.png"><img src="http://codebrief.com/old/uploads/2008/06/pblocks1-150x150.png" alt="" title="pblocks1" width="150" height="150" class="alignleft size-thumbnail wp-image-89" /></a></p>

<p>This is the first of several personal project&#8217;s that I plan to open source in the coming months. As I&#8217;ve slowly begun the process of migrating all of my personal projects from a private gitosis installation <del datetime="2011-06-06T21:50:42+00:00">to <a href="http://github.com">github</a></del> to a new server, I&#8217;ve realized that most of my 43 private repositories will amount to nothing in my hands alone. I&#8217;m also a big fan of free software without restrictions. With that in mind, I am licensing these projects under the <a href="http://www.opensource.org/licenses/mit-license.php">MIT license</a>.</p>

<p>Paperblocks is a flash 3d tetris game I made in my spare time years ago. I previously made a short blurb about it <a href="http://codebrief.com/2008/06/paperblocks-3d-tetris/">here</a>. It is built with Flex and <a href="http://blog.papervision3d.org/">Papervision3D</a> with a small php high scores backend. The original inspiration for the game was from <a href="http://en.wikipedia.org/wiki/Blockout">Blockout</a>, which was one of my favorites growing up.</p>

<p><a href="http://pblocks.com">Play the game</a> or check out the <a href="https://github.com/ghempton/pblocks">source code</a>. Cheers!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Windows 8 Isn't That Bad]]></title>
    <link href="http://codebrief.com/2011/06/windows-8-isnt-that-bad/"/>
    <updated>2011-06-01T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/06/windows-8-isnt-that-bad</id>
    <content type="html"><![CDATA[<p>There seems to be a large amount of <a href="http://daringfireball.net/2011/06/windows_8_fundamentally_flawed">backlash</a> directed towards Windows 8 due to the fact that it&#8217;s new UI exists alongside the old Windows desktop. I must confess that I was slightly shocked myself to witness the context switch take place on the <a href="http://www.microsoft.com/presspass/features/2011/jun11/06-01corporatenews.aspx">video</a>, but I was shocked in a good way. Ironically, the reason why I think it&#8217;s good to have a Windows desktop alongside a touch UI is based on the same reasoning as why I switched from Windows to OS X in the first place.</p>

<p>I am typing this right now on my latest generation MacBook Air. The reason why I switched to OS X was because <em>it was the best of both worlds</em>. I could have a Unix shell, Adobe products, as well be able to use XCode to develop iOS applications (which you can&#8217;t do on Windows, but that is a separate issue). I could do everything Windows could and more. Analogously, choosing between Windows 8 and iOS for a casual user is very similar.</p>

<p>I also have an iPad 2 and an iPad before that. People, mostly family, are always very attracted to my iPad and frequently ask me if they should buy one to replace their existing aging laptop. My answer is always a resounding no. Were that to happen, they would inevitably call me and ask how to open Office documents, view flash websites, and do all the other countless things that an iPad is not suited for.</p>

<p>Windows 8 solves this problem. Sure, there will be an initial period where some apps will <em>only</em> be available in desktop form. But, at least there will be a less elegant way to do things that otherwise couldn&#8217;t be done. Additionally, this will only result in low hanging fruit for developers. If the metro tiling interface takes off, consumers will prefer a metro based application and developers will build one. Similarly, Android&#8217;s additional OS-level features (at the sake of battery life, some might say) are one of the reasons why I prefer it over iOS.</p>

<p>Another argument against Windows 8 is that of market and developer confusion. <strong>There is no market and developer confusion</strong>. Apple has already set the precedent. Consumers and developers both know what they want and what to build respectively. The capability is there and the developer who builds what the consumer wants will win.</p>

<p>Based on WP7&#8217;s market performance, who knows what will happen. My argument here is not to say Windows 8 is a winner. It is simply to say that the the arguments against it are misguided. I, for one, would prefer to be able to do more than less. One thing that is certain, however, is that having more competitors and innovation in the mobile/touch landscape is a good thing.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What It's Like to be Recruited]]></title>
    <link href="http://codebrief.com/2011/06/what-its-like-to-be-recruited/"/>
    <updated>2011-06-01T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/06/what-its-like-to-be-recruited</id>
    <content type="html"><![CDATA[<p><img src="http://codebrief.com/old/uploads/2011/05/recuiter-gmail-sc.png" alt="252 Recruiter Emails" class="alignright" /></p>

<p>Roughly three months ago (in the beginning of March), for a variety of reasons, I decided to put my resume out there on the interwebs. Here I chronicle my experience being a software developer on some of the most popular and widely used job channels.</p>

<h2>Background</h2>

<p>For some context, I was doing research on an idea I had (now <a href="http://grouptalent.com">GroupTalent</a>) and was also willing to entertain the idea of flexible interesting mobile projects. My resume included the following:</p>

<ol>
<li>B.S. in CS and Math</li></li>
<li>SDE at Microsoft</li></li>
<li>YC Founder (Team Apart S&#8217;08, now defunct)</li></li>
<li>Misc. consulting</li></li>
<li>Independent app development (iOS and Android)</li></li>
</ol>


<p>My objective read:</p>

<blockquote><p>Seeking freelance or short term contract iPhone and Android development positions.</p></blockquote>

<p>I posted this resume on <a href="http://monster.com">Monster</a> and <a href="http://careerbuilder.com">CareerBuilder</a>. I had also previously created a profile on StackOverflow <a href="http://careers.stackoverflow.com/">careers</a> and GitHub <a href="http://jobs.github.com">jobs</a>. Additionally, and importantly, I had indicated that I would be willing to relocate.</p>

<h2>Results</h2>

<p>To relate my experience, I will begin with some numbers and then move into a more anecdotal portrayal.</p>

<p>Over the course of the roughly three month period after posting my resume, I diligently labeled all incoming emails from recruiters in GMail. Thankfully, I also use Google voice, and was easily able to identify and count calls and voicemails from recruiters. The numbers I am about to give exclude the numerous automatic emails sent from these sites; they all represent contact from actual people (or at least present themselves as so). The screenshot at the beginning of this post would suggest that I had received 252 emails, but this number is from when I began drafting this post roughly a week ago.</p>

<p>As I write this, all in all I have received: <strong>266 emails</strong> and <strong>96 voicemails</strong>. This roughly equates to 12.7 emails and 4.3 voicemails <em>per  workday</em>. There were also some additional calls that I actually answered or that didn&#8217;t result in a voicemail. My Monster.com profile was viewed 261 times and &#8220;saved&#8221; 37 times. My CareerBuilder.com profile showed up in 343 searches (presumably by employers), and was viewed 31 times. My profile on StackOverflow careers was viewed by employers a whopping <strong>1</strong> time and had 3 search hits. GitHub jobs doesn&#8217;t appear to reveal any data of this kind.</p>

<p>The emails varied immensely in personalization and adherence to what I was actually looking for. My CV&#8217;s objective of short term Android and iPhone projects functioned as a mere leitmotif or not at all. My overall impression was that many recruiters simply do blanket keyword searches for terms such as &#8220;java&#8221;. Interestingly enough, many recruiters reached out to me on the premise that they found my resume on other sites such as <a href="http://dice.com">Dice</a> that I had never even created a profile on. It turns out that most recruiters do not even interface with the job sites directly, but instead use 3rd party software which crawls all the job boards for them.</p>

<p>Employers ranged from small startups to large corporations, the average being somewhere in between. The companies also included the likes of desirable A-Companies such as Amazon and Zynga. The split of jobs that were local and those which required relocation was about half and half with perhaps a few more on the relocation side.</p>

<p>Most recruiters were either head hunters or part of 3rd party staffing companies, but many were internal recruiters as well. For the first week, I actually answered all incoming calls, but this eventually became unmanageable. I used the opportunity to hear them out and also sometimes give them a reverse pitch on GroupTalent for feedback. Some recruiters were actually extremely savy people who wanted to build a relationship with you. Others were pretty abrasive. My favorite conversation was with the recruiter who actually suggested that I take a job at a mega corp while I still could since everything was going to be outsourced in the near future anyways.</p>

<h2>Thoughts</h2>

<p>According to <a href="http://www.joelonsoftware.com/articles/FindingGreatDevelopers.html">Joel Spolsky</a>, most good developers will never even be exposed to this situation since they will never be on the market. Combine this with the fact that <a href="http://www.humbledmba.com/everyone-sucks-at-interviewing-everyone">everyone sucks at hiring</a> and you have an industry that is basically a crap shoot. I also wonder if companies realize that many of their candidates are acquired through pseudo-spam.</p>

<p>In the interest of full disclosure, I actually <em>have</em> used Monster a few years ago and did wind up with an excellent consulting gig that was very flexible, but my experience was similarly noisy. I consider myself at least a decent developer and believe that good developers are on the market or are at least willing to entertain new opportunities. I predict that in the coming years the demand for top talent will be even higher and companies will need to resort to new ways to find and incentivize developers. While the experience I have presented here can vary, especially for new grads and developers travelling through reputation or word of mouth, my goal here was simply to give some perspective.</p>

<p>What is your experience being recruited?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Five Reasons Why I Use Android and Two Reasons Why I Develop for iOS]]></title>
    <link href="http://codebrief.com/2011/05/five-reasons-why-i-use-android-and-two-reasons-why-i-develop-for-ios/"/>
    <updated>2011-05-28T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/05/five-reasons-why-i-use-android-and-two-reasons-why-i-develop-for-ios</id>
    <content type="html"><![CDATA[<p>Being both a mobile developer and an avid phone user, I have two somewhat different perspectives. As a user, over the last several years I have owned a multitude of mobile devices: G1, Nexus One, IPhone 3G, IPod Touch (4th Gen), IPad, and IPad 2. As a developer, I have a combined 13 apps in the android market and app store (all independently developed and released).</p>

<h2>Why I Use Android</h2>

<p>Despite the IPhone 4 having admittedly better hardware (damn that retina display is nice) I <em>much</em> prefer Android devices. The reasons have everything to do with software:</p>

<h3>1. Multitasking</h3>

<p>&#8220;Multitasking&#8221; on iOS is a joke. I&#8217;m speaking right now from the perspective of a user, but trust me, I also truly know this, having been in the shoes of a developer. Notifications are horribly presented in modal dialogs; in situations where I have a large number of notifications, usually all but the last one shown to me are lost. I also desperately long for an IM client which I can use on my IPad which I can naturally interact with while using other apps. No such app exists since all the apps are forced to go through the cumbersome notification system. On Android, as in a desktop operating system, applications can truly run in the background; on Android, IM can be almost indistinguishable from texting (which is coincidentally also better than iOS).</p>

<h3>2. Intents</h3>

<p>Android is an intent based operating system. What this means from a user&#8217;s perspective is a richer more deeply integrated experience. If I am browsing the web and click on a link to a product on Amazon.com, the context will switch and the product will be opened in the Amazon app. On iOS, clicking that link would just result in the link being opened in the browser (often times losing the context of the originating application). Android allows apps to have a deeper and more natural hook into the operating system and user experience. For example, in the coming years, when Google Voice finally gets a true VOIP client, it will be able to seamlessly replace the default calling application.</p>

<h3>3. Back Button</h3>

<p>The back button is a <em>killer</em> feature and is way more than just a physical button. The android operating system is essentially stack based. Going from the above example of clicking on an Amazon product link: after the Amazon app is opened, I can intuitively press the back button to return to the application from which I clicked the link. I cannot count the number of situations on iOS where I lose a retrievable context of where I was inside of an application by clicking on a link. Nor can I count the number of applications which pop open browser dialogs when you click on a link as a hack to fix this. Imagine how ridiculous it would be if it was the norm for desktop applications to all use an embedded browser. Imagine how <em>unusable</em> it would be. The closest equivalent on iOS for the back button (that I know of) is double tapping the home button (or four finger swiping) to get a list of the most recent apps and then clicking on the app you last used. Lots of users don&#8217;t even know you can do this.</p>

<p>The menu button on Android is also very convenient (although not as vital) and saves lots of prime mobile screen real estate.</p>

<h3>4. Apps</h3>

<p>As a user, I never <em>need</em> to buy an application. Moreover and surprisingly, there are many apps on Android that simply have no equivalent on iOS. If I want to use instant messaging, free apps exist. This is the status quo. Not so on iOS. Also, there is a GMail application which actually has an intuitive interface. I am shocked by tech-savy people who use the iOS mail application with their GMail account in an outlook-like fashion. Things like Wifi and USB tethering are also <em>built in</em> to the Android operating system.</p>

<h3>5. Navigation</h3>

<p>Newer version of android have a turn by turn navigation application by Google which uses data from Google Maps. Although some might consider this a smaller feature, this is hands down the best navigation application I have used and has rendered my Garmin navigation obsolete. I use this all the time. There is no equivalent for iOS, even though some apps exist in the app store with double digit price tags.</p>

<h2>Why I Develop for iOS</h2>

<p>Despite learning mobile development on Android and also preferring Android&#8217;s development framework and tools, I have shifted all of my app development to iOS (at least for first releases). One of my most recent games, <a href="http://itunes.apple.com/us/app/word-topple/id424710773?mt=8">Word Topple</a>, is only available on the app store. The reasons have nothing to do with software:</p>

<h3>1. Revenue</h3>

<p>iOS has a much more profitable app economy. Even though it is ridiculously hard to make a hit iOS app, an iOS application is much more lucrative than the same android application with the same number of users. On iOS, users <em>expect</em> to have to pay for applications and they do. Each user of an iOS application is also much more valuable than their Android counterparts.</p>

<p>To back this up with some data, I will reveal some numbers on one of my games, BeWorded (in the <a href="https://market.android.com/details?id=com.hempton.beworded">Android Market</a> and in the <a href="http://itunes.apple.com/us/app/beworded/id415661926?mt=8">App Store</a>). Both versions are identical ports and have never been marketed. They have also both not been updated in months. The primary source of revenue for this app is through AdMob advertising. Interestingly enough, both versions have had almost <em>exactly</em> the same number of impressions (~1.5 million). The iOS version has a CPM of $0.30 and the Android version has a CPM of $0.08. The iOS version is roughly <em>4x</em> more profitable with an identical user base. Some of my other Android apps have even worse CPMs.</p>

<h3>2. Game Framework Maturity</h3>

<p>Let&#8217;s face it, most user&#8217;s play <em>lots</em> of games on their mobile devices. Games are huge. On iOS, there are a number of game frameworks with very active communities, my favorite being <a href="http://www.cocos2d-iphone.org">cocos2d</a>. Android, on the other hand, suffers from a lack of mature game frameworks. I first started writing games on Android and have tried virtually all of the 2D frameworks I know of. I wanted a full 2D scene graph and none of them were sufficient. I ultimately wound up using an incomplete <a href="http://code.google.com/p/cocos2d-android-1/">port</a> of cocos2d to android which suffers considerably in performance and in completeness, but is getting a lot better. This fact has resulted in iOS being a much better platform for developers and users with respect to games.</p>

<h2>Thoughts on the Future</h2>

<p>Android is a much more advanced and well though out operating system compared to iOS. It is open. Its applications are free. Even its development tools are more modern (which I will go into in another post). Game frameworks will eventually catch up and the communities are growing. The biggest leg up iOS has over android at this point is hardware and aesthetics, and that gap is closing fast and might already be closed. Unlike the laptop market, other handset manufacturers like HTC and Samsung are producing <em>amazing</em> devices. The IPhone was clearly superior when I was on my G1. After upgrading to a Nexus One, my phone was superior to my friend&#8217;s IPhone 3GS&#8217;, before the IPhone 4 was released. Next generation phones like the soon to be released HTC Sensation and Samsung Galaxy S2 are going to blow existing devices out of the water. The bar for applications on Android is also increasing and the truly good, sexy apps are floating to the top.</p>

<p>Although I currently still develop primarily for iOS, I expect that to change soon. All of the low hanging iOS applications have long since been built and more and more apps are becoming free to compete with the incumbents. I expect this to affect the profitability of iOS development and the expectations of users. Android is also gaining market share and <em>truly</em> has a better user experience. People are starting to openly prefer their Android phones to their friend&#8217;s IPhones. If I had to make a long term wager on a mobile OS, all my money would be on Android.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Blog Rebranding and Redesign]]></title>
    <link href="http://codebrief.com/2011/05/blog-rebranding-and-redesign/"/>
    <updated>2011-05-23T00:00:00-07:00</updated>
    <id>http://codebrief.com/2011/05/blog-rebranding-and-redesign</id>
    <content type="html"><![CDATA[<p>Several events have converged, resulting in a new blog design and a new brand. <a href="http://www.slicehost.com">Slicehost</a> is <a href="http://www.readwriteweb.com/cloud/2011/05/rackspace-shutting-down-sliceh.php">shutting down</a>, forcing me to finally migrate over to <a href="http://www.linode.com/?r=e0eddc168073d6e0fc67a44ee35b0858076f93f2">linode</a> (which kicks ass by the way, should have moved over a long time ago) and I have finally acted on the realization that my personal brand needs to be stronger. Rather than simply copying my blog over, I used this opportunity to rebrand from my last name (hempton.com) to codebrief.com and to give it a custom design.</p>

<p>Having formerly been a Math and CS major in college, I have always had a penchant for <a href="http://www.amazon.com/gp/product/B001J87JTM/ref=as_li_tf_tl?ie=UTF8&tag=yoanme0e-20&linkCode=as2&camp=217145&creative=399353&creativeASIN=B001J87JTM">green engineering pads</a>, on which this theme is based. This theme is also open source and is up on GitHub <a href="https://github.com/ghempton/CodePad">here</a>. Enjoy! (P.S. I really wish more designers would use version control.)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Dead Simple jQuery Pagination Plugin]]></title>
    <link href="http://codebrief.com/2010/07/dead-simple-jquery-pagination-plugin/"/>
    <updated>2010-07-27T00:00:00-07:00</updated>
    <id>http://codebrief.com/2010/07/dead-simple-jquery-pagination-plugin</id>
    <content type="html"><![CDATA[<p>While working on one of my side-projects, I had the need for client-side pagination. Nothing I could find was simple enough for my use case, so I decided to write my own. Check it out on GitHub <a href="http://github.com/ghempton/jquery.paginate">here</a>.</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mounder: Desktop Notifications for StackOverflow.com]]></title>
    <link href="http://codebrief.com/2009/11/mounder-desktop-notifications-for-stackoverflow-com/"/>
    <updated>2009-11-25T00:00:00-08:00</updated>
    <id>http://codebrief.com/2009/11/mounder-desktop-notifications-for-stackoverflow-com</id>
    <content type="html"><![CDATA[<p><strong> UPDATE 1/20/2012: </strong> <em>This application is no longer supported and the download has been removed.</em></p>

<p>I spent the last few days teaching myself Flex 4 and AIR. Per my usual way of learning things I like to make (somewhat) functional applications. This time I made a desktop notification system for <a href="http://stackoverflow.com">Stackoverflow</a>. Currently it just notifies of new questions asked, subject to certain filters. Eventually I will add notifications for questions that have been answered, among other things. If you install it now, it should update to the latest version automatically in the future. Use the badge below to try it out and let me know what you think:</p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Flex 4 CSS Namespaces: Annoying Migration Issues]]></title>
    <link href="http://codebrief.com/2009/11/flex-4-css-namespaces-annoying-migration-issues/"/>
    <updated>2009-11-07T00:00:00-08:00</updated>
    <id>http://codebrief.com/2009/11/flex-4-css-namespaces-annoying-migration-issues</id>
    <content type="html"><![CDATA[<p>I started playing around with the beta of the <a href="http://labs.adobe.com/technologies/flex4sdk/">Flex 4 sdk</a> the other day. The purported features of the new version are very exciting to me, especially the support for advanced CSS selectors as well as enhanced component skinning capabilities.</p>


<p>Based on the backwards compatibility with Halo, my initial idea was to migrate one of my existing side projects from Flex 3 to Flex 4 and then incrementally switch over to Spark components as development progressed. In theory this sounded fairly easy, but ultimately this required lots of overhaul to my CSS files and lots of additional bloat. This is due to a design pattern that I favor which heavily depends on reusable custom components and CSS type selectors.</p>


<p>The design pattern is simple: I create custom reusable composite components which consist of several other components and then I style those components in a separate CSS File using type selectors. For instance, I will have a component called UserView which, for simplicity, would just consist of a VBox component containing Image and Label components. This would then be styled in an external css file, style.css, as follows:</p>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="nt">UserView</span> <span class="p">{</span> <span class="o">....</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>This component would then be reused in many locations throughout the application. This worked great in Flex 3, however due to Flex 4 requiring all CSS type selectors being qualified with a namespace, this breaks in Flex 4, resulting in none of the styles being applied. The workaround is to create a namespace inside the css file:</p>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="k">@namespace</span> <span class="s2">&quot;com.mypackage.views.*&quot;</span><span class="p">;</span>
</span><span class='line'><span class="nt">UserView</span> <span class="p">{</span> <span class="o">....</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now it works. The problem is, however, in large projects I normally have a <strong>multitude</strong> of these components in lots of <strong>different</strong> packages. Thus, since the CSS namespace spec requires that all the namespaces be declared at the top of the file, I have a huge number of namespaces at the top of the file and each component needs to be qualified. E.g:</p>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="k">@namespace</span> <span class="nt">views</span> <span class="s2">&quot;com.mypackage.views.*&quot;</span><span class="p">;</span>
</span><span class='line'><span class="k">@namespace</span> <span class="nt">forms</span> <span class="s2">&quot;com.mypackage.forms.*&quot;</span><span class="p">;</span>
</span><span class='line'><span class="o">...</span>
</span><span class='line'><span class="nt">views</span><span class="o">|</span><span class="nt">UserView</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
</span><span class='line'><span class="nt">forms</span><span class="o">|</span><span class="nt">Login</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
</span><span class='line'><span class="o">...</span>
</span></code></pre></td></tr></table></div></figure>


<p>This is frustrating because not only does it bloat the code, but it also decreases the spatial locality of the code, requiring me to jump around to mentally resolve namespaces.</p>


<p>If my classes were inside of a flex library, I could give them all the same namespace, e.g. http://ns.mycompany.com/2009, but I cannot find a convenient way to do this for classes which are part of a normal flex project and not pulled in from an external library.</p>


<p>Flex 4 is still great and by no means is this a deal breaker. Other people have overstated this as an <a href="http://aralbalkan.com/2202">EPIC FAIL</a> and others have oversimplified it as a <a href="http://blog.benstucki.net/?p=55">one-line fix</a> (which is only true if you are styling components from a single namespace). It would be nice if there was something like the following:</p>


<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="k">@namespace</span> <span class="s2">&quot;com.mypackage.**&quot;</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>


<p>Or at the very least:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='css'><span class='line'><span class="s2">&quot;com.mypackage.views.*&quot;</span><span class="o">|</span><span class="nt">UserView</span> <span class="p">{</span> <span class="o">...</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>Avoiding the requirement of having lots of declared namespaces.</p>
]]></content>
  </entry>
  
</feed>

