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

  <title><![CDATA[Mad Ramblings of a Lunatic Hacker]]></title>
  <link href="http://blog.nuclearsandwich.com/atom.xml" rel="self"/>
  <link href="http://blog.nuclearsandwich.com/"/>
  <updated>2012-05-16T23:09:05-07:00</updated>
  <id>http://blog.nuclearsandwich.com/</id>
  <author>
    <name><![CDATA[Steven! Ragnarök]]></name>
    
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[How I Used a "Debugging Feature" of Pry to Build Cage]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/05/16/how-i-used-a-debugging-feature-of-pry-to-build-cage/"/>
    <updated>2012-05-16T21:57:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/05/16/how-i-used-a-debugging-feature-of-pry-to-build-cage</id>
    <content type="html"><![CDATA[<p><a href="http://pry.github.com">Pry</a> is an alternative interactive Ruby environment
similar to IRB. In addition to looking a little nicer through nearly live
colorization, Pry offers some pretty powerful features for exploring, modifying,
and debugging Ruby applications in a live system.</p>

<p>Pry&#8217;s namesake ability to &#8220;pry&#8221; open an object is not limited to debugging use.
It&#8217;s actually a really straightforward way to build any kind of domain specific
REPL. I think I just coined that term but it fits well and you&#8217;ll soon see why.</p>

<h2>The Backstory</h2>

<p>When I working at <a href="http://nowbox.com">NOWBOX</a> I spent a lot of time hitting our
API during ad-hoc testing. I was doing enough of this that just using curl
wasn&#8217;t cutting it.</p>

<p>Don&#8217;t get me wrong, curl is awesome and super useful. But it lacks a few
niceties. Chief among them curl, like HTTP, is stateless without the use of
cookie files and given that we were using a token-based authentication system,
simulating device-API interaction using exclusively curl was neither fun nor
easy.</p>

<p>During this time, we were also using
<a href="https://github.com/brynary/rack-test">Rack::Test</a>, which I really like. It&#8217;s a
solid and purposeful DSL and great at what it does. What it isn&#8217;t good at is
being interactive. I&#8217;d get colourful explosions(stacktraces) whenever I tried to
pry into and look at a test using <code>Rack::Test</code>.</p>

<p>We already had the awesome <a href="https://github.com/technoweenie/faraday">Faraday</a>
included in our project, so I hacked together a quick rake task that would set
up a <code>Faraday::Connection</code> and pry into it. What did this get me? I now had my
interactive <code>Rack::Test</code>.</p>

<h3>Cage Version -1</h3>

<figure class='code'><figcaption><span>Rakefile</span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">task</span> <span class="ss">:client_console</span> <span class="k">do</span>
</span><span class='line'>  <span class="nb">require</span> <span class="s2">&quot;faraday&quot;</span>
</span><span class='line'>  <span class="nb">require</span> <span class="s2">&quot;pry&quot;</span>
</span><span class='line'>  <span class="n">uri</span> <span class="o">=</span> <span class="k">case</span> <span class="no">ENV</span><span class="o">[</span><span class="s2">&quot;target&quot;</span><span class="o">]</span>
</span><span class='line'>        <span class="k">when</span> <span class="s2">&quot;production&quot;</span>
</span><span class='line'>          <span class="s2">&quot;http://api.superawesomepage.com/1/&quot;</span>
</span><span class='line'>        <span class="k">when</span> <span class="s2">&quot;staging&quot;</span>
</span><span class='line'>          <span class="s2">&quot;http://api.staging.superawesomepage.com/1/&quot;</span>
</span><span class='line'>        <span class="k">else</span>
</span><span class='line'>          <span class="s2">&quot;http://localhost:3000/1/&quot;</span>
</span><span class='line'>        <span class="k">end</span>
</span><span class='line'>  <span class="no">Faraday</span><span class="o">::</span><span class="no">Connection</span><span class="o">.</span><span class="n">new</span><span class="p">(</span><span class="n">uri</span><span class="p">)</span><span class="o">.</span><span class="n">pry</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<h2>Building the Gem</h2>

<p>Pry made this really easy. So easy that later on, when I wanted to rewrite the
above code and turn it into a reusable gem I kept the same strategy.</p>

<p>I build my DSL class, <code>Cage::Console</code>, which also handles all the initialization
such as config file loading and default values for variables. It also overloads
some of Pry&#8217;s settings to get a more interesting prompt string and suppressing
they default <code>~/.pryrc</code> config file loading.</p>

<figure class='code'><figcaption><span>lib/cage/console.rb</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>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">class</span> <span class="nc">Cage</span><span class="o">::</span><span class="no">Console</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">initialize</span> <span class="n">config_file</span> <span class="o">=</span> <span class="kp">nil</span>
</span><span class='line'>    <span class="n">configure_pry</span>
</span><span class='line'>    <span class="n">read_config_file</span> <span class="no">File</span><span class="o">.</span><span class="n">expand_path</span> <span class="n">config_file</span> <span class="k">if</span> <span class="n">config_file</span>
</span><span class='line'>    <span class="n">default_to_rubygems</span>
</span><span class='line'>    <span class="n">reinitialize_connection</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1">## The rest of the show</span>
</span><span class='line'>  <span class="c1">## ...</span>
</span><span class='line'>  <span class="c1">## The party starter</span>
</span><span class='line'>  <span class="k">def</span> <span class="nc">self</span><span class="o">.</span><span class="nf">start!</span> <span class="o">*</span><span class="n">args</span>
</span><span class='line'>    <span class="kp">new</span><span class="p">(</span><span class="o">*</span><span class="n">args</span><span class="p">)</span><span class="o">.</span><span class="n">pry</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>The rest of the class is the domain specific stuff that deals with delegating to
the Faraday connection object and building the response object. I built my own
wrapper around Faraday&#8217;s response so I could improve how they are displayed as
return values.</p>

<figure class='code'><figcaption><span>lib/cage/response.rb</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='ruby'><span class='line'><span class="k">class</span> <span class="nc">Cage</span><span class="o">::</span><span class="no">Response</span>
</span><span class='line'>  <span class="c1">## Delegating code</span>
</span><span class='line'>  <span class="c1">## ...</span>
</span><span class='line'>  <span class="c1">## Prettification code</span>
</span><span class='line'>  <span class="k">def</span> <span class="nf">inspect</span>
</span><span class='line'>    <span class="o">&lt;&lt;-</span><span class="no">PRETTY</span>
</span><span class='line'><span class="sh">Status: #{status}</span>
</span><span class='line'>
</span><span class='line'><span class="sh">Headers:</span>
</span><span class='line'><span class="sh">#{headers.map { |k, v| &quot;  #{k}: #{v}&quot; }.join &quot;\n&quot;}</span>
</span><span class='line'>
</span><span class='line'><span class="sh">Body:</span>
</span><span class='line'><span class="sh">  #{body}</span>
</span><span class='line'>
</span><span class='line'><span class="sh">#&lt;Cage::Response:(#{url})&gt;</span>
</span><span class='line'><span class="no">      PRETTY</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>It&#8217;s certainly verbose but the primary function is to show you the complete
result of an HTTP request, which it does.</p>

<h2>Concluding</h2>

<p>That&#8217;s  basically all there is to it. This feature of Pry that&#8217;s mainly
advertised as a way to get hands-on with your objects for debugging is also a
great way to build a domain specific or domain focused interactive environment.
Depending on how much you want to customize Pry&#8217;s interface you don&#8217;t even need
a thorough understanding of Pry&#8217;s internals. If you&#8217;re more interested in the
features <em>of</em> Cage than the mechanics of its construction you can install it
from RubyGems using <code>gem install cage</code> or check out its <a href="http://blog.nuclearsandwich.com/cage">project page</a>.
The complete source for Cage is on
<a href="https://github.com/nuclearsandwich/cage">GitHub</a>. I hope you use Pry and Cage
to build awesome stuff!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Jeff Atwood Misses the Point]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/05/15/jeff-atwood-misses-the-point/"/>
    <updated>2012-05-15T02:51:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/05/15/jeff-atwood-misses-the-point</id>
    <content type="html"><![CDATA[<p>Jeff Atwood wrote an article this morning called <a href="http://www.codinghorror.com/blog/2012/05/please-dont-learn-to-code.html">Please Don&#8217;t Learn to Code</a>.
He addresses some serious problems with the way we present programming to the
external world, which is probably comes from a desire to dress up what we do as
cooler than plumbing. But he goes a step too far telling people <em>not</em> to learn
something. Programming ability is not a ticket to a magical land of unicorns,
fairies and premier upper-middle class salaries. Programming is diverting,
challenging, and interesting. It&#8217;s a great thing to make a career out of, but
also a fantastic hobby. There are many reasons to learn to program no matter who
you are. I&#8217;ve been preparing that article for ages and will hopefully finish it
some time after I&#8217;ve calmed down. There is a difference between a software
developer (engineer, if you prefer) and someone who knows how to program. I can&#8217;t
speak for &#8220;the movement&#8221; although, I&#8217;m pleased as punch that there is one but I
can say that aside from being honest about how much I make writing software and
how I learned what enables me to earn that I have never told someone the reason
to learn programming was to rake in the cash.</p>

<h4>The Mayor Learns to Program</h4>

<p>His opening remarks jab at the Mayor of New York&#8217;s supposed new year&#8217;s
resolution to learn to code suggesting we&#8217;d end up with</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>10 PRINT "I AM MAYOR"
</span><span class='line'>20 GOTO 10</span></code></pre></td></tr></table></div></figure>


<p>If Mayor Bloomberg gets that far, it would actually be awesome. I&#8217;m not
suggesting he spend his mayoral days learning Javascript but everyone has
nights, weekends, and hobbies. I&#8217;m sure the mayor of New York can afford to have
quite a few.</p>

<p>Mr. Atwood, I don&#8217;t want everyone to become a crack Java developer. I wouldn&#8217;t
wish that on my worst nemesis. What I want is for anyone with even a passing
interest in how computer software works to have access to tools and materials
they need to learn more about it as they please. And we don&#8217;t have that yet.
<a href="http://codeacademy.com">CodeAcademy</a> is doing an excellent job getting us closer and should be
applauded for doing so.</p>

<h4>Programming as a Life Skill</h4>

<blockquote><p>It is obvious to me how being a skilled reader, a skilled writer, and at least
high school level math are fundamental to performing the job of a politician.
Or at any job, for that matter. But understanding variables and functions,
pointers and recursion?</p></blockquote>

<p>Here you&#8217;re comparing big things (reading, writing, and mathematics) to little
things (variables, pointers, and functions). The individual concepts are of
little importance the same way homophones and perfect grammar are of little
importance. But how deeply can you trust a politician&#8217;s reasoning about software
and technology if they lack even a basic understanding about how that computer
works. There&#8217;s a startling <em>lack</em> of digital literacy among people outside of
software engineering and there are people trying to break down those barriers
and get the interesting and <em>relevant</em> information out there in understandable
ways.</p>

<p>Programming is absolutely not on the same level as reading or arithmetic
however, does your argument for not teaching it in schools then extend to arts
and music? Surely they are not as basic a skill as reading and arithmetic yet we
still perceive some value in teaching them to children.</p>

<p>You said yourself that a software developer&#8217;s job is to solve problems. Well
what is a JavaScript interpreter but an abstract problem solving sandbox? Is
there a specific reason you <em>don&#8217;t</em> want problem solving to be a general skill?
Are you frightened of our field losing status as the only problem solvers?</p>

<p>The critical thinking skills that I started developing when I started learning
to code are what sustain me both physically and mentally. I would love to be
teaching these skills in elementary school for that reason alone. Programming is
engaging, and while it won&#8217;t engage everyone, we should at least be providing
the same opportunities we used to afford music, art, and wood shop. How many
people who took wood shop in high school went on to become carpenters? Probably
not many. But how many gained some level of appreciation for the craft? I&#8217;m sure
that number is far higher. I didn&#8217;t have wood shop at my high school, but I was
fortunate in that my father, uncle, and grandfather all work with wood in
various capacities and that allowed me to see how enjoyable and creative the
process is.</p>

<h4>In Which We are Likened to Plumbers</h4>

<blockquote><p>I can also recognize plumbing problems when I see them without any
particular training in the area.</p></blockquote>

<p>Yes, it doesn&#8217;t take a plumber to notice a clogged toilet. Just like it doesn&#8217;t
take a web developer to recognize that <code>404 Not Found</code> or <code>500 Internal Server
Error</code> means something went wrong but can you do anything about that clog
without a plunger? And where did you learn to use it? Unless you were born with
the knowledge of the existence and use of plungers, someone showed you how to
use it. That&#8217;s all I&#8217;m advocating here. Teach everyone to use the plungers of
coding. It&#8217;s interesting to remark however, that there is very little someone
with a programming plunger can fix.  It takes so much more to get any real work
done. So why bother? A little bit of understanding never killed anyone and
you&#8217;ll have at least some basic understanding of what your programmer is doing
for you if you know how tough it is to</p>

<h4>Wrapping Up</h4>

<p>I&#8217;m about to arrive in my last operating systems class of the year, so I need to
go and I want to publish this while I&#8217;m still caffeinated and disappointed
enough to go head-on against one of the authors and developers whom I deeply
respect. Much of your argument is extremely valid and the &#8220;everyone should
learn programming&#8221; {initiative,movement,meme} should accept this criticism,
which I do, and synthesize it so that we can better reach our goal.</p>

<p>However, you&#8217;ve thrown the baby out with the bathwater in your haste to put a
stop to misinformation and are losing a really powerful way to engage inquiring
minds of all ages with a deeply interesting and modern art, computer
programming.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Stop Counting Your Points]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/05/09/stop-counting-your-points/"/>
    <updated>2012-05-09T14:51:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/05/09/stop-counting-your-points</id>
    <content type="html"><![CDATA[<p>I walked into class yesterday afternoon where my professor teaches, back-to-back, a
section of upper division Data Structures and Algorithms followed by my section
of Formal Languages and Automata. On Monday, both classes had an exam. (Not my
best I&#8217;m afraid, I spent the weekend at
<a href="http://farmhouse.la/conf">FarmhouseConf</a> rather than studying. Worth it.) I
arrived to class today and overheard a familiar story as the last class was
leaving. A student was contesting his score on a particular problem. The
crux of his reasoning was that while he <em>was</em> wrong, he &#8220;felt&#8221; he &#8220;earned more
points&#8221; than what was recorded. I&#8217;m normally not a fan of the air-quotes for
emphasis or sarcasm, but in this case they were also the exact words used by the
student in question.</p>

<p>There&#8217;s something odd about people who pay attention to the points rather than
what they learned. I will be the first to jump in and bitch about how much I pay
for tuition but also freely admit that I pay far less than an out-of-state or
private school student. School is fucking expensive. So why? Why why why why
<em>why?</em> would you haggle over how many points you &#8220;earned&#8221;, when you can and
should be figuring out what you didn&#8217;t learn which cost you those points. On
tests where I do poorly, I often spend about as much time trying to figure out
what I did wrong as I did taking the test in the first place. I&#8217;m also a really
shitty student. I elect not to take notes and I am presently writing the first
draft of this post in class while something I already know is being reviewed.</p>

<p>Situations like this one baffle me, but also emphasizes that there&#8217;s no metric I
can use other than day-to-day individual progress to represent the achievements
of my students lest they (or I) become fixated on the metric. I keep incredibly
detailed notes about the individual skills and weak points of anyone who I
regularly teach or mentor, but I neither have nor will try to grade or rate
them. Why fixate on numerals when you could fixate on learning new stuff?</p>

<p>The vocabulary choices of this student remind me of something my seventh grade
history teacher talked about on the first day of school. Which is the subtle and
subconscious vocabulary choices of students when discussing grades. &#8220;I got an A.
I got an A. He <em>gave</em> me an F.&#8221; It&#8217;s only human to want to take credit for our
achievements while marginalizing our failures. I have certainly been guilty of
this in the past. I have <strike>been given</strike> achieved three failing
grades in my life, two in high school and one in college.</p>

<ul>
<li><p><em>I earned</em> an F in second semester Geometry because I failed to find the
subject interesting and couldn&#8217;t be arsed to do the homework or get up before
7AM to get to class on time.</p></li>
<li><p><em>I earned</em> an F in second semester American History because I elected to take
no notes in spite of the fact that our notebooks were going to be collected
and graded.</p></li>
<li><p>Incidentally, the one college course I failed was an online Jazz History
course during a winter session. I failed because I completely forgot I
registered. I never signed in or even thought about it until it showed up on
my transcript.</p></li>
</ul>


<p>I don&#8217;t look too far down on this guy though. When <em>I</em> was taking the very same
Data Structures class, albeit with a different professor, we were required to
submit our assignments online to a system which auto-grades our programming
assignments by running our own JUnit tests, and analyzing them for coverage. As
well as JUnit tests written by our professor on our code. One thing the system
did that I absolutely hated was run Checkstyle with the official SJSU Java Style
guidelines encoded in XML. Well, this style guide was written before Java had
Generics and had never been updated. So Checkstyle threw a fit when I had
<code>Node&lt;E&gt;</code> instead of <code>Node &lt; E &gt;</code>. In order to get it to shut up (and claim the
final five points on the assignment) I had to ruin my code with this offensively
spaced style.</p>

<p>I mentioned this to the professor and he suggested that it was always an option
to sacrifice those points in the name of doing things right and grades be
damned. Since then, I&#8217;ve submitted plenty of assignments that don&#8217;t precisely
meet specification. Mostly I get docked because I don&#8217;t include Eclipse project
files with my source code which means the professors have to find the command
line and run Ant (I also provide Makefiles). In any case, it was eye opening to
hear a professor give me permission to get a less-than-optimal score simply
because something else is more important.</p>

<p>So stop counting your points and start making sure you learn. Besides, learning
is more fun.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Two Reviews: The Developer's Code and Code Simplicity]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/04/10/two-reviews-the-developers-code-and-code-simplicity/"/>
    <updated>2012-04-10T01:59:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/04/10/two-reviews-the-developers-code-and-code-simplicity</id>
    <content type="html"><![CDATA[<p><strong><em>Disclaimer</em></strong>: I am affiliated with neither O&#8217;Reilly nor Pragmatic Press and
have received no special discounts or compensation beyond the regular sales they
make available to the general public.</p>

<p><em>That is all</em></p>

<p>Recently I&#8217;ve read two really excellent books. <a href="http://pragprog.com/book/kcdc/the-developer-s-code">The Developer&#8217;s Code</a> by Ka
Wai Cheung, and <a href="http://www.codesimplicity.com/">Code Simplicity</a> by Max Kanat-Alexander. I should start off
by saying that they were both great (and short!) reads and I&#8217;d recommend either
of them to anyone. Particularly young developers still getting their first five
years&#8217; experience(1). Though I&#8217;ve been reading a <a href="https://trello.com/board/i-heart-books/4e7238ede06bdd000002d5e1">fair few</a> books in between
these two, something about them struck me as similar. Given that it&#8217;s been
months since I read The Developer&#8217;s Code and no review materialized, I figured
I&#8217;d give some brief words about each book now.</p>

<h2>The Developer&#8217;s Code</h2>

<p>This book is aimed at younger developers, or even folks who haven&#8217;t yet decided
to become software developers. It gives a pretty good overview of the industry
in which we work and how it&#8217;s perceived. The author seems utterly enamored with
code generation and found a way to bring it up in nearly every chapter. I&#8217;m not
really a fan of it at all unless it&#8217;s the runtime kind of code generation.
However, it&#8217;s largely incidental to the work as a whole. Lastly, chapter 6
discusses teaching and <em>every single one of you must read it now</em>. It&#8217;s not
even eight pages and yet he collects a handful of techniques it has taken me
more seven years of instructing(2) to be able to put to words. The book was
worth the full price to see these words written in front of me. If you need to
borrow it, let me know. <a href="http://twitter.com/sgharms">@sgharms</a> has my copy right
now.</p>

<h2>Code Simplicity</h2>

<p>I will admit to buying this book as an impulse buy because the ebook was
half-off on <a href="http:///oreilly.com">O&#8217;Reilly.com</a>. I&#8217;m ever so glad I did though
as it&#8217;s been a very easy and enjoyable read. At first I felt the method of
describing the author&#8217;s observations as Laws was considerably presumptive
behavior. However, like the laws of gravity and motion in the physics world, the
precise wordings have genericity<a href="https://en.wikipedia.org/wiki/Generic_property">(3)</a> and a timeless quality. One of the
stand-out aspects of this book to my mind was the complete absence of software
testing until the very last law of the book. I was impressed by this because as
I&#8217;ve <a href="http://blog.nuclearsandwich.com/blog/2011/10/28/there-are-10-types-of-tests-you-need-both-of-them/">written before</a>, testing is not itself an end, it is a means to the end
of successful, quality software that performs its duty of helping people.
Throughout the book there is discussion of evidence and verification, from which
testing should arise naturally. While I respect the author&#8217;s desire to add a
specific law of software testing, I think it could be omitted as a duplicate in
a <a href="http://youtu.be/p-RGN21TSGk">George Carlin-esque</a> fashion.</p>

<p>Thanks for your eyes,</p>

<p>Steven!</p>

<p><strong>(1)</strong> I&#8217;m talking <em>real</em> experience. Not LOL I was writing C64 machine language in
the womb by tugging on the umbilical cord in binary Morse code.</p>

<p><strong>(2)</strong> When I was sixteen, I was reassigned from lifeguarding to teaching
photography at the boy scout camp where I was working. I had no idea at the
time, but the shake-up resulted in the discovery of two of the great passions in
my life, photography and teaching. I went on in subsequent years to teach
lifeguarding, teach teaching lifeguarding, and now teach programming and
software development to whomever I can.</p>

<p><a href="https://en.wikipedia.org/wiki/Generic_property"><strong>(3)</strong></a> Using the mathematical definition of &#8220;nearly always holds true.&#8221;</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bound by our Past]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/04/04/bound-by-our-past/"/>
    <updated>2012-04-04T20:43:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/04/04/bound-by-our-past</id>
    <content type="html"><![CDATA[<p>I was about to ask a question on Identi.ca and Twitter, when I realized I would
probably be flamed into oblivion if I didn&#8217;t explain myself in more than 140
characters.</p>

<p>My question: <strong>Why are we still typing <code>rake db:migrate</code> instead of <code>rails
db:migrate</code>?</strong></p>

<p>Before you scoff and walk away. Hear me out. I <em>get</em> that Rake is a more general
tool than Rails and we can use it to automate all sorts of cool tasks. In fact
I&#8217;ve been using Rake to do all kinds of bonkers stuff in my projects since I
first started learning Ruby. Teaching at <a href="http://railsbridge.org">RailsBridge</a> this weekend, I had a
surprisingly high number of students ask &#8220;What is rake?&#8221;. I was really happy
when I got this question so much because it means that they&#8217;re actually thinking
about what they&#8217;re typing, which is hugely important. Each time it was asked, my
smile quickly faded. What should I tell them. &#8220;Rake is Ruby&#8217;s Make, It&#8217;s like
make but in Ruby.&#8221; would work for anyone who has been using or programming UNIX
for any significant amount of time, but for many Railsbridge students (and many
people learning Rails), Ruby is what will expose them to all of that, so we
can&#8217;t use it as the base of our teaching metaphor(1).</p>

<p>I settled for &#8220;Rake is a tool for automating common tasks in a project. The name
comes from a program called make, but since Rake is written in Ruby, it&#8217;s Rake.&#8221;</p>

<p>While my students seemed satisfied with that answer, I sure wasn&#8217;t. The whole
purpose of Railsbridge is to demystify programming and software development.
We&#8217;re not trying to build an army of new software developers (but I&#8217;d love to),
just trying to grant people some basic coding literacy and comfort. Trying to do
this in an environment where some commands start with <code>rake</code> (assets:precompile
is another culprit) and others with <code>rails</code> and the only way to know which is to
be in the club already or have someone tell you is suboptimal.</p>

<p>So, developers, why are Rails&#8217;s built in Rake tasks still Rake tasks and should
we start the discussion of baking them into the Rails command for Rails 4.0?
Without a better answer than &#8220;it&#8217;s always been that way&#8221;, I think we should.</p>

<p>(1) More information and musings on them forthcoming.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[On Learning: Making and Checking Assumptions]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/04/02/on-learning-making-and-checking-assumptions/"/>
    <updated>2012-04-02T10:38:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/04/02/on-learning-making-and-checking-assumptions</id>
    <content type="html"><![CDATA[<p>With increasing frequency, I&#8217;ve been afforded the opportunity to teach people
who are completely new to programming and this inevitably leads to me espousing
my preferred method for learning anything: Making an assumption and verifying or
refuting it through experimentation.</p>

<p>Yesterday I had the pleasure of teaching two fantastic burgeoning developers the
concept of method composition in Ruby. For experienced developers, it is as
natural as breathing, but too often our memories of our early programming
experiences are clouded over with the same terror we see in the eyes of our
students.</p>

<p>At almost every stage there were simple questions, questions it would have taken
me seconds to address had I given a direct answer. But learning to program (or
do much else) needs to go deeper than just assembling facts. In order to do
well, we have to have our own mental interpreters and compilers and process the
code in our minds. The sooner we start developing this trait in new programmers,
the better off they&#8217;ll be. So my general answer was</p>

<blockquote><p>&#8220;Well, what do you <em>think</em> will happen?&#8221;</p></blockquote>

<p>Queue audience groan. By asking this ad nauseum and forcing them to give me an
answer before hitting enter, I&#8217;m contributing in a real way to building their
mind&#8217;s Ruby interpreter.</p>

<p>If this sounds eerily like the <a href="https://en.wikipedia.org/wiki/Scientific_method">scientific method</a>, that&#8217;s because it is! We
just condensed it for tiny, one or two line experiments in Ruby!</p>

<h2>Not Just for N00bs</h2>

<p>I&#8217;ve finally started reading <a href="http://mitpress.mit.edu/sicp/">SICP</a> and one of the very first exercises
revealed one of my achilles&#8217; heels.</p>

<p>I was asked to give the value of the evaluated expression below:</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class='scheme'><span class='line'><span class="p">(</span><span class="nb">- </span><span class="mi">9</span> <span class="mi">1</span><span class="p">)</span>
</span></code></pre></td></tr></table></div></figure>


<p>I can <em>never</em> remember what this shakes out to. Is it <code>9 - 1 = 8</code> or <code>1 - 9 =
-8</code>? I didn&#8217;t know off the top of my head. But before I fired up Racket to see
what the answer was, I forced myself to make a guess. Would it be 8, or -8? My
guess was 8.</p>

<p>Only after forming that hypothesis did I throw that expression into an
interpreter.</p>

<p>As it turns out, it does evaluate to <code>8</code>. <strong><em>Assumption Verified! A winner
is me!</em></strong> Would it have mattered if I&#8217;d been wrong? Not really, I would have
learned the same lesson.</p>

<p>The rise of <a href="https://en.wikipedia.org/wiki/Test-driven_development">Test Driven Development</a> is actually the rise of the application
(in a very minor and partial way) of the scientific method in Software Engineering.
We&#8217;re making assumptions about the goals (end-to-end tests) and design (unit
tests) of our software and codifying them in form of our tests. These get
challenged and verified or refuted whenever we run our tests. As our software
changes, so do our hypotheses around it.</p>

<p>So regardless of whether you&#8217;re writing code for the first time, or a veteran
software developer, take the advice of John and John of They Might Be Giants,
<em>you need a test</em>.</p>

<iframe
    width="640" height="480"
    src="http://www.youtube.com/embed/9kf51FpBuXQ?rel=0"
    frameborder="0" allowfullscreen>
</iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Santa Clara Swarm Coding]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/03/20/santa-clara-swarm-coding/"/>
    <updated>2012-03-20T21:53:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/03/20/santa-clara-swarm-coding</id>
    <content type="html"><![CDATA[<p><a href="http://clojurewest.org">Clojure/west</a> was last weekend. Needless to say it was a blast! I learned a
ton and as ever, am totally charged up and excited to hack on a bunch of crazy
ideas. One of the highlights of the weekend was participating in the Swarm
Coding event led by <a href="https://github.com/technomancy">@technomancy</a>. If you were in the rogue Vim group I was
hosting, I did eventually get the source up on GitHub <a href="https://github.com/nuclearsandwich/vimswarm">here</a>.</p>

<p>For others, is anyone interested in attending a South Bay Area Swarm Coding
night once every couple of weeks or so? Since I&#8217;m the one putting it forward, I
suggest we go somewhere in Santa Clara (I have a number of ideas as to where)
but I&#8217;m also open to other areas so long as they don&#8217;t crawl too far North. It&#8217;s
not that I don&#8217;t love San Francisco but it&#8217;s hard to get up there with school.</p>

<p>If anyone is interested, I&#8217;m attempting to schedule the first one for some night
the week of April 1st through 7th. If you&#8217;re not sure what Swarm Coding is,
check out Phil&#8217;s <a href="https://github.com/technomancy/clojurewest2012-slides/blob/master/Hagelberg-SwarmCoding.pdf?raw=true">slides (pdf)</a> from Clojure/west. In short, everyone logs into a
shared tmux session running either Vim or Emacs and all collaborate on a
project.</p>

<p>Don&#8217;t be disuaded if you&#8217;ve never programmed in Clojure before, it&#8217;s actually a
really fun way to learn no matter what your initial skill level is. If there&#8217;s a
quorum of newcomers, we can also do a session on tooling before diving into the
code.</p>

<p>Does this sound like the best idea? I haven&#8217;t bothered to set up a mailing list
or anything so if you&#8217;re interested hit me up on <a href="https://identi.ca/nuclearsandwich">Identi.ca</a>, <a href="https://twitter.com/nuclearsandwich">Twitter</a>, or
good old <a href="mailto://steven@nuclearsandwich.com">email</a> and let me know which day of the week works best for you.
Then I&#8217;ll cast the information back out to everyone.</p>

<p>Come on out and have fun making Clojure stuff!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Good Eats and Drinks for Clojure/west]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2012/03/14/good-cheap-eats-for-clojure-slash-west/"/>
    <updated>2012-03-14T11:19:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2012/03/14/good-cheap-eats-for-clojure-slash-west</id>
    <content type="html"><![CDATA[<p>Clojure/west is only feeding us lunch on Friday. That leaves us to our own
devices for Friday&#8217;s dinner, after-after-party drinks, Saturday&#8217;s lunch,
dinner, and drinks.</p>

<p>Furthermore, Clojure/west&#8217;s website lists the official guide from the city of
San Jose, which includes a lot of duds and places far away from the conference
venue. There&#8217;s not much I like about Downtown San José but the few things I do
enjoy are places to eat and drink.</p>

<p>For the impatient, <a href="http://g.co/maps/r8kcf">here&#8217;s the map</a> of everything.</p>

<p>As a student at San José State, I spend a lot of time in this part of town and
have compiled a short list of places to eat and drink while you&#8217;re in town for
the conference. If you&#8217;re venturing further afield than downtown or just want to
hang out. I exist on the Twitters as
<a href="https://twitter.com/nuclearsandwich">@nuclearsandwich</a></p>

<p>I&#8217;ve included below a description of my usual haunts and a like to Google&#8217;s
walking directions from the conference hotel.</p>

<h3>Good Karma</h3>

<p>To my mind, <a href="http://g.co/maps/j342r">Good Karma</a> is the best food in Downtown
San José. Yes it&#8217;s a vegan restaurant but the food is stellar. They have a
selection of entrées such as Spicy Basil Tofu and Chana Masala which they serve
on a plate with brown rice and house gravy, or in a wrap. The spicy basil tofu
and Pra-Ram are my favorites at the moment. The other best thing about Good
Karma is their amazing beer selection. Even if you don&#8217;t make it out for the
food, treat yourself to a good beer. I wrote most of this article from Good
Karma. If you&#8217;re an IPA fan, Good Karma currently has a host of exceptional IPAs
including Russian River&#8217;s Pliny the Elder, one of my favorites in the genre.</p>

<h3>La Lune Sucrée</h3>

<p><a href="http://g.co/maps/6ckzq">La Lune Sucrée</a> only opened up recently. It&#8217;s above
average for a student&#8217;s lunch and I generally consider coming here a treat. They
have a number of French staples such as croque-monsieur which I cannot speak
toward, but their Apple and Brie (with ham if you want it) sandwich has walnuts
and cranberries and is quite yummy as is the vegetable quiche. They also have
one of my favorite ginger ales but it comes in massive one liter bottles.</p>

<h3>Single Barrel</h3>

<p><a href="http://g.co/maps/sh5mk">Single Barrel</a> is cocktail heaven. Your first drink
here, you&#8217;re not allowed to order from the menu and you&#8217;ll probably never want
to. Instead your bartender is going to ask you what sort of flavors you enjoy
and through a serious of questions, arrive at a cocktail that suits you well.
Come in the mood to relax and take your time with the drinks here as they aren&#8217;t
cheap. Also be warned that they don&#8217;t take groups larger than six since it is a
speakeasy in a low-ceilinged basement. They have chess, checkers, Connect Four,
and Scrabble so long as you keep the volume down.</p>

<h3>Tandoori Oven</h3>

<p><a href="http://g.co/maps/x6md8">Tandori Oven</a> is mostly here because some of you won&#8217;t
want to eat at Good Karma for every meal. I&#8217;ve eaten here once or twice and
never been disappointed, but there&#8217;s better Indian closer to where I live so
this restaurant is not in my regular rotation.</p>

<h3>Satori Tea Bar</h3>

<p><a href="http://g.co/maps/2bv9c">Satori Tea Bar</a> isn&#8217;t a place to eat lunch or dinner
and the hours are quite restricted. However, if you need to take a break and go
somewhere quiet and contemplative where you can drink delicious oolongs and rare
greens or try the delicious guayusa, which is similar to yerba mate but sweeter.</p>

<p>A quick stop at Satori for tea to go would also be nice walking back from the
Mmmoon</p>

<h3>The Mmmoon</h3>

<p>Despite its silly name, <a href="http://g.co/maps/shze2">The Mmmoon</a> makes really
delicious empanadas both sweet and savory. The sauce they use is quite unique
and although I&#8217;ve seen it in a number of other empanada restaurants throughout
the Bay Area, this is the best one I&#8217;ve had. Lunch here can be cheap and
filling. They also deliver within five miles of their location which includes
the conference venue.</p>

<h3>Grande Pizzeria</h3>

<p>I&#8217;ve only eaten at <a href="http://g.co/maps/nxcpq">Grande</a> because the school regularly
hosts mixers with IBM, Cisco, and NetApp here. The pizza is alright and they
have a few &#8220;good enough&#8221; beers and an inexpensive happy hour that coincides with
the dinner break.</p>

<h3>La Victoria</h3>

<p>This is the quintessential college eatery. The food here won&#8217;t be great, but
when you&#8217;re starving at 2AM it will be a feast. Their orange salsa is also raved
about but I don&#8217;t think much of it. I tend to avoid
<a href="http://g.co/maps/jez57">La Vic</a> because the food is only &#8220;vegetarian&#8221; if you&#8217;re
willing to apply large double quotes to the term.  It made the list because
you&#8217;ve not properly been to Downtown San José until you&#8217;ve been to La Victoria.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Sightread Your Code]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/11/29/sightread-your-code/"/>
    <updated>2011-11-29T09:50:00-08:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/11/29/sightread-your-code</id>
    <content type="html"><![CDATA[<p><em>Sightreading is an essential skill for any musician. Turns out it&#8217;s pretty
important for good software developers as well.</em></p>

<h2>What is Sightreading?</h2>

<p>I&#8217;ve been listening to a ton of <a href="http://rubyrogues.com">Ruby Rogues</a>, so let&#8217;s begin with a
definition.</p>

<p>From Wikipedia,</p>

<blockquote><p> <strong>Sightreading</strong> <em>is the reading and performing of a piece of written music,
specifically when the performer has not seen it before.</em></p></blockquote>

<p>Musicians are always evaluated on their ability to read and interpret musical
scores on command, a musician&#8217;s time isn&#8217;t cheap and rehearsing a specific piece
of music is a privilege reserved often reserved for school ensembles and AAA
film score recordings. I exaggerate a little, but honestly, professional
musicians are not afforded a lot of rehearsal time. They are instead expected to
walk up to a piece, play their bit expressively while fitting in with the rest
of the ensemble perfectly, sometimes without ever hearing them.</p>

<p>If you&#8217;re wondering how on Earth this could possibly relate to software, look no
further than your first day on your current project. Most software developers
don&#8217;t have the privilege of starting from scratch when they begin a new job or
contract.  Instead we are thrown into an existing one and expected to decrease
the bug count. Some people might say that&#8217;s an unfair expectation, but it is, in
fact, no different from expecting a professional musician to walk into the
studio, read your score, play their piece once or twice, then collect their
check and leave.</p>

<p>Western music has a complex but accepted system of notation that all musicians
and composers are expected to be familiar with. On top of this base language
there are sets of idioms particular to certain genres. By writing works in this
language and leveraging (often subconsciously) these idioms composers create
music that musicians can read and follow and interpret even <em>as</em> they play.</p>

<p>In the case of software development, the language and idioms are still present,
but they are the languages and idioms of computer programs rather than those of
western music.</p>

<h2>Sightreading Code</h2>

<p>So what&#8217;s the point of sightreading code? Here&#8217;s three scenarios from every
stage of one&#8217;s career.</p>

<ol>
<li>You&#8217;re fresh out of University and in a technical interview. You&#8217;ve been
  asked to find and fix the two known bugs in a text formatting program.</li>
<li>You&#8217;ve just started your first day at a new job and you&#8217;ve been tasked with
  extending an existing project with new features.</li>
<li>You&#8217;re a super celebrity master contractor and people pay you way too much
  money. You walk up to code you&#8217;ve never seen before and need to make magic
  happen in order to justify your absurd cost.</li>
</ol>


<p>In each case your value hinges on picking up a brand new codebase and running
with it. Since you can&#8217;t control the quality of code you didn&#8217;t write you can&#8217;t
make any excuses regarding what&#8217;s already written. At this point you have two
options. Skim the code, or read it all.</p>

<p>I will tell you right now, <strong>skimming doesn&#8217;t work.</strong> You can&#8217;t read every other
line or seek for specific variable names and actually follow what is going on.
When you do so, you screw it up.</p>

<p><em>Disclaimer: Slight boorishness follows</em></p>

<blockquote><p>If you ask me a question about my code, I&#8217;m going to assume you&#8217;ve read every
relevant line.</p></blockquote>

<p>Relevant lines are tough to pin down, but at the very least the entire method in
question is a good start. When you haven&#8217;t done so, it&#8217;s plain disrespectful and
arrogant on your part, especially when your question is answered (or nullified)
by something directly in that body of code. By skimming and then bringing up
something you saw during the skim, you waste your time and mine.</p>

<p>Everyone who has taught me up until a year ago will roll their eyes at me for
this because I was the best at skimming (meaning I was the worst reader/pupil) I
actively avoid jumping to conclusions about what I read and take a concerted
effort to answer as much as I can on my own before escalating a problem.
Furthermore, when I do I often have a much better handle on what question I am
asking than I would otherwise have had.</p>

<p>In all seriousness, when you do this I start to think about spending less time
with you. I warn everyone I&#8217;m comfortable warning not to skim <strong><em>ever</em></strong>.
Including you, dear reader.</p>

<p>Since skimming code doesn&#8217;t work, our only remaining option is to actually read
the code completely. This probably sounds like a lot of work, that&#8217;s because it
is, but so is reading and performing an entire ten minute piece in half an hour
and musicians still manage to get it done.</p>

<p>In order to determine how we can become more effective code sightreaders, we
again look to our musician friends who have been doing this for some time.
Musicians who want to improve their sightreading do the following things.</p>

<h3>Musicians Know and Practice Scales</h3>

<p>Musicians who practice their scales are the ones with the best technical chops,
their fingers are the most agile, their articulation superb and they&#8217;re
comfortable with any given set of notes.</p>

<p>For programmers who wish to improve sightreading, there&#8217;s simple no replacement
for knowing the language you&#8217;re in. If you&#8217;ve never looked at C before, you&#8217;ll
spend 20 minutes figuring out what <code>int main() {</code> is, or spend that time
figuring out the precise semantics of a line ending conditional in Ruby.</p>

<p><em>If you don&#8217;t know the language, you&#8217;ll spend time figuring out what the
language is doing instead of what the program is doing. Know your language.</em></p>

<h3>Musicians Study Music Theory</h3>

<p>Every musician who works with written music needs at least a basic understanding
of music theory. Without it, reading music, let alone interpretting it, is
impossible. Over time many musicians gain an intuitive understanding of theory.
They realize all major scales are the same but starting from a different note,
then slowly absorb more as they go. But some of the best musicians actively
learn theory as theory and can leverage that to do amazing things as Jazz
improvisers, composers, and virtuosos.</p>

<p>As computer scientists, we need to know the design patterns used in our field.
Decorators, strategies, delegation, they all need to be second nature if we
intend to approach a new body of code and immediately see what&#8217;s going on.
Additionally, these patterns establish a common vocabulary you can use to
discuss code with other programmers regardless of their language and experience.
If you both know the patterns, they can add precision and expressiveness to your
non-executable communication.</p>

<p><em>Knowing patterns allows you to see and apply them instantly when you enter a
new codebase or team. Use them as a common vocabulary.</em></p>

<h3>Musicians Sightread During Practice</h3>

<p>Lastly, and hopefully most obviously, musicians practice the act of sightreading
during their own self-directed practice. My high school band director, once said
to our ensemble that if you do something for the first time during the show,
you&#8217;re practicing in front of a live audience, not performing.</p>

<p>Likewise, don&#8217;t assume that if you know your languange and some patterns you&#8217;ll
be an extraordinary sightreader. You need to apply that knowledge frequently if
you want to temper it into skill. Trust me, you do <em>not</em> want to do it on the
job your first few times. If you do, you&#8217;ll likely feel rushed and sink back
into skimming. So find an open source library you use, pop into it&#8217;s source code
and get reading.</p>

<p><em>Don&#8217;t do your practicing in front of a live audience. Read open source code in
order to get better at sightreading.</em></p>

<h2>Wrapping Up</h2>

<p>Thus far I&#8217;ve made the assumption that you will have no control over the
codebases that you sightread. While this is often the case when starting out,
we often spend a significant amount of time with one codebase and start to grow
into and learn it. While this certainly helps, one of the main differences
between musical scores and software projects is that individual scores seldom
change between performances whereas software is in constant flux. If you wrote
it a week ago you&#8217;ll be sightreading it again next week. If you wrote it a month
ago, how many hands have been at it since you last looked at it? Sightreading is
a constant and ongoing process in software.</p>

<p>As a writer of software, you can and should take steps to make your software
more sightreadable but I&#8217;ve throw a big wall of text at everyone so I think
I&#8217;ll tackle that subject at a later date.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Who I Am and Where I Am Going]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/11/28/who-i-am-and-where-i-am-going/"/>
    <updated>2011-11-28T13:35:00-08:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/11/28/who-i-am-and-where-i-am-going</id>
    <content type="html"><![CDATA[<h2>So <em>who am I now?</em></h2>

<p>Basically I am not anybody. I&#8217;m a student of Computer Science
and Mathematics at San José State University. I have been fiddling with
computers my whole life but would say that the decision to embrace quality
software design only happened about a year and a half ago. My entire formal
education save for one functional programming class which I only had last semester
has been Java but for a token course each in C, C++, and Assembly taught by a
professor who had to mentally translate everything into Java and then translate
it back to answer questions. As a result, I&#8217;m really behind in a lot of stuff I
shouldn&#8217;t be behind in.</p>

<p>In the past two years I&#8217;ve found myself making money doing things in Ruby.
The best thing about Ruby is that it&#8217;s fun to do things right, compared to Java
where you are actively punished for trying to do so. I have made it my business
to be a good Rubyist and live up to <a href="http://blog.nuclearsandwich.com/blog/2011/08/19/why-ruby-needs-heroes">those who inspired me</a> to learn the
language and participate in the community. As part of this process I&#8217;ve read
voraciously on Ruby and software craftmanship, lurked in IRC, and made a
nuisance of myself at conferences and Ruby meetups. The process has made me a
lot of new friends, at times both inflated and deflated my ego, and overall
given me a much grander perspective on what the important things are in life and
in software development.</p>

<p>Because it&#8217;s rather difficult to code in 90 minute spats with shoddy internet,
the great majority (read: all but school related) of my projects are in-progress
and incomplete. I <em>despise</em> this about myself. One of the main things I still
suck at is cranking out a project in a weekend. And since most of my projects
are started to apply a specific bit of knowledge or insight, or leverage a
specific language or language feature I wish to do more with, I tend to start
a new one more often than continue work on the old ones. While I don&#8217;t think it
too much of a problem, it&#8217;d definitely feel better to have one or two completed
works in my portfolio that <em>aren&#8217;t</em> a top-down recursive descent parser, of
which I have three with a fourth (Clojure, this time) in progress.</p>

<h2>Just <em>where is he going with this..?</em></h2>

<p>Well now, I&#8217;m working as a Ruby developer, I&#8217;ve finally made it to a Railsbridge
workshop and absolutely love teaching there. More to the credit of Steve&#8217;s open
commit policy than to my own artistry I am a contributor to <a href="http://hackety-hack.com">Hackety-Hack.com</a></p>

<p>I&#8217;ve just decided to apply to January&#8217;s Ruby Mendicant University session though
the upcoming weeks are going to be maddeningly busy for me and I may have to
hold off until the next one comes around. I had the pleasure of taking Peter
Cooper&#8217;s Ruby Reloaded course which I highly recommend for those who learned
just enough Ruby to be potent with Rails but still aren&#8217;t sure what&#8217;s going on
in some cases.</p>

<p>I&#8217;ve picked up Clojure and and revisited Haskell and am loving both. I&#8217;ve got a
few ideas in mind for beginning Clojure projects and am preparing for a return
to Archlinux as my primary OS as I simply can&#8217;t tolerate OS X any longer.</p>

<p>I want to start being the type of programmer that inspired me to get as far as
I&#8217;ve had the privilege of getting thus far and I&#8217;ll do it one application,
library, and blog article at a time. Starting&#8230;</p>

<p><strong><em>now.</em></strong></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[There Are 10 Types of Tests. You Need Both of Them]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/10/28/there-are-10-types-of-tests-you-need-both-of-them/"/>
    <updated>2011-10-28T02:22:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/10/28/there-are-10-types-of-tests-you-need-both-of-them</id>
    <content type="html"><![CDATA[<p>Over the course of the last year, and especially in the last two to three months
I have been internalizing and witnessing for myself the extreme benefits of
accompanying your code with a test suite which matches your code in quality.
By this I mean that it is difficult (and damn frustrating) to write good tests
for poor code. At my current skill level as a programmer there&#8217;s code in my
primary code base that is so bad (yep, I wrote that code too) that I am unable
to write good tests for it. Up until four or five weeks ago, coinciding with my
second readings of <a href="http://pragprog.com/book/achbd/the-rspec-book">The RSpec Book</a>, and <a href="http://pragprog.com/book/hwcuc/the-cucumber-book">The Cucumber Book</a>, sitting in
as a guest panelist on <a href="http://rubyrogues.com/book-club-exceptional-ruby/">Ruby Rogues</a>, and watching a bunch of
<a href="https://www.destroyallsoftware.com/screencasts">Destroy All Software</a>, I realized that in order to gain the benefits of TDD
being touted by some of the most respected members of the Ruby community, I
needed better tests. Specifically better isolated tests.</p>

<h2>Isolated Tests</h2>

<p>I recently had to completely justify my desire to add and grow isolated tests
for production code. The argument against doing so was simply that if the <em>whole
point</em> of isolated tests is to know when something breaks in the future, an
integrated test suite will pick up those failures just as well. Therefore
isolated tests are a waste of time and engineering effort.</p>

<p>This argument <em>is</em> correct, provided the only thing you use your isolated tests
for is protection from regressions. However, doing so leaves out what is to my
mind the <strong>greatest</strong> and most profound advantage of isolated testing, which is
immediate, focused feedback. I definitely think I&#8217;m inventing terms here so
please indulge me while I clarify them.</p>

<ul>
<li>Immediate: <em>The result (success or failure) can be observed right away.</em></li>
<li>Focused: <em>The cause of any failure is known to be within the system under
test.</em></li>
</ul>


<p>Anyone who has worked in software for a substantial amount of time knows that
we are each our own worst enemy and the temptation to add unnecessary complexity
is a constant bother. How many of us have added arguments to methods only to
use the default value every time. I call these bullshit arguments, because they
piss me off when I have to put up with them. The joy in a test with truly
immediate feedback is the laser focus that they give you when working on a
system. You&#8217;re literally doing one thing at a time and checking that you get the
expected result even when it isn&#8217;t success. When you get the failure you expect,
you simply move on, and when you get an unexpected failure it causes you to
identify the disparity between your mental model of the system and the computer
model and correct it. Since these tests are isolated and generally run in less
than a second, there is essentially no penalty for running the tests with
monstrous frequency. When you do have to stop, it is to make a correction,
even if it is just a mental correction. The time you save fixing it early is
more than enough to justify the low cost of running the test.</p>

<p>One of the downsides of this type of testing is that you are treating anything
which isn&#8217;t the system under test as an external service and therefore
stubbing the interactions with it. This works great for fast, clean-room tests
but it means that the burden of ensuring that the assumptions you make in one
test are validated in the respective tests for your other systems is entirely on
the programmer and since programmers are human, this will eventually lead to
mistakes.</p>

<p>My personal favorite aspect of isolated tests is how informative they can be
about your system. It&#8217;s pretty common knowledge that if your tests are a pain in
the ass to write, it&#8217;s a good indication that your code is too-tightly coupled
and refactoring to follow the <a href="http://avdi.org/devblog/2011/07/05/demeter-its-not-just-a-good-idea-its-the-law/">Law of Demeter</a> and <a href="http://blog.rubybestpractices.com/posts/gregory/055-issue-23-solid-design.html">SOLID</a> design
principles is a good idea.</p>

<h2>Integrated Tests</h2>

<p>One of the scariest things that happened to me in recent memory was discovering
that people were surprised when after arguing in favor of getting higher quality
unit tests I was still unsatisfied because our integrated tests also needed
attention and improvement. I found this a little disturbing (okay, I found this
really disturbing) because I can&#8217;t imagine how long it would take to manually
verify that I didn&#8217;t overlook anything in the major refactoring or feature
addition I just performed. I certainly don&#8217;t budget the time to manually test
every resource and parameter combination by hand. I might do so initially
because a major disadvantage to integrated tests is in the difficulty of doing
exploratory testing at this level. As a result, when writing integrated tests, I
tend to rely on manual experimentation to determine how my system behaves in
undefined situations, make a decision on the appropriateness of that behavior
and then solidify that set of interactions into a group of tests. One of the
nice things about integrated tests is that once written, they tend not to change
unless your expected end-user behavior changes. This is afforded by the
&#8220;bigger picture&#8221; nature of integrated tests where you are less concerned with
the exact behavior of any one unit and instead are validating the result of
system-wide operation and interaction. Thus, integrated tests are largely immune
to internal refactoring.</p>

<p>As one can imagine, the strengths of isolated tests are the weaknesses of
integrated tests. When something is wrong, particularly in a complex interaction
that touches many parts of the system, it can be unclear exactly where the
problem in the codebase is when an integrated test fails. If you get an actual
exception, you&#8217;ll have a stacktrace to guide you, but those tend to be unhelpful
errors like an unexpected nil and rarely is it obvious at what level the nil was
assigned and how long it had been propagated upward until the failure. So it
can be said that integrated tests are not focused since there is no indication
of precisely where in the system the failure has occurred. Additionally,
integrated tests mandate that you test your full software stack. Any persistence
layers, external services, background tasks, and other specific tools you&#8217;re
using should be tested during this phase. As you can imagine testing all of
these things takes time and computing power. It is not feasible to expect even
a subset of an integrated test suite to run in the same magnitude of time as
isolated tests, what this means is the tests are no longer immediate. Thus,
they are not suitable for running at every pass of your TDD cycle. Only when you
believe the feature to be complete.</p>

<h2>Conclusions</h2>

<p>So if isolated tests don&#8217;t identify incongruities between subsystems and
integrated tests are too slow to run during an immediate feedback TDD cycle,
which do you use? As you may have surmised from the title, the answer is&#8230;
both.</p>

<p><a href="http://pragprog.com/book/hwcuc/the-cucumber-book">The Cucumber Book</a> suggests that &#8220;It&#8217;s sometimes said that unit tests ensure
you &#8216;build the thing right&#8217;, while acceptance tests ensure you &#8216;build the
right thing&#8217;.&#8221; I also like Avdi Grim&#8217;s simile of mocks being like hydrogen
peroxide in that they both fizz up around problems.</p>

<p>With our twin goals of systematic coverage and focus during development in mind,
let&#8217;s recap how each set of tests is used.</p>

<p>When you know what you you&#8217;re building but not how, reach for the integrated
tests. Define the desired outcome at the high level and then run that test again
when you think you&#8217;ve got it down. Start thinking about the different aspects of
that problem and decomposing them. Then devise a system of smaller tests
mirroring the smaller objects and functions you&#8217;ll use to accomplish that goal.
Isolated tests are there once you&#8217;re ready to do exactly that. There to aid
you in that mission and guide you toward good design decisions. &#8220;I&#8217;ll do what
the tests tell me&#8221; is not an uncommon phrase from me.</p>

<p><em>Isolated regression tests are a side effect of good TDD, they&#8217;re more important
during the process than after.</em></p>

<p><em>Integrated tests are the ones you bring home and show your mother. The ones you
can be proud of at the end of the day.</em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Look at Ruby Case Expressions]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/09/08/a-look-at-ruby-case-expressions/"/>
    <updated>2011-09-08T08:33:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/09/08/a-look-at-ruby-case-expressions</id>
    <content type="html"><![CDATA[<p>Ruby, like many languages has a case-when construct for more refined conditional
execution than if-then-else can provide. Technically all case constructs could
be written as if-then-else-if-then&#8230;else but you wouldn&#8217;t enjoy it.</p>

<h2>Ruby&#8217;s case-when is an expression</h2>

<p>However, there are a number of things that make Ruby&#8217;s case-when special. The
first comes from Ruby&#8217;s functional roots. It&#8217;s powerful but deceptively simple.
Ruby&#8217;s case-when construct is an <em>expression</em>. Which means, among other things,
it returns a value.</p>

<p>In a traditional imperative style a case statement might look like:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">conditional_variable</span> <span class="o">=</span> <span class="ss">:some_default_value</span>
</span><span class='line'><span class="k">case</span> <span class="n">our_condition</span>
</span><span class='line'><span class="k">when</span> <span class="ss">:first</span>
</span><span class='line'>  <span class="n">conditional_variable</span> <span class="o">=</span> <span class="ss">:one_thing</span>
</span><span class='line'><span class="k">when</span> <span class="ss">:then</span>
</span><span class='line'>  <span class="n">conditional_variable</span> <span class="o">=</span> <span class="ss">:another</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>The that isn&#8217;t ideal for a number of reasons. <code>conditional_variable</code> is set
visibly three times which as any freshman can tell you is frowned upon.
Academics have stuffier reasons for it but the most important is that it
decreases readability because we aren&#8217;t sure what the value will be after
execution. Setting it so many times is also a code duplication, albeit a small
one. We can take advantage of Ruby&#8217;s case-when <em>expression</em> with this code:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="n">conditional_variable</span> <span class="o">=</span> <span class="k">case</span> <span class="n">our_condition</span>
</span><span class='line'>                       <span class="k">when</span> <span class="ss">:first</span>
</span><span class='line'>                         <span class="ss">:one_thing</span>
</span><span class='line'>                       <span class="k">when</span> <span class="ss">:then</span>
</span><span class='line'>                         <span class="ss">:another</span>
</span><span class='line'>                       <span class="k">else</span>
</span><span class='line'>                         <span class="ss">:some_default_value</span>
</span><span class='line'>                       <span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>Doesn&#8217;t that look nicer? <code>conditional_variable</code> is only set once and the
intent is clear, we want the value to depend on <code>our_condition</code>.</p>

<h2>case-when uses triple equals for comparison</h2>

<p>This got me good this morning and spawned this article. If you&#8217;re not familiar
with <code>===</code> in Ruby then the best explanation comes from <em>_why&#8217;s Poignant Guide
to Ruby</em> which really is worth reading. I&#8217;ve referred back to it multiple times
to help myself and those around me fully understand basic Ruby concepts like
<code>nil</code>, truthiness and falsiness, and, <strong>fanfare please</strong>, double equals versus
triple equals.</p>

<blockquote><p>The double equals gives the appearance of a short link of ropes, right
along the sides of a red carpet where only <code>true</code> can be admitted.</p></blockquote>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">if</span> <span class="n">approaching_guy</span> <span class="o">==</span> <span class="kp">true</span>
</span><span class='line'>  <span class="nb">puts</span> <span class="s2">&quot;That necklace is classic&quot;</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<blockquote><p>&#8230;
[This case-when statement]</p></blockquote>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">case</span> <span class="n">year</span>
</span><span class='line'><span class="k">when</span> <span class="mi">1894</span>
</span><span class='line'>  <span class="s2">&quot;Born.&quot;</span>
</span><span class='line'><span class="k">when</span> <span class="p">(</span><span class="mi">1895</span><span class="o">.</span><span class="n">.</span><span class="mi">1913</span><span class="p">)</span>
</span><span class='line'>  <span class="s2">&quot;Childhood in Lousville, Winston Co., Mississippi.&quot;</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'>  <span class="s2">&quot;No information about this year.&quot;</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<blockquote><p>is identical to</p></blockquote>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">if</span> <span class="mi">1894</span> <span class="o">===</span> <span class="n">year</span>
</span><span class='line'>  <span class="s2">&quot;Born.&quot;</span>
</span><span class='line'><span class="k">elsif</span> <span class="p">(</span><span class="mi">1895</span><span class="o">.</span><span class="n">.</span><span class="mi">1913</span><span class="p">)</span> <span class="o">===</span> <span class="n">year</span>
</span><span class='line'>  <span class="s2">&quot;Childhood in Lousville, Winston Co., Mississippi.&quot;</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'>  <span class="s2">&quot;No information about this year.&quot;</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<blockquote><p>The <strong>triple equals</strong> is a length of velvet rope, checking values much like
the <strong>double equals</strong>. It&#8217;s just: the triple equals is a longer rope and it
sags a bit in the middle. It&#8217;s not as strict, it&#8217;s a bit more flexible.
Take the Ranges above. <code>(1895..1913)</code> isn&#8217;t at all equal to <code>1905</code>.</p>

<p>No, the Range <code>(1895..1913)</code> is only truly equal to any other Range
<code>(1895..1913)</code>. In the case of a Range, the triple equals cuts you a break
and lets the Integer <code>1905</code> in, because even though it&#8217;s not equal to the
Range, it&#8217;s included in the set of Integers represented by the Range. Which
is good enough in some cases, such as the timeline I put together earlier.</p></blockquote>

<h2>My Mistake</h2>

<p>This is what I did which caused me to write this as penance.</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="k">def</span> <span class="nf">local_tweet_object</span> <span class="n">input</span>
</span><span class='line'>  <span class="n">tweet_hash</span> <span class="o">=</span> <span class="k">case</span> <span class="n">input</span><span class="o">.</span><span class="n">class</span> <span class="c1"># the screw-up</span>
</span><span class='line'>  <span class="k">when</span> <span class="nb">String</span>
</span><span class='line'>    <span class="no">MultiJson</span><span class="o">.</span><span class="n">decode</span> <span class="n">input</span>
</span><span class='line'>  <span class="k">when</span> <span class="no">Hash</span>
</span><span class='line'>    <span class="n">input</span>
</span><span class='line'>  <span class="k">else</span>
</span><span class='line'>    <span class="nb">fail</span> <span class="no">ArgumentError</span><span class="o">.</span><span class="n">new</span><span class="p">(</span>
</span><span class='line'>      <span class="s2">&quot;Cannot process </span><span class="si">#{</span><span class="n">input</span><span class="o">.</span><span class="n">class</span><span class="si">}</span><span class="s2"> only String or Hash&quot;</span><span class="p">)</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'>  <span class="no">LocalTweet</span><span class="o">.</span><span class="n">new</span> <span class="n">tweet_hash</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>This code was raising the following error.</p>

<p><code>ArgumentError: I don't want Hash give me only String or Hash</code>
&#8230; <em>huh?</em></p>

<p>At first glance it looked fine, but then we remember that case-when uses <code>===</code>.
Again, we think &#8220;this shouldn&#8217;t be an issue, if it&#8217;s good enough for <code>==</code> it
should be fine for <code>===</code>.&#8221; But <code>===</code> behaves specially for certain types in Ruby
such as Classes, Arrays, and as we saw before, Ranges.</p>

<p>For simple scalar values <code>===</code> acts like you expect.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>12 === 12 #=> true
</span><span class='line'>12 === 13 #=> false
</span><span class='line'>:rats === :rats #=> true
</span><span class='line'>"pens" === "pens" #=> true
</span><span class='line'>"space" === "fact" #=> false</span></code></pre></td></tr></table></div></figure>


<p>And we know how <code>===</code> treats ranges</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(8..64) === 32 #=> true</span></code></pre></td></tr></table></div></figure>


<p>But note that</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(8..64) === (8..64) #=> false</span></code></pre></td></tr></table></div></figure>


<p>Suddenly!</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Integer === 12 #=> true!</span></code></pre></td></tr></table></div></figure>


<p>waitaminute.. what?</p>

<p>So Ruby can tell that <code>12</code> is a type of Integer and thus <code>===</code> can be described
partially as an includes and typeof operator. But there are some further
gotchas.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[ 1, 2, 3 ] === 1#=> true
</span><span class='line'>[ 1, 2, 3 ] === [ 1, 2, 3 ]                         #=> true
</span><span class='line'>[ 1, 2, 3 ] === [ 1, 2 ]                            #=> false
</span><span class='line'>{ :foo => :bar } === { :foo => :bar }               #=> true
</span><span class='line'>{ :foo => :bar } === :foo                           #=> false
</span><span class='line'>{ :foo => :bar, :baz => :qux } === { :foo => :bar } #=> false</span></code></pre></td></tr></table></div></figure>


<p><code>===</code>&#8217;s behavior isn&#8217;t completely intuitive even within Ruby&#8217;s standard Classes.
Which brings us (finally) back around to my original error.
<code>Hash === Hash #=&gt; false</code></p>

<p>The fix is simple, just change</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>case input.class</span></code></pre></td></tr></table></div></figure>


<p>to</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>case input</span></code></pre></td></tr></table></div></figure>


<p>I posted on identi.ca a friendly notice about this easy mistake and was asked to
provide clarification. So here, just over 24 hours late, it is. The full source
code is provided <a href="https://gist.github.com/1112335">here</a></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Switching to Octopress]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/09/03/switching-to-octopress/"/>
    <updated>2011-09-03T14:31:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/09/03/switching-to-octopress</id>
    <content type="html"><![CDATA[<p>First post!</p>

<p>Well, not quite. It is the first post with the new blogging engine <a href="http://octopress.org">Octopress</a>
I was having a lot of trouble with Posterous&#8217;s post by email and their
antiquated markdown version. So here I am, on this shiny new, happily Vim-able
platform.</p>

<p>The joy begins.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why You Shouldn't Use Factories in Unit-level Tests or Specs]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/08/31/why-you-shouldnt-use-factories-in-unit-level-tests-or-specs/"/>
    <updated>2011-08-31T05:11:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/08/31/why-you-shouldnt-use-factories-in-unit-level-tests-or-specs</id>
    <content type="html"><![CDATA[<p>They&#8217;re tightly fucking coupled! That&#8217;s Why</p>

<p><strong>UPDATE:</strong> Or as Steve Klabnik puts it more precisely and politely:</p>

<blockquote><p>factories are integration tests by definition, because they do not exercise a
single unit.</p></blockquote>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why Ruby Needs Heroes]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/08/19/why-ruby-needs-heroes/"/>
    <updated>2011-08-19T12:12:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/08/19/why-ruby-needs-heroes</id>
    <content type="html"><![CDATA[<p><em>A reflection on the Ruby community&#8217;s tendency to celebrate individual
developers and what good comes of it.</em></p>

<p>The Ruby community isn&#8217;t unique in its tendency for celebrating rockstar
developers but after examining the communities history it would seem that we
burn them out bright and fast.</p>

<p>When I first became involved in the community I had heard of almost no one. My
first hero is my friend Erik Ostrom to whom I owe a great deal for my first and
second introductions to Ruby. Without you Erik I would be missing out on the
most fun, passionate, and rewarding hacking I have ever done. I have you to
thank for my introductions to rhe MVC pattern, idiomatic programming, and the
process of developing software. I also owe you a big thanks for pointing me to
_why&#8217;s (Poignant) Guide to Ruby.</p>

<p>Which leads nicely into my second hero <em>why the lucky stiff. The Guide when I
first read it was the most refreshing and maddeningly beautiful piece of
technical literature I had ever encountered and remains so to this day. Never
before had I seen a language presented side by side with English hold its
expressiveness the way Ruby did. It took me three tries to finish the Guide but
I have read over its pages many times reminding myself to &#8220;use what Ruby gives
[me]&#8221; and it is still my goto for explaining nil, truthiness, and falsiness in
Ruby. If I were to teach programming in an art department, The Guide would be my
textbook. But </em>why gave me more than the guide. Through Camping I was able to
study &#8220;magic&#8221; and be exposed to the raw untamed power of metaprogramming in
Ruby. Even though I had missed the whole hullabaloo surrounding _why&#8217;s exit
from the community by a matter of weeks his work has had a lasting and profound
effect on me and I thank him.</p>

<p>Like many developers my first full application in Ruby and real test of what I
learned was using Ruby on Rails. Rails 2.3.5 to be precise. This marks me as a
new kid on the block I know, but let&#8217;s face it, I am. I have been living with
Ruby for little more than two years. But that&#8217;s the evolution of community
without new blood it dries out. Anyway through this early stage I had a
collection of mentors. The most prolific of which wasn&#8217;t even aware of it at the
time.</p>

<p>Ryan Bates, your Railscasts helped guide me not only on specific challenges I
was facing building my first production app but also provided my first exposure
to lots of quality Ruby code and process. One thing the Ruby community gets on a
fundamental level is that process matters and you were my first big introduction
to that. You also introduced me to rvm and by extension my next hero.</p>

<p>Wayne Seguin, rvm is a colossal undertaking. Managing development environments
has always been a pain and you shaved one of the biggest, hairiest yaks ever to
stand in the middle of the room.
MixedMetaphorException: &#8220;Yaks aren&#8217;t elephants.&#8221;</p>

<p>You are also a fabulous example of a project maintainer I don&#8217;t have a specific
IRC story of my own but that only speaks to the quality of your work. You&#8217;re
also a wonderful example of a polyglot Rubyist and really show what can happen
when Rubyists take their knowledge and experience and apply it to funny little
languages like bash.</p>

<p>Last April I had the pleasure of meeting Steve Klabnik at the very first
CodeConf. One of the coolest things about you Steve is that you&#8217;re pretty much
my age. It was so inspiring to see you, such an obviously accepted member of the
Ruby community, so close to my own age. You indirectly informed me that the amount
of effort required to really get involved and make a difference wasn&#8217;t in the
depressingly distant future and this has motivated me substantially in my
efforts to give back even as I receive.</p>

<p>Thanks man, you rock</p>

<p>Lately I have been reading a lot of stuff from Avdi Grimm. You&#8217;re style is so
refined and decisive. Few people think about the meaning and reason behind their
code and design decisions as you clearly do. Lately I have been turning to your
writings when I find myself wondering about the best way to do something.</p>

<p>So my journey through Ruby has brought me across the paths of these heroes and
so many more. But what motivates me to think of these fine folks this way even
when they may not want the attention. How many feel overly pressured by or
undeserving of their status. When thinking on this, I am reminded of Firefly.
(If you haven&#8217;t seen it, seriously do yourself a favor and watch it.)</p>

<!--![Jaynestown](/images/blog/jaynestown.jpg) -->


<p>Specifically the Hero of Canton episode in which Jayne, the least noble of the
protagonists, is remembered as a folk hero on a backwater mining colony for
accidentally dropping crates of money over the mining camps. At the end Jayne
can&#8217;t understand what they see in him when dropping the money at all was simply
a dishonest mistake as the episode wraps up he&#8217;s told that the statue in his
honor isn&#8217;t for him, it is for the miners. We build heroes out of you because we
see qualities in you we hope to someday find in ourselves. So please, whether
you&#8217;re a Jayne Cobb or Malcom Reynolds, if someone thinks of you as their hero,
just be proud that you&#8217;ve done something extraordinary and they hope to follow
suit.</p>

<p>Happy _whyday,
Steven!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[CoffeeScript: An Outsider Opinion]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/07/03/coffeescript-an-outsider-opinion/"/>
    <updated>2011-07-03T18:16:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/07/03/coffeescript-an-outsider-opinion</id>
    <content type="html"><![CDATA[<p><em>Thoughts on CoffeeScript from a server-side developer just getting started with
frontend and JavaScript development.</em></p>

<p>Firstly, if you’re unfamiliar with CoffeeScript, I recommend reading elsewhere
for a proper overview and introduction. The CoffeeScript homepage and the
Introductory Chapter of The Litte CoffeeScript Book are good resources for that.
If you’re really impatient CoffeeScript is in the author’s own words
&#8220;JavaScript’s less ostentatious kid brother.&#8221; I’ve also heard it called
&#8220;Javascript for Ruby and Python programmers&#8221; and &#8220;What Javascript should have
been&#8221; by several of my peers. It also seems that it could’ve been called
CilantroScript<a href="http://coffeescript.com">1</a> as it seems to have an instantly polarizing effect on people
in online communities such as Reddit and the Ruby on Rails community.</p>

<h2>So why did I start working with CoffeeScript? A number of reasons.</h2>

<p>I am a backend developer and want to grow my frontend skills.
1. I’m starting to experiment with Node.js on the server.
2. Jeremy Ashkenas’s talk at CodeConf on literate programming blew my mind.
3.I know Ruby, so I should enjoy a “Javascript for Rubyists”, right?
4. It is going to be a Ruby on Rails default soon so I might as well check it
out now.
5. I like new and shiny things.</p>

<p>One of the quandries I faced when deciding to learn CoffeeScript was the fact
that I don’t know JavaScript. I spent 6 months noodling with Ruby before picking
up Rails and am still getting my feet wet with Python before taking Django for a
spin. So why on Earth would someone with my MO pick up CoffeeScript without
first becoming proficient with javascript? (Aside: I’m tired of the CamelCasing)
The answer comes from the first sentence (topic sentence, for those still in Jr.
High School) in the second paragraph of the coffeescript home page.</p>

<blockquote><p>The golden rule of CoffeeScript is: “It’s just JavaScript”.</p></blockquote>

<p>As it turns out that isn’t entirely true since coffeescript is a class based
object oriented language and javascript is prototype based. This was actually a
mark against coffeescript for me since part of my desire to learn javascript was
to dally in prototype based OOP. (Luckily there’s still Io for that.) But for
the most part Coffee really is just javascript.</p>

<p><strong>EDIT: Jeremy Ashkenas has kindly clarified this point for me.</strong></p>

<blockquote><p>CoffeeScript is prototype based to the precise same extent that JavaScript is.
The &#8220;class&#8221; keyword is just sugar for JavaScript’s constructor function +
prototype chain combination. To mangle Shakespeare:</p>

<blockquote><p>What’s in a name? That which we call a class by any other name would smell
as sweet. Call it a prototype if you like — it’s the same thing in code.</p></blockquote></blockquote>

<p>Thanks Jeremy, apologies for misapprehending.</p>

<h2>So why the bother?</h2>

<p>A while back I invested some of my hard-earned and short-in-supply cash to pick
up a ten-pack of PeepCode tokens. I have to say, I’ve derived an intense amount
of value from PeepCode but more on that later. I started with PeepCode’s Meet
CoffeeScript, had they produced a Meet JavaScript I would have started there,
but they didn’t. It took around six hours to watch the three and a half hour
video. Almost immediately after, I started PeepCode’s Meet Node.js screencast
and attempted to do it in javascript for about eight minutes. The appeal of
coffeescript was immediately clear.</p>

<p>In JavaScript, I have to worry about whether or not every line ends in a
semicolon, that there are no extraneous commas, yet commas where necessary,
and that I’ve remembered the var keyword on all my local variables. All that
stuff is important in JavaScript it doesn’t actually effect my application in
any way. In CoffeeScript, I can focus on the behavior of my code rather than the
presentation of it. Instead of scrutinizing each line for a semicolon and each
block for matching curly braces. I’m affirming that all my variables are scoped
properly and that my code does what I want it to do. It doesn’t add much to
javascript but rather, reduces the amount of worry and focus on what is at the
end of the day arbitrary stuff.</p>

<p>Sure, I have Vim configured with the fantastic Synastic plugin and I get
notified when I drop a semicolon or have an unmatched brace but what’s the
point? Basic sanity checking is all it can really do. Why even waste the time
to go back and insert those in the first place?</p>

<h2>Conclusion</h2>

<p>I’m still continuing my education in JavaScript, CoffeeScript, jQuery, Node.js,
and prototype-based OOP. I’m armed with the beta copy of the CoffeeScript book
by Trevor Burnham from Pragmatic Programmers. I fully intend to use CoffeeScript
for all of my development in Javascript environments, server- and client-side,
work and play, for the foreseeable future.</p>

<h2>My CoffeeScript Resources</h2>

<ol>
<li><a href="http://coffeescript.com">The CoffeeScript Website and Documentation</a></li>
<li><a href="http://peepcode.com/products/coffeescript">Meet CoffeeScript</a></li>
<li><a href="http://pragprog.com/book/tbcoffee/coffeescript">CoffeeScript: Accelerated JavaScript Development by Trevor Burnham</a></li>
<li><a href="http://jashkenas.github.com/coffee-script/documentation/docs/command.html">The Annotated CoffeeScript Source</a></li>
<li><a href="http://arcturo.com/library/coffeescript/index.html">The Little CoffeeScript Book</a></li>
<li><a href="http://oreilly.com/catalog/9780596517748/">Javascript: The Good Parts by Douglas Crockford</a></li>
<li><a href="http://eloquentjavascript.net/">Eloquent Javascript by Marjin Haverbeke</a></li>
<li><a href="http://autotelicum.github.com/Smooth-CoffeeScript/">Smooth CoffeeScript by autotelicum</a> via
<a href="http://twitter.com/raynos2">@Raynos2</a></li>
</ol>


<hr />

<ol>
<li>Cilantro (or Coriander) is an herb which to some people tastes pleasantly
citrus-like and to others is rank and revolting or soapy. As a result many
people either love it or hate it. Few are ambivalent about Cilantro. The same
is true of CoffeeScript in my observation.</li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Sane Configuration Setup for Rack Applications on Heroku]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/06/25/a-sane-configuration-setup-for-rack-applications-on-heroku/"/>
    <updated>2011-06-25T09:05:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/06/25/a-sane-configuration-setup-for-rack-applications-on-heroku</id>
    <content type="html"><![CDATA[<p><strong><em>Update:</em></strong> The Github repo I linked at the end of this article was private
and I forgot to make it public. It is now, sorry. ~Steven!</p>

<p>Recently, Nowmov has started using <a href="http://heroku.com">Heroku</a> for application
deployment. In the past I&#8217;ve always been hesitant toward &#8220;hosted
solutions&#8221; but a combination of focusing my time and the flexibility and
power of Heroku&#8217;s Celadon Cedar stack has brought me into contact with
one such solution.</p>

<p>One of the first peculiarities/gotchas/side-effects of many of these
hosted solutions is that they don&#8217;t provide shell or ftp access. Nor can
you write to the file system from your application. This caused us some
interesting problems during the migration.</p>

<ol>
<li><p>Rails convention dictates that <code>config/settings.yml</code>,
<code>config/database.yml</code> and friends not be stored in source control and
that we should store template files instead so developers are aware of
setup specific configuration details. However, our inability to push
files not in source control to Heroku leaves us unable to use the
standard convention for configuration details. The way Heroku bypasses
this leads to the next hurdle.</p></li>
<li><p>The whole point of Heroku is that you don&#8217;t deal with IT, just your
code. This means that you don&#8217;t really care where your PostgreSQL
database is or what port you use to connect to your Redis instance. But
you still need to connect to those things! So what does Heroku do? They
give you environment variables. <code>heroku run 'echo $DATABASE_URL'</code>
returns a big long uri corresponding to your app&#8217;s database. With this
specific config variable, Heroku is kind enough to render a
<code>database.yml</code> from it using erb. But it only works ActiveRecord
compatible database.ymls, which is not all of them, believe it or not.
(I&#8217;m looking at you Sequel) Inspect your Heroku config variables by
running <code>heroku config</code> from an app directory. The amount of scary
looking crap in there might surprise you!</p></li>
</ol>


<p>You can even add your own config variables such as
<code>MR_FANCY_PANTS=the_worlds_best_pants</code> with
<code>heroku config:add MR_FANCY_PANTS=sad_deep_inside ARTIST="Jonathan
Coulton"</code> this command will expose both your variables to your code
using Ruby&#8217;s <code>ENV</code> hash.</p>

<p>In your code you&#8217;d get to it like this:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1">#!ruby</span>
</span><span class='line'><span class="k">def</span> <span class="nf">controller_action</span>
</span><span class='line'>  <span class="k">if</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;ARTIST&#39;</span><span class="o">]</span> <span class="o">==</span> <span class="s2">&quot;Jonathan Coulton&quot;</span>
</span><span class='line'>    <span class="vi">@still_alive</span> <span class="o">=</span> <span class="kp">true</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>But then this also has to work locally! So you need to do somethig like
this:</p>

<figure class='code'> <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='ruby'><span class='line'><span class="c1">#!ruby</span>
</span><span class='line'><span class="k">def</span> <span class="nf">controller_action</span>
</span><span class='line'>  <span class="k">if</span> <span class="p">(</span><span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;ARTIST&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="no">SETTINGS</span><span class="o">[</span><span class="ss">:artist</span><span class="o">]</span><span class="p">)</span> <span class="o">==</span> <span class="s2">&quot;Jonathan Coulton&quot;</span>
</span><span class='line'>    <span class="vi">@still_alive</span> <span class="o">=</span> <span class="kp">true</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>Alternatively, you could set up all these environment variables using a
rake or thor task before launching your app but who wants to deal with
that? My favorite solution to a problem is a coding solution.</p>

<p>And you have to do that <em>everywhere</em> you want to use a situation
specific configuration. I don&#8217;t know about you but that seems hacky,
error prone, and repetitive to me. Smelly code, in other words. In
working on my recent projects I&#8217;ve been studying a large number of small
Ruby applications. Mostly Sinatra but some in Rails and Padrino as well.
In all those apps, I never found a ubiquitously deployed solution for
the configuration situation in a Heroku-style environment so I left it
to simmer a few days and dealt with <code>ENV[:KEY] || SETTINGS['key']</code> all
over my app. Then, over too much cold brew coffee I came up with a
workable solution. While this is the very first time I&#8217;ve seen this
solution in a web application. It actually comes from messing around in
<code>irb</code> earlier in the week trying to alter prompt strings for vanity&#8217;s sake.</p>

<p>Everyone open <code>irb</code> right now! Just go to a terminal and do it! Got it? Okay</p>

<p><code>&gt; IRB.conf</code></p>

<p>You&#8217;ll see how this inspired my solution later on. Or perhaps I&#8217;m not as
brilliant as I think I am and it&#8217;s obvious to you already (<em>likely</em>).</p>

<p>So let&#8217;s say we&#8217;re working on a lightweight Sinatra application and we
know that it&#8217;ll start simple and grow in complexity later on. Since
we&#8217;re smart we&#8217;re going to namespace the whole thing under a module.
Namely <code>Saneconf</code> Our skeleton looks like this:</p>

<figure class='code'><figcaption><span>Main Application File - app.rb </span></figcaption>
 <div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="c1">#!ruby</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;rubygems&#39;</span> <span class="c1"># Only needed for Ruby 1.8</span>
</span><span class='line'><span class="nb">require</span> <span class="s1">&#39;bundler&#39;</span>
</span><span class='line'><span class="c1"># After this line, I shouldn&#39;t even have to *think* about dependencies.</span>
</span><span class='line'><span class="no">Bundler</span><span class="o">.</span><span class="n">require</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># This is the initilization file for the Saneconf API. All set up, library</span>
</span><span class='line'><span class="c1"># loading and application level settings are done here.</span>
</span><span class='line'><span class="k">module</span> <span class="nn">Saneconf</span>
</span><span class='line'>  <span class="c1"># If there&#39;s a better/safer way to do this generically do let me know.</span>
</span><span class='line'>  <span class="c1"># I haven&#39;t encountered a setup where this didn&#39;t work.</span>
</span><span class='line'>  <span class="k">def</span> <span class="nc">Saneconf</span><span class="o">.</span><span class="nf">root</span><span class="p">;</span> <span class="no">Dir</span><span class="o">.</span><span class="n">pwd</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1"># This one is important so we set it early and use a constant.</span>
</span><span class='line'>  <span class="c1"># Set Rack environment if not specified.</span>
</span><span class='line'>  <span class="no">RACK_ENV</span> <span class="o">=</span> <span class="no">ENV</span><span class="o">[</span><span class="s1">&#39;RACK_ENV&#39;</span><span class="o">]</span> <span class="o">||</span> <span class="s2">&quot;development&quot;</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1"># Create an accessor to a module attribute which defaults to a</span>
</span><span class='line'>  <span class="k">def</span> <span class="nc">Saneconf</span><span class="o">.</span><span class="nf">conf</span><span class="p">;</span> <span class="vi">@conf_hash</span> <span class="o">||=</span> <span class="no">Hash</span><span class="o">.</span><span class="n">new</span><span class="p">;</span> <span class="k">end</span>
</span><span class='line'>
</span><span class='line'>  <span class="c1"># Handles initialization and preprocessing of application settings be they</span>
</span><span class='line'>  <span class="c1"># from Heroku&#39;s Environment or a local `settings.yml`.</span>
</span><span class='line'>  <span class="n">require_relative</span> <span class="s1">&#39;config/setup.rb&#39;</span>
</span><span class='line'>
</span><span class='line'>  <span class="k">class</span> <span class="nc">App</span> <span class="o">&lt;</span> <span class="no">Sinatra</span><span class="o">::</span><span class="no">Base</span>
</span><span class='line'>    <span class="n">get</span> <span class="s1">&#39;/&#39;</span> <span class="k">do</span>
</span><span class='line'>      <span class="s2">&quot;&lt;h1&gt;So nice to be sane again, eh? </span><span class="si">#{</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;ARTIST&#39;</span><span class="o">]</span><span class="si">}</span><span class="s2">?&lt;/h1&gt;&quot;</span>
</span><span class='line'>    <span class="k">end</span>
</span><span class='line'>  <span class="k">end</span>
</span><span class='line'><span class="k">end</span>
</span></code></pre></td></tr></table></div></figure>


<p>That looks cool and all, but what the hell is <code>config/setup.rb</code>? Answer: It&#8217;s
where the magic happens, let&#8217;s go take a look:</p>

<figure class='code'><figcaption><span>The Magic Happens Here - config/setup.rb </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>
</pre></td><td class='code'><pre><code class='rb'><span class='line'><span class="c1">#!ruby</span>
</span><span class='line'><span class="k">if</span> <span class="no">File</span><span class="o">.</span><span class="n">exists?</span> <span class="s2">&quot;config/settings.yml&quot;</span>
</span><span class='line'>  <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">merge!</span><span class="p">(</span>
</span><span class='line'>    <span class="no">YAML</span><span class="o">.</span><span class="n">load_file</span><span class="p">(</span><span class="s2">&quot;config/settings.yml&quot;</span><span class="p">)</span><span class="o">[</span><span class="no">Saneconf</span><span class="o">::</span><span class="no">RACK_ENV</span><span class="o">]</span><span class="p">)</span>
</span><span class='line'>    <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;RESQUE_SCHEDULE&#39;</span><span class="o">]</span> <span class="o">=</span>
</span><span class='line'>      <span class="no">YAML</span><span class="o">.</span><span class="n">load_file</span><span class="p">(</span><span class="s2">&quot;config/resque_schedule.yml&quot;</span><span class="p">)</span>
</span><span class='line'><span class="k">else</span>
</span><span class='line'>  <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">merge!</span><span class="p">(</span><span class="no">ENV</span><span class="p">)</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="n">db</span> <span class="o">=</span> <span class="no">URI</span> <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;DATABASE_URL&#39;</span><span class="o">]</span>
</span><span class='line'><span class="n">redis</span> <span class="o">=</span> <span class="no">URI</span> <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;REDISTOGO_URL&#39;</span><span class="o">]</span>
</span><span class='line'><span class="c1"># Parse Postgres connection settings.</span>
</span><span class='line'><span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;DATABASE&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>  <span class="ss">:adapter</span> <span class="o">=&gt;</span> <span class="s2">&quot;</span><span class="si">#{</span><span class="n">db</span><span class="o">.</span><span class="n">scheme</span><span class="si">}</span><span class="s2">ql&quot;</span><span class="p">,</span> <span class="c1"># Add a &#39;ql&#39; cause ActiveRecord is stupid.</span>
</span><span class='line'>  <span class="ss">:host</span> <span class="o">=&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">host</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:port</span> <span class="o">=&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">port</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:database</span> <span class="o">=&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">path</span><span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="o">]</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:username</span> <span class="o">=&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">user</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:password</span> <span class="o">=&gt;</span> <span class="n">db</span><span class="o">.</span><span class="n">password</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Parse Redis connection settings.</span>
</span><span class='line'><span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;REDIS&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="p">{</span>
</span><span class='line'>  <span class="ss">:host</span> <span class="o">=&gt;</span> <span class="n">redis</span><span class="o">.</span><span class="n">host</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:port</span> <span class="o">=&gt;</span> <span class="n">redis</span><span class="o">.</span><span class="n">port</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:password</span> <span class="o">=&gt;</span> <span class="n">redis</span><span class="o">.</span><span class="n">password</span><span class="p">,</span>
</span><span class='line'>  <span class="ss">:db</span> <span class="o">=&gt;</span> <span class="n">redis</span><span class="o">.</span><span class="n">path</span><span class="o">[</span><span class="mi">1</span><span class="o">.</span><span class="n">.</span><span class="o">-</span><span class="mi">1</span><span class="o">]</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="c1"># Parse Resque Schedule YAML.</span>
</span><span class='line'><span class="k">if</span> <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;RESQUE_SCHEDULE&#39;</span><span class="o">].</span><span class="n">class</span> <span class="o">==</span> <span class="nb">String</span>
</span><span class='line'>  <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;RESQUE_SCHEDULE&#39;</span><span class="o">]</span> <span class="o">=</span> <span class="no">YAML</span><span class="o">.</span><span class="n">load</span> <span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">[</span><span class="s1">&#39;RESQUE_SCHEDULE&#39;</span><span class="o">]</span>
</span><span class='line'><span class="k">end</span>
</span><span class='line'>
</span><span class='line'><span class="no">Saneconf</span><span class="o">.</span><span class="n">conf</span><span class="o">.</span><span class="n">freeze</span>
</span></code></pre></td></tr></table></div></figure>


<p>All this does is check for the existence of a <code>settings.yml</code> and load  it&#8217;s
values into our (currently) empty configuration hash using an  in-place
<code>#merge!</code>. The reason we do this is because we very  purposefully didn&#8217;t supply
a mutator <code>Saneconf.conf=</code> for our config  hash. We don&#8217;t <em>want</em> it to be
overwritten later on. For the moment  though we can change existing keys and add
new ones. Next we handle all  non-scalar configuration by parsing some of the
scalar ones into hashes.  Arrays or any other Ruby object could be placed in the
<code>conf</code> hash. It  just happens that Hashes are commonly used by libraries like
ActiveRecord and the Ruby Redis interface for initialization. The reason  I
expand those here and not in place at point-of-use is mostly personal
preference. All I ever want to see in the app is <code>conf['VARIABLE']</code> and  I
shouldn&#8217;t have to think about it and whatever I&#8217;m trying to accomplish  at that
point in our app. Lastly, we call <code>#freeze</code> on the conf hash.  This is a method
every Ruby object has which makes it immutable,  throwing an exception if an
attempt is made to change it. This way, any  of your fellow developers will know
that whatever they&#8217;re doing belongs  in your application initialization code and
not in the middle of your  important code.   Hopefully this proves helpful, the
example code is available on
<a href="https://github.com/nuclearsandwich/saneconf">GitHub</a>.</p>

<p>Good hunting, Steven!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Engine Yard Whisky Dinner, CodeConf 2011]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/05/02/engine-yard-whisky-dinner-code-conf-2011/"/>
    <updated>2011-05-02T10:10:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/05/02/engine-yard-whisky-dinner-code-conf-2011</id>
    <content type="html"><![CDATA[<p><strong>Update 5/3/11: Scroll to the bottom to see a near comprehensive list of what
we drank. If I missed anything, do let me know.</strong></p>

<p>Firstly, I&#8217;d like to thank Engine Yard for knowing that geeks tend to be
inter-disciplinary and enjoy geeky discussion of things other than code! They
also made an excellent choice in inviting Craig because he&#8217;s clearly one of the
biggest geeks on the planet&#8230; in the field of Scotch Whisky. Since the Whisky
dinner was at Engine Yard&#8217;s office a group from the Convore chat for the
conference decided to meet at and walk from the hotel. I had to run back to the
Nowmov office to grab the rest of my stuff since I was intending to take the
train home directly from dinner. So myself, Steve Klabnik, Tom Preston-Werner
and his wife, and a bunch of other folks from the conference all walked down
over together. About three blocks from the hotel, I found $20. I&#8217;m not lying,
nor am I lying when I say that that was without a doubt the worst part of my
evening. The rest was just that awesome. Upon arrival we were told to snag
t-shirts, which were created specially for the evening and parodied GitHub&#8217;s
&#8220;Fork You&#8221; shirts, which you can customize with your GitHub handle by placing
your name on the back in the blank after http://github.com/________, in case you
haven&#8217;t seen them yet.</p>

<p>After snagging a shirt, we were directed toward the &#8220;soft drinks&#8221; which
consisted of Guinness, Stella Artois, and Lagunitas IPA. It was hard not to
notice the sea of clear plastic cups all around us, each filled with a small
measure of brown liquid. I had a beer or two over good conversation while Craig
and Randall were finishing up. I have to admin, I was a little anxious to get
started as I noticed that on the last table was a bottle marked Lagavulin, which
is a distillery which comes highly recommended by @vanden and @mcnalu on
Identi.ca, but which I haven&#8217;t been able to try yet. Add to that, the fact that
it is getting on toward 8:25 and the last train home for the night departs at
9:15 and is a ten minute walk away. Things finally start up and Randall
introduces Craig, who is very tall and has been wandering around enigmatically
the whole time. After a brief introduction by Randall, Craig tells us a little
about his history and current job:</p>

<blockquote><p>The only difference between myself and an alcoholic is I get paid.</p></blockquote>

<p>He launches into the official definition of Scotch Malt Whisky which is any
spirit which meets the following criteria:</p>

<ol>
<li>It is made using malted barley from Scotland exclusively.</li>
<li>It is distilled in Scotland.</li>
<li>It is aged in oak barrels for a minimum of three years.</li>
</ol>


<p>That&#8217;s it, that&#8217;s all that you need! Once everyone is on the same page, he
introduces us to the first whisky of the night.</p>

<h2>Johnnie Walker Black Label</h2>

<p>The Johnnie Walker, he explains, is significant because it sells. And provides
jobs for a vast number of people relative to the other distilleries. Economic
reasoning aside. We also discuss the very quick finish of the Johnnie Walker
which attempts to make up for some of the sweetness, whilst simultaneously
letting you get another glass without delay.</p>

<h2>Glenfiddich 12 Year</h2>

<p>Throughout the night, Craig&#8217;s explanations of the different whiskies was both
narrative and informative. Even if you didn&#8217;t care a hoot about the history of
Scotch whisky, he carried you forward with the story of it. I certainly saw more
faces in rapt attention than lost in smartphones. The Glenfiddich itself was as
smooth as I remember it being when I sampled some at Christmas, it lacked the
complexity of some of the ones we had later that night but I&#8217;ll definitely
consider it as a potential light whisky, or breakfast whisky, as Craig called
it.</p>

<h2>Aberlour 12 Year</h2>

<p>The Aberlour was the first of these that really got my attention, it was complex
yet smooth and had a much stronger oaky aroma than the others. Not much was said
about the Aberlour distillery itself though the transition topic between the
Aberlour and the Macallan discussed the difference between Scotches from the
Highlands, Speyside, and Islay. The gist of which was that they have
historically produced whiskies with certain characteristics but that the region
is no surefire indication of the actual product.</p>

<h2>The Macallan 12 Year</h2>

<p>I found the Macallan to be a little underwhelming, considering it&#8217;s such a high
profile Scotch. It certainly wasn&#8217;t bad, mind you, but it&#8217;s priced much higher
than Glenfiddich and has a very similar flavor profile. Though, I may have to
revisit it as I drank it rather hurriedly in order to get to the first of the
peated Islay whiskies.</p>

<h2>Caol Ila 12 Year</h2>

<p>Wow, just, wow. This was the stand-out Scotch of the evening for me.
Tremendously oak aroma which was also present, though subtler, in the taste.
The Caol Ila did not taste as peated as the Lagavulin or many of the whiskies
later enjoyed in the smoking room but it really made up for it with the great
oak flavor. I&#8217;m just raving at this point so I&#8217;ll say no more about it.</p>

<h2>Lagavulin 16 Year</h2>

<p>Before the Lavagulin we were treated to a brief and somewhat premature
announcement regarding the Fandabbydozy and the difficulty getting it into the
country, but more on that later. The Lagavulin has been recommended to me by
@vanden for some time. Basically since I asked the internet for Scotch
recommendations. Sadly I was never able to locate any. But Craig provided I
actually recall feeling a little underwhelmed by it, but I expect that&#8217;s because
I was so keen on the Caol Ila. This is another one I want to try again a little
earlier in the evening.</p>

<h2>Non-Smoking Room</h2>

<p>After the Lagavulin we were released into the wild to to visit the three rooms
which had been mysteriously marked Smoking Room, Non-Smoking Room, and Exam Room
since our arrival. Those who were familiar with certain properties of Scotch
like myself probably guessed at the difference between the two rooms and were
correct. The Non-Smoking room held the unpeated whiskies. In here I tried things
like the Macallan Cask Strength and the Clynelish 14 year, which was my favorite
of the non-smoking room. There was a third bottle in here but I can&#8217;t recall
what it was as there was no room for it on the back of my shirt.</p>

<h2>Smoking Room</h2>

<p>This is the room for me I knew it&#8217;d be awesome, what I didn&#8217;t know was just how
awesome it would be. My notes rapidly begin to decline in quality in this room.
So I know the scotches were excellent. In here was an Ardbeg 12 Year, the
Laphroaig Murray McDavid, and again, a third which I cannot recall because I ran
out of room on the shirt.</p>

<h2>Exam Room</h2>

<p>When he introduced the other two rooms, Randall also introduced the exam room.
In this room there were a number of cups containing an unnamed spirit. Our goal
was to try some and identify in as much detail as we could, using the techniques
we learned from Craig, the spirit in the cups. Everyone would pitch their card
with their guess written on it into the pile and the winner would get a bottle
of something wonderful to bring home. I was one of the last people in the room
and submitted my scrawled flavor notes just as they were getting ready to pick
the winner. What I wrote follows:</p>

<ul>
<li>Cardamom, floral, juniper</li>
<li>Almost like a genever</li>
<li>no peat</li>
<li>47% - 55% a.b.v.</li>
</ul>


<p>The instructions were to put as much detail as you could, so I rather
hubristically attempted to add some technical details in the hopes that it would
set me above the competition. It also proves I was pretty well into it that
evening. As it turns out, the exam room contained a gin rather than a whisky,
which had been aged in oak barrels. It was really good and I&#8217;ve been informed
that it&#8217;s available at Bi-Rite in San Francisco and intend to make my way down
there to get a bottle for myself as in addition to my newly acquired scotch
habit I&#8217;m also a gin drinker. So I wasn&#8217;t all that far from the mark and I have
to confirm with Randall but I&#8217;m pretty sure the alcohol content conforms to my
guess as well. However I didn&#8217;t take first place since a gentleman from Engine
Yard had received a bottle of the very same gin for his birthday and had sampled
it the previous night. There are two possible reasons for the events which
followed. Either everyone else was way more drunk than I was, or I have an
incredibly silver-tongued alter ego when drunk. I managed to convince Randall
that A: The guy from Engine Yard kinda sorta cheated by having had some the
previous night, and B: There should really be a runner-up prize anyway. By the
strangest of coincidences I just so happened to be the runner-up. Fancy that!</p>

<p>At the end of the night, they found an untouched bottle of the Murray McDavid to
award me with and I have been saving it for the launch of my side project which
I will talk about in a later post when it&#8217;s closer to being done. Right now the
powers that be (school) have conspired to take all of my free time and replace
it with homework. If there&#8217;s any justice I should have it up and running by the
end of May, but Tanj!</p>

<h2>Fandabbydozy</h2>

<p>What can I say about it&#8230; well, the Fandabbydozy was brought from Scotland
under unusual circumstances but we drank all the evidence of it away so it
should be fine to discuss. It was excellent. Certainly the first time I&#8217;d had a
single cask whisky. I didn&#8217;t pick up as many of the flavors described on the
bottle but I certainly did enjoy my first, and second, and third drams of this
bottle. (Randall was very generous with it though I tried to protest and let
other people enjoy it.)</p>

<p><em>Photo credit goes to Jacob Helwig.The originals are [here][1]</em></p>

<h2>In the End</h2>

<p>All in all, it was a great night, I took home a bottle of Laphroaig for my
fanatical devotion to flavor and by the time I left I was sober enough that I
got back to Union Square without getting lost. Thanks again to everyone at
GitHub and Engine Yard, the CodeConf speakers, fellow volunteers and attendees,
and in particular to Tom and Theresa Preston-Werner, Jacob Helwig, Steve
Klabnick, and Chris Bertels, all of whom were a source of excellent conversation
throughout the weekend. It turns out Chris and I work in the same office suite,
with different folks and in opposite corners so I&#8217;ll likely be pestering him
about Fancy for some time. And lastly, a HUUUGE thanks to Craig for his
fantastic presentation and excellent conversation. I look forward to having a
few drinks with you next time you&#8217;re in San Francisco. If anyone would like more
detail on the scotches or topics I wrote up here, I urge them to ping
@whiskycraig on Twitter.</p>

<h1>Complete List of Drinks</h1>

<ul>
<li>&#8220;Soft&#8221; Drinks

<ul>
<li>Lagunitas IPA</li>
<li>Stella Artois</li>
<li>Guinness</li>
</ul>
</li>
<li>Main Stage

<ul>
<li>Johnnie Walker</li>
<li>Glenfiddich 12 Year</li>
<li>Aberlour 12 Year</li>
<li>The Macallan 12 Year</li>
<li>Caol Ila 12 Year</li>
<li>Lavavulin 16 Year</li>
</ul>
</li>
<li>Non-Smoking Room

<ul>
<li>Macallan Cask Strength</li>
<li>Glengyle</li>
<li>Clynelish 14 Year</li>
</ul>
</li>
<li>Smoking Room

<ul>
<li>Ardbeg 12 Year</li>
<li>Murray McDavid</li>
</ul>
</li>
<li>Exam Room

<ul>
<li>Ransom Old Tom Gin</li>
</ul>
</li>
<li>Special Appearance

<ul>
<li>Fandabbydozy Single Cask</li>
</ul>
</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Most Interesting Day]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/04/27/a-most-interesting-day/"/>
    <updated>2011-04-27T11:19:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/04/27/a-most-interesting-day</id>
    <content type="html"><![CDATA[<p>Today was an interesting day. I helped to start an International holiday in
Corenominal Day, stopped for coffee when I was already running late despite the
fact that I loathe being tardy, tolerated and even enjoyed some aspects of
classes today, and got stung by a wasp that got trapped in my beard while I was
cycling home. All in all, today was quite eventful. Though I still didn&#8217;t get as
much done as I {needed,intended,wanted}. Oh well, there&#8217;s always tomorrow.</p>

<p><img src="http://blog.nuclearsandwich.com/images/blog/corenominal_day.jpg" alt="Corenominal Day" /></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An Awesome Earsome Between Poe and Debussy]]></title>
    <link href="http://blog.nuclearsandwich.com/blog/2011/04/18/an-awesome-earsome-between-poe-and-debussy/"/>
    <updated>2011-04-18T04:20:00-07:00</updated>
    <id>http://blog.nuclearsandwich.com/blog/2011/04/18/an-awesome-earsome-between-poe-and-debussy</id>
    <content type="html"><![CDATA[<p>Everybody I know please follow these instructions.</p>

<ul>
<li>Set aside 10 minutes.</li>
<li>Get good speakers or good headphones.</li>
<li>Set aside ten minutes to play both these videos at once.</li>
<li>Open both these videos at the same time in tabs. They are both sound only.
http://www.youtube.com/watch?v=sXU3RfB7308 with
http://www.youtube.com/watch?v=IkmwzG7cB_U</li>
</ul>


<p>You are listening to James Earl Jones (voice of Darth Vader) reading Edgar Allen
Poe&#8217;s &#8216;The Raven&#8217; with Claude Debussy&#8217;s &#8216;Nuages&#8217; playing in the background.
You may need to turn Vader down so the music can come out.</p>

<p><em>This is fucking cool.</em></p>
]]></content>
  </entry>
  
</feed>

