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

  <title><![CDATA[Razor Sharp Design]]></title>
  <link href="http://rzrsharp.net/atom.xml" rel="self"/>
  <link href="http://rzrsharp.net/"/>
  <updated>2012-02-17T13:25:34-05:00</updated>
  <id>http://rzrsharp.net/</id>
  <author>
    <name><![CDATA[Justin Reidy]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Goodbye, Brooklyn. Hello, Portland!]]></title>
    <link href="http://rzrsharp.net/2012/02/17/goodbye-brooklyn-hello-portland.html"/>
    <updated>2012-02-17T13:23:00-05:00</updated>
    <id>http://rzrsharp.net/2012/02/17/goodbye-brooklyn-hello-portland</id>
    <content type="html"><![CDATA[<p>Two and a half years ago, Meaghin and I moved from Washington, DC to Brooklyn.
Our move came as a bit of a shock to our family and friends - partly because of
its suddenness, and also because of its proximity to our marriage. The move to
Brooklyn was not motivated by a job opportunity or anything similar; instead,
we had started feeling constrained by DC after five years of living there, and
couldn&#8217;t imagine a more challenging and exciting place to live than New York
(and Brooklyn in particular). A week after getting married, we made the
decision to move, and three weeks after that, we found ourselves surrounded by
boxes in an apartment overlooking the East River and Manhattan.</p>

<p>The first few months of living in New York definitely delivered on the
&#8220;challenging&#8221; part of our expectations; not a day went by that didn&#8217;t evoke
memories of Seinfeld plot-lines. Crazy co-op boards? Difficult supers?
Ridiculous encounters on the subway? More than one New York stereotype proved
its roots in authenticity. But as we grew used to the city and its
neighborhoods, learned how to quickly cut from one area to another, discovered
which subway lines consistently failed, and realized that one should avoid 5th
Ave and Times Square at all costs, the challenges started to dissipate and left
only excitement. New York, in its intensity and genuine melting pot of cultures
and backgrounds, presents an amazing opportunity for people to define
themselves. What matters most to you, and why does it matter? In a city where
practically any hobby or interest can be pursued, you&#8217;ve got to seriously
prioritize your time, and that prioritization goes a long way towards
identifying exactly who you are.</p>

<p>But for all the excitement and growth, I started to notice another development
in myself: pernicious cynicism. While I had once dreamed of tackling big
problems and making the world a better place, years of living in DC and New
York made me view such ideas as hopelessly naive. The seeming intractability of
so many daily problems, the realization that apparently important movements
were actually driven by petty motivations; older, wiser me didn&#8217;t look at
idealists with disdain, but rather with a wistful admiration of their blissful
ignorance.</p>

<p>Then I spent time in Portland, OR.</p>

<p>It&#8217;s hard to describe the feeling of Portland. And I don&#8217;t mean the city
portrayed on Portlandia - although that show is certainly accurate in its
skewering. I have never been to a place where so many people devote themselves
to mastering a craft, not just because of the rewards of the mastery, but
because <em>not</em> mastering that craft is simply not an option. There&#8217;s an
entrepreneurial spirit that pervades Portland, but it&#8217;s one that&#8217;s devoted to
developing new ideas and contributing back to the community. Even this &#8220;return
to community&#8221; is not the traditional &#8220;I&#8217;ve done well so I&#8217;m giving back&#8221; idea,
but rather a networked entrepreneurship, a continuous exploration of &#8220;How can
my idea involve the unique work of that awesome <whatever>?&#8221;</p>

<p>Mikeal Rogers, organizer of NodeConf, <a href="http://www.mikealrogers.com/posts/what-is-the-maximum-number-of-courses.html">described Portland with
admiration</a>:</p>

<pre><code>There are times and places, great cities, that are remembered much more
fondly than they were thought of at the time. Paris in the twenties when it
was home to Hemingway, Picaso and Fitzgerald. Or San Francisco in the 50s
when the beat generation migrated from New York to call it home. So
impressionable were those years that the echo fuels future, lesser,
generations for decades.

When you're in Portland, Oregon you can't help but think it might be such
a place and the time. For what it will be remembered I have no idea, but
everyone seems to be bursting with creativity and no one is content until
they have done more.
</code></pre>

<p>Spending time in Portland pierced the shell of cynicism that I&#8217;d developed, and
rekindled my motivations to build something real and lasting, to improve my
community. Portland provides the inspiration; New York has provided the
confidence and skillset to do something about it.</p>

<p>So once again Meaghin and I find ourselves surrounded by boxes and preparing
for a big move. In a month I&#8217;ll be a resident of Portland. I can&#8217;t wait to find
out what the future will bring.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why JavaScript on the Server Isn't Such a Bad Idea]]></title>
    <link href="http://rzrsharp.net/2012/02/15/why-javascript-on-the-server-isnt-such-a-bad-idea.html"/>
    <updated>2012-02-15T14:39:00-05:00</updated>
    <id>http://rzrsharp.net/2012/02/15/why-javascript-on-the-server-isnt-such-a-bad-idea</id>
    <content type="html"><![CDATA[<p>Preaching the gospel of Node can be a tough job: how do you express your
excitement for the technology without coming across as a fanboy? And how do you
deal with people that view it as a cancer? I had to answer these questions when
crafting a presentation last week introducting Node.js as part of
a developer tech talk. Given the radically divergent opinions that Node has
elicited, I wanted to address the FUD head on.  I tried to focus on the gut
reaction most people tend to have towards Node (&#8220;WHO would want to code their
server in JS?!&#8221;), and I think the talk went fairly well. I&#8217;m embedding the
slides here if anyone would like to take a look. Speakerdeck is a fantastic
resource and I was happy to finally put it to use as a producer, instead of
just a reader.</p>

<script src="http://speakerdeck.com/embed/4f35ad1868bb50001f004b7f.js"></script>


<p>For even more insight into the developing world of &#8220;JavaScript everywhere&#8221;, check out <a href="http://www.youtube.com/watch?v=AG6dyk8lkZg">this video</a> from Joe McCann, principal architect of subPrint Interactive, on &#8220;End to End JavaScript&#8221;.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Welcome to 2012]]></title>
    <link href="http://rzrsharp.net/2012/01/30/welcome-to-2012.html"/>
    <updated>2012-01-30T16:31:00-05:00</updated>
    <id>http://rzrsharp.net/2012/01/30/welcome-to-2012</id>
    <content type="html"><![CDATA[<p>January&#8217;s been a long month; not in a <em>bad</em> sense, just sort of interminable. Looking through my links collection in notational velocity today, I found a good twenty plus from the last six weeks. I&#8217;ve culled them down a bit to the true standouts:</p>

<ul>
<li><p>An Object is not (Always) a Hash &mdash; Great post from Guillermo Rauch about <a href="http://www.devthought.com/2012/01/18/an-object-is-not-a-hash/">the perils of using Javascript Objects as Hashes</a>. Definitely some tricky gotchas here that you may not have thought about.</p></li>
<li><p>Hot Node Reloading &mdash; Also from Guillermo, a solution to the annoying problem of continuously restarting your node app during development: <a href="http://www.devthought.com/2012/01/29/staying-up-with-node-js/">Staying Up with Node.JS</a></p></li>
<li><p>Shedding Light on SPDY &mdash; If you haven&#8217;t been hearing a great deal about SPDY lately, you will be soon. SPDY, if you couldn&#8217;t tell from the name, serves as a next-generation protocol to speed up web communication. Nodejitsu posts <a href="http://blog.nodejitsu.com/what-is-node-spdy">a helpful introduction to SPDY</a>.</p></li>
<li><p>Improving your Git Logs &mdash; Git log, out of the box, is so wordy that it proves fairly worthless. Check out Oli Studholme&#8217;s <a href="http://oli.jp/2012/git-powerup/">aliases for taming the git log beast</a>.</p></li>
<li><p>Hack Learning &mdash; One of the key lessons I&#8217;ve learned as a developer is that getting good at something requires hours, and hours, and hours, and <strong>hours</strong> of work, and many of these hours will be exhausting displays of ignorance which you&#8217;ll want to quickly forget. The good news is that you can pick up nearly any skill with enough effort and time. Jack Kinsella provides a hack for cutting back on how many hours separate &#8220;terrible newb&#8221; from &#8220;fairly competent practitioner&#8221;. His <a href="http://www.jackkinsella.ie/2011/12/05/janki-method.html">Janki Method</a> may <em>sound</em> like a get rich quick scheme, but it&#8217;s really just a simple approach to improving your effiency at learning. Maybe you can cut those 10,000 hours of practice to a more managable&#8230; 6,000.</p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Year in Coffee]]></title>
    <link href="http://rzrsharp.net/2012/01/12/a-year-in-coffee.html"/>
    <updated>2012-01-12T13:48:00-05:00</updated>
    <id>http://rzrsharp.net/2012/01/12/a-year-in-coffee</id>
    <content type="html"><![CDATA[<p>Last year was the first that I dove deeply into the coffee world, turning what
was previously an interest into a full-blown passion. While I had previously
ground beans at home and brewed in a french press, I decided sometime in 2010
that I wanted to learn more. Going into 2011, I started brewing with an
aeropress and chemex, upgraded my grinder to a Baratza Virtuoso, and furthered my coffee knowledge by reading <a href="http://www.amazon.com/God-Cup-Obsessive-Perfect-Coffee/dp/0470173580">God in a Cup</a> and <a href="http://www.amazon.com/Uncommon-Grounds-History-Coffee-Transformed/dp/0465054676">Uncommon Grounds</a>. I began taking notes on my home brews and asking questions at coffee bars. And I bought <em>lots</em> of coffee. Lots and lots and lots of coffee.</p>

<p><img src="http://s3.cheeryobservations.com/coffee2011_redone.jpg" alt="Lots of coffee" /></p>

<p>Meaghin <a href="http://www.cheeryobservations.com/photography/2011-coffee-more-coffee-than-weeks-in-the-year/">has more pictures and a full rundown of our 2011 coffee purchases</a>, but I wanted to highlight a few bags in particular.</p>

<p><img src="http://s3.cheeryobservations.com/coffee2011_15.jpg" alt="Coava and Wrecking Ball" /></p>

<p><a href="http://www.wreckingballcoffee.com/">Wrecking Ball Coffee Roasters</a> is a new enterprise from Trish Rothgeb and Nick
Cho; I was lucky enough to get one of the first bags they shipped this year.
Their coffee presented a perfect example of what makes me love Ethiopian
coffees, offering a pleasantly light body without being too acidic. I like to
compare good east African coffees to pinot noir - almost all have a juiciness
to them, but the best are balanced with strong bass notes. I loved
Wrecking Ball&#8217;s fully biodegradable package. But beyond the coffee itself,
I was happy to order from Wrecking Ball because of Nick Cho. Cho used to run
the amazing Murky Coffee in Arlington, VA, which I visited very frequently when
I lived in the DC area. Ironically, I didn&#8217;t drink much coffee at the time, having
been exposed to some swill in college. But Murky is what enticed me to learn
more: the intoxicating smell of freshly ground Counter Culture coffee, the
precise movements of the baristas as they brewed espressos, the clear passion
of everyone involved. Drinking the Wrecking Ball made me feel as if I were
making up for the coffee I never enjoyed at Murky.</p>

<p>If Murky induced my coffee passion, <a href="http://coavacoffee.com">Coava</a> revealed the heights to which this
passion could be taken. I drank Coava&#8217;s David Mancia from Honduras early in the
year; later, I would visit Coava&#8217;s Portland shop in person. The David Mancia
completely blew my mind. Even in my early days of home-brewing, I couldn&#8217;t
screw this coffee up: chocalate, berries, an amazing finish, thick and juicy
and succulent. I couldn&#8217;t wait to see how Coava&#8217;s shop measured up to the
coffee they roasted, and found one of my favorite coffee shops in the country.
I can&#8217;t wait to go back.</p>

<p><img src="http://s3.cheeryobservations.com/coffee2011_21.jpg" alt="Coffee Collective" /></p>

<p>One of the highlights of 2011 was my trip to Copenhagen with Meaghin. Before the
trip, I greatly anticipated experiencing Danish culture, perhaps
most intrigued by their coffee culture. Almost everywhere we bought coffee in
Copenhagen, we felt pleased with the product, but <a href="http://thecoffeecollective.dk/">Coffee Collective</a> is an
entity unto itself. We visited their new location in Torvehallerne, a glorious
outdoor food market, a few times, trying various coffee drinks on each visit;
the Kieni from Nyeri, Kenya proved particularly delicious.</p>

<p>Two weeks into 2012 and as many bags brewed; I&#8217;m currently finishing up a great
roast from <a href="http://www.cafegrumpy.com">Cafe Grumpy</a>, from Finca La Coqueta in
Columbia. I look forward to finding out what my favorites will be <em>this</em> year.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Better Support for Helpers in vows-bdd]]></title>
    <link href="http://rzrsharp.net/2011/12/05/better-support-for-helpers-in-vows-bdd.html"/>
    <updated>2011-12-05T15:31:00-05:00</updated>
    <id>http://rzrsharp.net/2011/12/05/better-support-for-helpers-in-vows-bdd</id>
    <content type="html"><![CDATA[<p>This last week has been a particularly busy one, so I&#8217;ve been delayed in blogging,
but I released v0.2 of vows-bdd to NPM a week ago. There&#8217;s two changes of note.
The first is proper documentation for the library: you can see the docco documentation
<a href="http://rzrsharp.net/vows-bdd">here</a>. If you&#8217;re new to vows-bdd, or just want to learn
more about how it&#8217;s working, the docs should provide all the answers you&#8217;re looking
for.</p>

<p>The more important change relates to the testing syntax. In some conversations I had
online with <a href="http://graemef.com/">Graeme Foster</a>, I realized that the vows-bdd syntax
left some room for improvement. Specifically, the syntax introduced a potential for
redundancy when creating labels for integration tests. While named functions could
be used for test statements that were repeated, there wasn&#8217;t an easy to way to handle
repeated labels.</p>

<p>In order to make the use of test helpers even easier with vows-bdd, I have adjusted
the <code>given/when/then/and</code> syntax to allow for array arguments <em>in addition to</em> the
previous arguments of <code>label,test_function</code>. It&#8217;s easiest to demonstrate the change with
an example. One area of code that frequently is repeated is login code in integration tests.
Here&#8217;s how I had my tests setup with vows-bdd before:</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>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="c1"># a test snippet</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">given</span> <span class="s2">&quot;I am an admin user&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="vi">@user = </span><span class="nx">Model</span><span class="p">.</span><span class="nx">Factory</span><span class="p">.</span><span class="nx">create</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="p">{</span><span class="nv">role: </span><span class="s1">&#39;admin&#39;</span><span class="p">}</span>
</span><span class='line'>    <span class="nx">@callback</span><span class="p">()</span>
</span><span class='line'>    <span class="k">return</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I go to login&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">zombie</span><span class="p">.</span><span class="nx">visit</span> <span class="nx">Server</span><span class="p">.</span><span class="nx">path_for</span><span class="p">(</span><span class="s2">&quot;/login&quot;</span><span class="p">),</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I click login&quot;</span><span class="p">,</span> <span class="nf">(browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;email&quot;</span><span class="p">,</span> <span class="s2">&quot;#{@user.email}&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;#{@user.password}&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Login&quot;</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">then</span> <span class="s2">&quot;I should be on the admin index&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">shouldBeOn</span> <span class="nx">browser</span><span class="p">,</span> <span class="s2">&quot;/admin&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># snippet from another test</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">given</span> <span class="s2">&quot;I am an admin user&quot;</span><span class="p">,</span> <span class="o">&gt;</span>
</span><span class='line'>    <span class="vi">@password = </span><span class="s2">&quot;foo&quot;</span>
</span><span class='line'>    <span class="vi">@user = </span><span class="nx">Model</span><span class="p">.</span><span class="nx">Factory</span><span class="p">.</span><span class="nx">build</span><span class="p">(</span> <span class="s2">&quot;user&quot;</span><span class="p">,</span> <span class="nv">password: </span><span class="nx">@password</span><span class="p">,</span> <span class="nv">passwordConf: </span><span class="nx">@password</span><span class="p">,</span> <span class="nv">role: </span><span class="s2">&quot;admin&quot;</span> <span class="p">)</span>
</span><span class='line'>    <span class="nx">@user</span><span class="p">.</span><span class="nx">save</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I am logged in&quot;</span><span class="p">,</span> <span class="o">&gt;</span>
</span><span class='line'>    <span class="nv">user = </span><span class="nx">@user</span>
</span><span class='line'>    <span class="nv">cb = </span><span class="nx">@callback</span>
</span><span class='line'>    <span class="nv">pw = </span><span class="nx">@password</span>
</span><span class='line'>    <span class="nx">zombie</span><span class="p">.</span><span class="nx">visit</span> <span class="nx">Server</span><span class="p">.</span><span class="nx">path_for</span><span class="p">(</span><span class="s2">&quot;/login&quot;</span><span class="p">),</span> <span class="p">(</span><span class="nx">e</span><span class="p">,</span><span class="nx">browser</span><span class="p">,</span><span class="nx">status</span><span class="p">)</span> <span class="o">&gt;</span>
</span><span class='line'>      <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span> <span class="s2">&quot;email&quot;</span><span class="p">,</span> <span class="nx">user</span><span class="p">.</span><span class="nx">email</span>
</span><span class='line'>      <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span> <span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="nx">pw</span>
</span><span class='line'>      <span class="nx">browser</span><span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Login&quot;</span><span class="p">,</span> <span class="nx">cb</span>
</span><span class='line'>    <span class="k">return</span>
</span></code></pre></td></tr></table></div></figure>


<p>Even with the previous syntax, this code could be improved by creating a named <code>login</code>
function that handles the duplicated code. And you could add a property to that function
that provides a label. But I felt that the vows-bdd syntax should be improved to make
this code repetition even easier. So the new <code>[label,function]</code> syntax looks 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>
<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='coffeescript'><span class='line'><span class="c1"># first test </span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">scenario</span><span class="p">(</span><span class="s2">&quot;&#39;/admin&#39; is accessible to logged in admin users&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span><span class="p">(</span><span class="nx">I</span><span class="p">.</span><span class="nx">login_as</span> <span class="s2">&quot;an admin&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">then</span> <span class="s2">&quot;I should be on the admin index&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">shouldBeOn</span> <span class="nx">browser</span><span class="p">,</span> <span class="s2">&quot;/admin&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># other test</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">scenario</span><span class="p">(</span><span class="s2">&quot;Logging Out&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">given</span><span class="p">(</span><span class="nx">I</span><span class="p">.</span><span class="nx">login_as</span> <span class="s2">&quot;an admin&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I click logout&quot;</span><span class="p">,</span> <span class="nf">(browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">browser</span><span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Logout&quot;</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">then</span> <span class="s2">&quot;I should be redirected to the login page&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="c1">#continues</span>
</span></code></pre></td></tr></table></div></figure>


<p>The <code>login_as</code> function is included in a helper file:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<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='coffeescript'><span class='line'><span class="nv">exports.login_as = </span><span class="nf">(type_of_user) -&gt;</span>
</span><span class='line'>  <span class="nv">label = </span><span class="s2">&quot;I login as #{type_of_user}&quot;</span>
</span><span class='line'>  <span class="nv">fixture = </span><span class="nf">() -&gt;</span>
</span><span class='line'>    <span class="nv">cb = </span><span class="nx">@callback</span>
</span><span class='line'>    <span class="vi">@user = </span><span class="nv">user = </span><span class="nx">Model</span><span class="p">.</span><span class="nx">Factory</span><span class="p">.</span><span class="nx">create</span> <span class="nx">type_of_user</span><span class="p">.</span><span class="nx">match</span><span class="p">(</span><span class="sr">/a[n]? (\w+)/</span><span class="p">)[</span><span class="mi">1</span><span class="p">]</span>
</span><span class='line'>    <span class="nx">zombie</span><span class="p">.</span><span class="nx">visit</span> <span class="nx">Server</span><span class="p">.</span><span class="nx">path_for</span><span class="p">(</span><span class="s2">&quot;/login&quot;</span><span class="p">),</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>      <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;email&quot;</span><span class="p">,</span> <span class="s2">&quot;#{user.email}&quot;</span><span class="p">)</span>
</span><span class='line'>             <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;#{user.password}&quot;</span><span class="p">)</span>
</span><span class='line'>             <span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Login&quot;</span><span class="p">,</span> <span class="nx">cb</span>
</span><span class='line'>    <span class="k">return</span>
</span><span class='line'>  <span class="k">return</span> <span class="p">[</span><span class="nx">label</span><span class="p">,</span><span class="nx">fixture</span><span class="p">]</span>
</span></code></pre></td></tr></table></div></figure>


<p>Note that the function returns an array of arguments to be supplied to the vows-bdd
method. Also note that the fixture method is using <code>this</code> &mdash; which will point to the
vows <code>context</code> when the test is evaluated &mdash; and that the fixture returns <code>undefined</code>
to indicate to vows that the test should be performed asynchronously.</p>

<p>I think this new syntax works really perfectly for integration tests; it goes a long
way to supporting declarative testing style.</p>

<p>As always, please let me know if you run into any problems with the library or
have any suggestions!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Thanksgiving Week Links]]></title>
    <link href="http://rzrsharp.net/2011/11/21/thanksgiving-week-links.html"/>
    <updated>2011-11-21T16:17:00-05:00</updated>
    <id>http://rzrsharp.net/2011/11/21/thanksgiving-week-links</id>
    <content type="html"><![CDATA[<p>I&#8217;ve never been a fan of links posts - they always feel like &#8220;clips
episodes&#8221; from sitcoms to me - but I&#8217;ve realized that they can be pretty helpful, if
they&#8217;re well curated. I&#8217;m going to be experimenting with the &#8220;well curated&#8221; sort
of links posts. Please feel free to yell at me on twitter
if these get boring.</p>

<ul>
<li><p>A scaffold for your node - <a href="https://github.com/spiceapps/scaffoldit">scaffoldit</a>
is a customizable scaffold generator for your nodejs projects. I don&#8217;t think that there&#8217;s
<em>that</em> much boilerplate for express based apps, but this library is still pretty helpful for
getting my tests and basic app configured quickly.</p></li>
<li><p>Basic metaprogramming in Ruby - If you&#8217;re new to Ruby and are confused by some of
the metaprogramming enabled by methods like <code>repond_to?</code> and <code>method_missing</code>, check
out <a href="http://intridea.com/posts/dry-magic-methods">this helpful post</a> from the Intridea
blog.</p></li>
<li><p>Build first, talk later - Spencer Fry, founder of Carbonmade, offers some fine advice
to <a href="http://spencerfry.com/show-dont-tell">show don&#8217;t tell</a> - a prototype is worth
ten thousand words. I particularly like his observation that &#8220;The best thinking
about your product will come from actually building it.&#8221;</p></li>
<li><p>Productivity geekery - <a href="http://brettterpstra.com/app-review-dropzone/">Brett Terpstra reviews</a>
the mother-of-all-menubar-apps, Dropzone. I haven&#8217;t bought it yet myself, but I&#8217;m pretty close to pulling the trigger.</p></li>
<li><p>Writing your readme - Awhile back, nodejitsu offered
<a href="http://blog.nodejitsu.com/package-dependencies-done-right">some solid advice</a>
on setting up your node project&#8217;s <code>package.json</code> file.
Now they&#8217;re back with some more great advice, but this time it&#8217;s more universal:
<a href="http://blog.nodejitsu.com/how-to-write-a-readme">how to write a <em>helpful</em> readme for your next open source project</a>.</p></li>
<li><p>After reading Umair Haque&#8217;s excellent <a href="http://www.amazon.com/New-Capitalist-Manifesto-Building-Disruptively/dp/1422158586">New Capitalist Manifesto</a>, I&#8217;ve been thinking a great deal about the values
of sustainability in business and how value cycles drastically improve upon value chains.
I was excited to see <a href="http://www.avc.com/a_vc/2011/11/sustainability.html">Fred Wilson explore the same issues on his blog</a>:</p></li>
</ul>


<blockquote><p>sustainability is all about figuring out how to be in business forever. It is about business models that are win/win and lead to happy long term customer and supplier relationships. It is about avoiding the temptation to overeach. It is about avoiding the temptation to mazimize near term profits at the expense of long term health. It is about adapting the business to changing market dynamics. It is about building a team and a culture that can survive the loss of the leader and keep going. And it is about many more things like this.</p></blockquote>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Fix That Commit!]]></title>
    <link href="http://rzrsharp.net/2011/11/10/fix-that-commit.html"/>
    <updated>2011-11-10T16:55:00-05:00</updated>
    <id>http://rzrsharp.net/2011/11/10/fix-that-commit</id>
    <content type="html"><![CDATA[<p>While it sometimes seems as if everyone has already switched to git (or a similar distributed
version control system), I still meet people who are only leaving subversion
behind now. A lot of git&#8217;s idioms are impenetrable to those who are new to it, but the presence
of free resources like <a href="http://progit.org/book/">Pro Git</a> and <a href="http://gitready.com/">git ready</a> make the adjustment much easier.</p>

<p>Even though I&#8217;ve used git for awhile, I still need to look up the best way of performing
a task every now and then. One trick that comes in handy is editing existing commits.
<code>git --amend</code> allows for adding new files or changes to a previous commit, but you can
have even more control than that &#8211; changing <em>any</em> pre-pushed commit in your history.</p>

<p>Just get the hash of the commit you want to change. With a simple <code>git rebase &lt;commit&gt;^ --interactive</code>,
you can then make any changes you want. For each file, just type <code>git add &lt;file&gt;</code>. When
you&#8217;re done, <code>git commit --amend</code> and <code>git rebase --continue</code> will finish up your editing.</p>

<p>It&#8217;s always useful to review and cleanup your commit history before pushing your changes
upstream or issuing a pull request. With the ability to revisit any previous commit, you
can be more comfortable in a &#8216;commit-all-the-time&#8217; workflow.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Cleaning Up Yours Vows]]></title>
    <link href="http://rzrsharp.net/2011/11/10/cleaning-up-yours-vows.html"/>
    <updated>2011-11-10T11:07:00-05:00</updated>
    <id>http://rzrsharp.net/2011/11/10/cleaning-up-yours-vows</id>
    <content type="html"><![CDATA[<p>Learning a framework as you&#8217;re TDD-ing a project can be dangerous. But even if you
know what you&#8217;re doing, some of the conveniences of node.js can make you a bit sloppy
with your code. Namely, the ability to pull functions from files as you need them and pass
them around makes for some interesting problems.</p>

<figure class='code'><figcaption><span>foo.js</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">add</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">a</span><span class="o">+</span><span class="nx">b</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="nx">exports</span><span class="p">.</span><span class="nx">subtract</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">a</span><span class="p">,</span><span class="nx">b</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">a</span><span class="o">-</span><span class="nx">b</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<figure class='code'><figcaption><span>bar.js</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">add</span> <span class="o">=</span> <span class="nx">require</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">).</span><span class="nx">add</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="nx">add</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">));</span> <span class="c1">// 3</span>
</span></code></pre></td></tr></table></div></figure>


<p>If your functions are free of side effects, you&#8217;re not exactly committing
a serious coding sin. But go beyond the simple example above &#8211; starting to pass
around whole objects, or breaking the law of demeter &#8211; and soon your code doesn&#8217;t feel right.</p>

<p>I quickly ran into this problem with my vows tests. As I was about to merge a feature
branch to master, I reviewed my code and was a bit horrified at what I saw in my tests:</p>

<figure class='code'><figcaption><span>user_spec.coffee</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='coffeescript'><span class='line'><span class="p">{</span><span class="nx">cleanupDB</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s2">&quot;../helpers&quot;</span>
</span><span class='line'><span class="p">{</span><span class="nx">vows</span><span class="p">,</span><span class="nx">server</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s2">&quot;vows&quot;</span>
</span><span class='line'><span class="nv">mongoose = </span><span class="nx">require</span> <span class="s2">&quot;mongoose&quot;</span>
</span><span class='line'><span class="nv">User = </span><span class="nx">mongoose</span><span class="p">.</span><span class="nx">model</span> <span class="s2">&quot;User&quot;</span>
</span><span class='line'><span class="nv">assert = </span><span class="nx">require</span> <span class="s2">&quot;assert&quot;</span>
</span><span class='line'><span class="nv">Sinon = </span><span class="nx">require</span> <span class="s2">&quot;sinon&quot;</span>
</span><span class='line'><span class="p">{</span><span class="nx">Factory</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s2">&quot;../helpers&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>And this was just <em>one</em> of my tests. Yikes. Lots of bad things going on here:</p>

<ul>
<li>My test has a dependency on my model implementation, and not just the model itself;
if I switch the model off mongoose in the future, my test itself will need to change.</li>
<li>My test has a dependency on a particulra spying/mocking framework (Sinon)</li>
<li>There&#8217;s a lot of confusing imports; why is <code>server</code> required off of vows?</li>
<li>Repeating requires - one for <code>cleanupDB</code> and one for <code>Factory</code>.</li>
</ul>


<p>Bad bad bad.</p>

<p>My tests needed to be refactored to deal with this madness. I realized that there was
repeated code throughout my vows tests; not only could I clean things up with some proper
encapsulation, I could DRY my vows as well.</p>

<p>One cool feature of node is that if you include an <code>index</code> file in a directory, that
file is loaded when you require the directory. So I created a new <code>spec/helpers</code> directory,
and placed an <code>index</code> file inside.</p>

<figure class='code'><figcaption><span>spec/helpers/index.coffee</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="nv">process.env.NODE_ENV = </span><span class="s1">&#39;test&#39;</span>
</span><span class='line'>
</span><span class='line'><span class="nv">module.exports =</span>
</span><span class='line'>  <span class="nv">Server: </span> <span class="nx">require</span> <span class="s2">&quot;#{__dirname}/server_helpers&quot;</span>
</span><span class='line'>  <span class="nv">Test: </span> <span class="nx">require</span> <span class="s2">&quot;#{__dirname}/test_helpers&quot;</span>
</span><span class='line'>  <span class="nv">Model: </span> <span class="nx">require</span> <span class="s2">&quot;#{__dirname}/model_helpers&quot;</span>
</span></code></pre></td></tr></table></div></figure>


<p>And each of these helper files now encapsulates logic and functionality that I use
across my tests:</p>

<figure class='code'><figcaption><span>server_helpers</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>
<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>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
<span class='line-number'>52</span>
<span class='line-number'>53</span>
<span class='line-number'>54</span>
<span class='line-number'>55</span>
<span class='line-number'>56</span>
<span class='line-number'>57</span>
<span class='line-number'>58</span>
<span class='line-number'>59</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="nv">http = </span><span class="nx">require</span> <span class="s2">&quot;http&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.port = port = </span><span class="mi">3003</span>
</span><span class='line'><span class="nv">server = </span><span class="p">(</span><span class="nx">require</span> <span class="s2">&quot;#{__dirname}/../../app&quot;</span><span class="p">)</span>
</span><span class='line'><span class="nv">server.ready = </span><span class="nf">(callback) -&gt;</span>
</span><span class='line'>  <span class="k">if</span> <span class="nx">@active</span>
</span><span class='line'>    <span class="nx">process</span><span class="p">.</span><span class="nx">nextTick</span> <span class="nx">callback</span>
</span><span class='line'>  <span class="k">else</span>
</span><span class='line'>    <span class="vi">@active = </span><span class="kc">true</span>
</span><span class='line'>    <span class="nx">server</span><span class="p">.</span><span class="nx">listen</span> <span class="nx">port</span><span class="p">,</span> <span class="nf">(err,result) -&gt;</span>
</span><span class='line'>      <span class="nx">process</span><span class="p">.</span><span class="nx">nextTick</span> <span class="nx">callback</span>
</span><span class='line'>  <span class="k">return</span>
</span><span class='line'>
</span><span class='line'><span class="nx">process</span><span class="p">.</span><span class="kc">on</span> <span class="s2">&quot;exit&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>  <span class="k">if</span> <span class="nx">@active</span> <span class="k">then</span> <span class="nx">server</span><span class="p">.</span><span class="nx">close</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'><span class="nv">wait = </span><span class="o">-&gt;</span>
</span><span class='line'>  <span class="k">if</span> <span class="o">!</span><span class="nx">@active</span>
</span><span class='line'>    <span class="nx">process</span><span class="p">.</span><span class="nx">nextTick</span> <span class="nx">wait</span>
</span><span class='line'>  <span class="k">else</span>
</span><span class='line'>    <span class="k">return</span>
</span><span class='line'>
</span><span class='line'><span class="nx">server</span><span class="p">.</span><span class="nx">ready</span> <span class="nx">wait</span>
</span><span class='line'>
</span><span class='line'><span class="nv">makeRequest = </span><span class="nf">(url,params,method,callback) -&gt;</span>
</span><span class='line'>  <span class="nx">params</span> <span class="o">||=</span> <span class="s2">&quot;&quot;</span>
</span><span class='line'>  <span class="nv">encoding = </span><span class="s1">&#39;utf-8&#39;</span>
</span><span class='line'>  <span class="nx">server</span><span class="p">.</span><span class="nx">ready</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nv">request = </span><span class="nx">http</span><span class="p">.</span><span class="nx">request</span>
</span><span class='line'>      <span class="nv">host: </span><span class="s2">&quot;127.0.0.1&quot;</span>
</span><span class='line'>      <span class="nv">port: </span><span class="s2">&quot;#{port}&quot;</span>
</span><span class='line'>      <span class="nv">path: </span><span class="nx">url</span>
</span><span class='line'>      <span class="nv">method: </span><span class="s2">&quot;#{method}&quot;</span>
</span><span class='line'>      <span class="nv">headers:</span>
</span><span class='line'>        <span class="s1">&#39;content-type&#39;</span><span class="o">:</span> <span class="s2">&quot;application/x-www-form-urlencoded&quot;</span>
</span><span class='line'>        <span class="s1">&#39;content-length&#39;</span><span class="o">:</span> <span class="nx">params</span><span class="p">.</span><span class="nx">length</span>
</span><span class='line'>
</span><span class='line'>    <span class="nx">request</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;response&#39;</span><span class="p">,</span> <span class="nf">(response) -&gt;</span>
</span><span class='line'>      <span class="nv">response.body = </span><span class="s1">&#39;&#39;</span>
</span><span class='line'>      <span class="nx">response</span><span class="p">.</span><span class="nx">setEncoding</span> <span class="nx">encoding</span>
</span><span class='line'>      <span class="nx">response</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;data&#39;</span><span class="p">,</span> <span class="nf">(chunk) -&gt;</span>
</span><span class='line'>        <span class="nx">response</span><span class="p">.</span><span class="nx">body</span> <span class="o">+=</span> <span class="nx">chunk</span>
</span><span class='line'>      <span class="nx">response</span><span class="p">.</span><span class="kc">on</span> <span class="s1">&#39;end&#39;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>        <span class="nx">callback</span> <span class="kc">null</span><span class="p">,</span> <span class="nx">response</span>
</span><span class='line'>    <span class="k">if</span> <span class="nx">params</span>
</span><span class='line'>      <span class="nx">request</span><span class="p">.</span><span class="nx">write</span> <span class="nx">params</span>
</span><span class='line'>    <span class="nx">request</span><span class="p">.</span><span class="nx">end</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.server = </span><span class="nx">server</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.get = </span><span class="nf">(url,params,callback) -&gt;</span>
</span><span class='line'>  <span class="k">if</span> <span class="nx">arguments</span><span class="p">.</span><span class="nx">length</span> <span class="o">==</span> <span class="mi">2</span>
</span><span class='line'>    <span class="nv">callback = </span><span class="nx">arguments</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
</span><span class='line'>    <span class="nv">params = </span><span class="kc">null</span>
</span><span class='line'>  <span class="nx">makeRequest</span> <span class="nx">url</span><span class="p">,</span><span class="nx">params</span><span class="p">,</span><span class="s2">&quot;GET&quot;</span><span class="p">,</span><span class="nx">callback</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.post = </span><span class="nf">(url,params,callback) -&gt;</span>
</span><span class='line'>  <span class="nx">makeRequest</span> <span class="nx">url</span><span class="p">,</span><span class="nx">params</span><span class="p">,</span><span class="s2">&quot;POST&quot;</span><span class="p">,</span><span class="nx">callback</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>test_helpers.coffee</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='coffeescript'><span class='line'><span class="nv">Sinon = </span><span class="nx">require</span> <span class="s2">&quot;sinon&quot;</span>
</span><span class='line'><span class="nv">assert = </span><span class="nx">require</span> <span class="s2">&quot;assert&quot;</span>
</span><span class='line'><span class="nv">http = </span><span class="nx">require</span> <span class="s2">&quot;http&quot;</span>
</span><span class='line'><span class="nv">Model = </span><span class="nx">require</span> <span class="s2">&quot;./model_helpers&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.spy = </span><span class="nf">(object,method) -&gt;</span>
</span><span class='line'>  <span class="nx">Sinon</span><span class="p">.</span><span class="nx">spy</span> <span class="nx">object</span><span class="p">,</span> <span class="nx">method</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.stub = </span><span class="nf">(object, method, fn) -&gt;</span>
</span><span class='line'>  <span class="nx">Sinon</span><span class="p">.</span><span class="nx">stub</span> <span class="nx">object</span><span class="p">,</span> <span class="nx">method</span><span class="p">,</span> <span class="nx">fn</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.spyRender = </span><span class="o">-&gt;</span>
</span><span class='line'>  <span class="vi">@response = </span><span class="nx">http</span><span class="p">.</span><span class="nx">ServerResponse</span><span class="p">.</span><span class="nx">prototype</span>
</span><span class='line'>  <span class="nx">Sinon</span><span class="p">.</span><span class="nx">spy</span> <span class="nx">@response</span><span class="p">,</span> <span class="s2">&quot;render&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.spyModel = </span><span class="nf">(klass,method) -&gt;</span>
</span><span class='line'>  <span class="nx">Sinon</span><span class="p">.</span><span class="nx">spy</span> <span class="p">(</span><span class="nx">Model</span><span class="p">.</span><span class="nx">getType</span> <span class="nx">klass</span><span class="p">),</span> <span class="nx">method</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.assert = </span><span class="nx">assert</span>
</span></code></pre></td></tr></table></div></figure>




<figure class='code'><figcaption><span>model_helpers.coffee</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='coffeescript'><span class='line'><span class="nv">mongoose = </span><span class="nx">require</span> <span class="s2">&quot;mongoose&quot;</span>
</span><span class='line'><span class="nv">cleaner = </span><span class="k">new</span> <span class="p">(</span><span class="nx">require</span> <span class="s2">&quot;database-cleaner&quot;</span><span class="p">)(</span><span class="s2">&quot;mongodb&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.cleanupDB = </span><span class="o">-&gt;</span>
</span><span class='line'>  <span class="nv">mongo = </span><span class="nx">mongoose</span><span class="p">.</span><span class="nx">connection</span><span class="p">.</span><span class="nx">db</span>
</span><span class='line'>  <span class="nx">cleaner</span><span class="p">.</span><span class="nx">clean</span> <span class="nx">mongo</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.Factory = </span><span class="p">(</span><span class="nx">require</span> <span class="s2">&quot;#{__dirname}/factories&quot;</span><span class="p">).</span><span class="nx">Factory</span>
</span><span class='line'>
</span><span class='line'><span class="nv">exports.getType = </span><span class="nf">(Klass) -&gt;</span>
</span><span class='line'>  <span class="nx">mongoose</span><span class="p">.</span><span class="nx">model</span> <span class="nx">Klass</span>
</span></code></pre></td></tr></table></div></figure>


<p>My test logic dependencies are clean and encapsulated, making for both clearer
<code>require</code>s blocks and clearer tests themselves.</p>

<figure class='code'><figcaption><span>user_spec.coffee</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>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="p">{</span><span class="nx">Model</span><span class="p">,</span><span class="nx">Test</span><span class="p">,</span><span class="nx">Server</span><span class="p">}</span> <span class="o">=</span> <span class="nx">require</span> <span class="s2">&quot;../helpers&quot;</span>
</span><span class='line'><span class="nv">vows = </span><span class="nx">require</span> <span class="s1">&#39;vows&#39;</span>
</span><span class='line'><span class="nv">User = </span><span class="nx">Model</span><span class="p">.</span><span class="nx">getType</span> <span class="s2">&quot;User&quot;</span>
</span><span class='line'>
</span><span class='line'><span class="c1">#code removed for brevity</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">addBatch</span>
</span><span class='line'>    <span class="s2">&quot;Hashes password:&quot;</span><span class="o">:</span>
</span><span class='line'>      <span class="s2">&quot;when a new user is created&quot;</span><span class="o">:</span>
</span><span class='line'>        <span class="nv">topic: </span><span class="o">-&gt;</span>
</span><span class='line'>          <span class="vi">@user = </span><span class="nx">Model</span><span class="p">.</span><span class="nx">Factory</span><span class="p">.</span><span class="nx">build</span> <span class="s2">&quot;User&quot;</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">spy</span> <span class="nx">User</span><span class="p">,</span> <span class="s2">&quot;makeSalt&quot;</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">spy</span> <span class="nx">User</span><span class="p">,</span> <span class="s2">&quot;hashPassword&quot;</span>
</span><span class='line'>          <span class="nx">@user</span><span class="p">.</span><span class="nx">save</span> <span class="nx">@callback</span>
</span><span class='line'>          <span class="k">return</span>
</span><span class='line'>
</span><span class='line'>        <span class="s2">&quot;it creates a salt and stores it&quot;</span><span class="o">:</span> <span class="nf">(err,user) -&gt;</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">User</span><span class="p">.</span><span class="nx">makeSalt</span><span class="p">.</span><span class="nx">calledOnce</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">user</span><span class="p">.</span><span class="nx">salt</span> <span class="o">==</span> <span class="nx">User</span><span class="p">.</span><span class="nx">makeSalt</span><span class="p">.</span><span class="nx">returnValues</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
</span><span class='line'>
</span><span class='line'>        <span class="s2">&quot;it encrpyts the password&quot;</span><span class="o">:</span> <span class="nf">(err,user) -&gt;</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">User</span><span class="p">.</span><span class="nx">hashPassword</span><span class="p">.</span><span class="nx">calledOnce</span>
</span><span class='line'>          <span class="nx">Test</span><span class="p">.</span><span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">User</span><span class="p">.</span><span class="nx">hashPassword</span><span class="p">.</span><span class="nx">calledWith</span> <span class="nx">@user</span><span class="p">.</span><span class="nx">password</span>
</span><span class='line'>
</span><span class='line'>      <span class="nv">teardown: </span><span class="o">-&gt;</span>
</span><span class='line'>        <span class="nx">User</span><span class="p">.</span><span class="nx">hashPassword</span><span class="p">.</span><span class="nx">restore</span><span class="p">()</span>
</span><span class='line'>        <span class="nx">User</span><span class="p">.</span><span class="nx">makeSalt</span><span class="p">.</span><span class="nx">restore</span><span class="p">()</span>
</span><span class='line'>        <span class="nx">Model</span><span class="p">.</span><span class="nx">cleanupDB</span><span class="p">()</span>
</span></code></pre></td></tr></table></div></figure>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Indie Productivity]]></title>
    <link href="http://rzrsharp.net/2011/11/04/indie-productivity.html"/>
    <updated>2011-11-04T14:25:00-04:00</updated>
    <id>http://rzrsharp.net/2011/11/04/indie-productivity</id>
    <content type="html"><![CDATA[<p>Being a contract web developer means working in a large number of enterprise
environments. While clients and projects vary dramatically, enterprise
environments almost always share certain characteristics in common: locked down
networks, limited use of open source libraries (and certainly no
contribution!), extreme caution regarding new technologies, and reliance on
libraries and tools which some might consider&#8230; deprecated. Most of these
characteristics are perfectly logical, given the complexity of enterprise
projects and the security required by legal considerations. Enterprise software
is frequently disregarded as sloppy, boring, uncreative, and poor &#8211; and I&#8217;ve
certainly worked on these kinds of projects, and dealt with some
frustrating situations &#8211; but classifying <em>all</em> software in this way is unfair.
That said, even the best of enterprise projects feel constraining compared to
independent work.</p>

<p>Recent developments have certainly improvemed the enterprise work
environment. The proliferation of iOS devices has not only brought Macs into
the traditionally Windows-only world of the enterprise; it&#8217;s brought a new
focus on standards-based webapps, which has forced
a reconsideration of existing technology stacks. As enterprises have adopted
dynamic languages and agile approaches &#8211; albeit slowly &#8211; they&#8217;ve begun
upgrading their toolsets, as well. <a href="https://github.com/blog/978-introducing-github-enterprise">Github&#8217;s announcement of an enterprise plan</a> demonstrates that it&#8217;s starting to feel a little bit more
human within the confines of corporate intranets.</p>

<p>But even as the enterprise has evolved, the improvements made for individual
developer productivity have exploded. The ease with which a single developer
can build and deploy a scalable, cross-device, and revenue generating app is
beyond remarkable. The maturing of tools, languages, development environments,
and deployment strategies has created a fantastically productive environment.
To name a few favorites:</p>

<ul>
<li><p>Macbooks - The new Macbook Airs, when fully tricked out, offer incredibly
powerful development workhorses weighing less than 3 pounds and costing
less than $2k</p></li>
<li><p><a href="http://mxcl.github.com/homebrew/">Homebrew</a> - A package manager for Mac OS,
making that Macbook purchase perfect</p></li>
<li><p><a href="http://heroku.com">Heroku</a> - Have an idea for a new project? Deploy it for
free. Want to scale it? Flip a switch</p></li>
<li><p><a href="http://www.opscode.com/chef/">Chef</a> and <a href="http://puppetlabs.com/">Puppet</a> - Want
more control than Heroku offers? Fine, manage your own boxes with
a sane devops solution that you can take with you.</p></li>
<li><p>Git and <a href="http://github.com">Github</a> - Who could have ever imagined that
managing code could be so enjoyable?</p></li>
<li><p>zsh and <a href="https://github.com/robbyrussell/oh-my-zsh">oh-my-zsh</a> - Tab completion, customizable plugins, persistent Git HUD</p></li>
<li><p>The incredible profusion of programming languages, libraries, and frameworks - <a href="http://scala-lang.org">Scala</a>,
<a href="http://clojure.org">Clojure</a>,
<a href="http://nodejs.org">node.js</a>, the <a href="http://www.playframework.org/">Play framework</a>, NoSql solutions,
nginx, to say nothing of the maturing of Ruby (especially Rails) and Python - all of
these technologies make it easier than ever to work in one&#8217;s preferred
style without sacrificing power or performance. The communities around each
of these technologies, empowered by twitter, StackExchange, and Github,
ease learning curves and offer helpful answers to any questions.</p></li>
<li><p>The Apple App store, <a href="https://squareup.com/">Square</a>, <a href="http://stripe.com">Stripe</a>, <a href="http://recurly.com/">Recurly</a>,
and <a href="https://samurai.feefighters.com/">Samurai</a> enable developers to make money on their ideas and apps
with far less effort than in the past.</p></li>
</ul>


<p>Is there <em>any other industry</em> in which an individual has such a <em>dramatic</em>
advantage in tools, cost, and agility over large organizations?</p>

<p>It&#8217;s an exciting time for indie developers. And the future keeps looking better.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Back from Vacation]]></title>
    <link href="http://rzrsharp.net/2011/09/13/back-from-vacation.html"/>
    <updated>2011-09-13T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/09/13/back-from-vacation</id>
    <content type="html"><![CDATA[<p>I just returned from a fantastic vacation to London and Copenhagen. I&#8217;d visited
London, before but had never been to Copenhagen, or any Scandinavian country.
As an engineer, I could barely wrap my mind around the brilliant efficiencies
of the city. The train system is a wonder - incredibly efficient, clean,and
comprehensive, with the ability to get anywhere easily, and even allowing sales
of travel tickets via text message. My heart warmed at the first site of
a flotilla of bike-commuters sailing by on our walk to our hotel. The Danes
themselves consistently impressed us with their warmth and hospitality. I look
forward to returning soon.</p>

<p>My brain is struggling to return to coding productivity after its extended
vacation, so I&#8217;ve mostly been reviewing my RSS reader to aid in the transition.
Assaf Arkin, to whom I owe a massive debt for his creation of <a href="http://zombie.labnotes.org/">Node testingtool Zombie.js</a>,
wrote a <a href="http://labnotes.org/2011/09/06/what-self-can-teach-us-about-the-future-of-javascript/">great article on Self</a>
that deserves mentioning. Self, as most JS developers know, played an important
role in inspiring Brendan Eich&#8217;s creation of Javascript, but I was unaware of
the details of the language.</p>

<p>Assaf&#8217;s whole article is worth reading, but one particular quote stood out:</p>

<blockquote><p>language and environment come together to achieve a common goal: to create an environment that is malleable,
that allows learning through sharing and exploration,
that uses minimalism and consistency to foster reuse.</p></blockquote>

<p>Minimalism, consistency, malleability.</p>

<p>These words work not just as signposts of good language design, but of everything from
API construction to individual units of code. I&#8217;m certainly planning on using them
as my mantra as I slowly get back up to speed with work.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Introducing vows-bdd]]></title>
    <link href="http://rzrsharp.net/2011/08/16/introducing-vows-bdd.html"/>
    <updated>2011-08-16T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/08/16/introducing-vows-bdd</id>
    <content type="html"><![CDATA[<p>My work with Node.js has recently transformed from the occassional experiment to
the building of a full-on side project. It&#8217;s fascinating to be working with a set
of tools that are so rapidly developing; the energy and excitement in the Node
ecosystem far outweighs any annoyances with needing to adjust to changing APIs.</p>

<h3>Embracing Vows</h3>

<p>One of the tools which I&#8217;ve really enjoyed learning is <a href="http://vowsjs.org">Vows.js</a>.
Vows.js is a fully async Javascript testing library that allows for blazingly fast
execution. (It&#8217;s amazing how little changes in test speed can make TDD feel
much less onerous.)  Vows&#8217; syntax can be a little tough to adjust to, but the speed,
combined with the ability to construct &#8220;test batches&#8221;, make the barrier to entry
worth the effort.</p>

<p>While Vows is a near pefect tool for unit testing, I began to run into trouble with
full-stack integration testing. Check out the contrived example below:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<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>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="nx">vows</span><span class="p">.</span><span class="nx">describe</span><span class="p">(</span><span class="s2">&quot;Creating a User&quot;</span><span class="p">)</span>
</span><span class='line'>  <span class="p">.</span><span class="nx">addBatch</span>
</span><span class='line'>    <span class="s2">&quot;To create a user&quot;</span><span class="o">:</span>
</span><span class='line'>
</span><span class='line'>      <span class="s2">&quot;Given the server has started&quot;</span><span class="o">:</span>
</span><span class='line'>        <span class="nv">topic:</span>
</span><span class='line'>          <span class="nx">server</span><span class="p">.</span><span class="nx">ready</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>        <span class="s2">&quot;and the DB is populated&quot;</span><span class="o">:</span>
</span><span class='line'>          <span class="nv">topic:</span>
</span><span class='line'>            <span class="nx">setupFixtures</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>          <span class="s2">&quot;and another setup function is required&quot;</span><span class="o">:</span>
</span><span class='line'>            <span class="nv">topic: </span><span class="o">-&gt;</span>
</span><span class='line'>              <span class="nx">anotherSetup</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>            <span class="s2">&quot;When visiting the form at /user/new&quot;</span><span class="o">:</span>
</span><span class='line'>              <span class="nv">topic: </span><span class="o">-&gt;</span>
</span><span class='line'>                <span class="nv">ctx = </span><span class="k">this</span>
</span><span class='line'>                <span class="nx">server</span><span class="p">.</span><span class="nx">ready</span> <span class="o">-&gt;</span>
</span><span class='line'>                  <span class="nx">zombie</span><span class="p">.</span><span class="nx">visit</span> <span class="s2">&quot;http://localhost:#{port}/user/new&quot;</span><span class="p">,</span> <span class="nx">ctx</span><span class="p">.</span><span class="nx">callback</span>
</span><span class='line'>                <span class="k">return</span>
</span><span class='line'>
</span><span class='line'>              <span class="s2">&quot;then should allow entry of a username&quot;</span><span class="o">:</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>                <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=username]&quot;</span>
</span><span class='line'>
</span><span class='line'>              <span class="s2">&quot;should allow entry of first and last name&quot;</span><span class="o">:</span> <span class="nf">(err,b,s) -&gt;</span>
</span><span class='line'>                <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">b</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=firstName]&quot;</span>
</span><span class='line'>                <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">b</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=lastName]&quot;</span>
</span><span class='line'>
</span><span class='line'>              <span class="s2">&quot;should allow entry of a password&quot;</span><span class="o">:</span> <span class="nf">(err,b,s) -&gt;</span>
</span><span class='line'>                <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">b</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=password]&quot;</span>
</span><span class='line'>
</span><span class='line'>              <span class="s2">&quot;should allow confirmation of a password&quot;</span><span class="o">:</span> <span class="nf">(err,b,s) -&gt;</span>
</span><span class='line'>                <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">b</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=passwordConfirm]&quot;</span>
</span><span class='line'>
</span><span class='line'>              <span class="s2">&quot;and submitting the form&quot;</span><span class="o">:</span>
</span><span class='line'>                <span class="nv">topic: </span><span class="nf">(browser,status) -&gt;</span>
</span><span class='line'>                  <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;username&quot;</span><span class="p">,</span> <span class="s2">&quot;test&quot;</span><span class="p">)</span>
</span><span class='line'>                         <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;firstName&quot;</span><span class="p">,</span> <span class="s2">&quot;Justin&quot;</span><span class="p">)</span>
</span><span class='line'>                         <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;lastName&quot;</span><span class="p">,</span> <span class="s2">&quot;Reidy&quot;</span><span class="p">)</span>
</span><span class='line'>                         <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;foobar&quot;</span><span class="p">)</span>
</span><span class='line'>                         <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;foobar&quot;</span><span class="p">)</span>
</span><span class='line'>                         <span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Sign Up!&quot;</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>                <span class="s2">&quot;should create a new User&quot;</span><span class="o">:</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>                  <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">findNewUser</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'>        <span class="p">.</span><span class="nx">export</span> <span class="nx">module</span>
</span></code></pre></td></tr></table></div></figure>


<p>Ouch. All that nesting makes for pretty unreadable code - even in CoffeeScript.</p>

<h3>vows-bdd: an easier way to test</h3>

<p>I&#8217;ve never been a huge Cucumber fan, but modeling integration tests in a &#8220;given-when
-then&#8221; format makes them much easier for me to construct mentally. While the
<a href="https://github.com/jadell/prenup">prenup</a> library made long Vows tests easier to read by introducing a
fluent interface, I thought that I&#8217;d love to marry this fluent approach with BDD&#8217;s
&#8220;given-when-then&#8221;.</p>

<p>A couple days later and vows-bdd was born:</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>
<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>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="nx">Feature</span><span class="p">(</span><span class="s2">&quot;Creating a User&quot;</span><span class="p">)</span>
</span><span class='line'>  <span class="p">.</span><span class="nx">scenario</span><span class="p">(</span><span class="s2">&quot;Create a User via Form&quot;</span><span class="p">)</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">given</span> <span class="s2">&quot;the server is running&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">server</span><span class="p">.</span><span class="nx">ready</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="o">and</span> <span class="s2">&quot;the DB is popuplated&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">setupFixtures</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="o">and</span> <span class="s2">&quot;another setup function is called&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">anotherSetup</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I visit the form at user/new&quot;</span><span class="p">,</span> <span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">zombie</span><span class="p">.</span><span class="nx">visit</span> <span class="s2">&quot;http://localhost:#{port}/user/new&quot;</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">then</span> <span class="s2">&quot;I should see a username field&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=username]&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="o">and</span> <span class="s2">&quot;I should see entries for first and last name&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=firstName]&quot;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span> <span class="s2">&quot;:input[name=lastName]&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="o">and</span> <span class="s2">&quot;I should see a password entry&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">,</span> <span class="s2">&quot;:input[name=password]&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="o">and</span> <span class="s2">&quot;I should see a password confirmation&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">browser</span><span class="p">.</span><span class="nx">querySelector</span><span class="p">,</span> <span class="s2">&quot;:input[name=passwordConfirm]&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">when</span> <span class="s2">&quot;I submit the form&quot;</span><span class="p">,</span> <span class="nf">(browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">browser</span><span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;username&quot;</span><span class="p">,</span> <span class="s2">&quot;test&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;firstName&quot;</span><span class="p">,</span> <span class="s2">&quot;Justin&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;lastName&quot;</span><span class="p">,</span> <span class="s2">&quot;Reidy&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;foobar&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">fill</span><span class="p">(</span><span class="s2">&quot;password&quot;</span><span class="p">,</span> <span class="s2">&quot;foobar&quot;</span><span class="p">)</span>
</span><span class='line'>           <span class="p">.</span><span class="nx">pressButton</span> <span class="s2">&quot;Sign Up!&quot;</span><span class="p">,</span> <span class="nx">@callback</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="k">then</span> <span class="s2">&quot;a new User should be created&quot;</span><span class="p">,</span> <span class="nf">(err,browser,status) -&gt;</span>
</span><span class='line'>    <span class="nx">assert</span><span class="p">.</span><span class="nx">ok</span> <span class="nx">findNewUser</span><span class="p">()</span>
</span><span class='line'>
</span><span class='line'>  <span class="p">.</span><span class="nx">complete</span><span class="p">()</span>
</span><span class='line'>  <span class="p">.</span><span class="nx">finish</span><span class="p">(</span><span class="nx">module</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>Checkout the <a href="https://github.com/jmreidy/vows-bdd">repo on Github</a>
for more documentation and info.</p>

<h3>Open-Source is scary!</h3>

<p>The vast majority of my career has taken place in enterprise world, where code is
rarely, if ever, shared with anyone on the outside, and even <em>using</em> open-source
code is considered dangerous. While I&#8217;ve contributed to OSS libraries
before, I&#8217;ve never posted my own creation. It&#8217;s fairly nerve-wracking to put your
work out in the wild, especially when you&#8217;re building on top of such amazing
contributions from incredible developers.</p>

<p>In fact, I probably would&#8217;ve sat on this little library forever, constantly trying
to perfect it, if not for a
<a href="http://blog.nodejitsu.com/the-nodejs-philosophy">fantastic blog post</a>
written by Charlie Robbins(<a href="http://twitter.com/indexzero">@indexzero</a>)
over at Nodejitsu. I think his post perfectly expresses the spirt and mentality
of the Node community right now,
and his emphasis on experimentation via small bits of functionality made me realize:
this code may not be perfect, and it might not even do that much, but if <em>I</em> find it
useful, then maybe someone else will too.</p>

<p>So please - <a href="https://github.com/jmreidy/vows-bdd">checkout vows-bdd</a> and give it a whirl.
Any suggestions or comments would be very much appreciated!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA["This" in Anonymous Functions
]]></title>
    <link href="http://rzrsharp.net/2011/07/08/this-in-anonymous-functions.html"/>
    <updated>2011-07-08T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/07/08/this-in-anonymous-functions</id>
    <content type="html"><![CDATA[<p>Sometimes it&#8217;s difficult to find an easy answer to common coding questions. Because
Google ignores most punctuation, even the most exact queries fail to produce
relevant results. Questions about the nature and value of <code>this</code> in Javascript present
a particularly thorny problem, since &#8220;this&#8221; is about as common a word as you can find.</p>

<p>A common point of confusion in Javascript is that the value of <code>this</code> depends entirely
on a function&#8217;s context, and can even be overridden depending on how a function is
invoked. Hopefully this post will save time for new Javascript devs trolling through
Google&#8217;s depths:</p>

<blockquote><p>In anonymous functions, the value of <code>this</code> refers to the anonymous function itself,
and not the calling scope. However, the nature of closures allows the anonymous function
to still refer to the calling object.</p></blockquote>

<p>The above rule is demonstrated with the following nodejs code:</p>

<div>
  <pre>
    <code class='javascript'>var that = this;
that.foo = 'bar';
process.nextTick(function() { 
  console.log(&quot;this &quot; + this.foo + &quot; and that &quot; + that.foo) });</code>
  </pre>
</div>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[What Does Coffeescript's "do" Do?]]></title>
    <link href="http://rzrsharp.net/2011/06/27/what-does-coffeescripts-do-do.html"/>
    <updated>2011-06-27T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/06/27/what-does-coffeescripts-do-do</id>
    <content type="html"><![CDATA[<p>When reading over some Node.js source code written in Coffeescript, I came across
a couple uses of the Coffeescript <code>do</code> operator. While <code>do</code> is a very familiar tool
for Ruby developers, I wasn&#8217;t sure how Coffeescript used it, so I took at look at
its documentation, which states:</p>

<blockquote><p>When using a JavaScript loop to generate functions, it&#8217;s common to insert a closure
wrapper in order to ensure that loop variables are closed over, and all the
generated functions don&#8217;t just share the final values. CoffeeScript provides the
do keyword, which immediately invokes a passed function, forwarding any arguments.</p></blockquote>

<p>&#8220;All the generated functions don&#8217;t just share the final values.&#8221; Huh. This statement
didn&#8217;t mean a lot to me. A little searching on Google led to a fairly helpful post
on <a href="http://stackoverflow.com/questions/643542/doesnt-javascript-support-closures-with-local-variables/643664#643664">Stack Overflow</a>. The question there presented the following Javascript:</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">closures</span> <span class="o">=</span> <span class="p">[];</span>
</span><span class='line'><span class="kd">function</span> <span class="nx">create</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">closures</span><span class="p">[</span><span class="nx">i</span><span class="p">]</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">alert</span><span class="p">(</span><span class="s2">&quot;i = &quot;</span> <span class="o">+</span> <span class="nx">i</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><span class='line'><span class="kd">function</span> <span class="nx">run</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">closures</span><span class="p">[</span><span class="nx">i</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">create</span><span class="p">();</span>
</span><span class='line'><span class="nx">run</span><span class="p">();</span>
</span></code></pre></td></tr></table></div></figure>


<p>The question stated that the result of running this code was <code>5,5,5,5,5</code> instead
of the expect <code>0,1,2,3,4</code>. The answer which created the &#8220;correct&#8221; result
provided the code below:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<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">create</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">i</span> <span class="o">=</span> <span class="mi">0</span><span class="p">;</span> <span class="nx">i</span> <span class="o">&lt;</span> <span class="mi">5</span><span class="p">;</span> <span class="nx">i</span><span class="o">++</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">closures</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span><span class="p">(</span><span class="nx">tmp</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>      <span class="k">return</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>        <span class="nx">alert</span><span class="p">(</span><span class="s2">&quot;i = &quot;</span> <span class="o">+</span> <span class="nx">tmp</span><span class="p">);</span>
</span><span class='line'>      <span class="p">};</span>
</span><span class='line'>    <span class="p">})(</span><span class="nx">i</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>and also explained:</p>

<blockquote><p>JavaScript&#8217;s scopes are function-level, not block-level, and creating a closure just means that the enclosing scope gets added to the lexical environment of the enclosed function.</p></blockquote>

<p>OK, this was even less helpful. But after going back and reading the Coffeescript
docs again, the concept made sense. As always with Javascript, the <em>context</em> in
which a function is called demands as much attention as the function itself. Reading
the code in the Stack Overflow post, a developer&#8217;s brain automatically thinks of the
returned function at the time of evaluation. But in reality, each of those functions
created in the <code>create</code> function aren&#8217;t called until <em>after</em> the for loop has completed.
Thus, by the time each function is called, it evaluates <code>i</code> when <code>i</code> has already
finished the loop with a value of <code>5</code>. The closure-wrapping provided in the answer
is exactly what the <code>do</code> keyword in Coffeescript provides!</p>

<p>Here&#8217;s an example of the solution&#8217;s function, in Coffeescript:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="nv">closures = </span><span class="p">[]</span>
</span><span class='line'><span class="nx">create</span> <span class="o">-&gt;</span>
</span><span class='line'>  <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">..</span><span class="mi">5</span><span class="p">]</span>
</span><span class='line'>    <span class="nx">closures</span><span class="p">[</span><span class="nx">i</span><span class="p">]</span> <span class="o">=</span> <span class="nx">do</span> <span class="nf">(i) -&gt;</span>
</span><span class='line'>      <span class="o">-&gt;</span> <span class="nx">alert</span> <span class="nx">i</span>
</span></code></pre></td></tr></table></div></figure>


<p>Even with this contrived example, I find the Coffeescript easier to read, although
of course it&#8217;s personal preference. If you wanted to go really crazy with Coffeescript
syntax, you could write:</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='coffeescript'><span class='line'>  <span class="nv">closures = </span><span class="p">((</span><span class="nx">do</span> <span class="nf">(i) -&gt;</span> <span class="o">-&gt;</span> <span class="nx">alert</span> <span class="nx">i</span><span class="p">)</span> <span class="k">for</span> <span class="nx">i</span> <span class="k">in</span> <span class="p">[</span><span class="mi">0</span><span class="p">..</span><span class="mi">5</span><span class="p">])</span>
</span></code></pre></td></tr></table></div></figure>


<p>Two points for cool implementation, no points for readability!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Classes in Coffeescript]]></title>
    <link href="http://rzrsharp.net/2011/06/21/classes-in-coffeescript.html"/>
    <updated>2011-06-21T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/06/21/classes-in-coffeescript</id>
    <content type="html"><![CDATA[<p>Javascript is a prototypal language, a concept which is quite challenging for
programmers coming from almost any other language.
The most well-known explanation of Javascript&#8217;s prototypal nature is
<a href="http://javascript.crockford.com/inheritance.html">written by Douglas Crockford</a>,
the famous author of <a href="http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742">the book Javascript: The Good Parts</a>.
Many Javascript libraries attempt to plaster class structures into the language,
but they all depend on varying amounts of magic which can make me slightly
uncomfortable.</p>

<p>To a certain extent, Javascript&#8217;s prototypal nature should be embraced; as a
developer begins to understand how prototypes work, they <a href="http://blog.izs.me/post/4731036392/evolution-of-a-prototypal-language-user">recognize their power over traditional class-based code</a>.
That said, classical inheritance wouldn&#8217;t be as popular as it is if it weren&#8217;t a
fantastic means of modeling real world objects, so it&#8217;d be nice to &#8220;map&#8221;
Javascript code cleanly to a classical style, without manipulating the language unnecessarily.</p>

<p>Enter Coffeescript&#8217;s <code>class</code> directive.</p>

<p>Coffeescript doesn&#8217;t add classes to Javascript. However,
Coffeescript <em>does</em> combine some syntactic sugar with code generation to allow
classical-style coding.</p>

<p>Observe the following Coffeescript:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class='coffeescript'><span class='line'><span class="k">class</span> <span class="nx">Ninja</span>
</span><span class='line'>  <span class="nv">constructor: </span><span class="nf">(@numOfShurikens) -&gt;</span>
</span><span class='line'>
</span><span class='line'>  <span class="nv">throwShuriken: </span><span class="o">-&gt;</span>
</span><span class='line'>    <span class="nx">@numOfShurikens</span><span class="o">--</span>
</span><span class='line'>
</span><span class='line'><span class="k">class</span> <span class="nx">Ronin</span> <span class="k">extends</span> <span class="nx">Ninja</span>
</span><span class='line'>
</span><span class='line'>  <span class="nv">constructor: </span><span class="nf">(numOfShurikens) -&gt;</span>
</span><span class='line'>    <span class="k">super</span> <span class="nx">numOfShurikens</span><span class="o">+</span><span class="mi">1</span> <span class="c1">#ronins know to carry a spare</span>
</span></code></pre></td></tr></table></div></figure>


<p>I find Coffeescript code to be quite readable, but if you&#8217;re completely unfamiliar
with the syntax, be sure to check out its <a href="http://www.coffeescript.org">fantastic documentation</a>.
So with the Coffeescript above, we&#8217;ve created two &#8220;classes&#8221;: a superclass, and a subclass
which modifies its parent&#8217;s constructor while inheriting a function. What I find
exciting about this example is that Coffeescript isn&#8217;t actually creating any &#8220;pseudoclass&#8221;
objects behind the scenes; it&#8217;s simply mapping existing Javascript concepts into
a more developer-friendly DSL.</p>

<p>Here, take a look at the generated JS:</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>
</pre></td><td class='code'><pre><code class='javascript'><span class='line'><span class="kd">var</span> <span class="nx">Ninja</span><span class="p">,</span> <span class="nx">Ronin</span><span class="p">;</span>
</span><span class='line'><span class="kd">var</span> <span class="nx">__hasProp</span> <span class="o">=</span> <span class="nb">Object</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">hasOwnProperty</span><span class="p">,</span> <span class="nx">__extends</span> <span class="o">=</span> <span class="kd">function</span><span class="p">(</span><span class="nx">child</span><span class="p">,</span> <span class="nx">parent</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>  <span class="k">for</span> <span class="p">(</span><span class="kd">var</span> <span class="nx">key</span> <span class="k">in</span> <span class="nx">parent</span><span class="p">)</span> <span class="p">{</span> <span class="k">if</span> <span class="p">(</span><span class="nx">__hasProp</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="nx">parent</span><span class="p">,</span> <span class="nx">key</span><span class="p">))</span> <span class="nx">child</span><span class="p">[</span><span class="nx">key</span><span class="p">]</span> <span class="o">=</span> <span class="nx">parent</span><span class="p">[</span><span class="nx">key</span><span class="p">];</span> <span class="p">}</span>
</span><span class='line'>  <span class="kd">function</span> <span class="nx">ctor</span><span class="p">()</span> <span class="p">{</span> <span class="k">this</span><span class="p">.</span><span class="nx">constructor</span> <span class="o">=</span> <span class="nx">child</span><span class="p">;</span> <span class="p">}</span>
</span><span class='line'>  <span class="nx">ctor</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="nx">parent</span><span class="p">.</span><span class="nx">prototype</span><span class="p">;</span>
</span><span class='line'>  <span class="nx">child</span><span class="p">.</span><span class="nx">prototype</span> <span class="o">=</span> <span class="k">new</span> <span class="nx">ctor</span><span class="p">;</span>
</span><span class='line'>  <span class="nx">child</span><span class="p">.</span><span class="nx">__super__</span> <span class="o">=</span> <span class="nx">parent</span><span class="p">.</span><span class="nx">prototype</span><span class="p">;</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">child</span><span class="p">;</span>
</span><span class='line'><span class="p">};</span>
</span><span class='line'><span class="nx">Ninja</span> <span class="o">=</span> <span class="p">(</span><span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>  <span class="kd">function</span> <span class="nx">Ninja</span><span class="p">(</span><span class="nx">numOfShurikens</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">this</span><span class="p">.</span><span class="nx">numOfShurikens</span> <span class="o">=</span> <span class="nx">numOfShurikens</span><span class="p">;</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>  <span class="nx">Ninja</span><span class="p">.</span><span class="nx">prototype</span><span class="p">.</span><span class="nx">throwShuriken</span> <span class="o">=</span> <span class="kd">function</span><span class="p">()</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="k">this</span><span class="p">.</span><span class="nx">numOfShurikens</span><span class="o">--</span><span class="p">;</span>
</span><span class='line'>  <span class="p">};</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">Ninja</span><span class="p">;</span>
</span><span class='line'><span class="p">})();</span>
</span><span class='line'><span class="nx">Ronin</span> <span class="o">=</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">__extends</span><span class="p">(</span><span class="nx">Ronin</span><span class="p">,</span> <span class="nx">Ninja</span><span class="p">);</span>
</span><span class='line'>  <span class="kd">function</span> <span class="nx">Ronin</span><span class="p">(</span><span class="nx">numOfShurikens</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>    <span class="nx">Ronin</span><span class="p">.</span><span class="nx">__super__</span><span class="p">.</span><span class="nx">constructor</span><span class="p">.</span><span class="nx">call</span><span class="p">(</span><span class="k">this</span><span class="p">,</span> <span class="nx">numOfShurikens</span> <span class="o">+</span> <span class="mi">1</span><span class="p">);</span>
</span><span class='line'>  <span class="p">}</span>
</span><span class='line'>  <span class="k">return</span> <span class="nx">Ronin</span><span class="p">;</span>
</span><span class='line'><span class="p">})();</span>
</span></code></pre></td></tr></table></div></figure>


<p>See? No weird manipulation of Object prototypes, creation of fake classes, anything
like that. Just proper Javascript. Still, I found some of the idioms here a little
confusing when I first started looking at generated Coffeescript code.</p>

<p>First, why are the &#8220;classes&#8221; implemented as self-executing functions? Coffeescript
is simply protecting the code against potential namespace violations. Everything that
happens within the Coffeescript &#8220;class&#8221; is actually executable Javascript code -
similar to how Ruby&#8217;s classes work, actually. The &#8220;class&#8221; that&#8217;s returned, then,
is really just your constructor function, its modified prototype, and any properties
attached to the function object. Pretty straightforward. The major downside with this
approach is that you can&#8217;t create any private variables! (Normally in JS you can hide a
pseudo-private variable within a constructor function&#8217;s closure, but Coffeescript&#8217;s
class implementation prevents this.) Coffeescript&#8217;s solution is to simply refer to
&#8220;private&#8221; variables with an underscore and hope developers act like adults, but I&#8217;m
guessing this open-mindedness will be tightened up a bit as Ecmascript 5 becomes
the standard.</p>

<p>But&#8230; what is that <em>mess</em> of generated code at the top? The first part is pretty
clear - just copy object properties from one &#8220;class&#8221; to another, so that (for example)
Ninja.belt will be inherited by Ronin.belt. And assigning a <code>__super</code> pointer to
the parent class is straightforward. But what is that &#8220;constructor&#8221; code?
Why not just point the &#8220;subclass&#8221; prototype to the parent prototype?</p>

<p>It turns out this approach is the cleanest means of maintaining the prototype chain
across functions. Since there&#8217;s only one prototype object for any function, simply
assigning <code>Ronin.prototype=Ninja.prototype</code> will share a single object instance, so
adding properties to Ronin&#8217;s prototype would actually also add properties to Ninja&#8217;s
prototype &#8211; they&#8217;d be the same object instance. By creating an intermediary
object, the prototype chain is kept intact while breaking any chance for incorrectly
shared state. Finally, all Javascript objects have a constructor property which
point to the &#8220;creator&#8221; function, whose initial value is determined by the object&#8217;s
prototype. The intermediary object (which serves as the
child&#8217;s prototype) thus gets a pointer back to the appropriate function.</p>

<p>Taken in full, Coffeescript&#8217;s &#8220;class&#8221; DSL demonstrates what I love most about the
language: distilling Javascript idioms into clean, readable, maintainable code, and
eliminating boilerplate, but avoiding any non-Javascript abstractions or manipulations.
It just can take awhile to fully understand what&#8217;s going on under the hood.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Note On Npm]]></title>
    <link href="http://rzrsharp.net/2011/06/06/a-note-on-npm.html"/>
    <updated>2011-06-06T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/06/06/a-note-on-npm</id>
    <content type="html"><![CDATA[<p>In the last week, I&#8217;ve been experimenting a greal deal with node.js and CoffeeScript. I&#8217;ve been thoroughly enjoying the node programming approach and the general &#8220;feel&#8221; of the CoffeeScript language (or really, dialect would be a better term, since CoffeeScript is really just Javascript). I&#8217;ll be writing much more about my experiments soon.</p>

<p>In the meantime, a quick note about getting up and running yourself. I&#8217;m using <a href="http://npmjs.org/">npm</a> to manage dependencies for my node projects. If you have an old version of npm sitting around, you should note that it handles the installation of depencies differently now than it did pre-1.0. <code>npm install "module"</code> defaults to installing the dependency in the local directory - which is fine for a particular project, but doesn&#8217;t help you when you want to invoke a module from the command line or use a version acorss multiple projects. Globally installing a module requires you to supply a &#8220;-g&#8221; argument: <code>npm install -g "module"</code>. You can learn more about the rationale for the change on <a href="http://blog.nodejs.org/2011/03/23/npm-1-0-global-vs-local-installation/">the node.js blog</a>.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[attr_accessor Shortcut in Ruby]]></title>
    <link href="http://rzrsharp.net/2011/06/01/attr_accessor-shortcut-in-ruby.html"/>
    <updated>2011-06-01T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/06/01/attr_accessor-shortcut-in-ruby</id>
    <content type="html"><![CDATA[<p>Pivotal Labs&#8217; blog provides one of the most consistent sources of quality code writing
in my RSS reader. Whether in their Daily Standup posts, or their longer-form articles,
I&#8217;m constantly finding tidbits of quality Ruby and JS code. A couple weeks ago, <a href="http://pivotallabs.com/users/jdean/blog/articles/1706-form-backing-objects-for-fun-and-profit">Jeff
Dean wrote a solid piece on breaking out your form logic</a> in Rails models and controllers. If you&#8217;re a
Ruby developer, you should read the post in entirety. What most stuck out to me, though,
was a little syntactic sugar that I hadn&#8217;t enountered before for stating your public
attributes:</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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="no">ATTRIBUTES</span> <span class="o">=</span> <span class="o">[</span><span class="ss">:name</span><span class="p">,</span> <span class="ss">:email</span><span class="p">,</span> <span class="ss">:terms_of_service</span><span class="p">,</span> <span class="ss">:anti_bot_question_id</span><span class="p">,</span> <span class="ss">:anti_bot_answer</span><span class="p">,</span> <span class="ss">:ip_address</span><span class="o">]</span>
</span><span class='line'>
</span><span class='line'><span class="kp">attr_accessor</span> <span class="o">*</span><span class="no">ATTRIBUTES</span>
</span></code></pre></td></tr></table></div></figure>


<p>I&#8217;ll definitely be adding that to my shortcut list.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Mark Zuckerberg Eats What He Kills]]></title>
    <link href="http://rzrsharp.net/2011/05/26/mark-zuckerberg-eats-what-he-kills.html"/>
    <updated>2011-05-26T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/05/26/mark-zuckerberg-eats-what-he-kills</id>
    <content type="html"><![CDATA[<blockquote> I don&#8217;t have an issue with anything people choose to eat, but I do think they should take responsibility and be thankful for what they eat rather than trying to ignore where it came from.<p><cite>&#8211;Mark Zuckerberg, on his new food philosophy.</cite></p></blockquote>
<p>Interesting article from <a href="http://postcards.blogs.fortune.cnn.com/2011/05/26/mark-zuckerbergs-new-challenge-eating-only-what-he-kills/">Fortune</a> (of all places) on Mark Zuckerberg&#8217;s approach to eating, which he adopted as a sort of New Year&#8217;s resolution. Zuckerberg is apparently only eating meat from animals he has slaughtered himself. (How this sort of thing registers as financial news, I have no idea.</p>
<p>According to the article, Mark adopts a challenge for himself every year, in order to improve himself and better his understanding of the world, and this year&#8217;s challenge was to come to terms with the food he eats. &#8220;[M]y personal challenge is around being thankful for the food I have to eat. I think many people forget that a living being has to die for you to eat meat, so my goal revolves around not letting myself forget that and being thankful for what I have,&#8221; Zuckerberg wrote to Fortune.</p>
<p>Software engineers have a (partially undeserved) reputation of being ignorant pigs when it comes to food - with snack rooms at many offices stuffed with Funyuns and Twinkies - so it&#8217;s great to see one of the world&#8217;s most prominent engineers (and a celebrity in his own right) so consciously investigate the source of his food.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Hello World]]></title>
    <link href="http://rzrsharp.net/2011/05/26/hello-world.html"/>
    <updated>2011-05-26T00:00:00-04:00</updated>
    <id>http://rzrsharp.net/2011/05/26/hello-world</id>
    <content type="html"><![CDATA[<p>So here I am, back to actually writing. I somehow managed to write consistently
for awhile <a href="http://razorsharp.tumblr.com">over on tumblr</a>, but I&#8217;ve only posted there
once in the last six months. There have been a lot of &#8220;I&#8217;ve been meaning tos&#8221; and &#8220;I
plan ons&#8221; and &#8220;I&#8217;m looking to starts&#8221; over that same period of time, so before the
holiday weekend I decided to adopt an agile attitude toward my blog: I shutup and
put the least implemented solution on the web. I had just a few requirements: working
links, readable text, and a functional RSS feed. I&#8217;ve hit all those, so look to see
an actual design implemented in the future, along with service hooks and all that
good stuff. But in the meantime: content! And no excuses for me not to provide content.</p>

<p>This IS the first time I&#8217;ve actually been comfortable with my blogging setup. I decided
to abandon a CMS entirely and start using <a href="http://jekyllrb.com/">Jekyll</a>, which is
basically just a static site generator written in Ruby. There&#8217;s some great benefits
to this approach:</p>

<ul>
<li>hosting of the site becomes a complete commodity: I&#8217;m on Github pages now, but could
switch to Heroku or my own host with practically zero work;</li>
<li>I own my content, and I don&#8217;t need to worry about it ever being lost or taken down;</li>
<li>all of my content is stored in Git, so I know it&#8217;s safe and version controlled;</li>
<li>styling is as easy as editing HTML and CSS, so there&#8217;s no constraints of a CMS
templating system;</li>
<li>I&#8217;m writing my posts in Vim, which may seem torturtous to some, but I&#8217;ve come to appreciate
its power and lack of visual distraction.</li>
</ul>


<p>Beyond these benefits, I also think that I did not truthfully represent myself on
my Tumblr blog. I posted content in an attempt to earn re-blogs, and thus &#8220;go viral&#8221;.
Beyond that, I self-edited in an attempt to prevent any post from accidentally being
reblogged and triggering a flame war. Here, I have no illusions of an audience; I recognize
that barely anyone will ever read this, and I&#8217;m completely fine with that. Instead, I
hope that the people who DO end up reading this site come away with helpful technical information,
solutions to vexing bugs, or the occassional good recipe. (Although I will be adding
Disqus comments at some point).</p>

<p>So welcome to version 3 of this blog. I look forward to my attempts at providing
some stimulating writing!</p>
]]></content>
  </entry>
  
</feed>

