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

  <title><![CDATA[Steven Harman]]></title>
  <link href="https://stevenharman.net/atom.xml" rel="self"/>
  <link href="https://stevenharman.net/"/>
  <updated>2018-06-26T14:56:09+00:00</updated>
  <id>https://stevenharman.net/</id>
  <author>
    <name><![CDATA[Steven Harman]]></name>
    <email><![CDATA[hello@stevenharman.net]]></email>
  </author>
  <generator uri="http://octopress.org/">Octopress</generator>

  
  <entry>
    <title type="html"><![CDATA[Reclaim Your Domain Model From Rails]]></title>
    <link href="https://stevenharman.net/reclaim-your-domain-model-from-rails"/>
    <updated>2014-02-28T14:51:47-05:00</updated>
    <id>https://stevenharman.net/reclaim-your-domain-model-from-rails</id>
    <content type="html"><![CDATA[<p><strong>TL,DR;</strong> When building an application using Rails, I prefer to keep all my
model in <code>app/models/</code>. I reserve <code>lib/</code> for those other things - those
not-my-domain-things. I&rsquo;d like to explain the <em>what</em> and <em>why</em>.</p>

<p><img class="right" src="https://stevenharman.net/images/posts/deep-greens-med.jpg" width="300" title="&#34;Boundaries Amongst the Fields; Deep Greens&#34;" alt="&#34;Boundaries Amongst the Fields; Deep Greens&#34;"></p>

<p>Rails has a history of co-opting names, as happened when the <code>ActiveRecord</code>
library used the <a href="http://www.martinfowler.com/eaaCatalog/activeRecord.html" title="Active Record">active record pattern</a> name. A similar
co-opting has happened with the <a href="http://c2.com/cgi/wiki?ModelViewController" title="Model View Controller">MVC pattern</a> wherein many believe
Rails is an example of the MVC design pattern. In truth, it&rsquo;s probably closer
to <a href="http://en.wikipedia.org/wiki/Model_2" title="MVC Model 2">MVC Model 2</a>&hellip; but I digress.</p>

<h3>Model View What&rsquo;s-that-now?</h3>

<p><strong>MVC</strong> stands for Model, View, Controller. In Rails-land we know what the
<strong>Controllers</strong> are. And while we don&rsquo;t have <strong>Views</strong> in the way that MVC
meant, we do have view-templates, and we call those our views. The <strong>Model</strong> is
meant to be all the things it takes to model our problem domain. As applied to
Rails, the <strong>Model</strong> seems the most misunderstood/misused of the MVC
triumvirate.</p>

<!-- more -->


<p>Rails gave us the <code>app/models/</code> directory, a natural home for our model. Yet,
that was also where Rails dumped all our <code>ActiveRecord::Base</code>-derived objects.
Combined with the &ldquo;Skinny Controller, Fat Model&rdquo; mantra of 2006-ish Rails-land,
that directory had grown full of bloated, tightly coupled, low cohesion
<code>ActiveRecored::Base</code>-derived objects. <em>Our model!</em></p>

<h2>Models Too Fat?</h2>

<p>Eventually we realized that shoving all those disparate concerns into a single
class was a Bad Idea™. There was a movement afoot to thin down our now
overly-fat models. So, we re-learned <a href="http://en.wikipedia.org/wiki/Plain_Old_Java_Object" title="Plain Old Java Object">some forgotten lessons</a> and the use
of POROs became a Good Thing™. We needed to break our domain models down into
smaller, more cohesive objects, but we had a new problem. <em>Where to put these
new files?</em></p>

<p>As Rails had <em>reserved</em> <code>app/models/</code> directory for
<code>ActiveRecord::Base</code>-derived objects, we had to find a new home for those
POROs. As luck would have it, Rails had given us a <code>lib/</code> directory, and that
thing was basically deserted. We began breaking up our model and littering it
amongst the <code>app/models/</code> and <code>lib/</code> directories.</p>

<p>Our model had become more loosely coupled, with more cohesive parts, but it
wasn&rsquo;t living together. Why are we forcibly segregating the
<code>ActiveRecord::Base</code> portions from the rest of our model? If it&rsquo;s a single
domain model, why doesn&rsquo;t it live together?</p>

<p>These days I put all the domain-specific objects into the <code>app/models/</code>
directory. I reserve the <code>lib/</code> directory for things which could ostensibly be
<a href="http://rubygems.org/" title="A package manager for Ruby">gemified</a>.</p>

<h2>So. Many. Files. So Many Boundaries.</h2>

<p>I&rsquo;ve heard grumblings that having all the domain model living together
results in a lot of files in the <code>app/models/</code> directory, making it hard to
organize and navigate. To this I say, <em>YES, it does.</em></p>

<p>However, I suspect that is a sign of another problem. To wit, <em>do you actually
have multiple domains emerging, which could perhaps be broken out into discrete
apps?</em> If that is the case, make that boundary explicit and break out a new
application!</p>

<p>So long as those other domains are small or emerging it seems excessive to
split them out into their own apps. So, what do we do? Why we segregate them
with internal <a href="http://martinfowler.com/bliki/BoundedContext.html" title="Bounded Context">domain boundaries</a>, of course!</p>

<h3>An Example Boundary.</h3>

<p>A lot of apps have a search feature (or set of search features).
Search is a whole domain on its own, and often not germane to the primary
domain. Pull all search concerns into a namespace, <code>Search::</code>. To help with
organization, put all files to do with search in a directory of their own. For example,
<code>app/models/search/</code>, <code>app/controllers/search/</code>, <code>app/views/search/</code>, etc&hellip;</p>

<p>With just a few changes we&rsquo;ve reclaimed the <code>app/models/</code> directory, better
organized our files, and defined some new boundaries within our code base. Ah,
much better.</p>

<p><small>
<a href="http://www.flickr.com/photos/x1brett/8025844399/" title="Deep Greens - Aerial07"><em>Deep Greens</em> image</a> courtesy of Brett Jordan.
</small></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The No Man's Land of Web Development]]></title>
    <link href="https://stevenharman.net/the-no-mans-land-of-web-development"/>
    <updated>2013-12-20T14:23:00+00:00</updated>
    <id>https://stevenharman.net/the-no-mans-land-of-web-development</id>
    <content type="html"><![CDATA[<p>I think about the current state of web development experiences as a continuum.
On one end we have <em>traditional</em> Rails-era web apps - full page loads, with
bits of dynamism haphazardly mixed in. On the other are rich client-side
JavaScript apps with their own structure and life cycles, standing alone and/or
talking to an HTTP API.</p>

<p><img class="right" src="https://stevenharman.net/images/posts/no-mans-land-flanders-field.jpg" title="&#34;No Man's Land Flanders Field France 1919.&#34;" alt="&#34;No Man's Land Flanders Field France 1919.&#34;"></p>

<p>Rails-era web apps have some great tooling and deliver a pretty nice
development experience. The shift toward rich client-side web experiences has
lead to some great tooling that makes for a <a href="http://blog.testdouble.com/posts/2013-11-12-1st-class-web-development-with-lineman.html" title="1st-class web development with Lineman.">1st-class web development experience</a>.</p>

<h2>A no man&rsquo;s land</h2>

<p>Between these two approaches lies a no man&rsquo;s land. The tooling and techniques
are focused largely on either end of the continuum despite the large population
of apps living in the middle.</p>

<!-- more -->


<p>For too long we&rsquo;ve resorted to sprinkling JavaScript onto our Rails-era web
apps in an attempt to inch toward the rich and dynamic experiences we see at
the other end of the spectrum. However, not every application needs a full
rich-client experience. Often a Rails-era web app is <em>mostly</em> enough, except we
<em>require</em> some dynamism in portions of the application. But sprinkling on more
JavaScript only leads to larger tangles of costly and inflexible code. What we
really desire is that rich-client 1st-class web development experience paired with our
1st-class Rails-era web app development experience.</p>

<h2>For example</h2>

<p><a href="http://rubyonrails.org/" title="Web development that doesn't hurt">Rails</a> is a tool I use regularly, and it&rsquo;s often the first tool I reach
for when building those Rails-era web apps. My friends at <a href="http://testdouble.com" title="Custom Software Development | Columbus Ohio">Test Double</a>
have made great contributions to creating a great web development experience
for fat-client JavaScript applications with <a href="http://linemanjs.com/" title="Lineman takes everything you love about building server-side applications so that you can find joy in your client-side applications">Lineman</a>, especially when
paired with frameworks like <a href="http://angularjs.org/" title="HTML enhanced web apps!">AngularJS</a> or <a href="http://emberjs.com/" title="A framework for creating ambitious web applications.">Ember</a>. What I long
for, and believe is both needed and achievable, is a happy union of these two
approaches with tooling that supports them working together.</p>

<p>Sadly I don&rsquo;t have an answer for you. At least not today. But I know that
folks are working to enrich the middle ground, to reduce the frustration and
friction felt when using tools like Rails while also striving to build sensible
and coherent fat-client JavaScript apps with tools like AngularJS and Lineman.</p>

<p>If you&rsquo;re working to improve the middle ground, or you find yourself living
there, please share your thoughts, experiences, and advice so that we all might
learn and improve, together.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git Clean: Delete Already-Merged Branches]]></title>
    <link href="https://stevenharman.net/git-clean-delete-already-merged-branches"/>
    <updated>2013-10-01T15:20:00+00:00</updated>
    <id>https://stevenharman.net/git-clean-delete-already-merged-branches</id>
    <content type="html"><![CDATA[<h2>TL;DR</h2>

<p>To delete local branches which have alread been merged into <code>master</code>:</p>

<pre><code>$ git branch --merged master | grep -v "\* master" | xargs -n 1 git branch -d
</code></pre>

<p>You can omit the <code>master</code> branch argument to remove local branches which have
already been merged into the current <code>HEAD</code>:</p>

<pre><code>$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
</code></pre>

<h2>Breaking it down</h2>

<p>We start by getting a list of local branches which have already been merged
into the current branch (i.e. <code>HEAD</code>)</p>

<pre><code>$ git branch --merged

  add_new_user_gravatar_links
  assign_unique_key_to_uploads
* master
  remember_the_last_activity_per_user
  update_kaminari_to_thread_safe_version
</code></pre>

<p>We then pipe that to <code>grep</code> to match on the <code>"\*"</code> character, inverting that
match via <code>-v</code> to get all merged branches sans the current one.</p>

<pre><code>$ git branch --merged | grep -v "\*"

  add_new_user_gravatar_links
  assign_unique_key_to_uploads
  remember_the_last_activity_per_user
  update_kaminari_to_thread_safe_version
</code></pre>

<p>Finally we pipe that list in to <code>xargs</code> so we can strip apart the input and
pass it on to a new command. We use <code>-n 1</code> to ensure at most one argument is
taken from the input to be passed to the invocation of the new command. The
resulting commands that <code>xargs</code> will invoke are effectively</p>

<pre><code>$ git branch -d add_new_user_gravatar_links
$ git branch -d assign_unique_key_to_uploads
$ git branch -d remember_the_last_activity_per_user
$ git branch -d update_kaminari_to_thread_safe_version
</code></pre>

<p>Pulling it all back together, we have</p>

<pre><code>$ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

Deleted branch add_new_user_gravatar_links
Deleted branch assign_unique_key_to_uploads
Deleted branch remember_the_last_activity_per_user
Deleted branch update_kaminari_to_thread_safe_version
</code></pre>

<p>And there you have it. Go forth and clean up!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Bag of Methods Module and Grep-driven Development]]></title>
    <link href="https://stevenharman.net/bag-of-methods-module-and-grep-driven-development"/>
    <updated>2012-10-02T10:34:00+00:00</updated>
    <id>https://stevenharman.net/bag-of-methods-module-and-grep-driven-development</id>
    <content type="html"><![CDATA[<p>Always looking for more concise ways to express ideas, I&rsquo;d like to present two
terms for your consideration.</p>

<dl>
  <dt><a id='bomm'>BOMM</a> <em>|bäm|</em> <i>(abbreviation)</i></dt>
  <dd>Bag of Methods Module</dd>
  <dd>An anti-pattern for "sharing behavior" or "separating concerns" of an
  object. In practice such modules often contain code that is related in name or
  function, but lacking a cohesive purpose. See also: <em><a href='#gdd'
  title='Grep-driven Development'>GDD</a></em>.
  </dd>

  <dt><a id='gdd'>GDD</a> <i>(initialism)</i></dt>
  <dd>Grep-driven Development</dd>
  <dd>A software development process that relies on
  searching full source code to find usages of methods and deduce intended
  behavior of a piece of code. Often caused by lack of coherent and cohesive
  design. See also: <em><a href='#bomm' title='Bag of Methods
  Module'>BOMM</a></em>.
  </dd>
</dl>


<p>Thanks to fellow <a href="http://highgroove.com">Highgroover</a>, <a href="http://www.andylindeman.com">Andy Lindeman</a>, for helping me
to finally define these terms. Or at least, refine them.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Sensible Testing Is About Sensible Design]]></title>
    <link href="https://stevenharman.net/sensible-testing-is-about-sensible-design"/>
    <updated>2012-06-29T10:16:00+00:00</updated>
    <id>https://stevenharman.net/sensible-testing-is-about-sensible-design</id>
    <content type="html"><![CDATA[<p>If you&rsquo;ve not yet seen <a href="http://justinleitgeb.com/">Justin Leitgeb&rsquo;s</a> GoGaRuCo talk, <a href="http://justinleitgeb.com/wp-content/uploads/2012/06/SensibleTesting.pdf">Sensible Testing</a>, go check out the slides.
I hope the actual talk is posted soon;
I&rsquo;m sure it&rsquo;s more rich and full of context.</p>

<p>Overall I agree with most of Justin&rsquo;s points.
However, I get the feeling that he, like many folks, approaches testing as a method for verifying the correctness of code.
As I understand the thesis, <em>CUPID</em> is to testing what <em><a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod">SOLID</a></em> is to design.</p>

<p>While I&rsquo;m not opposed to laying down some names and concepts to improve the state of testing, I don&rsquo;t believe testing should be the goal.
It&rsquo;s not about testing.
I believe testing is a tool to be used in guiding your design.</p>

<!-- more -->


<h3>An example</h3>

<p>I realize that it&rsquo;s unfair to pick on sample code used in talks, but <em>&ldquo;Problem 2: Stubbing instead of mocking&rdquo;</em> provides a great illustration.
Here the author claims that we too often stub where we should be mocking.
He gives the following snippet:</p>

<p><img class="right" src="https://stevenharman.net/images/posts/sensible-testing-code.png" title="&#34;Problem 2: Stubbing instead of mocking&#34;" alt="&#34;Problem 2: Stubbing instead of mocking&#34;"></p>

<p>Firstly I had to get over the use of the old RSpec 1.0-style <code>#stub!</code> and the overly verbose <code>#and_return</code> syntax.
After resetting my brain I quickly realized the test was awkward.
I re-read it a few times and then asked, &ldquo;why stub, or mock for that matter, methods on the object under test?&rdquo;</p>

<h3>A design issue emerges</h3>

<p>This is a design issue!
The <code>BalanceCalculator</code> is doing too much work.
This is the &ldquo;S&rdquo; in SOLID - the Single Responsibility Principle.
The friction of this test suggests that we need to adjust the design.</p>

<p>For example, we could wrap the <em>account info</em> and <em>account type</em> into a cohesive object to be passed into the calculator.</p>

<h3>To stub or to mock?</h3>

<p>Forgiving that design issue for now, let&rsquo;s get back to the author&rsquo;s point -
<em>should we mock or stub those methods?</em></p>

<p>The methods in question are queries.
The <code>BalanceCalculator</code> presumably uses the results of those queries to do its work.
So why do we need to set an expectation that we should call those methods?
After all, if we don&rsquo;t call them we&rsquo;ll not have their resulting values.
Therefore we won&rsquo;t be able to do the work.
Therefore the test <strong>should</strong> fail.
Right?</p>

<p>And if we don&rsquo;t call those methods and the test passes, then they neither need to be mocked nor stubbed;
they are unnecessary.</p>

<p>So, to stub or mock&hellip; how do we know when to use which?</p>

<p>My heuristic is that stubs are for queries and mocks are for commands.
In a very generic sense I&rsquo;m talking about <a href="http://en.wikipedia.org/wiki/Command-query_separation">Command-query separation</a> applied to testing.</p>

<h3>It&rsquo;s all design</h3>

<p>In the end nearly everything we do is design in some sense.
Testing is no exception, and is in my opinion a much larger part of the design of software systems than it is given credit for.
Or at least, I believe we should be striving to make it so.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[The Accepts_nested_attributes_for Un-Solution]]></title>
    <link href="https://stevenharman.net/the-accepts_nested_attributes_for-un-solution"/>
    <updated>2012-05-15T21:50:00+00:00</updated>
    <id>https://stevenharman.net/the-accepts_nested_attributes_for-un-solution</id>
    <content type="html"><![CDATA[<p><img class="right" src="https://stevenharman.net/images/posts/merry-go-round.png" title="&#34;merry go round&#34;" alt="&#34;merry go round&#34;"></p>

<p>Why does Rails' <code>accepts_nested_attributes_for</code> approach always feel so darned
<em>wrong</em>?</p>

<p>My suspicion is that it feels wrong because it likely is wrong - or at least it
is likely the wrong tool for the job.</p>

<h3>An example</h3>

<p>An accounting of a recent ride I took into the <code>accepts_nested_attributes_for</code>
merry go round.</p>

<blockquote><p>In order to create a Message, I have to first create the Conversation it&rsquo;s a
part of.</p>

<p>This sounds like an explicit workflow, so I&rsquo;ll model it that way.</p>

<p><em>&hellip; hours later &hellip;</em></p>

<p>FFFUUU, this is too complicated! There must be an easier, more Rails-y way.</p>

<p>I know, Conversations can <code>accepts_nested_attributes_for :messages</code>. Brilliant!</p>

<p><em>&hellip; hours later &hellip;</em></p>

<p>FFFUUU, this is too complicated! There must be a simpler way.</p>

<p>I know, rather than shoehorning this into an overly-coupled mess I&rsquo;ll model
it as an explicit workflow!</p>

<p><strong>FML</strong>.</p></blockquote>

<p>Remember, <a href="http://www.confreaks.com/videos/860-railsconf2012-keynote-simplicity-matters" title="Simplicity Matters.">easy is not the same thing as simple</a>.</p>

<p><em>image via: <a href="http://blog.lolitanie.com/index.php/archives/2006/01/29/oh-oh-oh-merry-go-round/">lolitanie.com</a></em></p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[From Testing to Test-First to Test-Driven]]></title>
    <link href="https://stevenharman.net/from-testing-to-test-first-to-test-driven"/>
    <updated>2012-05-08T11:16:00+00:00</updated>
    <id>https://stevenharman.net/from-testing-to-test-first-to-test-driven</id>
    <content type="html"><![CDATA[<p>When I started writing tests, around 2005, I was stoked just to have the tests.</p>

<p>When I started writing tests first, around 2006, I was excited because I was
<em>Doing The TDD</em>.</p>

<p>A couple of years later I found that writing tests was getting really painful.
Painful because they were so damn hard to set up, and painful because I had to
wait <em>too damn long</em> (on the order of 10-15 minutes) for the test suite to
run. I reacted to the pain by changing how I write my tests; I discovered mock
objects. My tests got faster, but they were still painful.</p>

<h3>A realization</h3>

<p>In 2008 I was talking with <a href="http://coreyhaines.com/" title="The Software Journeyman">Corey Haines</a> about test pain,
object-oriented design, and &ldquo;listening&rdquo; to the former to influence the latter.
<a href="http://scottbellware.com">Scott Bellware</a> also contributed much insight, forcing me to really
think about what I hoped to gain from writing tests.</p>

<p>Those conversations help to crystallize it for me: the root cause of the pain
was not the tests, but the design of the code under test. I had been doing
test-<em>first development</em>, not test-<strong>driven design</strong>.</p>

<p>In the years since I&rsquo;ve honed my technique for driving design by listening to
tests and I continue to seek out the ideas and experiences of other
<a href="https://www.destroyallsoftware.com/screencasts" title="Screencasts for Serious Developers">fast test fanatics</a>.</p>

<p>The Ruby and Rails communities have accelerated this path for many. I would
say it&rsquo;s not uncommon for new folks to get started where I was in 2005 or
2006. What&rsquo;s more exciting is the growing numbers who are starting to feel
some pain in how they test. The next step is to become more aware of that
pain; lower your pain threshold and then make it stop hurting!</p>

<h3>It&rsquo;s a journey</h3>

<p>It was by no means an overnight endeavour. It literally took years of work for
me to figure this out, and I&rsquo;m both happy and proud to say that <em>I&rsquo;m still
learning</em>.  I hope by putting my experience out there, yours can be better,
faster, MOAR!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Another Git Repository Visualization, Just for Fun.]]></title>
    <link href="https://stevenharman.net/another-git-visualization-for-fun"/>
    <updated>2011-07-01T21:46:00+00:00</updated>
    <id>https://stevenharman.net/another-git-visualization-for-fun</id>
    <content type="html"><![CDATA[<p>I’ve created visualizations for Git repositories before – the one tracked a <a href="https://stevenharman.net/gain-new-insights-by-visualizing-what-youve-already-got" title="Gain New Insights by Visualizing What You’ve Already Got">product from its first commit through launch</a>. And while I still think there is some information and insight to be gleaned from such visualizations, the real reason I like to make them is&hellip; I think they&rsquo;re neat.</p>

<p>To celebrate launching the latest incarnation of <a href="http://versionone.com/" title="VersionOne - it's pronounced Agilé">VersionOne</a>, I made another visualization! This one tracks all changes made in our Git repository that occurred between our last major release (in late February) right through the very last commit that made it into the <a href="http://www.versionone.com/release/2011/spring/" title="VersionOne Spring 2011 Release">Spring 2011 release</a>.</p>

<p>Wow… that really sounded like a sales pitch, didn’t it? I hate sales pitches!</p>

<p>Enough of that. Enjoy!</p>

<iframe width="560" height="315" src="https://www.youtube.com/embed/fYv9XgzY9Cc" frameborder="0" allowfullscreen></iframe>



]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git Pull With Automatic Rebase]]></title>
    <link href="https://stevenharman.net/git-pull-with-automatic-rebase"/>
    <updated>2011-06-09T22:57:00+00:00</updated>
    <id>https://stevenharman.net/git-pull-with-automatic-rebase</id>
    <content type="html"><![CDATA[<p>To rebase, or not to rebase - for me its not really a question. I
generally prefer a clean, linear commit history. Why? Because merge bubbles make
history confusing, noisy, break <code>git bisect</code>.</p>

<p><a href="https://skitch.com/stevenharman/fdhm5/y-u-no-rebase"><img class="thumbnail right" src="https://stevenharman.net/images/posts/y-u-no-rebase-preview.jpg" title="Y U NO REBASE!?!" alt="y-u-no-rebase"></a>
Don&rsquo;t believe me? Check out the pretty log to the right. See all
those merge bubbles in there? <em>Eww!</em></p>

<h3>The Why?</h3>


<p>The workflow that caused those merges was as follows:</p>

<ol>
<li><code>git pull</code> (to bring local up to date)</li>
<li><em>hackity-hack</em></li>
<li><code>git commit</code></li>
<li><code>git pull</code></li>
<li><code>git push</code></li>
</ol>


<p>By default <code>git pull</code> will fetch any new commits from the remote, and
then merge any local changes in, resulting in the merge bubbles.</p>

<!-- more -->




<h3>A better approach</h3>


<p>I typically use the same workflow as above with one tweak.
Rather than <code>git pull</code> I use <code>git pull --rebase</code>.
The <code>--rebase</code> option will fetch the remote commits and rebase your commits on top of the new commits from the remote.
This is the &ldquo;re-writing&rdquo; of history folks often talk about.</p>

<h3>Make it better, automatically!</h3>


<p>You can tell git to use rebase, rather than merge, in one of two ways, depending on
your situation.</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'>$ git config branch.autosetuprebase always # Force all new branches to automatically use rebase</span></code></pre></td></tr></table></div></figure>


<p>You can add the <code>--global</code> switch to have all future branches, in all
repositories on this machine, behave this way.</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'>$ git config branch.*branch-name*.rebase true # Force existing branches to use rebase.</span></code></pre></td></tr></table></div></figure>




<h3>Get more info</h3>


<p>Be sure to check out the <a title="git-config Manual Page" href=
"http://www.kernel.org/pub/software/scm/git/docs/git-config.html" rel="external">git
man pages</a> for more info on what those options mean and when you may or may not want
to use them.</p>

<p>You might also want to check out my <a title="Git Workflows" href=
"https://github.com/stevenharman/git-workflows" rel="external">Git Workflows repository
on The GitHubs</a> where you can find a Keynote presentation (or PDF in the Downloads)
explaining <code>git rebase</code> vs. <code>git merge</code> Complete with
pictures!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[An Io Language Vim Plugin]]></title>
    <link href="https://stevenharman.net/an-io-language-vim-plugin"/>
    <updated>2011-02-11T16:27:00+00:00</updated>
    <id>https://stevenharman.net/an-io-language-vim-plugin</id>
    <content type="html"><![CDATA[<p>Who here doesn&rsquo;t enjoy a little color in their life? I know I do, especially when
used to highlight the syntax of a language - as anyone who&rsquo;s been around me while
downing a few pints can attest!</p>

<h3>Learning, Io, and Vim</h3>


<p><a href="https://stevenharman.net/images/posts/io-syntax.png"><img class="left" src="https://stevenharman.net/images/posts/io-syntax-thumb.png" title="Io Syntax Highlighting in Vim" ></a></p>

<p>In an attempt to feed our insatiable desire to learn, a
few of us at <a title="VersionOne: Simplifying Software Delivery" href=
"http://versionone.com" rel="external">VersionOne</a> are doing a book club on
<a title="Seven Languages in Seven Weeks: A Pragmatic Guide to Learning Programming Languages"
href=
"http://www.amazon.com/gp/product/193435659X?ie=UTF8&amp;tag=stevenharman-20&amp;linkCode=as2&amp;camp=1789&amp;creative=390957&amp;creativeASIN=193435659X"
rel="external">Seven Languages in Seven Weeks</a>. We&rsquo;re currently working on chapter
2: <a title="Io Language" href="http://iolanguage.com/" rel="external">Io</a>. My
current favorite editor is Vim. I wanted syntax highlighting for Io, in Vim.</p>

<p>I found a decent Vim script to get Io syntax highlighting, and then wrote a quick
<code>ftdetect</code> script to set Io-related files to use the Io syntax. The
resulting vim-io plugin is currently embedded <a title="vim-io: Io, for Vim!" href=
"https://github.com/stevenharman/config/tree/master/.vim/bundle/vim-io" rel=
"external">in my dotfiles on the GitHubs</a>, but if there&rsquo;s interest I can pull them
out into a standalone plugin.</p>

<p>Grab it, enjoy it, fork and improve it!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Caps Lock Is Dumb; Make It Useful]]></title>
    <link href="https://stevenharman.net/caps-lock-is-dumb-make-it-useful"/>
    <updated>2011-01-20T12:00:00+00:00</updated>
    <id>https://stevenharman.net/caps-lock-is-dumb-make-it-useful</id>
    <content type="html"><![CDATA[<p>I&rsquo;ve long thought that <code>Caps Lock</code> was quite dumb. Yes, I&rsquo;m sure there
is some archaic reason it exists, but the truth is I don&rsquo;t care. I don&rsquo;t
find it useful and am annoyed that it&rsquo;s taking up valuable room on my <a
title="The Home Row and Touch Typing"
href="http://en.wikipedia.org/wiki/Touch_typing" rel="external">Home
Row</a>. The more I use Vim the more angry I get at the <code>Caps Lock</code> key.</p>

<h3>Making Caps Lock Useful, on The Mac</h3>

<p>I long ago remapped <code>Caps Lock</code> to <code>Esc</code> on my Mac - which worked
great for <a title="the missing editor" href="http://macromates.com/"
rel="external">TextMate</a>. However, these days I spend the majority of
my time in <a title="Vim for the Mac"
href="http://code.google.com/p/macvim/" rel="external">Vim</a> or <a
title="Zeee Shell" href="http://www.zsh.org/" rel="external">Zsh</a> (in
Vim mode) where I&rsquo;d much prefer to have <code>Ctrl</code> on my Home Row.
Remapping <code>Caps Lock</code> to <code>Ctrl</code> is trivial on OS X; it&rsquo;s baked in
via <em>System Preferences > Keyboard Preferences > Modifier Keys</em>.</p>

<!-- more -->


<h3>Making Caps Lock Useful, on The Windows</h3>

<p>To my knowledge, there is nothing baked into the <acronym
title="Operating System">OS</acronym> that makes this easy, but there
are a handful of utilities that will let you remap most keys. I opted
for the Lo-Fi route - hacking the registry to remap <code>Caps Lock</code> to
<code>Ctrl</code>.</p>

<div><script src='https://gist.github.com/788631.js'></script>
<noscript><pre><code>REGEDIT4
 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Keyboard Layout]
 &quot;Scancode Map&quot;=hex:00,00,00,00,00,00,00,00,02,00,00,00,1d,00,3a,00,00,00,00,00
</code></pre></noscript></div>


<p>To use it, just download/save the raw <code>.reg</code> file to your Windows box,
and the run (double-click, whatever) it.</p>

<p>And there you have it. Good bye, annoying <code>Caps Lock</code>. Hello, useful
stuff!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A First Step to Better User Experience: Thinking Like a Human]]></title>
    <link href="https://stevenharman.net/a-first-step-to-better-user-experience-thinking-like-a-human"/>
    <updated>2010-12-08T12:18:00+00:00</updated>
    <id>https://stevenharman.net/a-first-step-to-better-user-experience-thinking-like-a-human</id>
    <content type="html"><![CDATA[<p>As we strive to build more humane user experiences it is important to
not only consider what data to, or <em>not to</em>, show, but also <em>how</em> we
present that data.</p>

<p>An example from our recent <a title="VersionOne: Conversations"
href="http://versionone.com/Product/Collaboration.asp"
rel="external">Conversations</a> feature is the date and time at which
portions of a conversation take place.</p>

<p><a href="https://stevenharman.net/images/posts/fuzzy-time.png"><img class="left" src="https://stevenharman.net/images/posts/fuzzy-time-thumb.png" title="humate date and time via jquery.timeago" ></a>
Notice the two highlighted areas. The
tooltip shows fully-formatted, and much more precise information, with
the &ldquo;less than a minute ago&rdquo; text being a more fuzzy, human-friendly
presentation of the same data.</p>

<p>There is no question that the precise data is valuable, but when it
comes to human users of a system, it may not be the most consumable
form. The full-fidelity information is still available to the user who
cares to engage the application, when he cares to engage it.</p>

<p>Whether its fuzzy dates and time, or using avatars instead of user
names, or any number of other examples, the point is to <em>think</em> about
the human experience when designing for, well, humans.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Handful of Git Workflows for the Agilist]]></title>
    <link href="https://stevenharman.net/a-handful-of-git-workflows-for-the-agilist"/>
    <updated>2010-08-12T12:44:00+00:00</updated>
    <id>https://stevenharman.net/a-handful-of-git-workflows-for-the-agilist</id>
    <content type="html"><![CDATA[<p>A few months back I gave <a href="http://www.thepathtoagility.org/" title="the path to agility conference">little talk</a> on the darling <acronym
title="Source Control Management">SCM</acronym> tool of the Open Source
world, <a href="http://git-scm.com/" title="Git: the fast version control system">Git</a>. After the conference, the organizers asked for a copy
of the presentation materials I&rsquo;d used - something I usually find little
value in as the content of a discussion is far more than just the
collateral used.</p>

<p>At any rate, I obliged, sent off a PDF, and have <a href="http://github.com/stevenharman/git-workflows" title="a handful of Git workflows for the agilist">opened the talk up</a>
for others to use and improve. You can find the source (Keynote
presentation, images, etc.) on GitHub. Fork and modify the talk to your
heart&rsquo;s content. ♡</p>

<p>Oh, and the <a href="http://github.com/stevenharman/git-workflows/downloads" title="download the PDF version">PDF is there</a> too.</p>

<p>Enjoy!</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Want to Make Money? Make Getting Paid the Easy Part!]]></title>
    <link href="https://stevenharman.net/want-to-make-money-make-getting-paid-the-easy-part"/>
    <updated>2010-04-07T12:52:00+00:00</updated>
    <id>https://stevenharman.net/want-to-make-money-make-getting-paid-the-easy-part</id>
    <content type="html"><![CDATA[<p>At least half a dozen times in the past three days I&rsquo;ve been so annoyed
by the payment process for various goods and/or services that I either
didn&rsquo;t purchase the thing, or had a minor meltdown after the whole
ordeal was over.</p>

<p>Why do merchants insist on making it so damned difficult for their
customers to get the goods?</p>

<h3>A few frustrating examples</h3>

<p>Ever been to a sporting event where the beer vendor only accept cash,
has no cash-register, and yet insists on charging a partial dollar
amount per unit of booze? $6.65 for a beer. Really? Just call it $7
and make the math easy for everyone. Or have a cash register at each
kiosk. Or, here&rsquo;s a novel idea, start accepting plastic!</p>

<p>Need to renew your vehicle registration? Just do it online! But be
prepared to spend an extra $5 for the <em>convenience</em> of, you know…
actually giving them the money now rather than sending a check and them
having to pay someone to physically handle the thing.</p>

<h3>Two simple rules for making money</h3>

<ol>
<li>If you&rsquo;re selling something someone wants: <strong>make it easy for them to
give you their money!</strong></li>
<li>If you&rsquo;re selling something someone does not want: <strong>make them want
it!</strong></li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Gain New Insights by Visualizing What You’ve Already Got]]></title>
    <link href="https://stevenharman.net/gain-new-insights-by-visualizing-what-youve-already-got"/>
    <updated>2010-02-24T22:32:00+00:00</updated>
    <id>https://stevenharman.net/gain-new-insights-by-visualizing-what-youve-already-got</id>
    <content type="html"><![CDATA[<p>I don’t know about you, but I like pretty things. Things that engage me. Shiny things. I enjoy seeing <em>the same old thing</em> in new and interesting ways. I suppose I’m just a visual kinda’ person.</p>

<p>Unfortunately, the desire for visual representation is at odds with the high bandwidth flood of information we’re subjected to these days. Even if we manage to trim the overwhelming flood of information down to a laser-focused stream, it takes an immense amount of effort to make sense of it.</p>

<h3>For example</h3>


<p>For years the primary way we’ve looked at the activity or interaction within various source control management systems is via log files. Yep… plain, text-laden, indecipherable logs chock full of entries each a similitude of it’s predecessors.</p>

<iframe width="560" height="315" src="https://www.youtube.com/embed/S_mMKXFaLaE" frameborder="0" allowfullscreen></iframe>




<!-- more -->


<p>However, thanks to projects like <a title="Processing" href="http://processing.org/" rel="external">Processing</a> there may be a change on the horizon. Using tools of their ilk we can build exciting new ways to <em>see</em> and consume the vast seas of data we’re drowning in. By visualizing the data we are able to discover new and interesting patterns, behaviors, and insights.</p>

<h3>An example</h3>


<p>The above video is an example of one such visualization I produced using <a title="Gource - software version control visualization" href="http://code.google.com/p/gource/" rel="external">Gource</a> to analyze the Git repository of one of the product’s we’ve build at <a title="VersionOne: Simplifying Software Delivery" href="http://versionone.com/" rel="external">VersionOne</a>.</p>

<p>For reference, each branch (line) is a different directory containing files. Each leaf (dot) is a file, with different file types (Ruby, JavaScript, C#, etc.) having different colors. Each contributor is represented by their name and Gravatar.  The colored lines that occasionally connect a contributor to a file are color coded to represent adds (green), changes (orange) and deletes (red).</p>

<p>A few interesting things this visualization leads me to think about are</p>

<ul>
<li>how much churn happens in various parts of the code base?</li>
<li>where are we spending time?</li>
<li>is new-feature work well isolated? (perhaps an indicator of composition)</li>
<li>are there <em>specialists</em> within the team?</li>
</ul>


<p>Do any interesting things pop to mind when you watch the video? Let me know by leaving a comment.</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Why Don't We Ask Why?]]></title>
    <link href="https://stevenharman.net/why-dont-we-ask-why"/>
    <updated>2010-02-18T12:58:00+00:00</updated>
    <id>https://stevenharman.net/why-dont-we-ask-why</id>
    <content type="html"><![CDATA[<p>Have you ever thought about just how much time we software folk spend
focused on the technologies we&rsquo;re using, on implementation minutia,
and on all of the shiny new <em>solutions</em> we <em>should</em> be using?</p>

<p><a href="http://www.flickr.com/photos/marcobellucci/3534516458/" title="photo via: http://www.flickr.com/photos/marcobellucci/3534516458/"><img class="right" src="https://stevenharman.net/images/posts/question-mark.jpg"></a></p>

<p>Now contrast that with how often we stop to think about the <strong>Whys</strong>?</p>

<p>Why are we being asked to solve <em>fizz-buzz-thing</em>; do we understand the
motivation and context behind the problem, or are we fixated on how
we&rsquo;ll build the solution? Are we asking why a problem occurred, or are
we merely focused on how we fixed it, this time?</p>

<h3>Why don&rsquo;t we ask &ldquo;Why?&rdquo;</h3>

<p>Frankly, because we&rsquo;d rather spend our time in the comfortable arena
of <strong>how</strong> than venture into the sometimes uneasy realm of <strong>why</strong>.</p>

<blockquote><p>She didn't want to know how a thing was done, but why. That can be<br/>embarrassing. You ask *Why* to a lot of things and you wind up<br/>very unhappy indeed, if you keep at it.<br/>- Captain Beatty</p><footer><strong>Ray Bradburry</strong> <cite><a href='http://www.amazon.com/dp/0345342968/?tag=stevenharman-20'>Fahrenheit 451</a></cite></footer></blockquote>




<!-- more -->


<p>Asking why often forces us to face the truth, and that truth can be
uncomfortable. We need to have the courage to face those truths and
coninue to ask why; we must have the <a href="http://en.wikipedia.org/wiki/Extreme_Programming#Values" title="XP Values - Courage">courage</a> to pop the why stack.</p>

<p>It&rsquo;s only by asking why that we&rsquo;ll gain the understanding, insight,
and context necessary to effectively solve the problems we&rsquo;re faced
with, to grow, and to improve.</p>

<p>So, <em>why</em> are you reading this post? :)</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[YAGNI Ain't What You Think It Is]]></title>
    <link href="https://stevenharman.net/yagni-aint-what-you-think-it-is"/>
    <updated>2010-01-07T13:33:00+00:00</updated>
    <id>https://stevenharman.net/yagni-aint-what-you-think-it-is</id>
    <content type="html"><![CDATA[<p>In the software development vernacular the term <acronym title="You aren't gonna need it">YAGNI</acronym> is often used as a device to put down attempts at prematurely adding functionality - things which are only speculatively required.
This makes sense given that is basically the <a href="http://www.xprogramming.com/Practices/PracNotNeed.html" title="You're NOT gonna need it">definition</a> that <a href="http://www.xprogramming.com/" title="XProgramming : an Agile Software Development Resource">Ron Jeffries</a> and our <acronym title="eXtreme Programming">XP</acronym> predecessors came up with so long ago.</p>

<h3>Is that the whole story?</h3>

<p><a href="http://www.flickr.com/photos/z6p6tist6/501709581/" title="photo via: http://www.flickr.com/photos/z6p6tist6/501709581/"><img class="right" src="https://stevenharman.net/images/posts/stop-sign.jpg"></a> In short, I don&rsquo;t think so.</p>

<p>I&rsquo;ve long believed there was more to YAGNI than what had been canonically defined and was commonly understood.
However, until recently I was never able to put my finger on what was missing.</p>

<p>While listening to an episode of <a href="http://www.cincomsmalltalk.com/blog/blogView?showComments=true&amp;printTitle=Industry_Misinterpretations_164:_Going_for_the_Longball&amp;entry=3436948975" title="Industry Misinterpretations 164: Going for the Longball">Industry Misinterpretations</a> I heard <a href="http://www.threeriversinstitute.org/Kent%20Beck.htm" title="Kent Beck @ Three Rivers Institute">Kent Beck</a> make a subtle point about the need to make progress being more important than the completeness of the thing you&rsquo;re building at the point you&rsquo;re building it.
Lending from Kent&rsquo;s insight and mixing in much of my own experience, I realized YAGNI is not about delaying building things until you need them;
it&rsquo;s that gaining real experience in the problem domain, while making concrete progress, is more important than trying to achieve a complete solution <em>right now</em>.</p>

<p>Do you think it&rsquo;s too early to update the <a href="http://en.wikipedia.org/wiki/You_ain't_gonna_need_it" title="You ain't gonna need it">Wikipedia article</a>?</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[OMG, Better Rake (for .net)!]]></title>
    <link href="https://stevenharman.net/omg-better-rake-for-dot-net"/>
    <updated>2009-11-23T13:58:00+00:00</updated>
    <id>https://stevenharman.net/omg-better-rake-for-dot-net</id>
    <content type="html"><![CDATA[<p>If you ask me, when it comes tools for writing automated build scripts
nothing packs more bang for the buck than <a href="http://rake.rubyforge.org/" title="Rake - Ruby Make">Rake</a>. Until recently,
using Rake to build .net solutions required a magic concoction of hacked
together scripts which rarely exhibited Ruby&rsquo;s appreciation for beauty
nor Rake&rsquo;s spirit of simplicity.</p>

<p>Luckily our buddy <a rel="met friend"
href="http://www.lostechies.com/blogs/derickbailey/" title="Derick
Bailey's blog">Derick Bailey</a> decided it was time to bite the bullet
and start building some <em><a href="http://www.lostechies.com/blogs/derickbailey/archive/2009/09/17/how-a-net-developer-hacked-out-a-rake-task.aspx" title="How A .NET Developer Hacked Out a Rake Task">real Rake tasks</a></em> that were special suited
for building .net code. The result is <a href="http://github.com/derickbailey/Albacore" title="Albacore: A Suite Of Rake Build Tasks For .NET Solutions">Albacore</a>.</p>

<!-- more -->


<h3>Using Rake for .net <acronym title="In Real Life">IRL</acronym></h3>

<p>I&rsquo;ve been using Rake to <a href="http://stevenharman.net/blog/archive/2009/05/29/being-lazy-with-rake.aspx" title="Being Lazy with Rake">be lazy</a> for a while. And we, the
<a href="http://versionone.com/" title="VersionOne: Simplifying Software Delivery">VersionOne</a> dudes &amp; dudettes, have been using it to help automate
our <acronym title="Continuous Integration">CI</acronym> builds for over
a year now. And just last week we started ditching much of our
hacky-Rake-script inventory in favor of more concise, tested, and
readable Rake tasks via Albacore.</p>

<p>During the migration I&rsquo;ve run into a few small hitches here and there,
but nothing that I couldn&rsquo;t track down, write a test for, and fix
within a couple of <a href="http://www.infoq.com/news/2009/09/Pomodoro" title="Pomodoro - An Agile Approach to Time Management">tomatoes</a>. In one case I discovered an issue,
called Derick to confirm, suggested a fix, and had a new Albacore Gem
published within a couple of hours. <em>Hawt!</em></p>

<p>Albacore already has a decent number of tasks baked in, and the list is
growing all the time!</p>

<ul>
<li><a href="http://wiki.github.com/derickbailey/Albacore/assemblyinfotask">AssemblyInfoTask</a> - Generate an AssemblyInfo.cs file.
Currently only supports C#</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/expandtemplatestask">ExpandTemplatesTask</a> - expand template files with #{setting}
markers, using YAML configuration files as the data</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/ncoverconsoletask">NCoverConsoleTask</a> - Run code coverage analysis through NCover&rsquo;s <code>NCover.Console</code></li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/ncoverreporttask">NCoverReportTask</a> - Check code coverage and get detailed
reports through NCover&rsquo;s <code>NCover.Reporting</code></li>
<li>NUnitTask - run NUnit test suites</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/msbuildtask">MSBuildTask</a> - Build a Visual Studio solution (<code>.sln</code>) or
MSBuild file</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/renametask">Rename Task</a> - Rename a file</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/sftptask">SftpTask</a> - Upload a file to a remote server via secure FTP
connection</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/sqlcmdtask">SQLCmdTask</a> - Run scripts and other commands through SQL
Server&rsquo;s <code>sqlcmd.exe</code></li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/sshtask">SshTask</a> - Run a command on a remote system via a secure
shell connection</li>
<li><a href="http://wiki.github.com/derickbailey/Albacore/ziptask">ZipTask</a> - Package your build artifacts into a .zip for
easier distribution source data</li>
</ul>


<h3>Contribute!</h3>

<p>As we move more and more of our custom stuff over I&rsquo;ll continue to add
features to Albacore, enhancing the great work the core team is doing.
In fact, I&rsquo;m already planning a <a href="http://github.com/derickbailey/Albacore/issues/#issue/27" title="Albacore::NAntTask - for migrating to Rake">NAnt task</a> to help those folks in
the process of migrating from an existing NAnt-based build script to
Rake. Look for it soon!</p>

<h3>Resources</h3>

<ul>
<li><a href="http://github.com/derickbailey/Albacore" title="Albacore: A Suite of Rake Build Tasks For .Net Solutions">Albacore on GitHub</a></li>
<li><a href="http://wiki.github.com/derickbailey/Albacore" title="Albacore Wiki">Albacore Wiki</a></li>
<li><a href="http://codebetter.com/blogs/david_laribee/archive/2008/08/25/omg-rake.aspx" title="OMG Rake!">OMG Rake!</a> - The original post which first inspired many to
use Rake with .net</li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Reading Code Is Key to Writing Good Code]]></title>
    <link href="https://stevenharman.net/reading-code-is-key-to-writing-good-code"/>
    <updated>2009-11-18T14:06:00+00:00</updated>
    <id>https://stevenharman.net/reading-code-is-key-to-writing-good-code</id>
    <content type="html"><![CDATA[<p>As humans we seem to have an innate desire for structure in our lives. Structure permeates through our societies; it&rsquo;s found within our families, education systems, governments, etc. I suppose it&rsquo;s no surprise then that we also seek to <em>force</em> structure upon the work that we, as software developers, do.</p>

<p>The problem is the work we do isn&rsquo;t structured. It is not deterministic. There is no grand blue print, process, nor methodology that we can follow to pay dirt.</p>

<p>We live in a chaotic and complex world that is itself continuously changing and adapting.</p>

<p>Software product development is a creative activity taking place in the midst of that complex and adaptive world. So doesn&rsquo;t it make sense that we, as software developers, might benefit from admitting that we are indeed doing creative, unstructured, adaptive work? <em>I sure think so!</em></p>

<!-- more -->


<h3>Looking outward for inspiration</h3>

<p>I&rsquo;ve recently been looking outward to other creative professions and trades for inspiration and insights into how they work. One thing I&rsquo;ve realized is that those folks spend an immense amount of time studying and seeking inspiration from the work of others both within and outside their own field.</p>

<p>For example, a musician doesn&rsquo;t just sit in his garage all day, banging out albums. He listens to and is influenced by the music of many other musicians. An author doesn&rsquo;t simply site down and write manuscript after manuscript. She spends countless hours reading the classics, studying the words, flow, and style of other authors. The same thing goes for painters, actors, architects, etc. And all of these people are constantly immersing them selves in works outside their area; musicians reading Hemingway, singer/song writers studying Salvador Dali, painters listening to Mozart, cats and dogs living together&hellip;</p>

<p>How arrogant of we programmers then to think that we won&rsquo;t, or don&rsquo;t, benefit from reading code written by - <em>gasp</em> - someone else!</p>

<h3>Read, learn, and be inspired</h3>

<p><img class="right" src="https://stevenharman.net/images/posts/text.jpg" title="Yay for reading!" >
In my experience we spend a great deal more time reading code than actually <em>writing</em> it. Whether it be the code you wrote just a few minutes ago or something you&rsquo;ve inherited and are now maintaining, you&rsquo;re reading it. Of course, that&rsquo;s only considering the motive of reading code because you&rsquo;re currently working with.</p>

<p>The greatest motivator for reading code is the opportunity it provides for learning and serving as a source of inspiration. Reading code exposes you to techniques, view points, styles, idioms, and algorithms that you may not have otherwise come across.</p>

<p>In my own career it was by reading code written in Ruby that I first started to develop an appreciation for beauty and aesthetics in code. It also opened me to new ways of thinking about problems and exposed many pains and frictions with the techniques I had been using to that point.</p>

<h3>Where to start?</h3>

<p>I realize it&rsquo;s probably obvious, but I&rsquo;m going to say it anyhow - a great way to start reading other&rsquo;s code is to pull down an Open Source project and dive in. Of course, that&rsquo;s not to say that all Open Source code bases are necessarily examples of great code' so you might also want to leverage your network to find examples. Or, use your Google-fu to see what others are reading. Or maybe check out:</p>

<ul>
<li><a href="http://katas.softwarecraftsmanship.org/" title="Software Craftsmanship - Katas">Katacasts</a> by <a title="Corey Haines" href="http://www.coreyhaines.com/" rel="friend met">Corey Haines</a> and Chris Parsons</li>
<li><a href="http://www.hanselman.com/blog/CategoryView.aspx?category=Source+Code">The Weekly Source Code</a> series by <a title="Scott Hanselman's Computer Zen" href="http://www.hanselman.com" rel="colleague met">Scott Hanselman</a></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Prefer Dependency Injection to Service Location]]></title>
    <link href="https://stevenharman.net/prefer-dependency-injection-to-service-location"/>
    <updated>2009-09-25T14:17:00+00:00</updated>
    <id>https://stevenharman.net/prefer-dependency-injection-to-service-location</id>
    <content type="html"><![CDATA[<p>There is currently a thread running over in the StructureMap Users mailing list asking <a href="http://groups.google.com/group/structuremap-users/browse_thread/thread/2ee1a7eab03d7f2a">if we really need constructor injection</a> when using an Inversion of Control container. Before any one rips off on a rant let me say that I worked with <a title="JonKruger.com" href="http://www.jonkruger.com/" rel="friend met co-worker">Jon</a> in my former life and I&rsquo;m fairly certain he&rsquo;s merely conducting a thought experiment, trying to sure up his own beliefs. A worthwhile exercise, if you ask me.</p>

<p>At any rate, I have a few points I wanted to throw out there; most of them basic and mere reiterations of the words of others, but I&rsquo;m gong to do it anyhow!</p>

<!-- more -->


<h3>The question at hand</h3>

<p>I would encourage you to go read the full thread (it&rsquo;s a quick read&hellip; 4 minutes, tops!), but knowing many of you are lazy like me, I&rsquo;ll reprint Jon&rsquo;s original question here.</p>

<p><em>Again, please go read the full thread so you have the full context.</em></p>

<blockquote><p>Whenever I tell people about StructureMap (or using <acronym title="Dependency Injection">DI</acronym> in general), I mention that two of the benefits are that (a) StructureMap will create objects and all their dependencies for you and (b) it enables you to fake out the dependencies in a test.</p><p>Why do we need constructor injection to do this?  I can call `ObjectFactory.GetInstance()` anytime I want and it will work.  And I could leave SM configured for my tests and call `ObjectFactory.Inject()` to stub things out.</p><p>So theoretically, I wouldn't even need constructor injection, right?</p><footer><strong>Jon Kruger</strong> <cite><a href='http://groups.google.com/group/structuremap-users/browse_thread/thread/2ee1a7eab03d7f2a'>StructureMap ML_</a></cite></footer></blockquote>


<h3>Let&rsquo;s get the jargon down</h3>

<p>To be clear, Jon proposing using <a href="http://martinfowler.com/articles/injection.html#UsingAServiceLocator" title="Using a Service Locator">Service Location</a> rather than <a href="http://en.wikipedia.org/wiki/Dependency_injection" title="Dependency Injection">Dependency Injection</a>.</p>

<p>While Service location is better than <a href="http://www.lostechies.com/blogs/jimmy_bogard/archive/2009/07/03/how-not-to-do-dependency-injection-in-nerddinner.aspx">poor-man&rsquo;s DI</a>, using it as suggested above is still introducing a high degree of coupling as all of these classes now have an opaque and highly concrete dependency on the container. This is effectively creating a new form of <code>Global</code>. <em>Eww!</em></p>

<p>The key to using Service Location within <strong>new code</strong> is to keep it tucked away in the deepest, darkest corners of your infrastructure. For example, if you&rsquo;re building something on the asp.net mvc stack, you might use Service Location within a custom <code>IControllerFactory</code> to create each of your controllers.</p>

<p>If you&rsquo;re dealing with <strong>legacy code</strong>, full of concrete dependencies, you might use Service Location as technique for teasing things apart with a goal of decreased hard coupling. In the end this may result in wholesale replacement of some modules.</p>

<p>When it comes to Dependency Injection and dependencies in general, I agree with <a href="http://blog.scottbellware.com/" rel="friend met">Scott Bellware&rsquo;s</a> point of view; make your <a href="http://codebetter.com/blogs/scott.bellware/archive/2007/06/28/164867.aspx" title="Dependency Patterns: Optional Dependencies and Primal Dependencies">dependencies explicit &amp; transparent</a> by requiring them in the constructor. My gut reaction is also to avoid translucent (setter-injected) dependencies as they make it harder to tell what dependencies an object will need to do its job - the shape of the object isn&rsquo;t as clear as with explicit constructor dependencies.</p>

<h3>Feeling the friction</h3>

<p>I tend to be lazy and prefer to feel friction of poor design early so I can change direction quickly. For example, when a constructor gets too large it&rsquo;s a signal to stop and consider <a href="http://butunclebob.com/ArticleS.UncleBob.PrinciplesOfOod" title="Uncle Bob's Principles of Object Oriented Design">Single Responsibility Principle, Separation of Concerns, etc</a>. In a similar vein, I don&rsquo;t usually advocate use of an <a href="http://www.lostechies.com/blogs/joshuaflanagan/archive/2009/02/03/auto-mocking-explained.aspx" title="Auto-mocking Explained">auto-mocking container</a>. Or at least not for folks who&rsquo;ve not yet acquired a strong nose for design and simplicity; the friction helps keep you on the rails.</p>

<p>Later in the tread Jon mentions some friction he&rsquo;s been feeling when setting up the <a href="http://stevenharman.net/blog/archive/2009/05/27/toward-a-better-use-of-context-specification.aspx" title="Toward a Better Use of Context/Specification">context</a> of his tests (or specs). Namely he&rsquo;s having to set up and inject a lot of concrete objects for interaction within his unit tests. To me this is an indication that those tests may actually be integration tests. After all, they are flexing the integration of a several modules in concert, right?</p>

<p>I say, call them what they are, fire up the fully configured container, and move on.</p>

<p>I prefer to make the implicit explicit, to be able easily see the shape of an object, and in getting forced feedback when my design starts to slip off the rails.</p>
]]></content>
  </entry>
  
</feed>
