<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>nick evans - devblog</title>
	<atom:link href="http://ekenosen.net/nick/devblog/feed/" rel="self" type="application/rss+xml" />
	<link>http://ekenosen.net/nick/devblog</link>
	<description>thoughts on software craftsmanship and other technobabble</description>
	<lastBuildDate>Wed, 27 May 2009 18:00:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>pair programming pros and cons</title>
		<link>http://ekenosen.net/nick/devblog/2009/05/pair-programming-pros-andcons/</link>
		<comments>http://ekenosen.net/nick/devblog/2009/05/pair-programming-pros-andcons/#comments</comments>
		<pubDate>Wed, 27 May 2009 18:00:02 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=180</guid>
		<description><![CDATA[I typed up the following in response to Bryan Liles&#8217; recent Pair Programming Showdown.  There are better pair programming lists out there, but this is mine for today.
positive:

 distractions are less common, it needs to be something that distracts both of you; get back into &#8220;the flow&#8221; faster (also a reason to do TDD); helps [...]]]></description>
			<content:encoded><![CDATA[<p>I typed up the following in response to Bryan Liles&#8217; recent <a href="http://smartic.us/2009/05/26/pair-programming-showdown/">Pair Programming Showdown</a>.  There are better pair programming lists out there, but this is mine for today.</p>
<h2>positive:</h2>
<ul>
<li> distractions are less common, it needs to be something that distracts both of you; get back into &#8220;the flow&#8221; faster (also a reason to do TDD); helps those among us with Attention Deficit be productive at *all* (this is an important one for me).</li>
<li> higher <a href="http://c2.com/cgi/wiki?BusNumber">bus number</a>, more team ownership of code, less personal jurisdiction</li>
<li> communication of design decisions is much easier/faster: &#8220;here, let me show you what I mean.&#8221;</li>
<li> creative tension, generally leads to better design decisions, better names for variables/classes/etc, better quality. Automatic &#8220;code review&#8221; on all pair produced code, at the time when it&#8217;s easiest to enact suggestions.</li>
<li> because you&#8217;ve cut the number of concurrent tasks your team can work on in half, you&#8217;ve made it easier to coordinate a larger team and juggle the team&#8217;s current tasks and priorities. In other words, pairing makes it easier to scale the team. Your team members are less likely to step on each other&#8217;s feet.</li>
<li> team culture grows more quickly, quick tips (did you know how to do X in vim? see how inject makes this simpler?) spread through the team more quickly. This could be mentoring of junior developers, or new fresh ideas for senior developers, or peers balancing and pulling each other out. A pairing team tends to gravitate towards the *highest* common denominator, versus individuals working together, tend to be bottlenecked by the weakest link.</li>
<li> pairing and TDD(BDD) go great together, even if you aren&#8217;t occasionally ping-pong pairing</li>
<li> morale boost: team camaraderie grows faster.</li>
</ul>
<h2>difficult or negative:</h2>
<ul>
<li> requires soft-skills, i.e. getting along with other devs, communicating, not being stubborn, etc.
<ul>
<li> good pair programming is a learned skill, but often is treated like something that should Just Work (and is obviously no good if it goes poorly on the first try).</li>
<li> the pairing experience can be spoiled by either person in the pair.</li>
<li> programmers are overwhelmingly introverts, and we would much rather just work (and be) alone, even if it isn&#8217;t the best thing for the team.</li>
</ul>
</li>
<li> fewer tasks can be done concurrently. When you are being asked to finish 20 &#8220;highest priority&#8221; tasks by yesterday, even though it is probably faster to have four people pair on them, doing only two tasks at a time, our instincts are to divide and conquer (four tasks concurrently).</li>
<li> either there is no music (no headphones) or you need to agree/compromise on what to listen to.</li>
<li> it can be hard to replace the personal pride of &#8220;I did this&#8221; with the team pride of &#8220;we did this&#8221;, even if &#8220;We did this&#8221; really means &#8220;I did this and so-and-so helped out and it was better than if I did it alone.&#8221;</li>
<li> pairing (done right) can be more exhausting than working alone. this is mostly because you aren&#8217;t getting distracted as much, you are forced to defend your (often bad) ideas, and you have gotten more done. but still, it&#8217;s more *work* than working alone.</li>
<li> working with different editors is tricky. doable, but tricky. it slows you down and dampens some of the benefits.</li>
<li> remote pairing is tricky. doable, but tricky. it slows you down and dampens some of the benefits.</li>
<li>Awkward pairing:
<ul>
<li> mindless routine tasks feel like a waste of time, and sometimes they are.</li>
<li> research and spiking and experimentation are sometimes very appropriate for pairing, sometimes not at all, and it&#8217;s hard to tell when is which (very context sensitive).</li>
<li> pairing without the cadence of TDD(BDD) often feels awkward. (ahem&#8230; perhaps you should start to TATFT then!)</li>
<li> pairing done wrong (and sometimes even &#8220;done right&#8221;), might not *feel* very productive to one member of the pair. at that point, that person probably feels it is a waste of time, and the other person feels slightly guilty for wanting to pair. Note, this might be far more about emotions and perception than about logic and empirical reality.</li>
</ul>
</li>
</ul>
<h2>In summary</h2>
<p>Because of the above positives, pairing usually results in better code, done in less time, with more team members able to take ownership over it, than if the developers had worked on it individually.  Programming isn&#8217;t constrained by typing speed but by thinking, and two heads are better than one.</p>
<p>The above negatives mean that (in my experience), even when an entire team agrees that pairing is a good thing (in the abstract or based on experience) and the team has agreed to pair some or most of the time, the team often pairs less often or gets less out of it than expected.</p>
<p>Unfortunately, although I&#8217;ve experienced all of the positive reasons for pairing, I tend to get far too influenced and disheartened by the negative.  As a result, I usually pair far less often than I know I should, and both I and my team are less effective as a result.  Any suggestions?</p>
<p>See also these posts: <a rel="nofollow" href="http://www.jroller.com/obie/entry/pair_programming_redux">Obie Fernandez, responding to criticism of his pair programming comments</a>, <a rel="nofollow" href="http://anarchycreek.com/2009/05/26/how-tdd-and-pairing-increase-production/">Mike Hill: How TDD and Pairing Increase Production</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2009/05/pair-programming-pros-andcons/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>please don&#8217;t use before(:all)</title>
		<link>http://ekenosen.net/nick/devblog/2009/02/please-dont-use-before-all/</link>
		<comments>http://ekenosen.net/nick/devblog/2009/02/please-dont-use-before-all/#comments</comments>
		<pubDate>Sat, 07 Feb 2009 08:00:01 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[rspec]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=167</guid>
		<description><![CDATA[Please do not use &#8220;before(:all)&#8221; (in rspec) unless it is imperative for performance reasons.  Even then, it should only be used with the utmost care given towards any global or shared state, and with no expectations on order of the spec run.  You will cause strange build failures if you do not heed [...]]]></description>
			<content:encoded><![CDATA[<p>Please do not use &#8220;<code>before(:all)</code>&#8221; (in rspec) unless it is imperative for performance reasons.  Even then, it should only be used with the utmost care given towards any global or shared state, and with no expectations on order of the spec run.  You <em>will</em> cause strange build failures if you do not heed this warning.</p>
<p>Each individual example (&#8221;<code>it</code>&#8221; blocks) should be able to run by itself or in any order and the example group (&#8221;<code>describe</code>&#8221; blocks) may run in any order, even in random order.</p>
<p><em>Corollaries</em>:  If you change any global or shared state inside an example, please ensure that you reset it to a baseline before the next example.  If you depend on any global shared state, please set it to a baseline before this example.  Both of these are achieved easily with a <code>before(:each)</code> block (or <code>after(:each)</code> in some cases).</p>
<p>Nine times out of ten, when I see a weird sporadic build failure and there is a <code>before(:all)</code> nearby, I can fix it merely by changing it to a <code>before(:each)</code>.   The original author of the spec assumed that it would always run front to back and then proceed to change global or shared state in some of examples (sometimes inadvertantly).</p>
<p>Although I&#8217;ve phrased this advice for rspec, it applies equally to test/unit in ruby, or xUnit on any platform.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2009/02/please-dont-use-before-all/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>mock abuse &#8211; asserting the implementation</title>
		<link>http://ekenosen.net/nick/devblog/2009/02/mock-abuse/</link>
		<comments>http://ekenosen.net/nick/devblog/2009/02/mock-abuse/#comments</comments>
		<pubDate>Tue, 03 Feb 2009 17:00:10 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[mocks]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[shoulda]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=109</guid>
		<description><![CDATA[I use mocks (and stubs and other test doubles) for checking expectations: I&#8217;m a &#8220;mockist&#8220;.  Likewise, a guideline for specs or unit tests is to focus on testing your code (separately from integration tests which might exercise the full stack), and assume that the framework has tested its own code.  However, I think that this [...]]]></description>
			<content:encoded><![CDATA[<p>I use mocks (and stubs and other test doubles) for checking expectations: I&#8217;m a &#8220;<a href="http://martinfowler.com/articles/mocksArentStubs.html">mockist</a>&#8220;.  Likewise, a guideline for specs or unit tests is to focus on testing <em>your</em> code (separately from integration tests which might exercise the full stack), and assume that the framework has tested its own code.  However, I think that this guideline is sometimes taken too far, leading to mock abuse.</p>
<p>Here are some guidelines that help me follow another important principle: <em>test the interface, not the implementation</em>.</p>
<ul>
<li>If the test looks like a copy and paste or trivial transformation of the production code, something is probably wrong.</li>
<li>&#8220;Complex&#8221; code should be avoided in specs, <em>especially</em> if it is a reproduction of the production code (e.g. SQL, <code>ActiveRecord::Base#find</code> conditions, and non-trivial regular expressions).</li>
<li>I prefer business language <em>examples</em> over technical language <em>modeling</em> (e.g. &#8220;<code>belongs_to</code>&#8221; or &#8220;<code>verifies_format_of</code>&#8220;).</li>
</ul>
<h3>Some (bad) examples</h3>
<p>As an example of what I&#8217;m talking about: <a href="http://tammersaleh.com/posts/testing-named_scope">Testing Named Scope with shoulda&#8217;s <code>should_have_named_scope</code></a> (also <code>should_belong_to</code>,  <code>should_have_one</code>, and <code>should_have_many</code> from <a href="http://dev.thoughtbot.com/shoulda/classes/ThoughtBot/Shoulda/ActiveRecord/Macros.html">shoulda&#8217;s ActiveRecord Macros</a>).  <a href="http://api.rubyonrails.com/classes/ActiveRecord/NamedScope/ClassMethods.html#M001906">The rails documentation for <code>named_scope</code></a> also suggests that you can test it by looking at the <code>proxy_options</code> method.</p>
<p>What&#8217;s wrong with the following?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># from rails rdoc:</span>
expected_options = <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:colored</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">'red'</span> <span style="color:#006600; font-weight:bold;">&#125;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
assert_equal expected_options, Shirt.<span style="color:#9900CC;">colored</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">'red'</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">proxy_options</span>
<span style="color:#008000; font-style:italic;"># from shoulda</span>
should_have_named_scope <span style="color:#ff3333; font-weight:bold;">:eighteen</span>,  <span style="color:#ff3333; font-weight:bold;">:conditions</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#123;</span> <span style="color:#ff3333; font-weight:bold;">:age</span> <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006666;">18</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># example of the sort of thing I've seen in codebases I work with</span>
Model.<span style="color:#9900CC;">should_receive</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:find</span><span style="color:#006600; font-weight:bold;">&#41;</span>
     .<span style="color:#9900CC;">with</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span>,
           :conditions <span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#006600; font-weight:bold;">&#91;</span><span style="color:#996600;">&quot;foo =&gt; ? and (bar like ? or blatz in ?)&quot;</span>,
                           foo, bar, blatz<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">and_return</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#006600; font-weight:bold;">&#91;</span>...<span style="color:#006600; font-weight:bold;">&#93;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># I've also seen bastardizations of the above for SQL building</span>
<span style="color:#008000; font-style:italic;"># code which gets piped into a mocked Model.find_by_sql</span></pre></div></div>

<p>Should your specs care if those conditions are created as hashes or arrays, or even at all?  From the outside, it is completely unimportant whether it uses named_scope or a conditions hash behind the scenes.   What you <em>should</em> care about is whether or not they return the correct objects, don&#8217;t return the wrong objects, and (maybe) stack appropriately with other named scopes or finder methods.</p>
<p>More practically, those conditions hashes qualify as production code that represents the <em>very core of the business logic</em> you are supposed to be testing.  If you expect that <code>{:colored =&gt; 'red'}</code>, but the column name is &#8220;<code>color</code>&#8221; or the value is actually stored in hex RGB, you won&#8217;t have a hint that the code is broken.  If you expect that <code>{:age =&gt; 18},</code> your specs won&#8217;t remind you that you were actually supposed to be matching 18 and older.  If you expect the wrong SQL, then your specs have lost their power to help you find the right SQL.  You are <em>wide open</em> for letting sloppy bugs through the very specs that should have caught them.</p>
<p>So, these mocks verify expectations that don&#8217;t matter much, but they copy and paste the bits that <em>do</em> matter, the parts you really should be testing.   You are gaining &#8220;code coverage&#8221;, and thus false confidence.  It&#8217;s like a weird form of <a href="http://en.wikipedia.org/wiki/Regulatory_capture">regulatory capture</a>.  However, a few examples of what you should and should not match would clarify many mistakes immediately.  When working with examples, the boundaries that you need to poke often become obvious.</p>
<h4>Good examples: Named scope or finder methods</h4>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># the following lines would generally be done using factories</span>
good_examples = <span style="color:#006600; font-weight:bold;">&#91;</span>FooBar.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>...<span style="color:#006600; font-weight:bold;">&#41;</span>,
                 FooBar.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>...<span style="color:#006600; font-weight:bold;">&#41;</span>, ...<span style="color:#006600; font-weight:bold;">&#93;</span>
bad_examples  = <span style="color:#006600; font-weight:bold;">&#91;</span>FooBar.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>...<span style="color:#006600; font-weight:bold;">&#41;</span>
                 FooBar.<span style="color:#9900CC;">create</span>!<span style="color:#006600; font-weight:bold;">&#40;</span>...<span style="color:#006600; font-weight:bold;">&#41;</span>, ...<span style="color:#006600; font-weight:bold;">&#93;</span>
<span style="color:#008000; font-style:italic;"># now exercise the code under test</span>
results = FooBar.<span style="color:#9900CC;">my_spectacular_finder_or_named_scope</span><span style="color:#006600; font-weight:bold;">&#40;</span>...<span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#008000; font-style:italic;"># expectations</span>
good_examples.<span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> results.<span style="color:#9900CC;">should</span>     <span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
bad_examples. <span style="color:#9900CC;">each</span> <span style="color:#006600; font-weight:bold;">&#123;</span><span style="color:#006600; font-weight:bold;">|</span>e<span style="color:#006600; font-weight:bold;">|</span> results.<span style="color:#9900CC;">should_not</span> <span style="color:#9966CC; font-weight:bold;">include</span><span style="color:#006600; font-weight:bold;">&#40;</span>e<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
<span style="color:#008000; font-style:italic;"># or perhaps</span>
results.<span style="color:#9900CC;">should</span> == good_examples</pre></div></div>

<p>This wins in almost every regard over mocking SQL or checking the conditions hash or proxy_options.  It is clear what is being tested and how. We are oriented towards results, not implementation. The examples should make it clear if we are missing anything.</p>
<p>However, it is not as concise, but it doesn&#8217;t matter how concise bad specs are.  We could make macros to make the above code more concise, while still retaining the clarity.  It would also be nice to follow the &#8220;one assertion per example&#8221; rule, so that developers get fine grained failure notifications.</p>
<p>And it may be slower if it hits the DB, but it doesn&#8217;t matter how fast bad specs run.  This is a trade-off  of the ActiveRecord ORM style: to test that you wrote the right queries, you need run the queries and verify the results.</p>
<p>Alternatively, this style is well suited to <a href="http://cukes.info/">cucumber</a> or <a href="http://fitnesse.org/">fit</a> tables, enabling the subject matter experts to easily contribute their own examples (and detect mistakes that the developer wouldn&#8217;t know about).</p>
<h3>Good examples: Validations</h3>
<p>Sorry to pick on <a href="http://thoughtbot.com/projects/shoulda/">shoulda</a> above&#8230; but it was the easiest example to google for.  To balance the scales there, I do like two of the macros shoulda uses for validations: <code>should_allow_values_for</code> and <code>should_not_allow_values_for</code>.  I also wrote up a short little rspec matcher that does about the same thing.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#008000; font-style:italic;"># shoulda's macros</span>
should_not_allow_values_for <span style="color:#ff3333; font-weight:bold;">:phone_number</span>, <span style="color:#996600;">&quot;abcd&quot;</span>, <span style="color:#996600;">&quot;1234&quot;</span>
should_allow_values_for     <span style="color:#ff3333; font-weight:bold;">:phone_number</span>, <span style="color:#996600;">&quot;(123) 456-7890&quot;</span>
<span style="color:#008000; font-style:italic;"># my rspec validation matchers</span>
it <span style="color:#006600; font-weight:bold;">&#123;</span> should.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:phone_number</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">of</span> <span style="color:#996600;">&quot;abcd&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
it <span style="color:#006600; font-weight:bold;">&#123;</span> should.<span style="color:#9900CC;">reject</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:phone_number</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">of</span> <span style="color:#996600;">&quot;1234&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
it <span style="color:#006600; font-weight:bold;">&#123;</span> should.<span style="color:#9900CC;">accept</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:phone_number</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">of</span> <span style="color:#996600;">&quot;(123) 456-7890&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
it <span style="color:#006600; font-weight:bold;">&#123;</span> should.<span style="color:#9900CC;">accept</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:phone_number</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">of</span> <span style="color:#996600;">&quot;(123)456-7890&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span>
it <span style="color:#006600; font-weight:bold;">&#123;</span> should.<span style="color:#9900CC;">accept</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:phone_number</span><span style="color:#006600; font-weight:bold;">&#41;</span>.<span style="color:#9900CC;">of</span> <span style="color:#996600;">&quot;123-456-7890&quot;</span> <span style="color:#006600; font-weight:bold;">&#125;</span></pre></div></div>

<p>Specs that verify that the &#8220;appropriate&#8221; regular expression was sent to <code>validates_format_of</code> scare me.  Regular expressions aren&#8217;t just opaque blobs, they are a DSL, a programming language in their own right.  Regexes are code, and we test code.  You shouldn&#8217;t care that a particular regular expression is sent to a particular rails validation macro; you care that <em>your model validations work appropriately</em>, i.e. accept some values and reject others.</p>
<h3>When I&#8217;ll ignore my own advice</h3>
<p>Here are some contraindications:</p>
<p><strong><em>I just don&#8217;t know what to do</em></strong>:  I might be exploring new realms, and feel a bit lost.  Writing some specs, <em>any</em> specs, is a good way to learn, a good way to keep focused while working, and a good way to just get the job done (<a href="http://rubyhoedown2008.confreaks.com/05-bryan-liles-lightning-talk-tatft-test-all-the-f-in-time.html">TATFT</a>).  Even if the specs are no good and tightly coupled to implementation, at least they can act as &#8220;change notifiers&#8221;.  The next time someone edits the code, they&#8217;ll trigger a build failure that will force them to re-evaluate the specs.  Maybe they&#8217;ll come at it with more knowledge and improve the situation.</p>
<p>Pair programming <em>significantly</em> reduces the likelihood of this occurring.</p>
<p><strong><em>too much yak shaving, time to punt</em></strong>:  I know what to do, but it&#8217;s too much work.  For example, if you have some models that are so truly heinous that you cannot simply or clearly create them right there in your spec, my first instinct would be to invest some time in my <a href="http://www.dcmanges.com/blog/38">factories</a>.  It&#8217;ll pay off.  But that is <a href="http://sethgodin.typepad.com/seths_blog/2005/03/dont_shave_that.html">yak-shaving</a>, and it may be too much for now.  &#8220;Emergency mocking&#8221; is excusable.  Document your compromise in the spec, and hopefully that <a href="http://martinfowler.com/bliki/TechnicalDebt.html">technical debt</a> will be repaid in the future.</p>
<p>But excessive mocking can feel like yak-shaving too.  Weigh your options before going the &#8220;quick and dirty&#8221; route; it might actually be <em>slow</em> and dirty.</p>
<p><strong><em>debugging and sanity checks</em></strong>:  If I&#8217;m trying to figure out <em>why</em> the results aren&#8217;t what I expect them to be, I&#8217;ll probably throw in some extra assertions about the implementation, as a sanity check.  I might delete them when I&#8217;m done or keep them in but document them as special.</p>
<p>There may be other contraindications, but these are what come to my mind.</p>
<p>What do you think?</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2009/02/mock-abuse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Ubuntu is &#8220;too easy&#8221;?!</title>
		<link>http://ekenosen.net/nick/devblog/2009/01/ubuntu-is-too-easy/</link>
		<comments>http://ekenosen.net/nick/devblog/2009/01/ubuntu-is-too-easy/#comments</comments>
		<pubDate>Tue, 20 Jan 2009 00:00:09 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[geekery]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=111</guid>
		<description><![CDATA[I&#8217;d like to respond to a meme that has spread around the linux neighborhoods of the Internet for a while now:
&#8220;I&#8217;ve been using Ubuntu for quite some time now and, honestly, I&#8217;m getting a little tired of having everything handed to me. I want to switch to a less noob friendly distro.&#8221;
&#8220;Is anyone else worried, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;d like to respond to a meme that has spread around the linux neighborhoods of the Internet for a while now:</p>
<blockquote><p>&#8220;I&#8217;ve been using <a href="http://www.ubuntu.com/">Ubuntu</a> for quite some time now and, honestly, I&#8217;m getting a little tired of having everything handed to me. I want to switch to a less noob friendly distro.&#8221;</p>
<p>&#8220;Is anyone else worried, that because Ubuntu is so stable, and because you rarely have to fix issues, that your Linux knowledge is fading?&#8221;</p>
<p>&#8220;I want to use a distro that will challenge me to learn how things work.&#8221;</p></blockquote>
<p>And so on&#8230;</p>
<h2>My response</h2>
<p>You might enjoy giving <a href="http://www.debian.org/">Debian</a> a try.  You also have the option to go with <a href="http://www.archlinux.org/">Arch Linux</a> or <a href="http://www.slackware.com/">Slackware</a> or <a href="http://www.gentoo.org/">Gentoo</a> or <a href="http://www.linuxfromscratch.org/">Linux from Scratch</a>, etc.   You could also install <a href="http://www.ubuntu.com/products/whatisubuntu/serveredition/jeos">Ubuntu JeOS</a> or <a href="http://www.ubuntu.com/products/whatisubuntu/serveredition">Ubuntu Server</a> (or another distro&#8217;s simpler versions) and then only apt-get or compile software as you want it.</p>
<p>If you are the type of person making the same sort of remarks as above, you obviously have a lot of time.  I&#8217;m jealous of you.  <img src='http://ekenosen.net/nick/devblog/wp-includes/images/smilies/icon_wink.gif' alt=';-)' class='wp-smiley' />   But lots of time is not limitless time.  So if you want a challenge that will pay off, I suggest that your time might be better invested by sticking with Ubuntu (or Debian), and simply diving under the hood a bit more.</p>
<p>I don&#8217;t mean to say that any of the other distros or paths you might choose aren&#8217;t valid&#8230; one of them may well be a better fit for you and your ambitions than Ubuntu.  But, unlike <a href="http://www.microsoft.com/WINDOWS/">proprietary</a> <a href="http://www.apple.com/macosx/">OSes</a>, Ubuntu&#8217;s hood is <em>not</em> welded shut.   Much of the &#8220;magical&#8221; hand-holding is done in shell, perl, or python scripts.  So you may not even need to look further than your own box for the source.   And just because Ubuntu is intended to be user-friendly with no-assembly-required doesn&#8217;t make it any less configurable or less geek friendly, nor does it get in the way of your deconstructing and reconstructing it (and wondering about those leftover pieces at the end).   The wires and pipes are all showing, there&#8217;s no magic going on, and you are in control of your box.</p>
<h3>for example</h3>
<p>Are you interested in mucking around with webservers?  Then go ahead and compile <a href="http://httpd.apache.org/">apache</a>/<a href="http://nginx.net/">nginx</a>/<a href="http://www.lighttpd.net/">lighttpd</a>/etc from source yourself.   Muck about with the config files.   Spend days with man pages and google and upstream&#8217;s bugtrackers.  Use the distro&#8217;s packages as a &#8220;cheat sheet&#8221; to see what patches, config, scripts, etc the distro maintainers used, and then selectively pick and choose your own way from there.   Rig up benchmarks or compare them on features, ease of configuration, etc.</p>
<p><strong>Post</strong> your troubles/successes/thoughts/etc to mailing lists and blog about what you&#8217;ve done.   Post the results to <a href="https://launchpad.net/">launchpad</a> or <a href="http://github.com/">github</a> or some other publicly accessible DVCS repo.   <strong>Respond</strong> to the comments of the people who tell you you&#8217;re doing it all wrong (many of them are right).  <strong>Adjust</strong> your approach and <strong>iterate</strong> until something else more interesting catches your interest.</p>
<h3>other examples</h3>
<p>Or do the same thing with&#8230;</p>
<ul>
<li> mail servers (<a href="http://www.postfix.org/">postfix</a>/<a href="http://www.sendmail.org/">sendmail</a>/<a href="http://www.exim.org/">exim</a>/etc)</li>
<li>filesystems:
<ul>
<li>local: ext3, <a href="http://xfs.org">XFS</a>, <a href="http://ext4.wiki.kernel.org/">ext4</a>, etc</li>
<li><a href="http://www.tldp.org/HOWTO/LVM-HOWTO/">LVM</a>, <a href="http://tldp.org/HOWTO/Software-RAID-HOWTO.html">software RAID</a></li>
<li>networked: <a href="http://nfs.sourceforge.net/nfs-howto/">NFS</a>, <a href="http://www.samba.org/">Samba</a>, <a href="http://www.openafs.org/">AFS</a>, etc.</li>
</ul>
</li>
<li><a href="http://wiki.debian.org/XStrikeForce">X Windows</a></li>
<li><a href="http://www.gnome.org/">GNOME</a> or <a href="http://www.kde.org/">KDE</a></li>
<li>Dig into <a href="http://www.freedesktop.org/wiki/Software/hal">HAL</a> and <a href="http://www.freedesktop.org/wiki/Software/dbus">D-BUS</a> and all of those magical goings-on beneath the covers, and learn how to make them do your bidding.</li>
<li>Learn about <a href="http://www.linuxfoundation.org/en/LSB">LSB</a> and <a href="http://freedesktop.org">freedesktop.org</a>.</li>
<li>Figure out what Ubuntu did wrong with <a href="http://www.pulseaudio.org/">pulseaudio</a>, and then fix it or swap it out with another audio stack.</li>
<li>Learn <a href="http://www.debian.org/doc/FAQ/ch-pkgtools.en.html">how dpkg/apt does its magic</a>,
<ul>
<li>understand the <a href="http://www.debian.org/doc/debian-policy/">Debian packaging guidelines</a> (and why they are wonderful or horrible or just don&#8217;t meet your needs or desires),</li>
<li>and start your own <a href="https://help.launchpad.net/Packaging/PPA">Launchpad PPA</a> for software packaged the way you like it.</li>
</ul>
</li>
<li>Run &#8220;<code>ps faux</code>&#8221; and make it your mission to discover the purpose behind every running process and how it got there&#8230; and then remove or replace the ones you don&#8217;t want.
<ul>
<li>Run &#8220;<code>dpkg -l</code>&#8221; and do the same thing with every package on your system.</li>
</ul>
</li>
<li>Install <a href="http://www.bootchart.org/">bootchart</a> and figure out how to shave several more seconds off of your boot-time.</li>
<li>Restore the geeky log messages to the Ubuntu boot screen.</li>
<li>Spend a week figuring out out to use <a href="http://www.suckless.org/wmii/">wmii</a>,
<ul>
<li>another week with <a href="http://xmonad.org/">xmonad</a>,</li>
<li>and another with <a href="http://awesome.naquadah.org/">awesome</a>;</li>
<li>Ubuntu doesn&#8217;t force you to use metacity or compiz (or GNOME).</li>
</ul>
</li>
<li>Install the 64-bit version,
<ul>
<li>discover all the myriad places it breaks horribly,</li>
<li>and file bug reports with all of those packages.</li>
</ul>
</li>
<li>Obsessively install the latest beta version of some software you like a lot,
<ul>
<li>and report the new bugs on every release.</li>
</ul>
</li>
</ul>
<p>When you&#8217;ve picked out an interesting challenge and jumped into it: <em><strong>Post, respond, adjust, iterate.</strong></em></p>
<h2>personally</h2>
<p>I personally use my own compiled version of ruby and related libraries, because the ruby upstream maintainers released a new &#8220;minor&#8221; version with myriad backwards incompatibilities (and a few segfaults), and the Debian/Ubuntu maintainers followed their advice and upgraded. But the software at my day job still needs that older version.  Ubuntu doesn&#8217;t make it hard to do this for the packages that I know and care about, and I get to continue relying on Ubuntu for everything else I don&#8217;t care about and don&#8217;t want to spend time on (right now).</p>
<p>Several years ago, I compiled compiz/beryl myself.  Then I switched to someone else&#8217;s apt repository.  Now I just use the compiz provided by Ubuntu (and I can spend those regained several hours a week geeking out on something else).</p>
<p>Years ago, I used debian unstable for everything.   Now I really appreciate the stability and twice a year upgrades of Ubuntu.  Generally, my &#8220;<code>ls /etc/apt/sources.list.d/ | wc -w</code>&#8221; stays between 2 and 6 (currently 3).  Occasionally this less stable software is an unwelcome source of bugs and a time-sink.  But I try to always file bugs.</p>
<h2>So then&#8230;</h2>
<p>The opportunities for non-hand-holding non-newbie stuff in Ubuntu is <em>limitless</em>.  You could transform yourself into one of the gurus that holds other people&#8217;s hands.  You could even make it your goal to become a <a href="http://www.debian.org/doc/maint-guide/">Debian package maintainer</a> or an <a href="https://wiki.ubuntu.com/MOTU">Ubuntu MOTU</a> or a GNOME contributor or a KDE contributor or a $FOO contributor (which will look <em>mighty</em> nice on a résumé).</p>
<h3>but practice safe geeking</h3>
<p>But above all, consider doing your experimentation on a spare computer or in a <a href="http://www.virtualbox.org/">VirtualBox</a> VM, so that when your friends ask you to play a movie or browse the web or do something simple (that their &#8220;welded-shut&#8221; Mac or Windows box can handle just fine), you don&#8217;t need to say &#8220;oh my computer&#8217;s currently hosed&#8230; {<em>sound,X Windows,TV Tuner,booting,etc</em>} doesn&#8217;t work.  It&#8217;ll be back up in a week.&#8221;  In my experience, that excuse can get kinda embarrassing. <img src='http://ekenosen.net/nick/devblog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<div class="wp-caption aligncenter" style="width: 675px"><a href="http://xkcd.com/456/"><img title="From original: This really is a true story, and she doesn't know I put it in my comic because her wifi hasn't worked for weeks." src="http://imgs.xkcd.com/comics/cautionary.png" alt="xkcd.com web comic" width="665" height="277" /></a><p class="wp-caption-text">From xkcd.com, Cautionary, CC licenced By-NC.</p></div>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2009/01/ubuntu-is-too-easy/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>ruby defined? # =&gt; &#8220;expression&#8221;</title>
		<link>http://ekenosen.net/nick/devblog/2008/12/ruby-defined-expression/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/12/ruby-defined-expression/#comments</comments>
		<pubDate>Thu, 11 Dec 2008 17:00:36 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=93</guid>
		<description><![CDATA[Ever spend a long time debugging something, only to find out an hour or two later that you were staring at the problem all along, and you should have realized it from the beginning?  And then, of course, the solution only requires a tiny tweak to one line, perhaps merely the addition of a [...]]]></description>
			<content:encoded><![CDATA[<p>Ever spend a long time debugging something, only to find out an hour or two later that you were staring at the problem all along, and you should have realized it from the beginning?  And then, of course, the solution only requires a tiny tweak to one line, perhaps merely the addition of a few parenthesis.</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? RAILS_ENV
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;constant&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? RAILS_ENV <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> RAILS_ENV == <span style="color:#996600;">&quot;development&quot;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;expression&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#9966CC; font-weight:bold;">defined</span>? RAILS_ENV<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#006600; font-weight:bold;">&amp;&amp;</span> <span style="color:#006600; font-weight:bold;">&#40;</span>RAILS_ENV == <span style="color:#996600;">&quot;development&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span></pre></div></div>

<p>D&#8217;oh!  <em>(let&#8217;s ignore for now the issue of whether or not the &#8220;fixed&#8221; code is reasonable to run anyway)</em></p>
<p>I was curious to see if the expression was evaluated, and it appears that it is&#8230; sort of:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">def</span> foo
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span>   <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;:foo&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">def</span> bar
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span>   <span style="color:#ff6633; font-weight:bold;">$stderr</span>.<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;:bar&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span>   <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#996600;">&quot;hell&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? foo
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;method&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? bar
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;method&quot;</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? foo <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">1</span>
<span style="color:#ff3333; font-weight:bold;">:foo</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#996600;">&quot;expression&quot;</span>
<span style="color:#ff3333; font-weight:bold;">:bar</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#9966CC; font-weight:bold;">defined</span>? bar <span style="color:#006600; font-weight:bold;">||</span> <span style="color:#006666;">1</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">nil</span></pre></div></div>

<p>Notice: the methods were executed, but the exception from <code>bar</code> was caught and squirreled away somewhere, and <code>defined?</code> the returned <code>nil</code>, even though the method and expression were certainly &#8220;defined&#8221;.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/12/ruby-defined-expression/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>a better progress bar for rspec</title>
		<link>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/#comments</comments>
		<pubDate>Tue, 09 Dec 2008 20:00:26 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[rspec]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=53</guid>
		<description><![CDATA[Updated 2008-12-10: added screenshot and video.
I&#8217;ve always been a little bit bemused by the default ruby test/unit and rspec output: a series of dots, one for each passing test (or example), and the dots become &#8220;F&#8221; characters in the event of a failure.  Most importantly: it&#8217;s simple, unambiguous about pass/fail, and easy to read at [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Updated 2008-12-10:</strong> <em>added screenshot and video.</em></p>
<p>I&#8217;ve always been a little bit bemused by the default ruby test/unit and rspec output: a series of dots, one for each passing test (or example), and the dots become &#8220;F&#8221; characters in the event of a failure.  Most importantly: it&#8217;s simple, unambiguous about pass/fail, and easy to read at a glance, so no problem there.  You get a feel for the speed at which the tests are running, and you can visualize how many tests have run already.  And it&#8217;s easy enough to have them output in color (red or green), to make the errors visually pop out.  And it&#8217;s drop dead simple.  That&#8217;s good.</p>
<h3>So what&#8217;s missing?</h3>
<p><em>(for my tastes)</em></p>
<ul>
<li><strong>Immediate Feedback</strong>:  Yeah, the default output gives me an &#8220;F&#8221;, but what am I supposed to do with an &#8220;F&#8221;?  I won&#8217;t know where and what that &#8220;F&#8221; was until the end of the entire test run, when the summary is dumped.  When running through a (functional) test suite that takes three minutes or even fifteen minutes, that just doesn&#8217;t work.</li>
<li><strong>Concise output</strong>: if everything is passing, I don&#8217;t need to see 4000+ dots displayed across my screen.  It would be nice if the entire output would fit into a single line (when there are no failures).</li>
<li><strong>Percentage</strong>:  A nice to have, not a need to have.  But knowing how many tests have already run is generally not as interesting to me as how many tests are there total, and what percentage of them have run.</li>
<li><strong>ETA</strong>: This isn&#8217;t so important for the short test runs that I do over and over again during the BDD cycle&#8230; because I expect those tests to finish in under 10 seconds anyway.  But anything more than 10 seconds, and I get distracted.  An ETA helps me limit my distraction.</li>
</ul>
<h3>So what do I do about it?</h3>
<p>Basically, what I want is a progress bar and that the errors and warnings be displayed immediately. I also want warnings to be printed for slow specs. When using color, I want the entire progress bar printed in green if everything is good, yellow if there has been a warning, and red if there has been an error.</p>
<p>Fortunately, rspec makes it <em>very</em> simple to write a custom output formatter. So, a couple of weekends ago, I threw something together in about half an hour.  I&#8217;ve used it ever since, and I&#8217;m pretty happy with it (I&#8217;ve tweaked it a little bit).</p>
<h3>What does it look like?</h3>
<p>A static image doesn&#8217;t really show off the progress bar very well, but here&#8217;s a screenshot (click thumbnail for full-size):</p>
<p style="text-align: center;"><a href="http://ekenosen.net/nick/devblog-uploads/2008/12/rspec_progress_bar_example.jpg"><img class="size-medium wp-image-87 aligncenter" title="rspec_progress_bar_example" src="http://ekenosen.net/nick/devblog-uploads/2008/12/rspec_progress_bar_example-300x276.jpg" alt="" width="300" height="276" /></a></p>
<p>And here is a video, so you can see it in action (very low quality, sorry):</p>
<p style="text-align: center;"><embed id="VideoPlayback" src="http://video.google.com/googleplayer.swf?docid=-6454522180447850859&#038;hl=en&#038;fs=true" style="width:400px;height:326px" allowFullScreen="true" allowScriptAccess="always" type="application/x-shockwave-flash"> </embed></p>
<h3>The code</h3>
<p><a href="http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb">http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb</a></p>
<p>It&#8217;s currently hosted in a <a href="http://bazaar-vcs.org/">bzr</a> branch, but I&#8217;ll stick it up on github if anyone really cares about that.  Also, it depends upon the progressbar gem, so you&#8217;ll need to install that.</p>
<h3>To use it</h3>
<p>The location you download the script to is not important, but this is where I&#8217;m (currently) keeping it. You could also use bzr to pull down the entire branch.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">$ gem install progressbar
&nbsp;
$ mkdir -p ~/lib/rspec/
$ cd ~/lib/rspec
$ wget http://ekenosen.net/bzr/rspec_support/compact_progress_bar_formatter.rb
&nbsp;
$ spec --require ~/lib/rspec/compact_progress_bar_formatter.rb -c -f Spec::Runner::Formatter::CompactProgressBarFormatter path/to/specs</pre></div></div>

<p>I&#8217;m currently using some bash aliases to keep the spec command line nice and short.  Perhaps there&#8217;s a better way?  In <code>~/.bash_aliases</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">alias  spb='spec        --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'
alias sspb='script/spec --require ~/lib/rspec/compact_progress_bar_formatter.rb --format Spec::Runner::Formatter::CompactProgressBarFormatter --color'</pre></div></div>

<p>For rake tasks, I use a <code>spec/local_spec.opts</code> (<code>spec/spec.opts</code> is checked into version control as a default).</p>
<h3>Nitpicking</h3>
<p>I cheated: I didn&#8217;t develop it BDD-style.  I intend to fix that soon by rewriting it spec-first; certainly before adding any more functionality. <a href="http://rubyhoedown2008.confreaks.com/05-bryan-liles-lightning-talk-tatft-test-all-the-f-in-time.html">TATFT</a> indeed.</p>
<p>I&#8217;d really like to be able to send the threshold (for reporting of slow specs) in on the command line.  It might be easy to do, I haven&#8217;t looked into it&#8230; I&#8217;m currently just editing the file every time I want to change the threshold (e.g. normal specs run with a threshold of 0.1 sec, functional specs run with a threshold of 5 or 10 seconds).  Messy.</p>
<p>Also, it would be nice if the command line didn&#8217;t need to be so long&#8230; perhaps a supported gem/plugin system for rspec?  If that were easily doable, then I would probably package this up into a gem.</p>
<p>I had to break into the progressbar&#8217;s internals a little bit&#8230; it didn&#8217;t publically expose all of the functionality I wanted.  Still, that&#8217;s better than creating my own progressbar library.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/12/better-progress-bar-for-rspec/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Times and time zones considered dangerous (especially in tests)</title>
		<link>http://ekenosen.net/nick/devblog/2008/12/times-and-time-zones-considered-dangerous/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/12/times-and-time-zones-considered-dangerous/#comments</comments>
		<pubDate>Fri, 05 Dec 2008 17:30:28 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=29</guid>
		<description><![CDATA[Just wanted to put out a note of caution to other developers.  Any code (test/spec or production) that depends on global environment settings or non-deterministic functions needs to be treated with fear and trembling.  As a concrete example of this maxim, code that deals with Time, Date, and DateTime has the possibility to trip you [...]]]></description>
			<content:encoded><![CDATA[<p>Just wanted to put out a note of caution to other developers.  Any code (test/spec or production) that depends on global environment settings or non-deterministic functions needs to be treated with fear and trembling.  As a concrete example of this maxim, code that deals with <code>Time</code>, <code>Date</code>, and <code>DateTime</code> has the possibility to trip you up with <em>both</em> global environment and non-determinism.  I recently discovered a potential bug related to this&#8230; but it took me 45 minutes to track down&#8230; so I wrote up the following afterwards:</p>
<hr />nota bene: some of the methods described herein are not defined by Ruby&#8217;s core library&#8217;s but by Rails&#8217; <code>ActiveSupport</code>.</p>
<p>Any non-determinism in tests is dangerous, and <code>Time.now</code> and its close cousins are certainly on that list.  Whether the code which depends on the current date is in the production code or in the spec code, we&#8217;ll need to be very careful of it, lest it trip us up.</p>
<p>I&#8217;ve known this for a long time&#8230; but I just spent about 45 minutes perplexed with a particularly stupid bug that simply required an attentive eye to unravel&#8230; I&#8217;ll gladly share my debugging session (condensed for time and minus the aggravation and going in circles), and hopefully save someone else the hassle:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">yesterday</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>Well <em>that</em> shouldn&#8217;t ever happen.  Confused yet?  Or do you already know where this is going?  I spent a great deal of time wondering if it was some weird interaction between the <code>Date</code>, <code>Time</code>, and <code>DateTime</code> classes (and trust me, those weird interactions do exist, although maybe they weren&#8217;t the cause of this particular bug).</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Sun, <span style="color:#006666;">24</span> Aug <span style="color:#006666;">2008</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">yesterday</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Fri, <span style="color:#006666;">22</span> Aug <span style="color:#006666;">2008</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Sat, <span style="color:#006666;">23</span> Aug <span style="color:#006666;">2008</span> <span style="color:#006666;">23</span>:<span style="color:#006666;">24</span>:<span style="color:#006666;">35</span> <span style="color:#006600; font-weight:bold;">-</span>0400</pre></div></div>

<p>Ummm&#8230; nothing that would explain the comparison results above&#8230; but that&#8217;s curious&#8230; DateTime.now gives a different inspect output than the others.  I wonder why?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">yesterday</span>.<span style="color:#9966CC; font-weight:bold;">class</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Date</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span>.<span style="color:#9966CC; font-weight:bold;">class</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">Date</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9966CC; font-weight:bold;">class</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span></pre></div></div>

<p>Intriguing.  Certainly not what I expected, given that all of these values were obtained from class methods on <code>DateTime</code>.  Perhaps this means that the comparison requires some coercion to work&#8230;  I didn&#8217;t investigate the source to see if it uses &#8220;<code>to_datetime</code>&#8221; as opposed to &#8220;to_time&#8221;, but I&#8217;m assuming that it does, because of the following:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span>.<span style="color:#9900CC;">to_time</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_time</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">false</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span>.<span style="color:#9900CC;">to_datetime</span> <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_datetime</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> <span style="color:#0000FF; font-weight:bold;">true</span></pre></div></div>

<p>So what does <code>Date#to_datetime</code> do to screw us over?</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">yesterday</span>.<span style="color:#9900CC;">to_datetime</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Fri, <span style="color:#006666;">22</span> Aug <span style="color:#006666;">2008</span> 00:00:00 0000
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">tomorrow</span>.<span style="color:#9900CC;">to_datetime</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Sun, <span style="color:#006666;">24</span> Aug <span style="color:#006666;">2008</span> 00:00:00 0000
<span style="color:#006600; font-weight:bold;">&gt;&gt;</span> <span style="color:#CC00FF; font-weight:bold;">DateTime</span>.<span style="color:#9900CC;">now</span>.<span style="color:#9900CC;">to_datetime</span>
<span style="color:#006600; font-weight:bold;">=&gt;</span> Sat, <span style="color:#006666;">23</span> Aug <span style="color:#006666;">2008</span> <span style="color:#006666;">23</span>:<span style="color:#006666;">28</span>:<span style="color:#006666;">11</span> <span style="color:#006600; font-weight:bold;">-</span>0400</pre></div></div>

<p>Do you see it?  The answer is right there, but it&#8217;s easy to miss.  I missed it over and over again for about 40 minutes.  &#8221;<code>-0400</code>&#8221; &#8212; the timezone.  The timezone had been screwing me up all along.  The DateTime object has my timezone from the get-go, but the Date objects were converted as UTC. Lovely&#8230; just lovely.</p>
<p>Now, I wasn&#8217;t the original author of the code.  Just an archaeologist.  My guess: the code worked when it was built (during business hours, not in the wee hours of the night when the timezones would trip them up), and it looked like the simplest thing needed.  Generally, you really can&#8217;t fault a developer for going that route. I certainly don&#8217;t.  But times and dates and especially anything related to the <em>current</em> <span class="nfakPe">time</span> and date&#8230; well, these are special animals, and need to be dealt with special care.</p>
<p>The long and short of it?  Timezones are global environment state, and you need to be aware of it with any code (especially tests) that deal with time.  Avoid <code>DateTime.yesterday</code> or <code>DateTime.tomorrow</code> like the plague in your test/spec code (unless you enjoy tests that spuriously fail near the witching hour).  You should write your tests (and your production code) in such a way that you can simulate different timezones and different times of day in order to tease out bugs.  And if you need to compare or convert dates and times in your production code, be very aware of what time and timezone your business rules will require, especially if you have any <code>Date</code> objects that might be automatically coerced into <code>DateTime</code> objects.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/12/times-and-time-zones-considered-dangerous/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>what is more gitish than&#8230;</title>
		<link>http://ekenosen.net/nick/devblog/2008/11/what-is-more-gitish-than/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/11/what-is-more-gitish-than/#comments</comments>
		<pubDate>Sun, 30 Nov 2008 19:00:16 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[dvcs]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=22</guid>
		<description><![CDATA[&#8220;What is more Gitish than a dozen geeks passing around a laptop with an awesome patch so everyone can sign off on it, then four core Git developers trying to figure out how to use git send-email for 10 minutes?&#8221; &#8211; from GitTogether 2008
You do realize that this completely plays into certain negative stereotypes of [...]]]></description>
			<content:encoded><![CDATA[<p>&#8220;What is more Gitish than a dozen geeks passing around a laptop with an awesome patch so everyone can sign off on it, then four core Git developers trying to figure out how to use git send-email for 10 minutes?&#8221; &#8211; from <a href="http://github.com/blog/196-gittogether-2008">GitTogether 2008</a></p>
<p>You do realize that this completely plays into certain negative stereotypes of <a href="http://git.or.cz/">git</a>, don&#8217;t you?  Passing a laptop around so that people can sign a patch/commit?  This seems to me like something a DVCS ought to make easy (easier than passing a laptop around).  Git <em>core developers</em> take more than a minute to figure out how to work with <code>git send-email</code>?  The fact that these things seem very &#8220;gitish&#8221; is evidence for some of git&#8217;s more negative stereotypes (some deserved, some not).</p>
<p>The article also mentions some much needed UI improvement to the index/cache workflow, and that sounds great.  I hope git continues to take a good critical look at some of its current UI decisions.</p>
<p>For the record, I prefer <a href="http://bazaar-vcs.org/">bzr</a>, but I don&#8217;t hate git.  It&#8217;s a great and powerful piece of software, and has served the linux kernel and other Free/Libre/Open-Source projects tremendously.  It&#8217;s considerably better than svn or cvs for most open source projects, and it has some strengths that make it better than the other DVCS tools for <em>certain</em> projects.  But I do think it is over-hyped.  And I wouldn&#8217;t willingly inflict it upon myself for any personal project.  I personally think that most projects would be better served by one of the other open source DVCS tools: especially <a href="http://bazaar-vcs.org/">bzr</a> (my VCS of choice), or <a href="http://www.selenic.com/mercurial/">hg</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/11/what-is-more-gitish-than/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>features of rails migrations you should probably use</title>
		<link>http://ekenosen.net/nick/devblog/2008/11/rails-migrations-features/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/11/rails-migrations-features/#comments</comments>
		<pubDate>Sat, 29 Nov 2008 19:00:02 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[migrations]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=25</guid>
		<description><![CDATA[I recently paired with another developer to fix a bug in a rails DB migration.  As we cleaned up the code in order to analyze the bug, we noticed two simple features that were not being used, and the other developer recommended that I write up an email to point these features out to everyone [...]]]></description>
			<content:encoded><![CDATA[<p>I recently paired with another developer to fix a bug in a rails DB migration.  As we cleaned up the code in order to analyze the bug, we noticed two simple features that were not being used, and the other developer recommended that I write up an email to point these features out to everyone else.  And now I&#8217;m cleaning up that email to post here.  Hopefully this helps someone else out.  Both of these (and more) are documented at<a href="http://api.rubyonrails.org/classes/ActiveRecord/Migration.html"> http://api.rubyonrails.org/classes/ActiveRecord/Migration.html</a></p>
<h3>Cool feature: say_with_time</h3>
<p>If you find yourself putting comments around your code to explain to developers what&#8217;s going on, please consider instead using &#8220;<code>say_with_time</code>&#8220;.  Then you can document what is happening both in the code <em>and</em> on the console when the migration is actually running&#8230; and you&#8217;ll get other nice info printed out (like the elapsed time) as well.</p>
<h3>Important feature: ActiveRecord::IrreversableMigration</h3>
<p>If the migration cannot safely or easily be migrated downwards, then we need to communicate that clearly to other developers.  But &#8220;<code>puts</code>&#8221; isn&#8217;t good enough.  Instead, &#8220;<code>raise ActiveRecord::IrreversableMigration</code>&#8220;.</p>
<p>For complicated migrations, even if it is <em>possible</em> to safely reverse the migration, I strongly prefer simply raising the exception.  It&#8217;s too easy to make a mistake, and then you&#8217;ll have a DB that claims to be at one version, but has corrupted data for that version, which will most likely lead to more pain and suffering down the line.</p>
<p>If the migration is just cleaning up bad data, then there&#8217;s probably no real need to reverse it.  But in that case maybe you should at least print out a message to the screen letting the developer know that nothing is happening, and why that is okay.</p>
<p>Since I rarely ever use down migrations, my threshold is probably lower than most; if <code>:Rinvert</code> from <a href="http://rails.vim.tpope.net/">rails.vim</a> can&#8217;t automatically generate the down migration, then I will probably simply raise the exception.  I&#8217;ve personally witnessed too many needless bugs due to corrupted data and too many broken down migrations to invest any significant time into them.  At any rate, developers should use discretion with down migrations.</p>
<p>Oh, and <em>please</em> don&#8217;t <em>ever</em> run down migrations in production.  That&#8217;s what database backups are for, and you are backing up before you upgrade your production database, <em>aren&#8217;t you?</em></p>
<h3>Use the progressbar gem for long running data migrations</h3>
<p>And one other thing that is not included with rails that you should probably be using anyway: <a href="http://0xcc.net/ruby-progressbar/index.html.en">the progressbar gem</a>.  If you any long running data migrations, this is a must.  And just because it isn&#8217;t long running for you with your developer DB doesn&#8217;t mean it won&#8217;t be long running during deployment to production.  It&#8217;s trivially easy to use, and your deployer&#8217;s won&#8217;t be stuck wondering if their connection has been dropped or the migration has locked up.  And the ETA will let them know if they have time to get a cup of coffee.  The other developers and deployers will thank you.</p>
<h3>Simple Example</h3>
<p><em>(albeit, also a poorly contrived example)</em></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">require</span> <span style="color:#996600;">'progressbar'</span>
&nbsp;
<span style="color:#9966CC; font-weight:bold;">class</span> CreateWidgetAuxiliaryFrobs <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Migration</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">up</span>
    create_table <span style="color:#ff3333; font-weight:bold;">:widget_auxiliary_frobs</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>t<span style="color:#006600; font-weight:bold;">|</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#996600;">&quot;widget_id&quot;</span>
      t.<span style="color:#CC0066; font-weight:bold;">string</span>  <span style="color:#996600;">&quot;frob_type&quot;</span>
      t.<span style="color:#CC0066; font-weight:bold;">integer</span> <span style="color:#996600;">&quot;frobitude&quot;</span>
      <span style="color:#008000; font-style:italic;"># etc...</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    say_with_time<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;migrating froms from widgets&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      widgets = Widget.<span style="color:#9900CC;">find</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#ff3333; font-weight:bold;">:all</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      pbar = ProgressBar.<span style="color:#9900CC;">new</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;Generating Widget Frobs&quot;</span>, widgets.<span style="color:#9900CC;">size</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      widgets.<span style="color:#9900CC;">each</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>w<span style="color:#006600; font-weight:bold;">|</span>
       <span style="color:#008000; font-style:italic;"># this code changes the data irreversibly</span>
       <span style="color:#008000; font-style:italic;"># this code can't be (easily) rewritten with a SQL UPDATE or INSERT</span>
       <span style="color:#008000; font-style:italic;"># etc  etc  etc</span>
       pbar.<span style="color:#9900CC;">inc</span>
      <span style="color:#9966CC; font-weight:bold;">end</span>
      pbar.<span style="color:#9900CC;">finish</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
    say_with_time<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;delete obsolete widget/wadgit data&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#9966CC; font-weight:bold;">do</span>
      Wadget.<span style="color:#9900CC;">delete_all</span><span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#996600;">&quot;value = 'kerfluffle'&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>
      remove_column <span style="color:#ff3333; font-weight:bold;">:widget</span>, <span style="color:#ff3333; font-weight:bold;">:foo</span>
      remove_column <span style="color:#ff3333; font-weight:bold;">:widget</span>, <span style="color:#ff3333; font-weight:bold;">:bar_id</span>
      <span style="color:#008000; font-style:italic;"># etc...</span>
    <span style="color:#9966CC; font-weight:bold;">end</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
&nbsp;
  <span style="color:#9966CC; font-weight:bold;">def</span> <span style="color:#0000FF; font-weight:bold;">self</span>.<span style="color:#9900CC;">down</span>
    <span style="color:#CC0066; font-weight:bold;">raise</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::IrreversibleMigration</span>
  <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></td></tr></table></div>

<h3>If the dataset is <em>very </em>large</h3>
<p>If the dataset is especially large, you&#8217;ll want to iterate through it in a less naive manner than I did above: &#8220;<code>Widget.find(:all).each</code>&#8220;.  At the very least, you&#8217;ll want to iterate in such a way that already handled objects can be garbage collected prior to the end of the loop.  This might be necessary to avoiding the dreaded <code>NoMemoryError</code> (or decreased speed due to massive swapping).  This can be handled simply by iterating through the dataset using pagination, but you could also employ a more sophisticated strategy.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/11/rails-migrations-features/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TDD (Test Driven Development) is not about testing</title>
		<link>http://ekenosen.net/nick/devblog/2008/10/tdd-test-driven-development-is-not-about-testing/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/10/tdd-test-driven-development-is-not-about-testing/#comments</comments>
		<pubDate>Mon, 27 Oct 2008 01:00:08 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[bdd]]></category>
		<category><![CDATA[testing]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=9</guid>
		<description><![CDATA[The ruby/rails developer community seems to talk far more about automated developer testing than many other developer communities.  This is great.  There&#8217;s some disagreement and debate as to the level and type of testing that should be done, and that is to be expected.  There&#8217;s some debate as to which testing tools one should use, [...]]]></description>
			<content:encoded><![CDATA[<p>The ruby/rails developer community seems to talk far more about automated developer testing than many other developer communities.  This is great.  There&#8217;s some disagreement and debate as to the level and type of testing that should be done, and that is to be expected.  There&#8217;s some debate as to which testing tools one should use, and that is also just fine and dandy (although I&#8217;ll admit that I don&#8217;t have a clue what the <a href="http://rspec.info/">rspec</a> haters are going on about).</p>
<p>First, anyone who claims that automated unit tests removes the need for QA testers or usability testing or any form of exploratory (manual) testing&#8230; they&#8217;re completely nuts. <img src='http://ekenosen.net/nick/devblog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />   Nor does it remove the need for code reviews, or refactoring, or paying attention to software design.  This seems to be main point of posts like like <a href="http://hamptoncatlin.com/2008/hampton-hates-automated-testing">Hampton Hates Automated Testing</a> and Luke Francl&#8217;s <a href="http://railspikes.com/2008/7/11/testing-is-overrated">&#8220;Testing is Overated&#8221;</a> talk at <a href="http://rubyfringe.org/">RubyFringe</a>.  However, this is not a claim that I&#8217;ve ever heard any XPer, agilist or TDD/BDD proponent make. Instead, they&#8217;ve been saying for years now that <a href="http://java.sys-con.com/node/37795">&#8220;test driven development is not about testing&#8221;</a>.  And talking about automated developer testing without talking about TDD/BDD seems to me like an adventure in missing the point.</p>
<p>If automated developer testing leads to undue confidence, then Hampton is correct: the developer&#8217;s hubris will allow more bugs to get through. In my experience, a humble/paranoid developer will benefit greatly from BDD and put out code with fewer bugs in less time. And an arrogant &#8220;my code doesn&#8217;t have bugs because of pet theory #462&#8243; developer will eventually get themselves into trouble <em>with or without automated tests</em>&#8230; but the automated tests <em>may</em> help them dig out from it and perhaps not get into that particular brand of trouble again.</p>
<p>People who confuse automated developer testing with QA testing often talk about &#8220;bugs&#8221; and &#8220;reducing defect count&#8221; as if the main point of automated developer testing is to reduce bugs.  Test Driven Development is about driving yourself towards a better design (which is often also more easily testable as a happy byproduct).  This is <a href="http://behaviour-driven.org/GettingTheWordsRight">why BDD (Behavior Driven Development) was coined</a>: to help people grok TDD without being biased by the word &#8220;test&#8221; and some of its other connotations.  Several other terms were tried out (<a href="http://alistair.cockburn.us/Dos+equis+driven+design">&#8220;eXecutable eXample Driven design&#8221;</a> or &#8220;XXD&#8221; was my personal favorite), but BDD is the one that seemed to catch on and win out.</p>
<p>Also, BDD isn&#8217;t meant to be a &#8220;crutch&#8221; for &#8220;if you&#8217;re not good about thinking about programming.&#8221; It&#8217;s about giving <em>all programmers</em>, the so-so programmers and the guru programmers, another paradigm through which to view their code. BDD is about imagining the best possible API/interface/outcome, giving some example of how that code might work (if only the implementation were there), and then filling in the implementation until it works. And then doing it again in short incremental improvements. <em>It&#8217;s about getting into &#8220;the flow&#8221; in minutes, instead of hours.</em></p>
<p>Yeah, those examples and their assertions also stay around until later as a regression suite. That&#8217;s nice. The better examples also hang around as documentation to future developers for how the system is expected to behave. That&#8217;s <em>very</em> nice. But, in my experience, they also allow me to develop better, cleaner code more quickly than otherwise&#8230; and the &#8220;tests&#8221; are both a happy byproduct and an enabler.</p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/10/tdd-test-driven-development-is-not-about-testing/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Hello world!</title>
		<link>http://ekenosen.net/nick/devblog/2008/10/hello-world/</link>
		<comments>http://ekenosen.net/nick/devblog/2008/10/hello-world/#comments</comments>
		<pubDate>Sun, 26 Oct 2008 23:11:29 +0000</pubDate>
		<dc:creator>nick</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[metablogging]]></category>

		<guid isPermaLink="false">http://ekenosen.net/nick/devblog/?p=1</guid>
		<description><![CDATA[So… at every software conference I go to, someone asks me, &#8220;where’s your blog?&#8221;  And developers like Jay Fields have made the case for why good developers have blogs.  But Wired has decided that blogs are now obsolete (in typically pretentious Wired manner).  And that means that now is absolutely the time for me to [...]]]></description>
			<content:encoded><![CDATA[<p>So… at every software conference I go to, someone asks me, &#8220;where’s your blog?&#8221;  And developers like Jay Fields have made <a href="http://blog.jayfields.com/2007/04/blogging-blog-as-skills-assessment.html">the case for why good developers have blogs</a>.  But Wired has <a href="http://www.wired.com/entertainment/theweb/magazine/16-11/st_essay">decided that blogs are now obsolete</a> (in typically pretentious Wired manner).  And that means that now is absolutely the time for me to start up my own blog.</p>
<p>Honestly, the thought of me blogging sort of weirds me out.</p>
<p>The permanence of data on the internet is part of it, but that exists with emails to public mailing lists, and comments on other blogs, and even with IRC transcripts&#8230; and doesn&#8217;t bother me as much.  But blogging is more like, &#8220;this site here represents my thoughts&#8221;.  So I&#8217;m going to put up a disclaimer here: not only does this site not represent the opinions of my employers (past, present, and future), but it might not represent my <em>own</em> thoughts (past, present, or future).  I reserve the right to change my mind, and also to post incomplete thoughts which a part of me disagrees with.</p>
<p>It seems like the responsibility and formality are expected to be a notch up from other more informal communication media: how often one posts, how well they write, etc.  I suppose these things aren&#8217;t that big of a deal.  I don&#8217;t hold other blog writers to any particularly high standards in this realm.  But still, these thoughts tend to increase stress levels, and why would I willingly do that to myself?</p>
<p>Most importantly, I don&#8217;t really think that I will write anything that I personally would be interested in reading.  I don&#8217;t think I have anything particularly important to say.  And I don&#8217;t really care if people across the world are affected by what I say.  Again, this isn&#8217;t something that I judge other bloggers by.</p>
<p>So what will I write about?  When will I write?  And what will happen when (not if) I’m embarrassed by what I’ve written?  Enough naval-gazing&#8230; we’ll see what happens.  <img src='http://ekenosen.net/nick/devblog/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ekenosen.net/nick/devblog/2008/10/hello-world/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
