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

  <title><![CDATA[Adventures in JavaScript Development]]></title>
  <link href="http://rmurphey.com/atom.xml" rel="self"/>
  <link href="http://rmurphey.com/"/>
  <updated>2013-03-16T20:53:25-04:00</updated>
  <id>http://rmurphey.com/</id>
  <author>
    <name><![CDATA[Rebecca Murphey]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Refactoring setInterval-based polling]]></title>
    <link href="http://rmurphey.com/blog/2013/02/04/refactoring-setInterval-polling/"/>
    <updated>2013-02-04T15:30:00-05:00</updated>
    <id>http://rmurphey.com/blog/2013/02/04/refactoring-setInterval-polling</id>
    <content type="html"><![CDATA[<p>I came across some code that looked something like this the other day, give or take a few details.</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">checkSyncStatus</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">if</span> <span class="p">(</span><span class="nx">App</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">))</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">check</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;/sync_status&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">dataType</span><span class="o">:</span> <span class="s1">&#39;json&#39;</span><span class="p">,</span>
</span><span class='line'>      <span class="nx">success</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">resp</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">if</span> <span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">status</span> <span class="o">===</span> <span class="s1">&#39;done&#39;</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">reloadUser</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>            <span class="nx">clearInterval</span><span class="p">(</span><span class="nx">App</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">));</span>
</span><span class='line'>            <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="kc">null</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="p">};</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="nx">setInterval</span><span class="p">(</span><span class="nx">check</span><span class="p">,</span> <span class="mi">1000</span><span class="p">));</span>
</span><span class='line'><span class="p">};</span>
</span></code></pre></td></tr></table></div></figure>


<p>The code comes from an app whose server-side code queries a third-party service for new data every now and then. When the server is fetching that new data, certain actions on the front-end are forbidden. The code above was responsible for determining when the server-side sync is complete, and putting the app back in a state where those front-end interactions could be allowed again.</p>

<p>You might have heard that <code>setInterval</code> can be a dangerous thing when it comes to polling a server*, and, looking at the code above, it&#8217;s easy to see why. The polling happens every 1000 seconds, <em>whether the request was successful or not</em>. If the request results in an error, or fails, or takes more than 1000 milliseconds, <code>setInterval</code> doesn&#8217;t care &#8211; it will blindly kick off another request. The interval only gets cleared when the request succeeds and the sync is done.</p>

<p>The first refactoring for this is easy: switch to using <code>setTimeout</code>, and only enqueue another request once we know what happened with the previous one.</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">checkSyncStatus</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">if</span> <span class="p">(</span><span class="nx">App</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">))</span> <span class="p">{</span> <span class="k">return</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">check</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;/sync_status&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">dataType</span><span class="o">:</span> <span class="s1">&#39;json&#39;</span><span class="p">,</span>
</span><span class='line'>      <span class="nx">success</span><span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">resp</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">if</span> <span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">status</span> <span class="o">===</span> <span class="s1">&#39;done&#39;</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">reloadUser</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>            <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
</span><span class='line'>          <span class="p">});</span>
</span><span class='line'>        <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>          <span class="nx">setTimeout</span><span class="p">(</span><span class="nx">check</span><span class="p">,</span> <span class="mi">1000</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><span class='line'>  <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="kc">true</span><span class="p">);</span>
</span><span class='line'><span class="p">};</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now, if the request fails, or takes more than 1000 milliseconds, at least we won&#8217;t be perpetrating a mini-DOS attack on our own server.</p>

<p>Our code still has some shortcomings, though. For one thing, we aren&#8217;t handling the failure case. Additionally, the rest of our application is stuck looking at the <code>syncCheck</code> property of our <code>App</code> object to figure out when the sync has completed.</p>

<p>We can use a promise to make our function a whole lot more powerful. We&#8217;ll return the promise from the function, and also store it as the value of our <code>App</code> object&#8217;s <code>syncCheck</code> property. This will let other pieces of code respond to the outcome of the request, whether it succeeds or fails. With a simple guard statement at the beginning of our function, we can also make it so that the <code>checkSyncStatus</code> function will return the promise immediately if a status check is already in progress.</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>
<span class='line-number'>31</span>
<span class='line-number'>32</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">Helpers</span><span class="p">.</span><span class="nx">checkSyncStatus</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">syncCheck</span> <span class="o">=</span> <span class="nx">App</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">);</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">syncCheck</span><span class="p">)</span> <span class="p">{</span> <span class="k">return</span> <span class="nx">syncCheck</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">dfd</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">Deferred</span><span class="p">();</span>
</span><span class='line'>  <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="nx">dfd</span><span class="p">.</span><span class="nx">promise</span><span class="p">());</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">success</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">resp</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="nx">resp</span><span class="p">.</span><span class="nx">status</span> <span class="o">===</span> <span class="s1">&#39;done&#39;</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">reloadUser</span><span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>        <span class="nx">dfd</span><span class="p">.</span><span class="nx">resolve</span><span class="p">();</span>
</span><span class='line'>        <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="kc">null</span><span class="p">);</span>
</span><span class='line'>      <span class="p">});</span>
</span><span class='line'>    <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">setTimeout</span><span class="p">(</span><span class="nx">check</span><span class="p">,</span> <span class="mi">1000</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">fail</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">dfd</span><span class="p">.</span><span class="nx">reject</span><span class="p">();</span>
</span><span class='line'>    <span class="nx">App</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;syncCheck&#39;</span><span class="p">,</span> <span class="kc">null</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">check</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="kd">var</span> <span class="nx">req</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;/sync_status&#39;</span><span class="p">,</span> <span class="p">{</span> <span class="nx">dataType</span><span class="o">:</span> <span class="s1">&#39;json&#39;</span> <span class="p">});</span>
</span><span class='line'>    <span class="nx">req</span><span class="p">.</span><span class="nx">then</span><span class="p">(</span> <span class="nx">success</span><span class="p">,</span> <span class="nx">fail</span> <span class="p">);</span>
</span><span class='line'>  <span class="p">};</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">setTimeout</span><span class="p">(</span><span class="nx">check</span><span class="p">,</span> <span class="mi">1000</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">return</span> <span class="nx">dfd</span><span class="p">.</span><span class="nx">promise</span><span class="p">();</span>
</span><span class='line'><span class="p">};</span>
</span></code></pre></td></tr></table></div></figure>


<p>Now, we can call our new function, and use the returned promise to react to the <em>eventual outcome</em> of the sync:</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">App</span><span class="p">.</span><span class="nx">Helpers</span><span class="p">.</span><span class="nx">checkSyncStatus</span><span class="p">().</span><span class="nx">then</span><span class="p">(</span>
</span><span class='line'>  <span class="c1">// this will run if the sync was successful,</span>
</span><span class='line'>  <span class="c1">// once the user has been reloaded</span>
</span><span class='line'>  <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;it worked&#39;</span><span class="p">);</span> <span class="p">},</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1">// this will run if the sync failed</span>
</span><span class='line'>  <span class="kd">function</span><span class="p">()</span> <span class="p">{</span> <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;it failed&#39;</span><span class="p">);</span> <span class="p">}</span>
</span><span class='line'><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>With a few more lines of code, we&#8217;ve made our function safer &#8211; eliminating the possibility of an out-of-control <code>setInterval</code> &#8211; and also made it vastly more useful to other pieces of the application that care about the outcome of the sync.</p>

<p>While the example above used <a href="http://api.jquery.com/deferred.promise/">jQuery&#8217;s promises implementation</a>, there are plenty of other implementations as well, including Sam Breed&#8217;s <a href="https://github.com/wookiehangover/underscore.Deferred">underscore.Deferred</a>, which mimics the behavior of jQuery&#8217;s promises without the dependency on jQuery.</p>

<p><small>* <a href="http://www.html5rocks.com/en/tutorials/websockets/basics/">Websockets</a> are a great way to eliminate polling all together, but in the case of this application, they weren&#8217;t an option.</small></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Onward]]></title>
    <link href="http://rmurphey.com/blog/2013/01/18/onward/"/>
    <updated>2013-01-18T10:30:00-05:00</updated>
    <id>http://rmurphey.com/blog/2013/01/18/onward</id>
    <content type="html"><![CDATA[<p>My friend IM&#8217;d me a link the other day to a document he and a colleague wrote
at the end of 2011, listing all the things they wanted to make happen in the
world of web development in 2012.</p>

<p>&#8220;We did almost all of it,&#8221; he said.</p>

<p>&#8220;Well shit,&#8221; I said. &#8220;I should write up something like this for 2013.&#8221;</p>

<p>&#8220;Why do you think I showed it to you?&#8221;</p>

<hr />

<p>A year ago I was working at Toura, a startup based in New York that was
developing software to make it easy to create content-centric mobile
applications. I started there as a consultant back in 2010, helping them write
a saner version of the prototype they&#8217;d developed in the months before.</p>

<p>I got the gig because apparently I spoke with their director of development,
Matt, at a meetup in Brooklyn, though I actually have no recollection of this.
By this time last year, I&#8217;d been there for more than a year, and Matt and I had
convinced the company a few months before that the technology we&#8217;d developed &#8211;
a JavaScript framework called Mulberry that ran inside of a Phonegap wrapper
&#8211; was worth open-sourcing.</p>

<p>I spent much of January and February speaking at meetups and events &#8211;
Vancouver, Boston, Austin, Charlotte &#8211; telling people why Mulberry was
something they might consider using to develop their own content-centric mobile
apps. By March, though, it was clear that Toura was headed in a direction that
was different from where I wanted to go. As it turned out, Matt and I gave our
notice on the same day.</p>

<hr />

<p>April was the first time in almost 10 years that I purposefully didn&#8217;t work for
a solid month. I spent almost two weeks in Europe, first in Berlin and then in
Warsaw for <a href="http://2013.front-trends.com/">Front Trends</a>. I sold my car &#8211; it
mostly just sat in the driveway anyway &#8211; to make Melissa feel a bit better
about the part where I wasn&#8217;t making any money.
<a href="http://twitter.com/theophani">Tiffany</a> was a marvelous host; we took the train
together from Berlin to Warsaw for the conference, barely talking the whole way
as we worked on our respective presentations. Warsaw was a two-day whirlwind of
wonderful people &#8211; Melanie, Milos, Chris, Alex, Frances &#8211; memorable for my
terrible laryngitis and capped by endless hours of post-conference celebration
in the hotel lobby, which was magically spotless when we made our way,
bleary-eyed, to the train station early the next morning.</p>

<p>I flew home two days later; two days after that, I started at
<a href="http://bocoup.com/">Bocoup</a>.</p>

<hr />

<p>Taking a job at Bocoup was a strategic change of pace for me. For 18 months, I
had been immersed in a single product and a single codebase, and I was the
architect of it and the expert on it. As fun as that was, I was ready to
broaden my horizons and face a steady stream of new challenges in the company
of some extremely bright people.</p>

<p>As it turned out, I ended up focusing a lot more on the training and education
side of things at Bocoup &#8211; I spent the summer developing an updated and more
interactive version of <a href="http://jqfundamentals.com">jQuery Fundamentals</a>, and
worked through the summer and fall on developing and teaching various
JavaScript trainings, including a really fun two-day course on writing testable
JavaScript. I also worked on creating a
<a href="http://training.bocoup.com/coaching/">coaching</a> offering, kicked off a
<a href="http://training.bocoup.com/screencasts/">screencasts</a> project, and had some
great conversations as part of <a href="https://plus.google.com/101066175187812737186/posts">Bocoup on Air</a>.
Throughout it all, I kept up a steady schedule of speaking &#8211; TXJS, the jQuery Conference,
Fronteers, Full Frontal, and more.</p>

<p>Though I was keeping busy and creating lots of new content, there was one thing
I wasn&#8217;t doing nearly enough of: writing code.</p>

<hr />

<p>I went to New York in November to speak at the New York Times <a href="http://opensourcesciencefair.com/">Open Source Science Fair</a>,
and the next day I dropped in on Matt, my old boss from Toura, before heading
to the airport. He&#8217;s working at another startup these days, and they&#8217;re using
<a href="http://emberjs.com/">Ember</a> for their front-end.  Though I was lucky enough to
get a guided tour of Ember from Tom Dale over the summer, I&#8217;d always felt like
I wouldn&#8217;t really appreciate it until I saw it in use on a sufficiently complex
project.</p>

<p>As it turned out, Matt was looking for some JavaScript help; I wasn&#8217;t really
looking for extra work, but I figured it would be a good chance to dig in to a
real Ember project. I told him I&#8217;d work for cheap if he&#8217;d tolerate me working
on nights and weekends. He gave me a feature to work on and access to the repo.</p>

<p>The first few hours with Ember were brutal. The next few hours were manageable.
The hours after that were magical. The most exciting part of all, despite all
the brain hurting along the way, was that I was solving problems with code
again. It felt good.</p>

<hr />

<p>With much love to my friends and colleagues at Bocoup, I&#8217;ve realized it is time
to move on. I&#8217;ll be taking a few weeks off before starting as a senior
software engineer at <a href="http://www.bazaarvoice.com/">Bazaarvoice</a>, the company
behind the ratings and reviews on the websites of companies such as WalMart,
Lowe&#8217;s, Costco, Best Buy, and lots more.</p>

<p>If you&#8217;re in the JS world, Bazaarvoice might sound familiar because <a href="http://alexsexton.com/">Alex Sexton</a>,
of yayQuery, TXJS, and redhead fame, works there. I&#8217;ll be joining the team he
works on, helping to flesh out, document, test, and implement a JavaScript
framework he&#8217;s been prototyping for the last several months.</p>

<p>I&#8217;ve gotten tiny peeks at the framework as Alex and the rest of the team have
been working on it, starting way back in February of last year, when I flew out
to Austin, signed an NDA, and spoke at BVJS, an internal conference the company
organized to encourage appreciation for JS as a first-class citizen. Talking to
Alex and his colleagues over the last few weeks about the work that&#8217;s ahead of
them, and how I might be able to help, has quite literally given me goosebumps
more than once. I can&#8217;t wait.</p>

<hr />

<p>I look back on 2012 with a lot of mixed emotions. I traveled to the UK,
to Amsterdam, to Warsaw, to Berlin two times. I broke a bone in a foreign
country, achievement unlocked. I learned about hardware and made my first
significant code contribution to an open-source project in the process. I met
amazing people who inspired me and humbled me, and even made a few new friends.</p>

<p>What I lost sight of, though, was making sure that I was seeking out new
challenges and facing them head on, making sure that I was seeking
opportunities to learn new things, even when they were hard, even when I didn&#8217;t
have to. I didn&#8217;t realize til my work with Ember just how thoroughly I&#8217;d let
that slip, and how very much I need it in order to stay sane.</p>

<p>And so while my friend probably has his list of things he will change in the
world of web development in 2013, and while maybe I&#8217;ll get around to making
that list for myself too, the list I want to be sure to look back on, 12 months
or so from now, is more personal, and contains one item:</p>

<p><em>Do work that requires learning new things all the time. Even if that&#8217;s a
little scary sometimes. Especially if that&#8217;s a little scary sometimes. In the
end you will be glad.</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Two Things about Conditionals in JavaScript]]></title>
    <link href="http://rmurphey.com/blog/2012/12/10/js-conditionals/"/>
    <updated>2012-12-10T21:40:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/12/10/js-conditionals</id>
    <content type="html"><![CDATA[<p>Just a quick post, inspired by <a href="http://laurakalbag.com/display-none/">Laura Kalbag&#8217;s post</a>, which included this gem:</p>

<blockquote><p>We shouldn’t be fearful of writing about what we know. Even if you write from the most basic point of view, about something which has been ‘around for ages’, you’ll likely be saying something new to someone.</p></blockquote>

<h2>One: There is no <code>else if</code></h2>

<p>When you write something like this &#8230;</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">saySomething</span><span class="p">(</span> <span class="nx">msg</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">msg</span> <span class="o">===</span> <span class="s1">&#39;Hello&#39;</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Hello there&#39;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">msg</span> <span class="o">===</span> <span class="s1">&#39;Yo&#39;</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Yo dawg&#39;</span><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>&#8230; then what you&#8217;re actually writing is this &#8230;</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">saySomething</span><span class="p">(</span> <span class="nx">msg</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">msg</span> <span class="o">===</span> <span class="s1">&#39;Hello&#39;</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Hello there&#39;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span> <span class="nx">msg</span> <span class="o">===</span> <span class="s1">&#39;Yo&#39;</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s1">&#39;Yo dawg&#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></code></pre></td></tr></table></div></figure>


<p>That&#8217;s because there is no <code>else if</code> in JavaScript. You know how you can write an <code>if</code> statement without any curly braces?</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='javascript'><span class='line'><span class="k">if</span> <span class="p">(</span> <span class="nx">foo</span> <span class="p">)</span> <span class="nx">bar</span><span class="p">()</span> <span class="c1">// please don&#39;t do this if you want your code to be legible</span>
</span></code></pre></td></tr></table></div></figure>


<p>You&#8217;re doing the same thing with the <code>else</code> part of the initial <code>if</code> statement when you write <code>else if</code>: you&#8217;re skipping the curly braces for the second <code>if</code> block, the one you&#8217;re providing to <code>else</code>. There&#8217;s nothing <em>wrong</em> with <code>else if</code> per se, but it&#8217;s worth knowing about what&#8217;s actually happening.</p>

<h2>Two: <code>return</code> Means Never Having to Say <code>else</code></h2>

<p>Consider some code like 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>
<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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">howBig</span><span class="p">(</span> <span class="nx">num</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">10</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;small&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&gt;=</span> <span class="mi">10</span> <span class="o">&amp;&amp;</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">100</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;medium&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&gt;=</span> <span class="mi">100</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;big&#39;</span><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>If the number we pass to <code>howBig</code> is less than 10, then our function will return <code>'small'</code>. As soon as it returns, none of the rest of the function will run &#8211; this means we can skip the <code>else</code> part entirely, which means our code could look like 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>
<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">function</span> <span class="nx">howBig</span><span class="p">(</span> <span class="nx">num</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">10</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;small&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">100</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;medium&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&gt;=</span> <span class="mi">100</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;big&#39;</span><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>But wait &#8211; if the first <code>if</code> statement isn&#8217;t true, and the second <code>if</code> statement isn&#8217;t true, then we will <em>always</em> return <code>'big'</code>. That means the third <code>if</code> statement isn&#8217;t even required:</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">function</span> <span class="nx">howBig</span><span class="p">(</span> <span class="nx">num</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">10</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;small&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span> <span class="nx">num</span> <span class="o">&lt;</span> <span class="mi">100</span> <span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="s1">&#39;medium&#39;</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">return</span> <span class="s1">&#39;big&#39;</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p><small><em>Note: this post was edited to improve a couple of the examples and to fix some typos.</em></small></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[This is the Cigarette]]></title>
    <link href="http://rmurphey.com/blog/2012/12/09/this-is-the-cigarette/"/>
    <updated>2012-12-09T19:40:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/12/09/this-is-the-cigarette</id>
    <content type="html"><![CDATA[<p><a href="http://www.flickr.com/photos/rdmey/8259827572/" title="Untitled by rdmey, on Flickr"><img src="http://farm9.staticflickr.com/8212/8259827572_73b5a4e269.jpg" width="200"></a></p>

<p>This is the cigarette I smoked* on Wednesday after I got out of a meeting in Boston and went to my desk and read my messages and learned that our birthmother &#8220;match&#8221; had fallen through.</p>

<p>The last three weeks have been among the happiest, most exciting, most terrifying times I can remember. Saying that we are sad and disappointed and et cetera doesn&#8217;t really cover it, but, well, there it is. Our search will continue.</p>

<p><small>* Don&#8217;t worry, Mom, I don&#8217;t usually smoke. Desperate times, desperate measures.</small></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[On Choosing a Syntax Highlighting Scheme for Your Next Presentation]]></title>
    <link href="http://rmurphey.com/blog/2012/11/29/choosing-presentation-color-scheme/"/>
    <updated>2012-11-29T20:20:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/11/29/choosing-presentation-color-scheme</id>
    <content type="html"><![CDATA[<p>This is a projector screen:</p>

<p><img src="http://d.pr/i/p2JW+"></p>

<p>You will notice that it is white, or some reasonable approximation thereof. It is probably made of a reflective material that sparkles a bit when light shines on it. Still: white.</p>

<p>Do you know what color this screen is when you use a projector to display this image onto it?</p>

<p><img src="http://d.pr/i/780F+" width="300px"></p>

<p>It is still white. Crazy, I know! The thing is, projectors cannot project black; they can only <em>not</em> project any light on a region that you intend to be black.</p>

<p>Chances are you are reading this on an LCD screen of some sort, where the rules are completely different: they usually start out essentially black, not white, and pixels are brightened as required. The pixels that start out dark can generally stay pretty dark.</p>

<p>On a projection screen, on the other hand, the appearance of black is nothing more than an optical illusion, made possible by the projector projecting brightness everywhere else.</p>

<p>What does this mean? Lots of things, but in particular, it means that you should never, ever, ever use a color scheme with a dark background &#8211; no matter how high-contrast and good it looks on your monitor &#8211; if you will be presenting using a projector that is projecting onto a white screen. At least, assuming that you intend for your audience to be able to actually read the code.</p>

<h3>Presentation Color Schemes That I Have Loved</h3>

<p><a href="https://gist.github.com/4171437">Ben Alman&#8217;s TextMate Theme</a>: Ben has tailored this to be incredible for presenting about JS code.</p>

<p><img src="http://d.pr/i/yyh1+"></p>

<p><a href="https://github.com/chriskempson/tomorrow-theme">Tomorrow Theme</a>: The light-background flavor is decent, but could probably stand to be higher-contrast, at least for some languages.</p>

<p><img src="http://d.pr/i/5oEs+"></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Show & Tell]]></title>
    <link href="http://rmurphey.com/blog/2012/11/25/times-open-science-fair/"/>
    <updated>2012-11-25T20:20:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/11/25/times-open-science-fair</id>
    <content type="html"><![CDATA[<p>I spoke at the <a href="http://opensourcesciencefair.com/">Times Open Source Science Fair</a> a couple of weeks ago. I&#8217;ll admit that I was pretty skeptical of the concept when I was first asked, but as someone who used to work as an editor at a tiny newspaper in upstate New York, I wasn&#8217;t about to say no when the Times asked me to come say hi.</p>

<p>A few days before the event, I got an email asking me for information about what I&#8217;d be showing off at my booth. Booth? Wat? They weren&#8217;t kidding about the science fair thing, but what the heck was I going to show at a booth?</p>

<p>It turns out this is basically the best idea ever. I recruited my Bocoup colleague <a href="http://twitter.com/rwaldron">Rick Waldron</a> to join me, and together we spent a whirlwind hour showing off <a href="https://github.com/rwldrn/johnny-five">robots powered by JavaScript</a> to an endless stream of people walking up to our booth. Rick did a great job of setting up a demo that people could play with, and they took turns moving <a href="https://www.sparkfun.com/products/9119">sliding potentiometers</a> that controlled <a href="https://www.sparkfun.com/products/9064">servos</a> that moved an arm with a gripper at the end, trying to pick up Bocoup stickers. Ours was one of about a <a href="http://open.blogs.nytimes.com/2012/11/21/open-source-science-fair-exhibitor-experiences/">dozen booths</a> showing off open-source projects, and the room was a wonderful madhouse.</p>

<p>After a break for dinner, I, <a href="http://twitter.com/jashkenas">Jeremy Ashkenas</a>, and <a href="http://twitter.com/holman">Zach Holman</a> each gave 20-minute talks, but the talks were really just icing on the evening. The &#8220;science fair&#8221; format promoted such <em>intentional interaction</em>, in a way that traditional conferences just can&#8217;t, no matter how great the hall track or the parties may be. The format invited and encouraged attendees to talk to the presenters &#8211; indeed, if they didn&#8217;t talk to the presenters, there wasn&#8217;t much else for them to do. By the time the official talks came around, a super-casual, super-conversational atmosphere had already been established, and the energy that created was tangibly different from any event I&#8217;ve been to before.</p>

<p>I love conferences, and the sharing of knowledge that happens there, and there&#8217;s a whole lot to be said for their speaker-audience format &#8211; don&#8217;t get me wrong. But I&#8217;d also love to see more events figure out how to integrate this show and tell format. &#8220;Booths&#8221; don&#8217;t need to mean &#8220;vendors trying to sell things&#8221; &#8211; they can actually be a great opportunity to facilitate conversation, and to let open source contributors show off their hard work.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Recent Talks]]></title>
    <link href="http://rmurphey.com/blog/2012/11/21/recent-talks/"/>
    <updated>2012-11-21T10:40:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/11/21/recent-talks</id>
    <content type="html"><![CDATA[<p><a href="http://infrequently.org/2012/11/bits-and-remainders/">A post from Alex Russell</a> reminded me that I&#8217;ve given a number of talks in the last few months, and some of them even have video on the internet.</p>

<p>I&#8217;ve been ridiculously spoiled to get to travel all over the place these last few months &#8211; San Francisco, New York, Amsterdam, Berlin, Brighton &#8211; and speak at some truly first-class conferences, sharing the stage, sharing meals, and sharing beers with some seriously amazing folks. My <a href="http://rmurphey.com/blog/2012/11/14/this-is-the-cup-of-coffee/">recent news</a> means I&#8217;ll be doing a lot less travel for the next little bit, but I&#8217;m ever-so-grateful for the opportunities I&#8217;ve had and the people I&#8217;ve gotten to see and meet these last few months.</p>

<h3>Writing Testable JavaScript</h3>

<p>This is the first talk I&#8217;ve developed that I&#8217;ve managed to give several times in rapid succession: three times in six days, including at <a href="http://2012.full-frontal.org/">Full Frontal</a>, the online <a href="http://environmentsforhumans.com/2012/javascript-summit/">JS Summit</a>, and to a group of developers at the New York Times. There&#8217;s no video yet, but the <a href="https://speakerdeck.com/rmurphey/writing-testable-javascript-mocha-version">slides are here</a>, and there should be video soon, I think.</p>

<p><script async class="speakerdeck-embed" data-id="eb8bb4800ff201308f97123138155402" data-ratio="1.33333333333333" src="http://rmurphey.com//speakerdeck.com/assets/embed.js"></script></p>


<h3>JS Minty Fresh</h3>

<p>A fun talk at <a href="http://fronteers.nl/congres/2012">Fronteers</a> about eliminating code smells from your JavaScript. The best feedback I got afterwards was from an attendee who said they felt at the beginning of the talk like the material was going to be too basic for them, and by the end of the talk, the material was nearly over their head. &#8220;I guess that makes you a good teacher,&#8221; he said. Aw!</p>

<iframe src="http://player.vimeo.com/video/53416986?badge=0" width="500" height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>




<p><a href="http://vimeo.com/53416986">Rebecca Murphey | JS Minty Fresh: Identifying and Eliminating Smells in Your Code Base | Fronteers 2012</a> from <a href="http://vimeo.com/fronteers">Fronteers</a> on <a href="http://vimeo.com">Vimeo</a>.</p>


<p><a href="http://rmurphey.com/js-minty-fresh/presentation/">Slides</a></p>

<p>If you like this, you should also check out the <a href="http://training.bocoup.com/screencasts/">screencasts</a> we released at Bocoup earlier this week.</p>

<h3>Beyond the DOM: Sane Structure for JS Apps</h3>

<p>An update of my code organization talk, delivered at the <a href="http://events.jquery.org/2012/sf/">jQuery Conference in San Francisco</a>. It&#8217;s fun for me to see how my thinking around code organization has evolved and improved since my first, now-almost-embarassing talk at the 2009 jQuery Conference in Boston.</p>

<iframe width="500" height="281" src="http://www.youtube.com/embed/cd7HHN6IkrU" frameborder="0" allowfullscreen></iframe>


<p><a href="https://speakerdeck.com/rmurphey/jquery-conference-sf-2012-beyond-the-dom-sane-structure-for-js-apps">Slides</a></p>

<h3>Johnny Five: Bringing the JavaScript Culture to Hardware</h3>

<p>This one was from the New York Times <a href="http://opensourcesciencefair.com/">Open Source Science Fair</a>, a fun night of about a dozen folks presenting open-source projects at &#8220;booths,&#8221; followed by short talks about open source by Jeremy Ashkenas, me, and Zach Holman. The slides don&#8217;t necessarily stand on their own very well, but the short version is: use JavaScript to make things in the real world, because it&#8217;s ridiculously easy and ridiculously fun.</p>

<p><script async class="speakerdeck-embed" data-id="6ab92f30161e0130f5111231381d612b" data-ratio="1.2994923857868" src="http://rmurphey.com//speakerdeck.com/assets/embed.js"></script></p>


<h3>Getting Better at JavaScript</h3>

<p>I put this together as a quickie for the Berlin <a href="http://up.front.ug/">UpFront</a> user group &#8211; it was the first talk I gave with my broken foot, and the last talk I&#8217;d give for weeks because I lost my voice a couple of hours later. There&#8217;s not a whole lot here, but it was a fun talk and a fun group, and a topic that I get plenty of questions about. Again, no video, but here are the slides:</p>

<p><script async class="speakerdeck-embed" data-id="50746953453e4d0002081c02" data-ratio="1.2994923857868" src="http://rmurphey.com//speakerdeck.com/assets/embed.js"></script></p>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[This is the Cup of Coffee]]></title>
    <link href="http://rmurphey.com/blog/2012/11/14/this-is-the-cup-of-coffee/"/>
    <updated>2012-11-14T10:40:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/11/14/this-is-the-cup-of-coffee</id>
    <content type="html"><![CDATA[<p><img src="http://farm9.staticflickr.com/8482/8187360514_db246b4ac9.jpg" width="400"></p>

<p>This is the cup of coffee I was making earlier this week when Melissa gave me a thumbs-up while she talked on the phone to a woman in Pennsylvania who had just finished telling Melissa that yes, indeed, after 10 weeks or three years of waiting depending on how you count, a 29-year-old woman who&#8217;s due to give birth in Iowa at the beginning of February has decided that Melissa and I should be so lucky as to get to be her baby girl&#8217;s forever family.</p>

<p>Most people get to post ultrasound pictures on Twitter at moments like these, but for now this will suffice to remind me of the moment I found out I would get to be a mom. My head is spinning, and while on the one hand it&#8217;s a little difficult to fathom that this is all just 10 weeks away, on the other hand I&#8217;m counting down the days.</p>

<p>Our adoption will be an open one; the meaning of &#8220;open&#8221; varies widely, but in our case it means we talked to the birth mother before she chose us, we&#8217;ll be meeting her in a few weeks, we&#8217;ll do our very best to be in Iowa for the delivery, and we&#8217;ll stay in touch with letters and pictures afterwards. Melissa and I are grateful that we&#8217;ll be able to adopt as a couple, though we are saddened that we have to adopt outside of our home state of North Carolina in order to do so. It&#8217;s important to us that our child have both of us as her <em>legal</em> parents, and I don&#8217;t hesitate to say that it&#8217;s downright shitty that we have to jump through significant legal and financial hoops &#8211; and stay in a hotel in Iowa with a newborn for an unknown number of days &#8211; to make it so. It is what it is, and good people are working and voting to make it better, and it can&#8217;t happen fast enough.</p>

<p>I&#8217;ve learned a lot about adoption these past few months, and I know a lot of people have a lot of questions, some of which they&#8217;re reluctant to ask. If you&#8217;re interested in learning more, I <em>highly</em> recommend <a href="http://www.amazon.com/In-On-It-Adoption-Relatives/dp/0982876505/ref=sr_1_1?ie=UTF8&amp;qid=1352948795&amp;sr=8-1&amp;keywords=in+on+it">In On It: What Adoptive Parents Would Like You to Know About Adoption</a>. You&#8217;re also welcome to ask me questions if you see me in real life or on the internets &#8211; I can&#8217;t promise I&#8217;ll know the answers, but I promise to do my best.</p>

<p>In the meantime, wish us luck :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Baseline for Front-End Developers]]></title>
    <link href="http://rmurphey.com/blog/2012/04/12/a-baseline-for-front-end-developers/"/>
    <updated>2012-04-12T11:30:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/04/12/a-baseline-for-front-end-developers</id>
    <content type="html"><![CDATA[<p>I wrote a README the other day for a project that I&#8217;m hoping other developers will look at and learn from, and as I was writing it, I realized that it was the sort of thing that might have intimidated the hell out of me a couple of years ago, what with its casual mentions of Node, npm, Homebrew, git, tests, and development and production builds.</p>

<p>Once upon a time, editing files, testing them locally (as best as we could, anyway), and then FTPing them to the server was the essential workflow of a front-end dev. We measured our mettle based on our ability to wrangle IE6 into submission or achieve pixel perfection across browsers. Many members of the community &#8211; myself included &#8211; lacked traditional programming experience. HTML, CSS, and JavaScript &#8211; usually in the form of jQuery &#8211; were self-taught skills.</p>

<p>Something has changed in the last couple of years. Maybe it&#8217;s the result of people starting to take front-end dev seriously, maybe it&#8217;s browser vendors mostly getting their shit together, or maybe it&#8217;s front-end devs &#8211; again, myself included &#8211; coming to see some well-established light about the process of software development.</p>

<p>Whatever it is, I think we&#8217;re seeing the emphasis shift from valuing trivia to valuing tools. There&#8217;s a new set of baseline skills required in order to be successful as a front-end developer, and developers who don&#8217;t meet this baseline are going to start feeling more and more left behind as those who are sharing their knowledge start to assume that certain things go without saying.</p>

<p>Here are a few things that <em>I</em> want to start expecting people to be familiar with, along with some resources you can use if you feel like you need to get up to speed. (Thanks to Paul Irish, Mike Taylor, Angus Croll, and Vlad Filippov for their contributions.)</p>

<h2>JavaScript</h2>

<p>This might go without saying, but simply knowing a JavaScript library isn&#8217;t sufficient any more. I&#8217;m not saying you need to know how to implement all the features of a library in plain JavaScript, but you should know when a library is actually required, and be capable of working with plain old JavaScript when it&#8217;s not.</p>

<p>That means that you&#8217;ve read <a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">JavaScript: The Good Parts</a> &#8211; hopefully more than once. You understand data structures like objects and arrays; functions, including how and why you would <code>call</code> and <code>apply</code> them; working with prototypal inheritance; and managing the asynchronicity of it all.</p>

<p>If your plain JS fu is weak, here are some resources to help you out:</p>

<ul>
<li><a href="http://eloquentjavascript.net">Eloquent Javascript</a>: A wonderful book (also available in print) that takes you back to JavaScript basics</li>
<li><a href="https://github.com/rmurphey/js-assessment">A Test-Driven JS Assessment</a>: A set of failing tests that cover various JavaScript topics; can you write code to make the tests pass?</li>
<li><a href="http://paulirish.com/2010/10-things-i-learned-from-the-jquery-source/">10 things I learned from the jQuery Source</a> is an oldie but goodie from Paul Irish that shows what you can learn by reading other people&#8217;s code.</li>
</ul>


<h2>Git (and a Github account)</h2>

<p>If you&#8217;re not on Github, you&#8217;re essentially unable to participate in the rich open-source community that has arisen around front-end development technologies. Cloning a repo to try it out should be second-nature to you, and you should understand how to <a href="http://nvie.com/posts/a-successful-git-branching-model/">use branches on collaborative projects</a>.</p>

<p>Need to boost your git skills?</p>

<ul>
<li><a href="http://help.github.com/">help.github.com</a></li>
<li><a href="http://help.github.com/git-cheat-sheets/">Github git cheat sheet</a></li>
<li><a href="http://cheat.errtheblog.com/s/git">More cheat sheet</a></li>
<li><a href="http://pinboard.in/u:rmurphey/t:git/">More git links</a></li>
</ul>


<h2>Modularity, dependency management, and production builds</h2>

<p>The days of managing dependencies by throwing one more script or style tag on the page are long gone. Even if you haven&#8217;t been able to incorporate great tools like <a href="http://requirejs.org">RequireJS</a> into your workflow at work, you should find time to investigate them in a personal project or in a project like <a href="https://github.com/tbranyen/backbone-boilerplate">Backbone Boilerplate</a>, because the benefits they convey are huge. RequireJS in particular lets you develop with small, modular JS and CSS files, and then concatenates and minifies them via its optimization tool for production use.</p>

<p>Skeptical of AMD? That&#8217;s no excuse to be doing nothing. At the very least, you should be aware of tools like <a href="https://github.com/mishoo/UglifyJS">UglifyJS</a> or <a href="https://developers.google.com/closure/compiler/">Closure Compiler</a> that will intelligently minify your code, and then concatenate those minified files prior to production.</p>

<p>If you&#8217;re writing plain CSS &#8211; that is, if you&#8217;re not using a preprocessor like Sass or Stylus &#8211; RequireJS can help you keep your CSS files modular, too. Use <code>@import</code> statements in a base file to load dependencies for development, and then run the RequireJS <a href="http://requirejs.org/docs/optimization.html#onecss">optimizer</a> on the base file to create a file built for production.</p>

<h2>In-Browser Developer Tools</h2>

<p>Browser-based development tools have improved tremendously over the last couple of years, and they can dramatically improve your development experience if you know how to use them. (Hint: if you&#8217;re still using <code>alert</code> to debug your code, you&#8217;re wasting a lot of time.)</p>

<p>You should probably find one browser whose developer tools you primarily use &#8211; I&#8217;m partial to <a href="https://developers.google.com/chrome-developer-tools/">Google Chrome&#8217;s Developer Tools</a> these days &#8211; but don&#8217;t dismiss the tools in other browsers out of hand, because they are constantly adding useful features based on developer feedback. Opera&#8217;s <a href="http://my.opera.com/dragonfly/blog/">Dragonfly</a> in particular has some features that make its developer tools stand out, such as an (experimental) CSS profiler, customizable keyboard shortcuts, remote debugging without requiring a USB connection, and the ability to save and use custom color palettes.</p>

<p>If your understanding of browser dev tools is limited, <a href="http://fixingthesejquery.com/#slide1">Fixing these jQuery</a> is a great (and not particularly jQuery-centric) overview of debugging, including how to do <a href="https://developers.google.com/chrome-developer-tools/docs/scripts-breakpoints">step debugging</a> &#8211; a life-altering thing to learn if you don&#8217;t already know it.</p>

<h2>The command line</h2>

<p>Speaking of the command line, being comfortable with it is no longer optional &#8211; you&#8217;re missing out on way too much if you&#8217;re not ready to head over to a terminal window and get your hands dirty. I&#8217;m not saying you have to do <em>everything</em> in the terminal &#8211; I won&#8217;t take your git GUI away from you even though I think you&#8217;ll be better off without it eventually &#8211; but you should absolutely have a terminal window open for whatever project you&#8217;re working on. There are a few command line tasks you should be able to do without thinking:</p>

<ul>
<li><code>ssh</code> to log in to another machine or server</li>
<li><code>scp</code> to copy files to another machine or server</li>
<li><code>ack</code> or <code>grep</code> to find files in a project that contain a string or pattern</li>
<li><code>find</code> to locate files whose names match a given pattern</li>
<li><code>git</code> to do at least basic things like <code>add</code>, <code>commit</code>, <code>status</code>, and <code>pull</code></li>
<li><code>brew</code> to use Homebrew to install packages</li>
<li><code>npm</code> to install Node packages</li>
<li><code>gem</code> to install Ruby packages</li>
</ul>


<p>If there are commands you use frequently, edit your <code>.bashrc</code> or <code>.profile</code> or <code>.zshrc</code> or whatever, and create an <a href="http://tldp.org/LDP/abs/html/aliases.html">alias</a> so you don&#8217;t have to type as much. You can also add aliases to your <code>~/.gitconfig</code> file. Gianni Chiappetta&#8217;s <a href="https://github.com/gf3/dotfiles">dotfiles</a> are an excellent inspiration for what&#8217;s possible.</p>

<p><em>Note: If you&#8217;re on Windows, I don&#8217;t begin to know how to help you, aside from suggesting <a href="http://www.cygwin.com/">Cygwin</a>. Right or wrong, participating in the open-source front-end developer community is materially more difficult on a Windows machine. On the bright side, MacBook Airs are cheap, powerful,  and ridiculously portable, and there&#8217;s always Ubuntu or another *nix.</em></p>

<h2>Client-side templating</h2>

<p>It wasn&#8217;t so long ago that it was entirely typical for servers to respond to XHRs with a snippet of HTML, but sometime in the last 12 to 18 months, the front-end dev community saw the light and started demanding pure data from the server instead. Turning that data into HTML ready to be inserted in the DOM can be a messy and unmaintainable process if it&#8217;s done directly in your code. That&#8217;s where <a href="http://www.slideshare.net/garann/using-templates-to-achieve-awesomer-architecture">client-side templating libraries</a> come in: they let you maintain templates that, when mixed with some data, turn into a string of HTML. Need help picking a templating tool? Garann Means&#8217; <a href="http://garann.github.com/template-chooser/">template chooser</a> can point you in the right direction.</p>

<h2>CSS preprocessors</h2>

<p>Paul Irish <a href="https://twitter.com/#!/paul_irish/status/188329390822801409">noted</a> the other day that we&#8217;re starting to see front-end devs write code that&#8217;s very different from what ends up in production, and code written with CSS preprocessors is a shining example of this. There&#8217;s still a vocal crowd that feels that pure CSS is the only way to go, but they&#8217;re <a href="http://www.stuffandnonsense.co.uk/blog/about/less">starting to come around</a>. These tools give you features that arguably should be in CSS proper by now &#8211; variables, math, logic, mixins &#8211; and they can also help smooth over the CSS property prefix mess.</p>

<h2>Testing</h2>

<p>One of the joys of writing modular, loosely coupled code is that your code becomes vastly easier to test, and with tools like <a href="https://github.com/cowboy/grunt">Grunt</a>, setting up a project to include tests has never been easier. Grunt comes with QUnit integration, but there are a host of testing frameworks that you can choose from &#8211; <a href="https://github.com/pivotal/jasmine/wiki">Jasmine</a> and <a href="http://visionmedia.github.com/mocha/">Mocha</a> are a couple of my current favorites &#8211; depending on your preferred style and the makeup of the rest of your stack.</p>

<p>While testing is a joy when your code is modular and loosely coupled, testing code that&#8217;s not well organized can be somewhere between difficult and impossible. On the other hand, forcing yourself to write tests &#8211; perhaps before you even write the code &#8211; will help you organize your thinking <em>and</em> your code. It will also let you refactor your code with greater confidence down the line.</p>

<ul>
<li>A short <a href="http://vimeo.com/20457625">screencast</a> I recorded about testing your jQuery with Jasmine.</li>
<li>An example of <a href="https://github.com/cowboy/jquery-bbq/blob/master/unit/unit.js">unit tests</a> on the jquery-bbq plugin.</li>
</ul>


<h2>Process automation (rake/make/grunt/etc.)</h2>

<p>Grunt&#8217;s ability to set up a project with built-in support for unit tests is one example of process automation. The reality of front-end development is that there&#8217;s a whole lot of repetitive stuff we have to do, but as a friend once told me, a good developer is a lazy developer: as a rule of thumb, if you find yourself doing the same thing three times, it&#8217;s time to automate it.</p>

<p>Tools like <code>make</code> have been around for a long time to help us with this, but there&#8217;s also <code>rake</code>, <code>grunt</code>, and others. Learning a language other than JavaScript can be extremely helpful if you want to automate tasks that deal with the filesystem, as Node&#8217;s async nature can become a real burden when you&#8217;re just manipulating files. There are lots of task-specific automation tools, too &#8211; tools for deployment, build generation, code quality assurance, and more.</p>

<h2>Code quality</h2>

<p>If you&#8217;ve ever been bitten by a missing semicolon or an extra comma, you know how much time can be lost to subtle flaws in your code. That&#8217;s why you&#8217;re running your code through a tool like <a href="http://www.jshint.com/">JSHint</a>, right? It&#8217;s <a href="http://www.jshint.com/options/">configurable</a> and has lots of ways to integrate it into your <a href="http://www.jshint.com/platforms/">editor or build process</a>.</p>

<h2>The fine manual</h2>

<p>Alas, there is no manual for front-end development, but <a href="https://developer.mozilla.org/en-US/">MDN</a> comes pretty close. Good front-end devs know to prefix any search engine query with <code>mdn</code> &#8211; for example, <code>mdn javascript arrays</code> &#8211; in order to avoid the for-profit plague that is w3schools.</p>

<h2>The End</h2>

<p>As with anything, reading about these things won&#8217;t make you an expert, or even moderately skilled &#8211; the only surefire way to get better at a thing is to <a href="http://rmurphey.com/blog/2011/05/20/getting-better-at-javascript/">do that thing</a>. Good luck.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Greenfielding]]></title>
    <link href="http://rmurphey.com/blog/2012/04/10/greenfielding/"/>
    <updated>2012-04-10T12:19:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/04/10/greenfielding</id>
    <content type="html"><![CDATA[<p>I&#8217;m officially one-third of the way through my self-imposed month of unemployment before I join <a href="http://bocoup.com">Bocoup</a> at the beginning of May, and I&#8217;ve been spending most of what would normally be my working hours on a small demo to support talks at <a href="http://2012.front-trends.com/">conferences</a> I will be <a href="http://backboneconf.com/">speaking at</a> this <a href="http://2012.texasjavascript.com/">summer</a>. It&#8217;s just a <a href="https://github.com/rmurphey/srchr-demo">little app</a> that searches various services, and displays the results &#8211; so simple that, when I showed it to Melissa, she helpfully asked why I wouldn&#8217;t just use Google.</p>

<p>It&#8217;s been about 18 months since I last got to start a project from scratch &#8211; in that case, the codebase that became <a href="http://mulberry.toura.com">Mulberry</a> &#8211; but even then, I didn&#8217;t have control over the full stack of technologies, just the JavaScript side of things. Over the course of my time on that project, I came to be extremely familiar with Dojo, fairly competent with Jasmine, decently comfortable with Ruby and its go-to simple server Sinatra, and somewhat conversational in Sass.</p>

<p>I spent most of my time on that project working with technologies with which I was already pretty comfortable. Interactions with new technologies came in dribs and drabs (except for that one time I decided to test my Ruby skills by rewriting our entire build process), and all of my learning was backed up by a whole lot of institutional knowledge.</p>

<p>The consulting world, of course, is a wee bit different: you interact frequently with new technologies, and you never know what a client might ask you to do. Learning comes in bursts, and the ability to quickly come up to speed with a technology is imperative. On a six-week project, you can&#8217;t spend the first 40 hours getting your bearings.</p>

<p>Even though I spent three years as a consultant, returning to that world of constant learning was feeling a tad intimidating. And so for this project, I decided to make a point of leaving that comfort zone, and intentionally chose technologies &#8211; Node, Bootstrap, Backbone, Mocha, RequireJS &#8211; that I hadn&#8217;t really had a chance to work with in depth (or at all).</p>

<h2>On Learning</h2>

<p>Greenfield projects are few and far between, and it&#8217;s easy to get in a rut by sticking with the tools you already know. Some of my most exciting times at Toura weren&#8217;t when I was writing JavaScript, but rather when I was learning how to talk to the computer in a whole new language. Greenfielding a personal project is a special treat &#8211; it never really has to be &#8220;finished,&#8221; and no one&#8217;s going to be mad at you if it turns out you made a shitty choice, so you&#8217;re free to try things that are less of a sure thing than they would need to be if you were getting paid.</p>

<p>Speaking personally, it can also be a little intimidating to learn a new thing because learning often involves asking for help, and asking for help requires admitting that I don&#8217;t already know how to do the thing that people might expect I already know how to do.</p>

<p>Sometimes the thing that gets in the way of starting a new learning project is actually the fear that I will get stuck. What does it mean if the person who talks at conferences about principles code organization can&#8217;t figure out how best to structure a particular app with Backbone? What does it mean if the person who&#8217;s been encouraging people to build their JavaScript can&#8217;t get RequireJS to generate a proper build? What will I say to <a href="http://blog.izs.me/">Isaac</a>, now that he is standing in front of me and introducing himself, when I have not in fact spent any quality time with Node prior to this past weekend?</p>

<p>Lucky for me, it turns out that all of this is mostly in my head. While I often preface my questions with a small dose of humility and embarrassment, it turns out that well articulated questions are usually greeted with thoughtful and helpful answers. If anything, I&#8217;m trying to be more communicative about the learning that I do, because I think it&#8217;s important that people feel comfortable acknowledging that they used to not know a certain thing, and now they do. I also try to gently remind people that just because they have known something for months or years doesn&#8217;t mean they should look down upon the person enthusiastically blogging about it today.</p>

<p>On that note &#8230; here&#8217;s what&#8217;s new to me these past couple of weeks :)</p>

<h2>Twitter Bootstrap</h2>

<p>I&#8217;ve written a lot of demo apps, and while my coding style has changed over the years, one thing has remained constant: they all look fairly terrible. In theory, we&#8217;re all smart enough to know that what a demo looks like doesn&#8217;t have any bearing on what it explains, but in reality a good-looking demo is simply more compelling, if only because the viewer isn&#8217;t distracted by the bad design.</p>

<p>With this in mind, I decided to give <a href="http://twitter.github.com/bootstrap/">Twitter Bootstrap</a> a try. When I first arrived at the site, I started looking for docs about how to set it up, but it turns out that I vastly overestimated Bootstrap&#8217;s complexity. Drop a style tag into your page (and, optionally, another style tag for the responsive CSS), look at the <a href="http://twitter.github.com/bootstrap/examples.html">examples</a>, and start writing your markup.</p>

<p>What I really loved is that there were patterns for everything I needed, and those patterns were easy to follow and implement. Within an hour or so I had a respectable-looking HTML page with markup that didn&#8217;t seem to suck &#8211; that is, it looked good <em>and</em> it was a decent starting point if I ever wanted to apply a custom design.</p>

<h2>Node</h2>

<p>If you&#8217;ve ever talked to me about Node, you know that I have pretty mixed feelings about it &#8211; some days I feel like the people writing JavaScript in the browser really would have benefited if the people who have gravitated to Node had stuck around to invest their collective smarts in the world where 99% of JavaScript is still written. But that doesn&#8217;t really have anything to do with Node the technology, so much as Node the new shiny thing unburdened by browser differences.</p>

<p>I&#8217;ve actually visited Node a couple of times previously &#8211; if you haven&#8217;t at least installed it, you might be living under a rock &#8211; and I was flattered that <a href="http://dev.garann.com">Garann</a> asked me to review her book <a href="http://shop.oreilly.com/product/0636920023258.do">Node for Front-End Developers</a>, but past experiences had left me frustrated.</p>

<p>This time, something was different. I don&#8217;t rule out that it might be me, or even that learning some of the ins and outs of Ruby might have prepared me to understand Node &#8211; and packages and dependency management and writing for the server instead of the browser &#8211; better this time around. It could also be that the Node ecosystem has reached a point of maturity that it just hadn&#8217;t reached the last time I poked around.</p>

<p>Regardless, I found that everything made a whole lot more sense this time, and my struggles this time were about forgetting to stringify an object before sending it as a response to a request, not about getting the server to start in the first place. I used the <code>q</code> module to give me my beloved promises for managing all the asynchronicity, and generally found it ridiculously pleasant to leave behind all the context switching I&#8217;d grown accustomed to while using JavaScript and Ruby side by side. I&#8217;ll probably still turn to Ruby for automating things on the command line (though I continue to be intrigued by <a href="https://github.com/cowboy/grunt">grunt</a>), but I&#8217;m ready to admit that it&#8217;s time for me to add Node to my toolbox.</p>

<h2>Mocha</h2>

<p>To be honest, I&#8217;d just planned on using <a href="https://github.com/pivotal/jasmine">Jasmine</a> for writing tests for this project, mostly because I&#8217;d never set up Jasmine myself, and I was interested in maybe getting it working with grunt for headless testing. I ended up bailing on that plan when, in the course of some Googling for answers about Jasmine, I came across <a href="http://visionmedia.github.com/mocha/">Mocha</a>.</p>

<p>Mocha is a super-flexible testing framework that runs on Node and in the browser. You can choose your assertion library &#8211; that is, you can choose to write your tests like <code>assert(1, 1).ok()</code> or <code>expect(1).to.be(1)</code> depending on your preference. I decided to use the latter style, with the help of <a href="https://github.com/LearnBoost/expect.js">expect.js</a>. You can also choose your reporting style, including the ability to generate docs from your tests.</p>

<p>I had to do a bit of finagling to get the browser-based tests working with my
RequireJS setup, and ultimately I ended up just using my app&#8217;s server, running
in dev mode, to serve the tests in the browser. I&#8217;m still working out how best
to run just one test at a time in the browser, but all in all, discovering Mocha has probably been the best part of working on this project.</p>

<h2>RequireJS</h2>

<p><a href="http://requirejs.org/">RequireJS</a> is another tool that I&#8217;ve dabbled with in the past, but for the last 18 months I&#8217;ve been spending most of my time with Dojo&#8217;s pre-AMD build system, so I had some catching up to do. I don&#8217;t have a ton to say about RequireJS except:</p>

<ul>
<li>It&#8217;s gotten even easier to use since I last visited it.</li>
<li>The docs are great and also gorgeous.</li>
<li>While I haven&#8217;t had to bother him lately, James Burke, the author and maintainer of RequireJS, is a kind and incredibly helpful soul.</li>
<li>The <a href="http://requirejs.org/docs/api.html#text"><code>text!</code></a> plugin makes working with client-side templates incredibly simple, without cluttering up your HTML with templates in script tags or hard-coding your templates into your JavaScript.</li>
<li>The <a href="https://github.com/tbranyen/use.js"><code>use!</code></a> plugin makes it painless to treat libraries that don&#8217;t include AMD support just like libraries that do. I hear it might become an official plugin soon; I hope it will.</li>
</ul>


<h2>Backbone</h2>

<p>This part was a tough choice, and I actually set out to use a different framework but ended up getting cold feet &#8211; even though this was just a personal project, it did need to reach some semblance of done-ness in some reasonable period of time. After a little bit of poking around at other options, I decided that, barring completely copping out and using Dojo, Backbone was going to be the best tool for this particular job on this particular schedule.</p>

<p>I&#8217;m pretty torn about this, because I decided to use a framework that I <em>know</em> has shortcomings and limited magic, and I <em>know</em> that other options would serve me better in the long term. But I also know that the long term doesn&#8217;t exactly matter for this particular project. The thing that swayed me, really, was that with Backbone, I didn&#8217;t feel like I needed to grasp a whole slew of concepts before I could write my first line of code.</p>

<p>I looked up plenty of things along the way, and rewrote my fair share of code when I discovered that I&#8217;d been Doing It Wrong, but I was able to maintain a constant forward momentum. With the other options I considered, I felt like I was going to have to climb a ladder of unknown height before making any forward progress.</p>

<p>I feel like I made the right choice for this project, but it&#8217;s a choice I&#8217;d spend a lot more time on for a &#8220;real&#8221; project, and I&#8217;d be much more inclined to invest the initial energy in getting up to speed if the payoff was clearer. This, though, is a choice that people seem to be consistently terrible at, and so I feel like I should beat myself up about it just a little. It&#8217;s all too common to dig a ginormous hole for ourselves by choosing the technology that lets us start writing code the soonest; on the flip side, it&#8217;s all too common to choose a technology that&#8217;s complete overkill for the task at hand.</p>

<h2>The End</h2>

<p>The master branch of the <a href="https://github.com/rmurphey/srchr-demo">repo for the project</a> should be mostly stable (if incomplete) if you want to check it out. I&#8217;m going to close comments on this post in the hopes that you&#8217;ll write your own post about what you&#8217;ve been learning instead :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[JavaScript: It's a language, not a religion]]></title>
    <link href="http://rmurphey.com/blog/2012/04/04/javascript-a-language-not-a-religion/"/>
    <updated>2012-04-04T11:18:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/04/04/javascript-a-language-not-a-religion</id>
    <content type="html"><![CDATA[<p>I have six things to say:</p>

<ol>
<li><p>I am in a committed relationship with my partner Melissa. We will celebrate
six years together on Sunday. We contribute frequently to political causes.</p></li>
<li><p>I was deeply saddened yesterday to learn that Brendan Eich contributed money
in support of a <a href="http://en.wikipedia.org/wiki/California_Proposition_8">political initiative</a> that
sought to <em>rescind the court-established right for same-sex couples to
marry</em> in the state of California. It has changed my view of him as a
person, despite the fact that we have had a positive and professional
relationship and he has been a great supporter of my JavaScript career. I
think he is on the wrong side of history, and I hope that courts will
continue to agree with me.</p></li>
<li><p>I had a frank, private, and face-to-face conversation with Brendan about the
issue during JSConf. I shared my disappointment, sadness, and disagreement.</p></li>
<li><p>I have been dismayed to see this incident interpreted as a statement about
the JavaScript community as a whole. This community is made up of so many
people who believe so many different things, and yesterday I was reminded
that they are all just people, and JavaScript is just a language, not a
religion.  I shudder to think of a world where there is a political litmus
test for entry into the community.  Indeed, I am extremely torn about
introducing personal politics into my professional life*, as I fear it will
encourage professional colleagues to opine about personal beliefs that are
frankly none of their business. One of the great joys of working with
computers is that they <a href="http://raganwald.posterous.com/a-womans-story">do not care who I am or what I believe</a>;
I realize that to ask the same of people is unreasonable, but inviting
politics into the workplace is a treacherously slippery slope. Unless my
personal belief system presents an <em>imminent danger</em> to my colleagues, I am
loath to welcome discussion of it by people who otherwise have no
substantial or personal relationship with me.</p></li>
<li><p>I believe individual companies must determine how best to address these
issues, as their attitude toward them can have a significant impact on their
ability to hire and retain talented people. I support <em>constructive
pressure</em> on companies to align themselves with or distance themselves from
political causes, but I would not support a company that prohibited its
employees from participating in the political process. I urge anyone who is
hurt or offended by this incident to engage with Brendan and Mozilla
personally and professionally. Brendan is wrong on this issue, but he is a
thoughtful and intelligent person, and he is also a human being.</p></li>
<li><p>Finally: If this incident has made you angry or sad or disappointed, the most effective
thing you can do is follow in Brendan&#8217;s footsteps by <strong>putting your money
where your mouth is</strong>. Money speaks volumes in the American political
system, and there are campaigns in progress right now that will <a href="http://www.protectncfamilies.org/">impact the rights of gays and lesbians</a>.
Your <a href="https://protectallncfamilies.ngpvanhost.com/crmapi/contribute">contribution</a>
of $50, $100, or $1,000 &#8211; or, in lieu of money, your time &#8211; will have far
more impact than yet another angry tweet.</p></li>
</ol>


<p>And now I shall turn off the internet for a bit. Comments are disabled.
Shocker, I know.</p>

<p>* <em>It bears mentioning that, in certain cases, people making political
contributions are required to include information about their employer. The
inclusion of this information does not indicate that the employer supports &#8211;
or is even aware of &#8211; the contribution.</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bocoup]]></title>
    <link href="http://rmurphey.com/blog/2012/03/26/bocoup/"/>
    <updated>2012-03-26T10:00:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/03/26/bocoup</id>
    <content type="html"><![CDATA[<p><img src="http://rmurphey.com/images/bocoup.png" alt="bocoup" /></p>

<p>It wasn&#8217;t so long ago that I was giving my first talk about JavaScript at the
2009 jQuery Conference, and it was there that Bocoup&#8217;s Boaz Sender and Rick
Waldron created the (now-defunct) objectlateral.com, a celebration of an
unfortunate typo in the conference program&#8217;s listing of my talk.</p>

<p>A bond was forged, and ever since I&#8217;ve watched as <a href="http://bocoup.com">Bocoup</a>
has grown and prospered. I&#8217;ve watched them do mind-boggling work for the likes
of Mozilla, The Guardian, Google, and others, all while staying true to their
mission of embracing, contributing to, and evangelizing open-web technologies.</p>

<p>Today, I&#8217;m beyond excited &#8211; and also a wee bit humbled &#8211; to announce that
<a href="http://weblog.bocoup.com/welcome-rebecca-murphey">I&#8217;m joining their consulting team</a>.
As part of that role, I look forward to spending even more time working on and
talking about patterns and best practices for developing client-side JavaScript
applications. I also hope to work on new <a href="http://training.bocoup.com/">training offerings</a>
aimed at helping people make great client-side applications with web technology.</p>

<p>New beginnings have a terrible tendency to be accompanied by endings, and while
the Bocoup opportunity is one I couldn&#8217;t refuse, it&#8217;s with a heavy heart that I
bid farewell to the team at Toura. I&#8217;m proud of what we&#8217;ve built together, and
that we&#8217;ve shared so much of it with the developer community in the form of
<a href="http://github.com/Toura/mulberry">Mulberry</a>. The beauty of open source means
that I fully expect to continue working on and with Mulberry once I leave
Toura, but I know it won&#8217;t be the same.</p>

<p>I&#8217;ll be spending the next few days tying up loose ends at Toura, and then I&#8217;m
taking a break in April to hit JSConf, spend some time in Berlin, and head to
Warsaw to speak at <a href="http://2012.front-trends.com/">FrontTrends</a>. I&#8217;ll make my
way back home in time to start with Bocoup on May 1.</p>

<p>And so. To my teammates at Toura: I wish you nothing but the best, and look
forward to hearing news of your continued success. To Bocoup: Thanks for
welcoming me to the family. It&#8217;s been a long time coming, and I&#8217;m glad the day
is finally here.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Girls and Computers]]></title>
    <link href="http://rmurphey.com/blog/2012/03/25/girls-and-computers/"/>
    <updated>2012-03-25T12:00:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/03/25/girls-and-computers</id>
    <content type="html"><![CDATA[<p>After a week that seemed just chock full of
<a href="http://storify.com/ireneros/sexist-language-earns-sqoot-lots-of-fury">people</a>
being <a href="http://storify.com/charlesarthur/oh-hai-sexism">stupid</a> about women in
technology, I just found myself thinking back on how it was that I ended up
doing this whole computer thing in the first place.  I recorded a video a while
back for the <a href="http://highvisibilityproject.org/2011/10/rebecca-murphey/">High Visibility Project</a>, but that
really just told the story of how I ended up doing web development. The story
of how I got into computers begain when I was unequivocally a girl. It was
1982.</p>

<p>Back then, my dad made eyeglasses. My mom stayed at home with me and my
year-old sister &#8211; which she&#8217;d continue to do til I was a teenager, when my
brother finally entered kindergarten eight years later. Their mortgage was $79
&#8211; about $190 in today&#8217;s dollars &#8211; which is a good thing because my dad made
about $13,000 a year. We lived in Weedsport, New York, a small town just
outside of Syracuse. We walked to the post office to get our mail. The farmers
who lived just outside town were the rich people. In the winters the fire
department filled a small depression behind the elementary school with water
for a tiny skating rink. There were dish-to-pass suppers in the gym at church.</p>

<p>In 1982, Timex came out with the <a href="http://en.wikipedia.org/wiki/Timex_Sinclair">Timex Sinclair TS-1000</a>,
selling 500,000 of them in just six months. The computer, a few times thicker
than the original iPad but with about the same footprint, cost $99.95 &#8211; more
than that mortgage payment. When everyone else in town was getting cable,
my parents decided that three channels were good enough for them &#8211; it&#8217;s
possible they still had a black-and-white TV &#8211; and bought a computer instead.</p>

<p><img src="http://rmurphey.com/images/ts1000.JPG" alt="Timex Sinclair TS-1000" /></p>

<p>I remember tiny snippets of that time &#8211; playing kickball in my best friend
Beth&#8217;s yard, getting in trouble for tricking my mother into giving us milk that
we used to make mud pies, throwing sand in the face of my friend Nathan
because I didn&#8217;t yet appreciate that it really sucks to get sand thrown in your
face &#8211; but I vividly remember sitting in the living room of our house on
Horton Street with my father, playing with the computer.</p>

<p>A cassette player was our disk drive, and we had to set the volume just right
in order to read anything off a tape &#8211; there was actually some semblance of a
flight simulator program that we&#8217;d play, after listening to the tape player
screech for minutes on end. Eventually we upgraded the computer with a
fist-sized brick of RAM that we plugged into the back of the computer, bumping
our total capacity from 2K to 34K. I wrote programs in BASIC, though for the
life of me I can&#8217;t remember what any of them did. The programs that were the
most fun, though, were the ones whose assembly I painstakingly transcribed,
with my five-year-old fingers, from the back of magazines &#8211; pages and pages of
letters and numbers I didn&#8217;t understand on any level, and yet they made magic
happen if I got every single one right.</p>

<p>A string of computers followed. My parents bought a <a href="http://en.wikipedia.org/wiki/Coleco_Adam">Coleco Adam</a> when we moved
to Horseheads, New York &#8211; apparently the computer came with a certificate
redeemable for $500 upon my graduation from high school, but Coleco folded long
before they could cash it in. I made my first real money by typing a crazy
lady&#8217;s crazy manuscript about crazy food into an Apple IIe that we had plugged
into our TV, and my uncle and I spent almost the entirety of his visit from
Oklahoma writing a game of Yahtzee! on that computer, again in BASIC.</p>

<p><img src="http://rmurphey.com/images/rebecca-computer.jpg" alt="Me at a computer fair at the mall with my sister, my mother, and my friend
Michael" /></p>

<p><em>Above: Me at a computer fair at the mall with my sister, my
mother, and my friend Michael. &#8220;You were giving us all a tutorial, I can tell,&#8221;
says my mom. Note the 5-1/4&#8221; external floppy drive.</em></p>

<p>In middle school, I started a school newspaper, and I think we used some
prehistoric version of PageMaker to lay it out. When high school rolled around,
I toiled through hand-crafting the perfect letters and lines and arrows in
Technical Drawing so I could take CAD and CAM classes and make the computer
draw letters and lines and arrows for me, and quickly proceeded to school just
about every boy in the class. In my senior year of high school, I oversaw the
school yearbook&#8217;s transition from laying out pages on paper to laying out pages
with computers, this time the vaguely portable (it had a handle on the back!)
<a href="http://en.wikipedia.org/wiki/Macintosh_Classic">Mac Classic</a>.
We used PageMaker again; the screen was black and white and 9&#8221;, diagonally.</p>

<p><img src="http://rmurphey.com/images/mac-classic.jpg" alt="Macintosh Classic" /></p>

<p>It was around then that a friend gave me a modem and &#8211; to his eventual
chagrin, when he got the bill &#8211; access to his Delphi account, giving me my
first taste of the whole Internet thing in the form of telnet, gopher, and IRC.
When I went to college the following year, I took with me a computer with
perhaps a 10MB hard drive, and no mouse.</p>

<p>Once again I found myself poring over magazines to discover URIs and,
eventually, URLs that I could type to discover a whole new world of
information. In 1995, I spent the summer making my college newspaper&#8217;s web
site, previewing it in Lynx &#8211; it felt like there wasn&#8217;t much to learn when
there was so little difference between the markup and what I saw on the screen.
I would go to the computer lab to use NCSA&#8217;s Mosaic on the powerful RISC 6000
workstations, because they had a mouse. Yahoo! was about one year old. My
friend Dave, who lived down the street, installed Windows 95 that summer and
invited me over to show me. It was amazing. We were living in the future.</p>

<p>My early years with computers seem pretty tame &#8211; I wasn&#8217;t tearing them apart
or building my own or doing anything particularly interesting with them, but I
was using them, I was telling them what to do and they were mostly listening,
and <em>it never made me feel like I was weird</em>. To the contrary, it made me
feel powerful and empowered. I felt like a part of this ever-growing community
of people who understood, eventually, that computers were going to change the
world. It was the people who didn&#8217;t understand this who were weird and beneath
us. It was the people who understood computers better than me of whom I stood in
awe.</p>

<p>I can barely remember a time when computers weren&#8217;t a part of my life, and yet
when they first entered my life, their presence was incredibly exceptional.
These days, of course, computers are ubiquitous, but interaction with them at
the copy-assembly-from-the-back-of-a-magazine level is almost nonexistent.
Parents who can approach a computer with the same awe and wonder and
determination as a child &#8211; as I must imagine that my dad did in 1982 &#8211; are
likely equally rare.</p>

<p>In some ways, it is like the very ubiquity of technology has led us back to a
world where socially normative gender roles take hold all over again, and the
effort we&#8217;re going to need to put into overcoming that feels overwhelming
sometimes. Words can&#8217;t express my gratitude for the parents I have, for
that $99.95 investment they made in me, and for fact that I was lucky enough to
be 5 and full of wonder in 1982.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Thoughts on a (very) small project with Backbone and Backbone Boilerplate]]></title>
    <link href="http://rmurphey.com/blog/2012/03/11/thoughts-on-a-very-small-project-with-backbone-and-backbone-boilerplate/"/>
    <updated>2012-03-11T21:30:00-04:00</updated>
    <id>http://rmurphey.com/blog/2012/03/11/thoughts-on-a-very-small-project-with-backbone-and-backbone-boilerplate</id>
    <content type="html"><![CDATA[<p>I worked with <a href="http://documentcloud.github.com/backbone/">Backbone</a> and the
<a href="https://github.com/tbranyen/backbone-boilerplate">Backbone Boilerplate</a> for
the first time last weekend, putting together a small <a href="https://github.com/rmurphey/bvjs">demo app</a> for a presentation I gave last week at
BazaarVoice. I realize I&#8217;m about 18 months late to the Backbone party, here,
but I wanted to write down my thoughts, mostly because I&#8217;m pretty sure they&#8217;ll
change as I get a chance to work with both tools more.</p>

<h2>Backbone</h2>

<p>Backbone describes itself as a tool that &#8220;gives structure to web applications,&#8221;
but, at the risk of sounding pedantic, I think it would be more accurate to say
that it gives you tools that can help you structure your applications. There&#8217;s
incredibly little prescription about how to use the tools that Backbone
provides, and I have a feeling that the code I wrote to build my simple app
looks a lot different than what someone else might come up with.</p>

<p>This lack of prescription feels good and bad &#8211; good, because I was able to use
Backbone to pretty quickly set up an infrastructure that mirrored ones I&#8217;ve
built in the past; bad, because it leaves open the possibility of lots of
people inventing lots of wheels. To its credit, it packs a lot of power in a
very small package &#8211; 5.3k in production &#8211; but a real app is going to require
layering a lot more functionality on top of it. Ultimately, the best way to
think of Backbone is as the client-side app boilerplate you&#8217;d otherwise have to
write yourself.</p>

<p>My biggest complaint about Backbone is probably how unopinionated it is about
the view layer. Its focus seems to be entirely on the data layer, but the view
is still where we spend the vast majority of our time. Specifically, I think
Backbone could take a page from Dojo, and embrace the concept of &#8220;templated
widgets&#8221;, because that&#8217;s what people seem to be doing with Backbone views
anyway: mixing data with a template to create a DOM fragment, placing that
fragment on the page, listening for user interaction with the fragment, and
updating it as required. Backbone provides for some of this, specifically the
event stuff, but it leaves you to write your own functionality when it comes to
templating, placing, and updating. I think this is a solveable problem without
a whole lot of code, and want to spend some time trying to prove it, but I know
I need to look into the Backbone Layout Manager before I get too carried away.</p>

<h2>Backbone Boilerplate</h2>

<p>This project from Tim Branyen was a life-saver &#8211; it gave me an absolutely
enormous head start when it came to incorporating
<a href="http://requirejs.org/">RequireJS</a>, setting up my application directories, and
setting up a development server. It also included some great inline docs that
helped me get my bearings with Backbone.</p>

<p>There are a couple of ways I think the boilerplate could be improved, and I&#8217;d be
curious for others&#8217; opinions:</p>

<ul>
<li>The sample app includes the concept of &#8220;modules,&#8221; which seem to be a single
file that include the models, collections, views, and routes for a &#8230;
module. I don&#8217;t love the idea of combining all of this into a single file,
because it seems to discourage smart reuse and unit testing of each piece of
functionality. In the app I created, I abandoned the concept of modules, and
instead broke my app into &#8220;components&#8221;, &#8220;controllers&#8221;, and &#8220;services&#8221;. I
explain this breakdown in a bit more depth in the <a href="http://www.slideshare.net/rmurphey/bvjs">presentation I gave at BazaarVoice</a>. I&#8217;m not sure this is
the right answer for all apps, but I think modules oversimplify things.</li>
<li>The boilerplate includes a <code>namespace.js</code> file. It defines a namespace
object, and that object includes a <code>fetchTemplate</code> method. It seems this
method should only be used by views, and so I&#8217;d rather see something along
the lines of an enhanced View that provides this functionality. That&#8217;s what I
did with the <a href="https://github.com/rmurphey/bvjs/blob/master/app/components/base.js">base component module</a>
in my sample app.</li>
<li>I&#8217;m super-glad to see Jasmine included in the test directory, but
unfortunately the examples show how to write Jasmine tests, not Jasmine tests
for a Backbone app. As a community, we definitely need to be showing more
examples of how to test things, and this seems like a good opportunity to
distribute that knowledge.</li>
</ul>


<h2>Overall</h2>

<p>I feel a little silly that I&#8217;m just now getting around to spending any time
with Backbone, and I know that I only scratched the surface, but I like what I
saw. I think it&#8217;s important to take it for what it is: an uber-tiny library
that gets you pointed in the right direction. What I really want to see are
fuller-fledged frameworks that build on top of Backbone, because I think
there&#8217;s a lot more that can be standardized beyond what Backbone offers. I&#8217;m
hoping to have a bit more time in April to dig in, and hopefully I can flesh
out some of these ideas into something useful.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Community Conferences]]></title>
    <link href="http://rmurphey.com/blog/2012/03/08/community-conferences/"/>
    <updated>2012-03-08T08:29:00-05:00</updated>
    <id>http://rmurphey.com/blog/2012/03/08/community-conferences</id>
    <content type="html"><![CDATA[<p>In 2010, I helped put on the first TXJS. We sold our first tickets for $29, and
I think the most expensive tickets went for something like $129. We had about
200 people buy tickets, we had speakers like Douglas Crockford, Paul Irish, and
John Resig, and we had sponsors like Facebook and Google. Our total budget was
something like $30,000, and every out-of-town speaker had their travel and
accommodations paid for.</p>

<p>In May, O&#8217;Reilly Media is holding another JavaScript conference in San
Francisco, called FluentConf. I recently came to know that they are charging
$100,000 for top-tier sponsorships, and that they are offering a 10-minute
keynote as part of the package.</p>

<p>This turned my stomach, and not just because I believe it cheapens the
experience of attendees, who will pay hundreds of dollars themselves. What
really upset me was that a few weeks ago, I was approached to be on the speaker
selection committee of FluentConf, and that conversation led me to discover
that FluentConf would not be paying for speaker travel and accommodations. And
so the other day, I tweeted:</p>

<blockquote><p>conference #protip: save your money &#8211; and your speaking skills &#8211; for events that don&#8217;t sell their keynotes for $100k</p></blockquote>

<p>Last night, I was at the Ginger Man in Austin, and I checked the Twitters,
discovering that Peter Cooper, one of the chairs of FluentConf, had replied to
a conversation that arose from that tweet:</p>

<blockquote><p>@rmurphey @tomdale If you&#8217;re referring to Fluent, that is news to me.</p></blockquote>

<p>I will accept the weird fact that the co-chair of a conference didn&#8217;t know its
speaking slots were for sale &#8211; I gather that it is essentially a volunteer
role, and the co-chairs aren&#8217;t necessarily in the driver&#8217;s seat when it comes
to decisions like this. I let Peter know that, indeed, I had a PDF that
outlined all the sponsorship options.</p>

<p>This is the part where, in some alternate reality, a mutual understanding of
the offensiveness of this fact would have been achieved. What happened instead
was a whole lot of name-calling, misquoting, and general weirdness.</p>

<p>Here&#8217;s the deal. Conferences can run their event however they want, and they
can make money hand over fist. They can even claim they are the giving
JavaScript developers &#8220;an event of their own,&#8221; ignoring the existence of
the actual community-run JavaScript events that have been around for years now.  I
probably won&#8217;t go to or speak at an event that makes money hand over fist, but
I don&#8217;t have any problem with the existence of such events, or with people&#8217;s
involvement with them.  However, when a conference is making money hand over
fist &#8211; my back of the napkin calculations would suggest that FluentConf stands
to have revenues of well over a million dollars &#8211; then that conference has no
excuse not to pay the relatively paltry costs associated with speaker travel
and accommodations.</p>

<p>A conference does not exist without its speakers. Those who speak at an event
&#8211; the good ones, anyway &#8211; spend countless hours preparing and rehearsing, and
they are away from home and work for days. While I do not discount the benefits
that accrue to good speakers, the costs of being a speaker are non-trivial &#8211;
and that&#8217;s <em>before</em> you get into the dollar costs of travel and accommodations.</p>

<p>When an event is unwilling to cover even those hard costs &#8211; nevermind the
preparation time and time away from work and home &#8211; it materially affects the
selection of speakers.  It&#8217;s even worse when those same conferences claim to
desire <a href="http://fluentconf.com/fluent2012/public/content/about#diversity">diversity</a>;
the people they claim to want so badly are the very people most likely to be
discouraged when they find out they have to pay their own way to the stage.</p>

<p>In the conversation last night, I made this point:</p>

<blockquote><p>when only the people who can afford to speak can speak, then only the people who can afford to speak will
speak.</p></blockquote>

<p>Amy Hoy responded with a criticism of community-run conferences:</p>

<blockquote><p>and when only ppl who can order a ticket in 3 seconds can afford to come, only ppl who can order a ticket in 3 seconds can come</p></blockquote>

<p>I know that getting tickets to the actual community-run events is hard, but
that is because the community-run events flat-out ignore the economics of
supply and demand, choosing instead to sell tickets at affordable prices even
if it means they will sell out in a heartbeat, leaving a boatload of potential
profit on the table. And yet those events &#8211; JSConf, TXJS, and the like &#8211; have
still figured out how to cover speaker costs and provide attendees and sponsors
with unforgettable experiences.</p>

<p>When an event with revenues exceeding a million dollars is unwilling to cover
those costs, while simultaneously selling speaking slots, I do not hesitate for
a moment to call that event out, and I do not hesitate to call
on <a href="http://fluentconf.com/fluent2012/public/content/about#commitee">respected members of the community</a> to sever
their ties with the event. I&#8217;m not embarrassed about it, and you can call me all
the names you want.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mulberry: A development framework for mobile apps]]></title>
    <link href="http://rmurphey.com/blog/2011/09/18/introducing-mulberry/"/>
    <updated>2011-09-18T11:30:00-04:00</updated>
    <id>http://rmurphey.com/blog/2011/09/18/introducing-mulberry</id>
    <content type="html"><![CDATA[<p>I&#8217;ll be getting on stage in a bit at <a href="http://capitoljs.com">CapitolJS</a>, another
great event from Chris Williams, the creator of JSConf and all-around
conference organizer extraordinaire. My schtick at conferences in the past has
been to talk about the pain and pitfalls of large app development with
JavaScript, but this time is a little different: I&#8217;ll be announcing that <a href="http://toura.com">Toura Mobile</a> has created a framework built on top of PhoneGap that
aims eliminate some of those pains and pitfalls for mobile developers. We&#8217;re
calling it <a href="http://mulberry.toura.com">Mulberry</a>, and you&#8217;ll be seeing it on GitHub in the next few weeks.</p>

<p><strong>tl;dr</strong>: <a href="http://mulberry.toura.com">go here</a> and <a href="http://mulberry.toura.com/#tour">watch this video</a>.</p>

<p>While the lawyers are dotting the i&#8217;s and crossing the t&#8217;s as far as getting the code in your hands &#8211; we&#8217;re aiming for a permissive license similar to the licenses for PhoneGap and Dojo &#8211; I wanted to tell you a little bit about it.</p>

<p>Mulberry is two things. First, it&#8217;s command line tools (written in Ruby) that help you rapidly scaffold and configure an app, create content using simple Markdown and YAML, and test it in your browser, in a simulator, and on device. Second, and much more exciting to me as a JavaScript developer, it&#8217;s a framework built on top of the Dojo Toolkit for structuring an application and adding custom functionality in a sane way.</p>

<p>Mulberry lets you focus on the things that are unique to your application. It provides an underlying framework that includes a &#8220;router&#8221; for managing application state; built-in components and templates for displaying standard content types like text, audios, videos, feeds, and images; a simple API for defining custom functionality and integrating it with the system; and an HTML/CSS framework that uses SASS and HAML templates to make it easy to style your apps.</p>

<p>The basics of setting up an app are pretty well covered at the <a href="http://mulberry.toura.com">Mulberry
site</a>, but if you&#8217;re reading this, you&#8217;re probably a JavaScript developer, so I want to focus here on what Mulberry can do for you. First, though, let me back up and cover some terminology: Mulberry apps consist of a set of &#8220;nodes&#8221;; each node is assigned a template, and each template consists of components arranged in a layout. Nodes can have assets associated with them &#8211; text, audio, images, video, feeds, and data.</p>

<p>It&#8217;s the data asset that provides the most power to developers &#8211; you can create an arbitrary object, associate it with a node, and then any components that are in the template that&#8217;s being used to display the node will get access to that data.</p>

<p>A Twitter component offers a simple example. A node might have a data asset like this associated with it:</p>

<figure class='code'> <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='javascript'><span class='line'><span class="p">{</span> <span class="nx">term</span> <span class="o">:</span> <span class="s1">&#39;capitoljs&#39;</span><span class="p">,</span> <span class="nx">type</span> <span class="o">:</span> <span class="s1">&#39;twitter&#39;</span> <span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>We could define a custom template for this page (<code>mulberry create_template Twitter</code>), and tell that template to include a Twitter component:</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='yaml'><span class='line'><span class="l-Scalar-Plain">Twitter</span><span class="p-Indicator">:</span>
</span><span class='line'>  <span class="l-Scalar-Plain">screens</span><span class="p-Indicator">:</span>
</span><span class='line'>    <span class="p-Indicator">-</span> <span class="l-Scalar-Plain">name</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">index</span>
</span><span class='line'>      <span class="l-Scalar-Plain">regions</span><span class="p-Indicator">:</span>
</span><span class='line'>        <span class="p-Indicator">-</span>
</span><span class='line'>          <span class="l-Scalar-Plain">size</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">fixed</span>
</span><span class='line'>          <span class="l-Scalar-Plain">scrollable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">false</span>
</span><span class='line'>          <span class="l-Scalar-Plain">components</span><span class="p-Indicator">:</span>
</span><span class='line'>            <span class="p-Indicator">-</span> <span class="l-Scalar-Plain">PageNav</span>
</span><span class='line'>        <span class="p-Indicator">-</span>
</span><span class='line'>          <span class="l-Scalar-Plain">size</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">flex</span>
</span><span class='line'>          <span class="l-Scalar-Plain">scrollable</span><span class="p-Indicator">:</span> <span class="l-Scalar-Plain">true</span>
</span><span class='line'>          <span class="l-Scalar-Plain">components</span><span class="p-Indicator">:</span>
</span><span class='line'>            <span class="p-Indicator">-</span> <span class="l-Scalar-Plain">PageHeaderImage</span>
</span><span class='line'>            <span class="p-Indicator">-</span> <span class="l-Scalar-Plain">custom:Twitter</span>
</span></code></pre></td></tr></table></div></figure>


<p>Next, we&#8217;d define our Twitter component (<code>mulberry create_component Twitter</code>), which would create the skeleton of a component file:</p>

<figure class='code'> <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">dojo</span><span class="p">.</span><span class="nx">provide</span><span class="p">(</span><span class="s1">&#39;client.components.Twitter&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="nx">toura</span><span class="p">.</span><span class="nx">component</span><span class="p">(</span><span class="s1">&#39;Twitter&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">componentTemplate</span> <span class="o">:</span> <span class="nx">dojo</span><span class="p">.</span><span class="nx">cache</span><span class="p">(</span><span class="s1">&#39;client.components&#39;</span><span class="p">,</span> <span class="s1">&#39;Twitter/Twitter.haml&#39;</span><span class="p">),</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">prep</span> <span class="o">:</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">},</span>
</span><span class='line'>
</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><span class='line'>  <span class="p">}</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>One of the things the skeleton contains is a reference to the template for the component. The <code>create_component</code> command creates this file, which defines the DOM structure for the component. For the sake of this component, that template will just need to contain one line:</p>

<figure class='code'> <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='haml'><span class='line'><span class="nt">%ul</span><span class="nc">.component.twitter</span>
</span></code></pre></td></tr></table></div></figure>


<p>As I mentioned earlier, Mulberry components automatically get access to all of the assets that are attached to the node they&#8217;re displaying. This information is available as an object at <code>this.node</code>. Mulberry components also have two default methods that you can implement: the <code>prep</code> method and the <code>init</code> method.</p>

<p>The <code>prep</code> method is an opportunity to prepare your data before it&#8217;s rendered using the template; we won&#8217;t use it for the Twitter component, because the Twitter component will go out and fetch its data <em>after</em> the template is rendered. This is where the <code>init</code> method comes in &#8211; this is where you can tell your component what to do. Here&#8217;s what our Twitter component ends up looking like:</p>

<figure class='code'> <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>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">dojo</span><span class="p">.</span><span class="nx">provide</span><span class="p">(</span><span class="s1">&#39;client.components.Twitter&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="nx">mulberry</span><span class="p">.</span><span class="nx">component</span><span class="p">(</span><span class="s1">&#39;Twitter&#39;</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">componentTemplate</span> <span class="o">:</span> <span class="nx">dojo</span><span class="p">.</span><span class="nx">cache</span><span class="p">(</span><span class="s1">&#39;client.components&#39;</span><span class="p">,</span> <span class="s1">&#39;Twitter/Twitter.haml&#39;</span><span class="p">),</span>
</span><span class='line'>  <span class="nx">tweetTemplate</span> <span class="o">:</span> <span class="nx">dojo</span><span class="p">.</span><span class="nx">cache</span><span class="p">(</span><span class="s1">&#39;client.components&#39;</span><span class="p">,</span> <span class="s1">&#39;Twitter/Tweet.haml&#39;</span><span class="p">),</span>
</span><span class='line'>
</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="kd">var</span> <span class="nx">data</span> <span class="o">=</span> <span class="nx">dojo</span><span class="p">.</span><span class="nx">filter</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">node</span><span class="p">.</span><span class="nx">data</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">d</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="k">return</span> <span class="nx">d</span><span class="p">.</span><span class="nx">type</span> <span class="o">===</span> <span class="s1">&#39;twitter&#39;</span>
</span><span class='line'>        <span class="p">})[</span><span class="mi">0</span><span class="p">].</span><span class="nx">json</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>    <span class="nx">$</span><span class="p">.</span><span class="nx">ajax</span><span class="p">(</span><span class="s1">&#39;http://search.twitter.com/search.json?q=&#39;</span> <span class="o">+</span> <span class="nx">data</span><span class="p">.</span><span class="nx">term</span><span class="p">,</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">dataType</span> <span class="o">:</span> <span class="s1">&#39;jsonp&#39;</span><span class="p">,</span>
</span><span class='line'>      <span class="nx">success</span> <span class="o">:</span> <span class="nx">$</span><span class="p">.</span><span class="nx">proxy</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="s1">&#39;_onLoad&#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><span class='line'>  <span class="nx">_onLoad</span> <span class="o">:</span> <span class="kd">function</span><span class="p">(</span><span class="nx">data</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="kd">var</span> <span class="nx">tweets</span> <span class="o">=</span> <span class="nx">data</span><span class="p">.</span><span class="nx">results</span><span class="p">,</span>
</span><span class='line'>        <span class="nx">tpl</span> <span class="o">=</span> <span class="nx">mulberry</span><span class="p">.</span><span class="nx">haml</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">tweetTemplate</span><span class="p">),</span>
</span><span class='line'>        <span class="nx">html</span> <span class="o">=</span> <span class="nx">$</span><span class="p">.</span><span class="nx">map</span><span class="p">(</span><span class="nx">tweets</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">tweet</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>          <span class="nx">tweet</span><span class="p">.</span><span class="nx">link</span> <span class="o">=</span> <span class="s1">&#39;http://twitter.com/capitoljs/status/&#39;</span> <span class="o">+</span> <span class="nx">tweet</span><span class="p">.</span><span class="nx">id_str</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>          <span class="nx">tweet</span><span class="p">.</span><span class="nx">created_at</span> <span class="o">=</span> <span class="nx">dojo</span><span class="p">.</span><span class="nx">date</span><span class="p">.</span><span class="nx">locale</span><span class="p">.</span><span class="nx">format</span><span class="p">(</span>
</span><span class='line'>            <span class="k">new</span> <span class="nb">Date</span><span class="p">(</span><span class="nx">tweet</span><span class="p">.</span><span class="nx">created_at</span><span class="p">),</span> <span class="p">{</span>
</span><span class='line'>              <span class="nx">datePattern</span> <span class="o">:</span> <span class="s1">&#39;EEE&#39;</span><span class="p">,</span>
</span><span class='line'>              <span class="nx">timePattern</span> <span class="o">:</span> <span class="s1">&#39;h:m a&#39;</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="nx">tweet</span><span class="p">.</span><span class="nx">text</span> <span class="o">=</span> <span class="nx">tweet</span><span class="p">.</span><span class="nx">text</span><span class="p">.</span><span class="nx">replace</span><span class="p">(</span>
</span><span class='line'>            <span class="sr">/@(\S+)/g</span><span class="p">,</span>
</span><span class='line'>            <span class="s2">&quot;&lt;a href=&#39;http://twitter.com/#!/$1&#39;&gt;@$1&lt;/a&gt;&quot;</span>
</span><span class='line'>          <span class="p">);</span>
</span><span class='line'>
</span><span class='line'>          <span class="k">return</span> <span class="nx">tpl</span><span class="p">(</span><span class="nx">tweet</span><span class="p">);</span>
</span><span class='line'>        <span class="p">}).</span><span class="nx">join</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">this</span><span class="p">.</span><span class="nx">$domNode</span><span class="p">.</span><span class="nx">html</span><span class="p">(</span><span class="nx">html</span><span class="p">);</span>
</span><span class='line'>    <span class="k">this</span><span class="p">.</span><span class="nx">region</span><span class="p">.</span><span class="nx">refreshScroller</span><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>Note that when we define the <code>data</code> variable in the init method, we look at <code>this.node.data</code>, which is an array of all of the data objects associated with the node. We filter this array to find the first data object that is the right type &#8211; this means we can have lots of different data objects associated with a given node.</p>

<p>Note also that there&#8217;s a property <code>this.$domNode</code> that we&#8217;re calling jQuery methods on, and that we&#8217;re using jQuery&#8217;s <code>$.ajax</code> &#8211; Mulberry apps come with jQuery enabled by default, and if it&#8217;s enabled, helpers like <code>this.$domNode</code> become available to you. This means that very little knowledge of Dojo is required to start adding your own functionality to an app &#8211; if you need it, though, the full power of the Dojo Toolkit is available to you too.</p>

<p>Here&#8217;s what our component ends up looking like, with a little bit of custom CSS applied to our app:</p>

<p><img src="http://www.rebeccamurphey.com/i/4e760b2ff3b5b.jpg" title="A Mulberry app using a custom Twitter component" alt="screenshot" /></p>

<p>This is a pretty basic demo &#8211; Twitter is, indeed, the new <code>hello world</code> &#8211; but I hope it gives you a little bit of an idea about what you might be able to build with Mulberry. We&#8217;ve been using it in production to create content-rich mobile apps for our users for months now (connected to a web-based CMS instead of the filesystem, of course), and we&#8217;ve designed it specifically to be flexible enough to meet arbitrary client requests without the need to re-architect the underlying application.</p>

<p>If you know JavaScript, HTML, and CSS, Mulberry is a powerful tool to rapidly create a content-rich mobile application while taking advantage of an established infrastructure, rather than building it yourself. I&#8217;m excited to see what you&#8217;ll do with it!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Switching to Octopress]]></title>
    <link href="http://rmurphey.com/blog/2011/07/25/switching-to-octopress/"/>
    <updated>2011-07-25T08:14:00-04:00</updated>
    <id>http://rmurphey.com/blog/2011/07/25/switching-to-octopress</id>
    <content type="html"><![CDATA[<p>I&#8217;m taking a stab at starting a new blog at
<a href="http://rmurphey.com">rmurphey.com</a>, powered by
<a href="http://octopress.org/">Octopress</a>, which is a set of tools, themes, and other
goodness around a static site generator (SSG) called
<a href="https://github.com/mojombo/jekyll">jekyll</a>. A couple of people have noticed
the new site and wondered what I&#8217;m doing, so I thought I&#8217;d take a couple of
minutes to explain.</p>

<p>My old blog at <a href="http://blog.rebeccamurphey.com">blog.rebeccamurphey.com</a> is
managed using <a href="http://posterous.com">Posterous</a>. It used to be a self-hosted
WordPress site, but self-hosted WordPress sites are so 2009. One too many
attacks by hackers made it way more trouble than it seemed to be worth.
Posterous made switching from a WordPress install pretty easy, so, I did that.
All told, it took a few hours, and I was pretty happy.</p>

<p>For a few reasons, the old blog isn&#8217;t going anywhere:</p>

<ul>
<li>I ran into some trouble importing the old content into jekyll. I was tired
and I didn&#8217;t investigate the issues too much, so they&#8217;re probably solveable,
but &#8230;</li>
<li>Some of the old content just isn&#8217;t that good, and since time is a finite
resource, I don&#8217;t want to get too wrapped up in moving it over. Plus &#8230;</li>
<li>Frighteningly or otherwise, some of my posts have become reference material
on the internet. If I move them, I&#8217;ve got to deal with redirections, and I
have a feeling that&#8217;s not going to be an easy task with Posterous.</li>
</ul>


<p>In hindsight, I should have switched directly from WordPress to an SSG. Despite
my many complaints about Posterous &#8211; misformatted posts, lack of comment
hyperlinks, a sign-in requirement for commenting, and lots more &#8211; in the end
my decision to switch to a static site generator instead was more about having
easy control over my content <em>on my filesystem</em>.</p>

<p><a href="http://blog.guestlistapp.com/post/2304152860/five-reasons-to-use-a-static-site-generator-instead-of">This article</a>
explains it well, but the bottom line, I think, is that static site generators
are blogging tools for people who don&#8217;t need all the bullshit that&#8217;s been added
to online tools in the interest of making them usable by people who don&#8217;t know
wtf they&#8217;re doing. So, yes, to use an SSG, you have to know wtf you&#8217;re doing,
and for me that&#8217;s a good thing: the tool gets out of my way and lets me focus
on the writing.</p>

<p>As for Octopress, it seems pretty damn nifty &#8211; the default theme looks gorgeous on my
desktop and on my phone, and it seems they&#8217;ve taken care to put common
customization points in a single sass file. All that aside, though, one of my favorite parts
about it is that my content is truly my content. If Octopress pisses me off &#8211;
though I hope it won&#8217;t! &#8211; then I can simply take my markdown files and put
them in some other SSG, upload the whole thing to my GitHub pages, and be done
with it. Win all around.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Using object literals for flow control and settings]]></title>
    <link href="http://rmurphey.com/blog/2011/07/24/object-literals/"/>
    <updated>2011-07-24T00:00:00-04:00</updated>
    <id>http://rmurphey.com/blog/2011/07/24/object-literals</id>
    <content type="html"><![CDATA[<p>I got an email the other day from someone reading through <a href="http://jqfundamentals.com">jQuery Fundamentals</a> &#8211; they&#8217;d come across the section
about patterns for performance and compression, which is based on a
presentation by <a href="http://paulirish.com">Paul Irish</a> gave back at the 2009 jQuery
Conference in Boston.</p>

<p>In that section, there&#8217;s a bit about alternative patterns for flow control &#8211;
that is, deciding what a program should do next. We&#8217;re all familiar with the
standard if statement:</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">isAnimal</span><span class="p">(</span><span class="nx">thing</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">thing</span> <span class="o">===</span> <span class="s1">&#39;dog&#39;</span> <span class="o">||</span> <span class="nx">thing</span> <span class="o">===</span> <span class="s1">&#39;cat&#39;</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;yes!&quot;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;no&quot;</span><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>What stumped the person who emailed me, though, was when the same logic as we
see above was written like this:</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">isAnimal</span><span class="p">(</span><span class="nx">thing</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(({</span> <span class="nx">cat</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span> <span class="nx">dog</span> <span class="o">:</span> <span class="mi">1</span> <span class="p">})[</span> <span class="nx">thing</span> <span class="p">])</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;yes!&quot;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;no&quot;</span><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>What&#8217;s happening here is that we&#8217;re using a throwaway object literal to express
the conditions under which we will say a <code>thing</code> is an animal. We could have
stored the object in a variable first:</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">isAnimal</span><span class="p">(</span><span class="nx">thing</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">animals</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">cat</span> <span class="o">:</span> <span class="mi">1</span><span class="p">,</span>
</span><span class='line'>    <span class="nx">dog</span> <span class="o">:</span> <span class="mi">1</span>
</span><span class='line'>  <span class="p">};</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">animals</span><span class="p">[</span> <span class="nx">thing</span> <span class="p">])</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;yes!&quot;</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span> <span class="k">else</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">console</span><span class="p">.</span><span class="nx">log</span><span class="p">(</span><span class="s2">&quot;no&quot;</span><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>However, that variable&#8217;s only purpose would be to provide this one lookup, so
it can be argued that the version that doesn&#8217;t bother setting the variable is
more economical. Reasonable people can probably disagree about whether this
economy of bytes is a good tradeoff for readability &#8211; something like this is
perfectly readable to a seasoned developer, but potentially puzzling otherwise
&#8211; but it&#8217;s an interesting example of how we can use literals in JavaScript
without bothering to store a value in a variable.</p>

<p>The pattern works with an array, too:</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">animalByIndex</span><span class="p">(</span><span class="nx">index</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">return</span> <span class="p">[</span> <span class="s1">&#39;cat&#39;</span><span class="p">,</span> <span class="s1">&#39;dog&#39;</span> <span class="p">][</span> <span class="nx">index</span> <span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>It&#8217;s also useful for looking up values generally, which is how I find myself
using it most often these days in my work with <a href="http://toura.com">Toura</a>, where
we routinely branch our code depending on the form factor of the device we&#8217;re
targeting:</p>

<figure class='code'> <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">function</span> <span class="nx">getBlingLevel</span><span class="p">(</span><span class="nx">device</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="nx">phone</span> <span class="o">:</span> <span class="mi">100</span><span class="p">,</span>
</span><span class='line'>    <span class="nx">tablet</span> <span class="o">:</span> <span class="mi">200</span>
</span><span class='line'>  <span class="p">})[</span> <span class="nx">device</span><span class="p">.</span><span class="nx">type</span> <span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>As an added benefit, constructs that use this pattern will return the
conveniently falsy <code>undefined</code> if you try to look up a value that doesn&#8217;t have
a corresponding property in the object literal.</p>

<p>A great way to come across techniques like this is to read the source code of
your favorite library (and other libraries too). Unfortunately, once
discovered, these patterns can be difficult to decipher, even if you have
pretty good Google fu. Just in case your neighborhood blogger isn&#8217;t available,
IRC is alive and well in 2011, and it&#8217;s an excellent place to get access to
smart folks eager to take the time to explain.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Lessons From a Rewrite]]></title>
    <link href="http://rmurphey.com/blog/2011/07/06/lessons-from-a-rewrite/"/>
    <updated>2011-07-06T10:50:00-04:00</updated>
    <id>http://rmurphey.com/blog/2011/07/06/lessons-from-a-rewrite</id>
    <content type="html"><![CDATA[<p>MVC and friends have been around for decades, but it’s only in the last couple
of years that broad swaths of developers have started applying those patterns
to JavaScript. As that awareness spreads, developers eager to use their
newfound insight are presented with a target-rich environment, and the
temptation to rewrite can be strong.</p>

<blockquote><p>There’s a subtle reason that programmers always want to throw away the code
and start over. The reason is that they think the old code is a mess. … The reason
that they think the old code is a mess is because of a cardinal, fundamental
law of programming: It’s harder to read code than to write it. - <a href="http://www.joelonsoftware.com/articles/fog0000000069.html"> Joel Spolsky
</a></p></blockquote>

<p>When I started working with <a href="http://toura.com/"> Toura Mobile </a> late last year, they already had
a product: a web-based CMS to create the structure of a mobile application and
populate it with content, and a PhoneGap-based application to consume the
output of the CMS inside a native application. Customers were paying, but the
development team was finding that delivering new features was a struggle, and
bug fixes seemed just as likely to break something else as not. They contacted
me to see whether they should consider a rewrite.</p>

<p>With due deference to Spolsky, I don’t think it was a lack of readability
driving their inclination to rewrite. In fact, the code wasn’t all that
difficult to read or follow. The problem was that the PhoneGap side of things
had been written to solve the problems of a single-purpose, one-off
application, and it was becoming clear that it needed to be a flexible,
extensible delivery system for all of the content combinations clients could
dream up. It wasn’t an app — it was an app that made there be an app.</p>

<blockquote><p>Where a new system concept or new technology is used, one has to build a system
to throw away, for even the best planning is not so omniscient as to get it
right the first time. Hence plan to throw one away; you will, anyhow. - Fred
Brooks, <a href="http://en.wikipedia.org/wiki/The_Mythical_Man-Month"> The Mythical Man Month </a></p></blockquote>

<p>By the time I’d reviewed the code and started writing up my findings, the
decision had already been made: Toura was going to throw one away and start
from scratch. For four grueling and exciting months, I helped them figure out
how to do it better the second time around. In the end, I like to think we’ve
come up with a solid architecture that’s going to adapt well to clients’
ever-changing needs. Here, then, are some of the lessons we learned along the
way.</p>

<h2>Understand what you’re rewriting</h2>

<p>I had spent only a few days with the codebase when we decided that we were
going to rewrite it. In some ways, this was good — I was a fresh set of eyes,
someone who could think about the system in a new way — but in other ways, it
was a major hindrance. We spent a lot of time at the beginning getting me up to
speed on what, exactly, we were making; things that went without saying for
existing team members did not, in fact, go without saying for me.</p>

<p>This constant need for explanation and clarification was frustrating at times,
both for me and for the existing team, but it forced us to state the problem in
plain terms. The value of this was incredible — as a team, we were far less
likely to accept assumptions from the original implementation, even assumptions
that seemed obvious.</p>

<p>One of the key features of Toura applications is the ability to update them
“over the air” — it’s not necessary to put a new version in an app store in
order to update an app’s content or even its structure. In the original app,
this was accomplished via generated SQL diffs of the data. If the app was at
version 3, and the data in the CMS was at version 10, then the app would
request a patch file to upgrade version 3 to version 10. The CMS had to
generate a diff for all possible combinations: version 3 to version 10, version
4 to version 10, etc. The diff consisted of queries to run against an SQLite
database on the device. Opportunities for failures or errors were rampant,
a situation exacerbated by the async nature of the SQLite interface.</p>

<p>In the new app, we replicated the feature with vastly less complexity
— whenever there is an update, we just make the full data available at an
app-specific URL as a JSON file, using the same format that we use to provide
the initial data for the app on the device. The new data is stored on the
device, but it’s also retained in memory while the application is running via
Dojo’s Item File Read Store, which allows us to query it synchronously. The
need for version-by-version diffs has been eliminated.</p>

<p>Restating the problem led to a simpler, more elegant solution that greatly
reduced the opportunities for errors and failure. As an added benefit, using
JSON has allowed us to meet needs that we never anticipated — the flexibility
it provides has become a valuable tool in our toolbox.</p>

<h2>Identify pain points</h2>

<p>If the point of a rewrite is to make development easier, then an important step
is to figure out what, exactly, is making development hard. Again, this was
a time to question assumptions — as it turned out, there were things that had
come to be accepted burdens that were actually relatively easy to address.</p>

<p>One of the biggest examples of this was the time required to develop and test
anything that might behave differently on one operating system versus another.
For example, the Android OS has limited support for the audio and video tags,
so a native workaround is required to play media on Android that is not
required on iOS.</p>

<p>In the original code, this device-specific branching was handled in a way that
undoubtedly made sense at the beginning but grew unwieldy over time. Developers
would create Mustache templates, wrapping the template tags in <code>/* */</code> so the
templates were actually executable, and then compile those templates into plain
JavaScript files for production. Here are a few lines from one of those
templates:</p>

<figure class='code'> <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="cm">/*  */</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">mediaPath</span> <span class="o">=</span> <span class="s2">&quot;www/media/&quot;</span> <span class="o">+</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">pages</span><span class="p">.</span><span class="nx">currentId</span> <span class="o">+</span> <span class="s2">&quot;/&quot;</span><span class="p">;</span>
</span><span class='line'><span class="cm">/*  */</span>
</span><span class='line'><span class="cm">/*  */</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">mediaPath</span> <span class="o">=</span> <span class="p">[</span><span class="nx">Toura</span><span class="p">.</span><span class="nx">getTouraPath</span><span class="p">(),</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">pages</span><span class="p">.</span><span class="nx">currentId</span><span class="p">].</span><span class="nx">join</span><span class="p">(</span><span class="s2">&quot;/&quot;</span><span class="p">);</span>
</span><span class='line'><span class="cm">/*  */</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">imagesList</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">dimensionsList</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">namesList</span> <span class="o">=</span> <span class="p">[],</span> <span class="nx">thumbsList</span> <span class="o">=</span> <span class="p">[];</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">pos</span> <span class="o">=</span> <span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="nx">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'><span class="cm">/*  */</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">pos</span> <span class="o">=</span> <span class="mi">0</span><span class="p">,</span> <span class="nx">count</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'><span class="cm">/*  */</span>
</span></code></pre></td></tr></table></div></figure>


<p>These templates were impossible to check with a code quality tool like JSHint,
because it was standard to declare the same variable multiple times. Multiple
declarations of the same variable meant that the order of those declarations
was important, which made the templates tremendously fragile. The theoretical
payoff was smaller code in production, but the cost of that byte shaving was
high, and the benefit somewhat questionable — after all, we’d be delivering the
code directly from the device, not over HTTP.</p>

<p>In the rewrite, we used a simple configuration object to specify information
about the environment, and then we look at the values in that configuration
object to determine how the app should behave. The configuration object is
created as part of building a production-ready app, but in development we can
alter configuration settings at will. Simple <code>if</code> statements replaced fragile
template tags.</p>

<p>Since Dojo allows specifying code blocks for exclusion based on the settings
you provide to the build process, we could mark code for exclusion if we really
didn’t want it in production.</p>

<p>By using a configuration object instead of template tags for branching, we
eliminated a major pain point in day-to-day development. While nothing matches
the proving ground of the device itself, it’s now trivial to effectively
simulate different device experiences from the comfort of the browser. We do
the majority of our development there, with a high degree of confidence that
things will work mostly as expected once we reach the device. If you’ve ever
waited for an app to build and install to a device, then you know how much
faster it is to just press Command-R in your browser instead.</p>

<h2>Have a communication manifesto</h2>

<p>Deciding that you’re going to embrace an MVC-ish approach to an application is
a big step, but only a first step — there are a million more decisions you’re
going to need to make, big and small. One of the widest-reaching decisions to
make is how you’ll communicate among the various pieces of the application.
There are all sorts of levels of communication, from application-wide state
management — what page am I on? — to communication between UI components — when
a user enters a search term, how do I get and display the results?</p>

<p>From the outset, I had a fairly clear idea of how this should work based on
past experiences, but at first I took for granted that the other developers
would see things the same way I did, and I wasn’t necessarily consistent
myself. For a while we had several different patterns of communication,
depending on who had written the code and when. Every time you went to use
a component, it was pretty much a surprise which pattern it would use.</p>

<p>After one too many episodes of frustration, I realized that part of my job was
going to be to lay down the law about this — it wasn’t that my way was more
right than others, but rather that we needed to choose a way, or else reuse and
maintenance was going to become a nightmare. Here’s what I came up with:</p>

<ul>
<li><code>myComponent.set(key, value)</code> to change state (with the help of setter
methods from Dojo’s <a href="http://dojotoolkit.org/reference-guide/dijit/_Widget.html">dijit._Widget mixin</a>)</li>
<li><code>myComponent.on&amp;lt;Event&amp;gt;(componentEventData)</code> to announce state changes
and user interaction; Dojo lets us
<a href="http://dojotoolkit.org/reference-guide/dojo/connect.html">connect</a> to the
execution of arbitrary methods, so other pieces could listen for these
methods to be executed.</li>
<li><code>dojo.publish(topic, [ data ])</code> to announce occurrences of app-wide interest,
such as when the window is resized</li>
<li><code>myComponent.subscribe(topic)</code> to allow individual components react to
published topics</li>
</ul>


<p>Once we spelled out the patterns, the immediate benefit
wasn’t maintainability or reuse; rather, we found that we didn’t have to make
these decisions on a component-by-component basis anymore, and we could focus
on the questions that were actually unique to a component. With conventions
we could rely on, we were constantly discovering new ways to abstract and DRY
our code, and the consistency across components meant it was easier to work
with code someone else had written.</p>

<h2>Sanify asynchronicity</h2>

<p>One of the biggest challenges of JavaScript development — well, besides working
with the DOM — is managing the asynchronicity of it all. In the old system,
this was dealt with in various ways: sometimes a method would take a success
callback and a failure callback; other times a function would return an object
and check one of its properties on an interval.</p>

<figure class='code'> <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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">images</span> <span class="o">=</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">sqlite</span><span class="p">.</span><span class="nx">getMedias</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="s2">&quot;image&quot;</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'><span class="kd">var</span> <span class="nx">onGetComplete</span> <span class="o">=</span> <span class="nx">setInterval</span><span class="p">(</span><span class="kd">function</span> <span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">images</span><span class="p">.</span><span class="nx">incomplete</span><span class="p">)</span>
</span><span class='line'>    <span class="k">return</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">clearInterval</span><span class="p">(</span><span class="nx">onGetComplete</span><span class="p">);</span>
</span><span class='line'>  <span class="nx">showImagesHelper</span><span class="p">(</span><span class="nx">images</span><span class="p">.</span><span class="nx">objs</span><span class="p">,</span> <span class="nx">choice</span><span class="p">)</span>
</span><span class='line'><span class="p">},</span><span class="mi">10</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>The problem here, of course, is that if <code>images.incomplete</code> never gets set to
false — that is, if the <code>getMedias</code> method fails — then the interval will never
get cleared. Dojo and now jQuery (since version 1.5) offer a facility for
handling this situation in an elegant and powerful way. In the new version of
the app, the above functionality looks something like this:</p>

<figure class='code'> <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='javascript'><span class='line'><span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">Data</span><span class="p">.</span><span class="nx">get</span><span class="p">(</span><span class="nx">id</span><span class="p">,</span> <span class="err">‘</span><span class="nx">image</span><span class="err">’</span><span class="p">).</span><span class="nx">then</span><span class="p">(</span><span class="nx">showImages</span><span class="p">,</span> <span class="nx">showImagesFail</span><span class="p">);</span>
</span></code></pre></td></tr></table></div></figure>


<p>The <code>get</code> method of <code>toura.app.Data</code> returns an <a href="http://www.sitepen.com/blog/2010/05/03/robust-promises-with-dojo-deferred-1-5/">immutable promise</a>
— the promise’s then method makes the resulting value of the asynchronous get
method available to <code>showImages</code>, but does not allow <code>showImages</code> to alter the
value. The promise returned by the get method can also be stored in a variable,
so that additional callbacks can be attached to it.</p>

<p>Using promises vastly simplifies asynchronous code, which can be one of the
biggest sources of complexity in a non-trivial application. By using promises,
we got code that was easier to follow, components that were thoroughly
decoupled, and new flexibility in how we responded to the outcome of an
asynchronous operation.</p>

<h2>Naming things is hard</h2>

<p>Throughout the course of the rewrite we were constantly confronted with one of
those pressing questions developers wrestle with: what should I name this
variable/module/method/thing? Sometimes I would find myself feeling slightly
absurd about the amount of time we’d spend naming a thing, but just recently
I was reminded how much power those names have over our thinking.</p>

<p>Every application generated by the Toura CMS consists of a set of “nodes,”
organized into a hierarchy. With the exception of pages that are standard
across all apps, such as the search page, the base content type for a page
inside APP is always a node — or rather, it was, until the other day. I was
working on a new feature and struggling to figure out how I’d display a piece
of content that was unique to the app but wasn’t really associated with a node
at all. I pored over our existing code, seeing the word node on what felt like
every other line. As an experiment, I changed that word node to baseObj in
a few high-level files, and suddenly a whole world of solutions opened up to me
— the name of a thing had limiting my thinking.</p>

<p>The lesson here, for me, is that the time we spent (and spend) figuring out
what to name a thing is not lost time; perhaps even more importantly, the goal
should be to give a thing the most generic name that still conveys what the
thing’s job — in the context in which you’ll use the thing — actually is.</p>

<h2>Never write large apps</h2>

<p>I touched on this earlier, but if there is one lesson I take from every large
app I’ve worked on, it is this:</p>

<blockquote><p>The secret to building large apps is never build large apps. Break up your
applications into small pieces. Then, assemble those testable, bite-sized
pieces into your big application. - Justin Meyer</p></blockquote>

<p>The more tied components are to each other, the less reusable they will be, and
the more difficult it becomes to make changes to one without accidentally
affecting another. Much like we had a manifesto of sorts for communication
among components, we strived for a clear delineation of responsibilities among
our components. Each one should do one thing and do it well.</p>

<p>For example, simply rendering a page involves several small, single-purpose
components:</p>

<figure class='code'> <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>
<span class='line-number'>31</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">function</span> <span class="nx">nodeRoute</span><span class="p">(</span><span class="nx">route</span><span class="p">,</span> <span class="nx">nodeId</span><span class="p">,</span> <span class="nx">pageState</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="nx">pageState</span> <span class="o">=</span> <span class="nx">pageState</span> <span class="o">||</span> <span class="p">{};</span>
</span><span class='line'>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">nodeModel</span> <span class="o">=</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">Data</span><span class="p">.</span><span class="nx">getModel</span><span class="p">(</span><span class="nx">nodeId</span><span class="p">),</span>
</span><span class='line'>      <span class="nx">page</span> <span class="o">=</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">getCurrentPage</span><span class="p">();</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">nodeModel</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">Router</span><span class="p">.</span><span class="nx">home</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><span class='line'>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="o">!</span><span class="nx">page</span> <span class="o">||</span> <span class="o">!</span><span class="nx">page</span><span class="p">.</span><span class="nx">node</span> <span class="o">||</span> <span class="nx">nodeId</span> <span class="o">!==</span> <span class="nx">page</span><span class="p">.</span><span class="nx">node</span><span class="p">.</span><span class="nx">id</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">page</span> <span class="o">=</span> <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">PageFactory</span><span class="p">.</span><span class="nx">createPage</span><span class="p">(</span><span class="s1">&#39;node&#39;</span><span class="p">,</span> <span class="nx">nodeModel</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="nx">page</span><span class="p">.</span><span class="nx">failure</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">Router</span><span class="p">.</span><span class="nx">back</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><span class='line'>
</span><span class='line'>    <span class="nx">toura</span><span class="p">.</span><span class="nx">app</span><span class="p">.</span><span class="nx">UI</span><span class="p">.</span><span class="nx">showPage</span><span class="p">(</span><span class="nx">pf</span><span class="p">,</span> <span class="nx">nodeModel</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="nx">page</span><span class="p">.</span><span class="nx">init</span><span class="p">(</span><span class="nx">pageState</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1">// record node pageview if it is node-only</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="nx">nodeId</span> <span class="o">&amp;&amp;</span> <span class="o">!</span><span class="nx">pageState</span><span class="p">.</span><span class="nx">assetType</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">dojo</span><span class="p">.</span><span class="nx">publish</span><span class="p">(</span><span class="s1">&#39;/node/view&#39;</span><span class="p">,</span> <span class="p">[</span> <span class="nx">route</span><span class="p">.</span><span class="nx">hash</span> <span class="p">]);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">return</span> <span class="kc">true</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>The router observes a URL change, parses the parameters for the route from the
URL, and passes those parameters to a function. The Data component gets the
relevant data, and then hands it to the PageFactory component to generate the
page. As the page is generated, the individual components for the page are also
created and placed in the page. The PageFactory component returns the generated
page, but at this point the page is not in the DOM. The UI component receives
it, places it in the DOM, and handles the animation from the old page to the
new one.</p>

<p>Every step is its own tiny app, making the whole process tremendously testable.
The output of one step may become the input to another step, but when input and
output are predictable, the questions our tests need to answer are trivial:
“When I asked the Data component for the data for node123, did I get the data
for node123?”</p>

<p>Individual UI components are their own tiny apps as well. On a page that
displays a videos node, we have a video player component, a video list
component, and a video caption component. Selecting a video in the list
announces the selection via the list’s onSelect method. Dojo allows us to
connect to the execution of object methods, so in the page controller, we have
this:</p>

<figure class='code'> <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="k">this</span><span class="p">.</span><span class="nx">connect</span><span class="p">(</span><span class="k">this</span><span class="p">.</span><span class="nx">videoList</span><span class="p">,</span> <span class="s1">&#39;onSelect&#39;</span><span class="p">,</span> <span class="kd">function</span><span class="p">(</span><span class="nx">assetId</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="kd">var</span> <span class="nx">video</span> <span class="o">=</span> <span class="k">this</span><span class="p">.</span><span class="err">\</span><span class="nx">_videoById</span><span class="p">(</span><span class="nx">assetId</span><span class="p">);</span>
</span><span class='line'>  <span class="k">this</span><span class="p">.</span><span class="nx">videoCaption</span><span class="p">.</span><span class="nx">set</span><span class="p">(</span><span class="s1">&#39;content&#39;</span><span class="p">,</span> <span class="nx">video</span><span class="p">.</span><span class="nx">caption</span> <span class="o">||</span> <span class="s1">&#39;&#39;</span><span class="p">);</span>
</span><span class='line'>  <span class="k">this</span><span class="p">.</span><span class="nx">videoPlayer</span><span class="p">.</span><span class="nx">play</span><span class="p">(</span><span class="nx">assetId</span><span class="p">);</span>
</span><span class='line'><span class="p">});</span>
</span></code></pre></td></tr></table></div></figure>


<p>The page controller receives the message and passes it along to the other
components that need to know about it — components don’t communicate directly
with one another. This means the component that lists the videos can list
anything, not just videos — its only job is to announce a selection, not to do
anything as a result.</p>

<h2>Keep rewriting</h2>

<blockquote><p>It takes confidence to throw work away … When people first start drawing,
they’re often reluctant to redo parts that aren’t right … they convince
themselves that the drawing is not that bad, really — in fact, maybe they meant
it to look that way. - <a href="http://www.paulgraham.com/taste.html">Paul Graham, “Taste for Makers”</a></p></blockquote>

<p>The blank slate offered by a rewrite allows us to fix old mistakes, but
inevitably we will make new ones in the process. As good stewards of our code,
we must always be open to the possibility of a better way of doing a thing. “It
works” should never be mistaken for “it’s done.”</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A new chapter]]></title>
    <link href="http://rmurphey.com/blog/2011/05/31/a-new-chapter/"/>
    <updated>2011-05-31T00:00:00-04:00</updated>
    <id>http://rmurphey.com/blog/2011/05/31/a-new-chapter</id>
    <content type="html"><![CDATA[<p>It was three years ago this summer that I <a href="http://blog.rebeccamurphey.com/2-years-in-some-thoughts-on-working-for-mysel">got the call, bought the Yuengling, smoked the cigarettes</a>, and began life as an independent consultant. It&rsquo;s been (almost) three years of ups and downs, and, eventually, among the most rewarding experiences of my life. Day by day, I wrote my own job description, found my own clients, set my own schedule, and set my own agenda.</p>




<p>Starting tomorrow, it&rsquo;s time for a new chapter in my working life: I&rsquo;ll be joining <a href="http://toura.com">Toura Mobile</a> full-time as their lead JavaScript developer, continuing my work with them on creating a PhoneGap- and Dojo-based platform for the rapid creation of content-rich mobile applications.</p>




<p>I&rsquo;ve been working with Toura for about six months now, starting shortly after I met <a href="http://twitter.com/MattRogish">Matt Rogish</a>, their director of development, at a JavaScript event in New York. They brought me on as a consultant to review their existing application, and the eventual decision was to rewrite it from the ground up, using the lessons learned and knowledge gained from the first version to inform the second. It was a risky decision, but it&rsquo;s paid off: earlier this year, Toura started shipping apps built with the rewritten system, and the care we took to create modular, loosely coupled components from the get-go has paid off immensely, meeting current needs while making it easier to develop new features. With the rewrite behind us, these days we&rsquo;re using the solid foundation we built to allow users of the platform to create ever more customized experiences in their applications.</p>




<p>If you know me at all, you know that I&rsquo;ve been pretty die-hard about being an independent consultant, so you might think this was a difficult decision. Oddly, it wasn&rsquo;t &mdash; I&rsquo;ve enjoyed these last several months immensely, the team I work with is fantastic, and I&rsquo;ve never felt more proud of work I&rsquo;ve done. Whenever I found myself wondering whether Toura might eventually tire of paying my consulting rates, I&rsquo;d get downright mopey. Over the course of three years, I&rsquo;ve worked hard for all of my clients, but this is the first time I&rsquo;ve felt so invested in a project&rsquo;s success or failure, like there was a real and direct correlation between my efforts and the outcome. It&rsquo;s a heady feeling, and I hope and expect it to continue for a while.</p>




<p>By the way, I&rsquo;ll be talking about the rewrite at both <a href="http://2011.texasjavascript.com">TXJS</a> and <a href="http://gothamjs.com">GothamJS</a> in the next few weeks.</p>




<p>Also: <a href="http://toura.com/about/jobs/">we&rsquo;re hiring</a> :)</p>

]]></content>
  </entry>
  
</feed>
