<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="wordpress/2.1.2" -->
<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/"
	>

<channel>
	<title>Exploration Through Example</title>
	<link>http://www.exampler.com/blog</link>
	<description>Example-driven development, Agile software development, testing, Ruby, and other things of interest to Brian Marick</description>
	<pubDate>Wed, 01 Sep 2010 14:37:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.1.2</generator>
	<language>en</language>
			<item>
		<title>&#8220;Editing&#8221; trees in Clojure with clojure.zip</title>
		<link>http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/</link>
		<comments>http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/#comments</comments>
		<pubDate>Wed, 01 Sep 2010 10:46:03 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/</guid>
		<description><![CDATA[Clojure.zip is a library that lets you move around freely within trees and also create changed copies of them. This is a tutorial I wish I&#8217;d had when I started using it.
In this tutorial, I&#8217;ll use sequences as trees. You can create your own kind of trees if you want, but I won&#8217;t cover that. [...]]]></description>
			<content:encoded><![CDATA[<p>Clojure.zip is a library that lets you move around freely within trees and also create changed copies of them. This is a tutorial I wish I&#8217;d had when I started using it.</p>
<p>In this tutorial, I&#8217;ll use sequences as trees. You can create your own kind of trees if you want, but I won&#8217;t cover that. </p>
<p>Here&#8217;s what we&#8217;ll be working with:</p>
<pre>
user=> (def original [1 '(a b c) 2])
#'user/original
</pre>
<p>It&#8217;s a tree whose root is a vector with three children: 1, the subtree <code>(a,b,c)</code> and 2. We need to convert it into some sort of data structure that allows free movement. That&#8217;s done like this:</p>
<pre>
user=> (require '[clojure.zip :as zip])
nil
user=> (def root-loc (zip/seq-zip (seq original)))
#'user/root-loc
</pre>
<p>Notice that I used the alias <code>zip</code>. If you <code>refer</code> or <code>use</code> clojure.zip, you&#8217;ll find yourself overwriting useful functions like <code>clojure.core/next</code>. </p>
<p>Notice also that I explicitly wrapped the tree in a seq. If you use seq-zip on an unwrapped vector, you&#8217;ll get confusing results.</p>
<p>At this point, I&#8217;d describe <code>root-loc</code> as &#8220;the location (or <em>loc</em>) of the root of the <em>tomorrow tree</em>.&#8221; I say &#8220;tomorrow tree&#8221; because it&#8217;s not a tree itself, but something that can later be converted into a tree. In reality, <code>root-loc</code> names both the loc and the tomorrow tree, bundled up together, but I think it most straightforward to leave the tomorrow tree implicit.</p>
<p>(The actual data structure is called a &#8220;zipper&#8221;, which is a decent analogy for the actual implementation but didn&#8217;t help me understand how to use the library.)</p>
<p><b>Moving around inside a tomorrow tree</b></p>
<p>With the loc, we can move around:</p>
<pre>
user=> original
[1 (a b c) 2]
user=> (zip/node (zip/down root-loc))
1
</pre>
<p><code>zip/down</code> moves to the leftmost child of the current loc and returns that child&#8217;s loc. <code>zip/node</code> gives you the subtree of the original tree corresponding to its loc argument. It&#8217;s one of the main ways you get parts of a tree&#8212;regular lists, vectors, and the like&#8212;&#8221;out of&#8221; a tomorrow tree.</p>
<p>The <code>-&gt;</code> macro makes movement in the tomorrow tree much easier to understand:</p>
<pre>
user=> (-> root-loc zip/down zip/right zip/node)
(a b c)
user=> (-> root-loc zip/down zip/right zip/down zip/right zip/node)
b
</pre>
<p>Nevertheless, I always wrap anything but the simplest traversals in their own functions. </p>
<p>Here are some other movement functions for you to try: <code>up</code>, <code>left</code>, <code>rightmost</code>, and <code>leftmost</code>. Beware of (arguable) inconsistencies in the handling of edge cases. For example, <code>right</code> and <code>rightmost</code> behave differently when moving &#8220;off the end&#8221; of a list of siblings:</p>
<pre>
user=> original
[1 (a b c) 2]
user=> (def last-one (-> root-loc zip/down zip/right zip/right))
#'user/last-one
user=> (zip/node last-one)
2
user=> (-> last-one zip/<b>right</b>)
nil         ; off into nothingness
user=> (-> last-one zip/<b>rightmost</b> zip/node)
2           ; stays put
</pre>
<p><b>Parts of a tree</b></p>
<p>In addition to <code>zip/node</code>, there are other functions for recovering parts of the original tree. All work relative to the current loc.</p>
<pre>
user=> (def b (-> root-loc zip/down zip/right zip/down zip/right))
#'user/b
user=> (zip/node b)
b
user=> (zip/<b>lefts</b> b)
(a)
user=> (zip/<b>rights</b> b)
(c)
</pre>
<p>An interesting one shows all subtrees from the root of the tree down to just above the current loc:</p>
<pre>
user=> (zip/path b)
[  (1 (a b c) 2)
      (a b c)     ]
</pre>
<p><b>Changing the tree</b></p>
<p>A number of functions take a current loc (and associated tomorrow tree) and produce a new loc inside a different tomorrow tree. For example, let&#8217;s delete the &#8216;(a b c) subtree:</p>
<pre>
user=> (def loc-in-new-tree (zip/remove (zip/up b)))
#'user/loc-in-new-tree
</pre>
<p>How does the tree represented by this new tomorrow tree differ from the <code>original</code> tree? We can see that with the <code>root</code> function, which applies <code>zip/node</code> to the root of the tomorrow tree:</p>
<pre>
user=> (zip/root loc-in-new-tree)
(1 2)
user=> original
[1 (a b c) 2]
</pre>
<p>Where, exactly, is the new location? </p>
<pre>
user=> (zip/node loc-in-new-tree)
1
</pre>
<p>The new loc has &#8220;backed up&#8221; from its previous version. (That&#8217;s not an exact enough description, but it&#8217;ll do for a few more paragraphs.) The other editing functions return an &#8220;unchanged&#8221; loc (except in the sense that it&#8217;s pointing into a new tomorrow tree with a changed structure): <code>insert-left</code>, <code>insert-right</code>, <code>replace</code>, <code>edit</code>, <code>insert-child</code>, and <code>append-child</code>. Try them out.</p>
<p><b>In which I reveal I&#8217;m slow</b></p>
<p>At first, I easily forgot that these functions create a new tomorrow tree and don&#8217;t really &#8220;replace&#8221; or &#8220;insert&#8221; or &#8220;edit&#8221; parts of the old one. That is:</p>
<pre>
user=> (zip/root loc-in-new-tree)
(1 2)                ; I see that I've edited the tree.
user=> (zip/root b)
(1 (a b c) 2)        ; Wait - I thought I changed the tree?!
</pre>
<p>&#8220;Well, duh&#8221;, you might say, &#8220;it&#8217;s a functional language with immutable state, so <em>of course</em> it doesn&#8217;t change the old tree.&#8221; You&#8217;re absolutely right, but it was surprisingly easy for old habits to sneak up on me. So, two rules:</p>
<ul>
<li>
<p>
If you ever fail to use the return value of one of these functions, <em>you&#8217;re doing it wrong</em>.
</p>
</li>
<li>
<p>
If you ever write code like this:
</p>
<pre>
(let [stashed-location (zip/whatever ...)]
   ... make "changes" ...
   ... use stashed location ...)
</pre>
<p>you <em>might</em> be doing it wrong. Make sure that you&#8217;re not unthinkingly assuming that later changes to &#8220;the&#8221; tree are reflected in your <code>stashed-location</code>.
</li>
</ul>
<p><b>Whole-tree editing</b></p>
<p>Here&#8217;s an example of printing out a whole tree, one node at a time:</p>
<pre>
(defn print-tree [original]
  (loop [loc (zip/seq-zip (seq original))]
    (if (<b>zip/end?</b> loc)
      (zip/root loc)
      (recur (<b>zip/next</b>
                (do (println (zip/node loc))
                    loc))))))
</pre>
<p>This is an ordinary recursive loop. It visits each location in the tomorrow tree, stopping when <code>zip/end?</code> is true. <code>zip/next</code> returns a new current loc that is the next one in the tomorrow tree, where &#8220;next&#8221; means &#8220;in <a href="http://en.wikipedia.org/wiki/Tree_traversal#Depth-first_Traversal">preorder depth-first</a> order&#8221;. To see that, here&#8217;s what one run of the function prints:</p>
<pre>
user=> (print-tree [1 '(a (i ii iii) c) 2])
(1 (a (i ii iii) c) 2)
1
(a (i ii iii) c)
a
(i ii iii)
i
ii
iii
c
2
</pre>
<p>
To make changes to the tree, add a <code>cond</code>. The default case should hand the current loc to <code>zip/next</code>. The other cases should yield a loc pointing into a changed copy of the tomorrow tree:
</p>
<pre>
  (loop [loc (zip/seq-zip original-tree)]
    (if (zip/end?> loc)
      (zip/root loc)
      (recur (zip/next
          <b>(cond (subtree-to-change? loc)
                (modify-subtree loc)
                &#8230;
                :else loc</b>)))))
</pre>
<p>The tricky bit is making sure that <code>modify-subtree</code> returns a loc <em>just before</em> the next loc of interest (in a depth-first traversal). (It has to be before so that <code>zip/next</code> takes you to the interesting loc.) To get to that loc, you can use any of the movement functions (<code>zip/next</code>, <code>zip/up</code>, <code>zip/rightmost</code>, and so on). There&#8217;s also a <code>zip/prev</code> that returns the loc just before the current one. </p>
<p>To keep from confusing myself, I write little helper functions, each named by what it does <em>and</em> what loc it returns. So, for example, I have one function that glories in this name:</p>
<pre>
(defn <b>wrap-with-expect__at-rightmost-wrapped-location</b> [loc]
  (assert (start-of-arrow-sequence? loc))
  (let [right-hand (-> loc zip/right zip/right)
        edited-loc (<b>zip/edit</b> loc
                   (fn [loc] `(expect ~loc => ~(zip/node right-hand))))]
    (-> edited-loc zip/right zip/right zip/remove zip/remove)))
</pre>
<p>It takes a form like <code>... (f 1) =&gt; (+ 2 3) :next</code>, with the current loc being <code>(f 1)</code>,  and turns it into this:</p>
<pre>
... (expect (f 1) =&gt; (+ 2 3)) :next
</pre>
<p>&#8230; with the current loc being at the 3 so that the <code>zip/next</code> returns a loc at <code>:next</code>. This positioning works because I use <code>zip/remove</code>, which returns a loc that&#8217;s &#8220;backed up&#8221; to the previous loc in a depth-first traversal. (That&#8217;s the fix to my earlier imprecision about what <code>zip/remove</code> returns. It&#8217;s not the previous loc <em>at the same level</em>, which&#8212;for the sake of a simpler explanation&#8212;I earlier allowed you to assume.)</p>
<p>By building and testing these little functions first, my main cond-loop is easier to get right. You can see some more examples in my test package, <a href="http://github.com/marick/Midje">Midje</a>. You can look at both <a href="http://github.com/marick/Midje/blob/master/test/midje/fact_body_transformation_test.clj">the tests</a> and <a href="http://github.com/marick/Midje/blob/master/src/midje/fact_body_transformation.clj">the code</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/09/01/editing-trees-in-clojure-with-clojurezip/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A proposed check&#8217;n'balance for certifications</title>
		<link>http://www.exampler.com/blog/2010/08/13/a-proposed-checknbalance-for-certifications/</link>
		<comments>http://www.exampler.com/blog/2010/08/13/a-proposed-checknbalance-for-certifications/#comments</comments>
		<pubDate>Fri, 13 Aug 2010 12:18:25 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/08/13/a-proposed-checknbalance-for-certifications/</guid>
		<description><![CDATA[Earlier today, I found myself talking to Andrew Shafer and Corey Haines about certification. Certifications provided by people who make good money off them beg for distrust. So do certifications of courses or trainers when the certifiers get revenue from that activity. On balance, I think we&#8217;d have been better off without the certifications we [...]]]></description>
			<content:encoded><![CDATA[<p>Earlier today, I found myself talking to <a href="http://stochasticresonance.wordpress.com/">Andrew Shafer</a> and <a href="http://www.coreyhaines.com/">Corey Haines</a> about certification. Certifications provided by people who make good money off them beg for distrust. So do certifications of courses or trainers when the certifiers get revenue from that activity. On balance, I think we&#8217;d have been better off without the certifications we have, and I agree with the Agile Alliance&#8217;s <a href="http://www.agilealliance.org/news/agile-certification-a-position-statement/">position on certification</a>. (Disclosure: I was the main author.)</p>
<p>However. Here we are, aren&#8217;t we?</p>
<p>To improve the current situation, I propose the following, roughly inspired by <a href="http://www.consumerreports.org/cro/aboutus/mission/overview/index.htm">Consumer&#8217;s Union</a>.</p>
<ul>
<li>
<p>
There should be an <a href="http://www.agilealliance.org/">Agile Alliance</a> <a href="http://www.agilealliance.org/programs/">program</a> that applies to all courses, not just those that provide certifications.
</p>
</li>
<li>
<p>
This program will, with the Agile Alliance&#8217;s money, send spies to sign up for courses. They will anonymously write up detailed evaluations that will be posted on the Agile Alliance website.
</p>
</li>
<li>
<p>
It will also interview a random sample of course attendees. The ones contacted just after the course will be asked for their evaluation. The ones contacted a year after the course will be asked how valuable, in retrospect, the course was. These results will also be posted on the site.
</p>
</li>
<li>
<p>
These interviews and ratings will, over time, allow the writing of summary articles like the ones <a href="http://www.consumerreports.org/cro/index.htm">Consumer Reports Magazine</a> runs. Expect articles about &#8220;What to Expect from a Certified ScrumMaster&#8221; or &#8220;How to select a TDD course&#8221;.
</p>
</li>
<li>
<p>
Those running the program will pay careful attention to maintaining the trust of their readers.
</p>
</li>
</ul>
<p>It&#8217;s possible I&#8217;d participate in this. I have no desire to run it. I don&#8217;t care that much.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/08/13/a-proposed-checknbalance-for-certifications/feed/</wfw:commentRss>
		</item>
		<item>
		<title>An idea about testing inner functions in Clojure</title>
		<link>http://www.exampler.com/blog/2010/08/02/an-idea-about-testing-inner-functions-in-clojure/</link>
		<comments>http://www.exampler.com/blog/2010/08/02/an-idea-about-testing-inner-functions-in-clojure/#comments</comments>
		<pubDate>Mon, 02 Aug 2010 18:39:45 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/08/02/an-idea-about-testing-inner-functions-in-clojure/</guid>
		<description><![CDATA[While working on the &#8220;sweet&#8221; interface for Midge, I wrote this function:

metavar? and form-branch? are only useful within this function. I would have preferred to write it like this:

I didn&#8217;t because I wanted those two functions tested before I relied on them. So I need a format for testing inner functions. I&#8217;ve sketched out a [...]]]></description>
			<content:encoded><![CDATA[<p>While working on the &#8220;sweet&#8221; interface for <a href="http://github.com/marick/Midje">Midge</a>, I wrote this function:</p>
<script src="http://gist.github.com/505294.js?file=gistfile1.clj"></script>
<p><code>metavar?</code> and <code>form-branch?</code> are only useful within this function. I would have preferred to write it like this:</p>
<script src="http://gist.github.com/505299.js?file=gistfile1.clj"></script>
<p>I didn&#8217;t because I wanted those two functions tested before I relied on them. So I need a format for testing inner functions. I&#8217;ve sketched out a format and done (by hand) the transformation required to make it work. </p>
<p>I&#8217;ll start explaining it with this simple example:</p>
<script src="http://gist.github.com/505308.js?file=gistfile1.clj"></script>
<p>Before dealing with the daunting complexity of multiplication, I want to test <code>summer</code> with something like this:</p>
<script src="http://gist.github.com/505311.js?file=gistfile1.clj"></script>
<p>(I&#8217;m using the Midje sweet notation here. Read it as &#8220;It&#8217;s a fact that <code>(within (outer 1 2))</code>, <code>(summer)</code> produces 3.&#8221;)</p>
<p>To make this work, I&#8217;d redefine the <code>defn</code> macro for the duration of a test and have it produce a little extra metadata:</p>
<script src="http://gist.github.com/505321.js?file=gistfile1.clj"></script>
<p>I&#8217;m stashing away a function derived from <code>summer</code>. It creates the same lexical environment that <code>outer</code> does, and returns a function to call. Here&#8217;s the macro that would expand a <code>within</code>, together with a sample expansion:</p>
<script src="http://gist.github.com/505334.js?file=gistfile1.clj"></script>
<p>The expanded form is a little opaque, so here are the three steps:</p>
<ol>
<li>Retrieve the environment setting function from <code>outer</code>&#8217;s metadata.</li>
<li>Call it with the <code>outer</code> arguments.</li>
<li>Within that environment, call <code>summer.</code></li>
</ol>
<p>What if a later inner function uses a previously-defined one? Like this:</p>
<script src="http://gist.github.com/505338.js?file=gistfile1.clj"></script>
<p>One option would be to drag the earlier parts of the <code>let</code> into the metadata:</p>
<script src="http://gist.github.com/505340.js?file=gistfile1.clj"></script>
<p>In that case, the test would look like this:</p>
<script src="http://gist.github.com/505344.js?file=gistfile1.clj"></script>
<p>This test is a little not-thrilling because it&#8217;s clearer what <code>multiplier</code> does if you can see how it relies on <code>summer</code>. That could look like this:</p>
<script src="http://gist.github.com/505361.js?file=gistfile1.clj"></script>
<p>However, dragging the previous <code>let</code> clauses into the metadata has to be done anyway (in case non-function values are bound), so I&#8217;d be inclined not to gild this lily.</p>
<p>Creating the metadata wouldn&#8217;t be too hard in the common case where the <code>let</code> is the outermost form in the function&#8217;s definition. I doubt I could be persuaded to care about other cases.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/08/02/an-idea-about-testing-inner-functions-in-clojure/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;Quality is value to some person&#8221; restated</title>
		<link>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person-restated/</link>
		<comments>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person-restated/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 16:57:28 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person-restated/</guid>
		<description><![CDATA[Michael Bolton has asked me to improve the sentence in the headline. Here is my attempt. It stems from two of my beliefs:



It&#8217;s better to focus on the immediate problem than on convincing people of a universal truth.




Right action does not follow from thinking correctly. Thinking correctly follows from the habit of acting correctly.



The sentence [...]]]></description>
			<content:encoded><![CDATA[<p>Michael Bolton has asked me to improve the sentence in the headline. Here is my attempt. It stems from two of my beliefs:</p>
<ul>
<li>
<p>
It&#8217;s better to focus on the immediate problem than on convincing people of a universal truth.
</p>
</li>
<li>
<p>
Right action does not follow from thinking correctly. Thinking correctly follows from the habit of acting correctly.
</p>
</li>
</ul>
<p>The sentence is an <a href="http://www.thefreedictionary.com/saying">aphorism</a>: terse, stylish, true, and deep. I think its proponents value the aphoristic quality as much as they do the underlying sentiment. When I watch them use it, I believe they&#8217;d be happiest if they could generate an <a href="http://dictionary.reference.com/browse/epiphany">epiphany</a> (&#8221;a sudden, intuitive perception of or insight into the reality or essential meaning of something&#8221;). I&#8217;ll try and mimic some of the aphoristic terseness at first, even though I am explicitly not going for an epiphany.</p>
<p>Here goes:</p>
<blockquote><p>
<i>1. The setting: an unproductive conversation needs to be redirected. It&#8217;s likely that the conversation is happening because some important people are unhappy. But instead of talking about how to make them happy, we&#8217;re talking about whether they are </i>right<i> to be unhappy. We&#8217;ve come down to&#8212;explicitly or implicitly&#8212;competing definitions of quality.</i></p>
<p><i>2. There is a brief lull in the conversation. Our hero speaks.</i></p>
<p>&#8220;Different people care differently.&#8221; <i>(<a href="http://www.pages.drexel.edu/~ina22//scrnfmt/scrnfmtbeat.htm">beat</a>)</i></p>
<p><i>Because the sentence doesn&#8217;t obviously have anything to do with quality, it has a desirable &#8220;huh? where did that come from?&#8221; effect that keeps people from jumping into our hero&#8217;s pause-for-emphasis.</p>
<p></i><i>3. The hero speaks the following sentence with an &#8220;opening up / giving&#8221; hand movement, the sort where you bring your hand up and out, rotating it from palm down to palm up. This counters the harshness and <a href="http://en.wikipedia.org/wiki/Trochee">abruptness</a> of the first sentence: <b>Diff</b>-rent <b>pee</b>-pul <b>judge</b> <b>diff</b>-rent-ly.</i></p>
<p>&#8220;So different people will judge our product differently.&#8221; <i>(beat)</i></p>
<p><i>A little rhetorical flourish in the parallelism of the two sentences. The &#8220;so&#8221; at the beginning switches the meter to more <a href="http://en.wikipedia.org/wiki/Iamb">iambic</a>, gives it a little forward momentum, opens it up into a more conversational tone. &#8220;Judge&#8221; is a strong, active word (as is &#8220;care&#8221;), and focuses attention on what people are doing that the group must react to.</i></p>
<p><i>4. Someone tries to jump into the pause. Our hero gains time for one more utterance with a &#8220;just one more thing&#8221; head-tilt-back, audible intake of breath, and soft palms-out rotation of the hands, forefinger up. </p>
<p></i><i>5. The next bit takes long enough to give our hero a chance to make contact, via hand and head movements, with the people who are bored sick of the argument and have been sitting silently while the true believers battle it out. They&#8217;re being invited to break their silence to lend support.</i></p>
<p>&#8220;I predict that if we figure out which people we care about, and figure out what <i>they</i> care about, and how we can know their judgments before we get surprised like we were, we can live long and happy lives without ever agreeing what quality is. Let&#8217;s give it a try, OK?&#8221;</p>
<p><i>Long&#8212;because the problem isn&#8217;t simple. A program for action. Inviting a group of arguers to become &#8220;we&#8221; again. </p>
<p>The whole structure of the three parts is moving from authoritarian (&#8221;a fact you must recognize is&#8230;&#8221;) and abrupt to light (&#8221;long and happy lives&#8221;) and consensus-seeking (&#8221;we&#8221;, &#8220;OK&#8221;, ending on a rising question-tone). </p>
<p></i></p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person-restated/feed/</wfw:commentRss>
		</item>
		<item>
		<title>&#8220;Quality is value to some person&#8221;</title>
		<link>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person/</link>
		<comments>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 13:03:03 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[writing]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person/</guid>
		<description><![CDATA[I&#8217;ve long hated the sentence in the title, for a number of reasons. I threw away a long blog post about that yesterday, but let me just issue this challenge. How do the meanings of these three sentences differ?
Quality is value to some person.
Quality is quality to some person.
Value is value to some person.
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve long hated the sentence in the title, for a number of reasons. I threw away a long blog post about that yesterday, but let me just issue this challenge. How do the meanings of these three sentences differ?</p>
<p>Quality is <i>value to some person</i>.<br />
Quality is <i>quality to some person</i>.<br />
Value is <i>value to some person</i>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/07/12/quality-is-value-to-some-person/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Object-Oriented Design and Mock Objects: for non-programmers</title>
		<link>http://www.exampler.com/blog/2010/07/05/object-oriented-design-and-mock-objects-for-non-programmers/</link>
		<comments>http://www.exampler.com/blog/2010/07/05/object-oriented-design-and-mock-objects-for-non-programmers/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 00:38:04 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/07/05/object-oriented-design-and-mock-objects-for-non-programmers/</guid>
		<description><![CDATA[That&#8217;s the title of my Agile2010 workshop. Here&#8217;s the description:

We&#8217;re not shy about saying that testers, programmers, and everyone else in the team needs to become fluent in the business domain. But we&#8217;re blasé when programming practices and programming knowledge are the exclusive province of the programmers. That hampers communication and hurts teams. By simply [...]]]></description>
			<content:encoded><![CDATA[<p>That&#8217;s the title of my <a href="http://agile2010.agilealliance.org/">Agile2010</a> workshop. Here&#8217;s the description:</p>
<blockquote><p>
We&#8217;re not shy about saying that testers, programmers, and everyone else in the team needs to become fluent in the business domain. But we&#8217;re blasé when programming practices and programming knowledge are the exclusive province of the programmers. That hampers communication and hurts teams. By simply having people stand up, move around, and speak messages to each other, this workshop will show anyone who attends how advanced object-oriented programming and test-driven design works. Although tailored to non-programmers, programmers may find it useful too.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/07/05/object-oriented-design-and-mock-objects-for-non-programmers/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Release 0.1.1 of Midje, a Clojure mocking tool</title>
		<link>http://www.exampler.com/blog/2010/06/30/release-011-of-midje-a-clojure-mocking-tool/</link>
		<comments>http://www.exampler.com/blog/2010/06/30/release-011-of-midje-a-clojure-mocking-tool/#comments</comments>
		<pubDate>Thu, 01 Jul 2010 00:03:33 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[TDD]]></category>

		<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/06/30/release-011-of-midje-a-clojure-mocking-tool/</guid>
		<description><![CDATA[The devoted reader will recall that I earlier sketched a &#8220;little language&#8221; for mocking Clojure functions. I&#8217;ve finished implementing a usable&#8211;perhaps even pleasant&#8211;subset of it. I invite you to take a look. In keeping with my whole &#8220;work with ease&#8221; thing, I&#8217;ve made it dirt simple to try it out: one click and two shell [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.flickr.com/photos/gwilmore/1014691848/">devoted reader</a> will recall that <a href="http://www.exampler.com/blog/2010/06/10/tdd-in-clojure-a-sketch-part-1/">I earlier sketched</a> a &#8220;<a href="http://www.endpointcomputing.com/articles/littlelangs.html">little language</a>&#8221; for mocking Clojure functions. I&#8217;ve finished implementing a usable&#8211;perhaps even pleasant&#8211;subset of it. I invite you to <a href="http://github.com/marick/Midje#readme">take a look</a>. In keeping with my whole &#8220;<a href="http://www.exampler.com/ease-and-joy.html">work with ease</a>&#8221; thing, I&#8217;ve made it dirt simple to try it out: one click and two shell commands. You don&#8217;t even have to have Clojure installed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/06/30/release-011-of-midje-a-clojure-mocking-tool/feed/</wfw:commentRss>
		</item>
		<item>
		<title>A small note about collaborators</title>
		<link>http://www.exampler.com/blog/2010/06/19/a-small-note-about-collaborators/</link>
		<comments>http://www.exampler.com/blog/2010/06/19/a-small-note-about-collaborators/#comments</comments>
		<pubDate>Sat, 19 Jun 2010 22:43:10 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[agile]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/06/19/a-small-note-about-collaborators/</guid>
		<description><![CDATA[It&#8217;s often the case that a class has one or more collaborators that are used by many of its methods. When you want to override one for testing, you can either pass the test double into the constructor (probably as a default argument) or you can smash the double into an instance variable you happen [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s often the case that a class has one or more collaborators that are used by many of its methods. When you want to override one for testing, you can either pass the <a href="http://xunitpatterns.com/Test%20Double.html">test double</a> into the constructor (probably as a default argument) or you can smash the double into an instance variable you happen to know points to the collaborator.</p>
<p>I used to use the constructor approach, but I increasingly find myself using the Hulk! Smash! approach. It looks like this&#8230;</p>
<p>The object-to-be-tested names its collaborators and gives them the values they&#8217;ll use in production:</p>
<script src="http://gist.github.com/445330.js?file=gistfile1.builder"></script>
<p>I do this because I think of the collaborators as a static, declaration-like property of the class. (If I were ambitious, I&#8217;d convert <code>collaborators_start_as</code> into a class-level declaration like this:</p>
<script src="http://gist.github.com/445358.js?file=gistfile1.builder"></script>
<p>I haven&#8217;t been that ambitious yet, as it turns out.)</p>
<p>Each test declares which collaborators it overrides:</p>
<script src="http://gist.github.com/445335.js?file=gistfile1.builder"></script>
<p>Note that (in Ruby), I can even mock out classes, so I don&#8217;t have to go through contortions to pass in instances that an outside caller really would have no particular interest in:</p>
<script src="http://gist.github.com/445367.js?file=gistfile1.builder"></script>
<p>With several of the mocking packages available to me, I wouldn&#8217;t even have to go through the indirection of putting the class <code>ThingSource</code> into an instance variable. I could do this:</p>
<script src="http://gist.github.com/445370.js?file=gistfile1.builder"></script>
<p>I&#8217;m not bold enough to do that yet.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/06/19/a-small-note-about-collaborators/feed/</wfw:commentRss>
		</item>
		<item>
		<title>That $20 Billion BP deal</title>
		<link>http://www.exampler.com/blog/2010/06/17/the-20billion-bp-deal/</link>
		<comments>http://www.exampler.com/blog/2010/06/17/the-20billion-bp-deal/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 16:51:16 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[the larger world]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/06/17/the-20billion-bp-deal/</guid>
		<description><![CDATA[Various Republicans have characterized the recently announced 20 billion dollar deal between the government and BP as a &#8220;shakedown&#8221; for a slush fund, one that Obama doesn&#8217;t have constitutional authority to set up. From what I&#8217;ve read, it strikes me as a pretty straightforward deal, not wildly different than the way I used an escrow [...]]]></description>
			<content:encoded><![CDATA[<p>Various Republicans have characterized the recently announced <a href="http://www.nytimes.com/2010/06/17/us/politics/17obama.html">20 billion dollar deal</a> between the government and BP as a &#8220;<a href="http://bit.ly/avlVWt">shakedown</a>&#8221; for a <a href="http://mediamatters.org/research/201006170001">slush fund</a>, one that Obama doesn&#8217;t have <a href="http://www.wtaq.com/news/articles/2010/jun/17/some-republicans-consider-bp-deal-a-us-shakedown/">constitutional authority</a> to set up. From what I&#8217;ve read, it strikes me as a pretty straightforward deal, not wildly different than the way I used <a href="https://escrow.com/index.asp">an escrow company</a> as an independent party when selling testing.com. Or that unpleasant incident with my neighbor&#8217;s grill a few years back&#8230;</p>
<p>Me: You careless oaf! You burned up my lawn! </p>
<p>Him: I admit it. I take full responsibility. Sorry.</p>
<p>Me: You&#8217;re going to pay for this damage, you know. All of it.</p>
<p>Him: I will do that. </p>
<p>Me: I bet that big old maple that overhangs the house is going to have to come out. That&#8217;s going to cost you a bundle.</p>
<p>Him: Oh now, it doesn&#8217;t look that bad.</p>
<p>Me: I had a tree hit by lightning once. Didn&#8217;t look much worse than that, but carpenter ants got into it and the tree had to come out. The guys who took it out told me I should have done it right away, that the tree was worse off than it looked. I&#8217;m not waiting this time.</p>
<p>Him: Uh&#8230; Don&#8217;t know all that much about trees.</p>
<p>Me: Neither do I. Look. Let&#8217;s simplify this, keep at least some of it out of court. Let&#8217;s get <a href="http://abcnews.go.com/Business/bp-gulf-oil-spill-ken-feinberg-appointed-head/story?id=10933766">someone with experience at judging these kinds of damages</a> and have him decide, shrub by shrub, tree by tree, what you owe.</p>
<p>Him: Like the <a href="http://www.mediation-solution.com/mediation-defined.htm">independent mediator</a> written into lots of contracts.</p>
<p>Me: Right.</p>
<p><i>Some time passes as we dicker over who we both trust.</i></p>
<p>Me: Now, I&#8217;m pretty sure this is going to cost you over $2000&#8230;</p>
<p>Him: Aw, <a href="http://www.guardian.co.uk/environment/2010/jun/14/bp-survival-fears-oil-spill">that seems high</a>&#8230;</p>
<p>Me: That maple is <a href="http://seekingalpha.com/article/209166-bp-spill-size-estimates-keep-growing-along-with-potential-costs">four stories tall</a>!</p>
<p>Him: Hey, I still think it&#8217;ll be alright. But OK&#8212;so long as we get that mediator guy, the one I trust.</p>
<p>Me: And I want you to put the money in <a href="http://en.wikipedia.org/wiki/Escrow">escrow</a>.</p>
<p>Him: Aw, c&#8217;mon. You know I&#8217;m good for it. </p>
<p>Me: Yeah, well, my trust in you is not super-high right now.</p>
<p>Him: Well&#8230;</p>
<p>Me: Look. Back out of the deal if you want. You&#8217;re going to pay one way or the other. You can do it quickly or drag it out. Your choice.</p>
<p>Him: OK, OK: it&#8217;s a deal.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/06/17/the-20billion-bp-deal/feed/</wfw:commentRss>
		</item>
		<item>
		<title>TDD in Clojure, part 3 (one wafer-thin function; conclusions)</title>
		<link>http://www.exampler.com/blog/2010/06/17/tdd-in-clojure-part-3-one-wafer-thin-function-conclusions/</link>
		<comments>http://www.exampler.com/blog/2010/06/17/tdd-in-clojure-part-3-one-wafer-thin-function-conclusions/#comments</comments>
		<pubDate>Thu, 17 Jun 2010 14:02:26 +0000</pubDate>
		<dc:creator>Brian Marick</dc:creator>
		
		<category><![CDATA[TDD]]></category>

		<category><![CDATA[programming]]></category>

		<category><![CDATA[clojure]]></category>

		<guid isPermaLink="false">http://www.exampler.com/blog/2010/06/17/tdd-in-clojure-part-3-one-wafer-thin-function-conclusions/</guid>
		<description><![CDATA[Part 1
Part 2
All that remains is to add the locations of bordering cells to a given sequence of locations. A small wrinkle is that a border location may be next to more than one of the input locations, so duplicates need to be prevented. I could write the test this way:

I don&#8217;t like that. When [...]]]></description>
			<content:encoded><![CDATA[<p style="text-align: right; font-size: 0.8em"><a href="http://www.exampler.com/blog/2010/06/10/tdd-in-clojure-a-sketch-part-1/">Part 1</a><br />
<a href="http://www.exampler.com/blog/2010/06/16/tdd-in-clojure-part-2-in-which-i-recover-fairly-gracefully-from-a-stupid-decision/">Part 2</a></p>
<p>All that remains is to add the locations of bordering cells to a given sequence of locations. A small wrinkle is that a border location may be next to more than one of the input locations, so duplicates need to be prevented. I could write the test this way:</p>
<script src="http://gist.github.com/441208.js?file=gistfile1.clj"></script>
<p>I don&#8217;t like that. When the test fails, it&#8217;ll likely be hard to discover how the expected and actual values differ. And I bet that a failure would more likely be due to a typo in the expected value than to an actual bug. The test is <i><a href="http://www.exampler.com/ease-and-joy.html">just awkward</a></i>. </p>
<p>I like this version better:</p>
<script src="http://gist.github.com/441184.js?file=gistfile1.clj"></script>
<p>It is a clearer statement of the relationship between two concepts: a location&#8217;s neighborhood and the border of a set of locations. More pragmatically, it&#8217;s less typing. (When I first started coding in this style, it <a href="http://www.exampler.com/blog/2010/01/13/mocks-the-removal-of-test-detail-and-dynamically-typed-languages/">surprised me</a> how much test setup clutter went away. I had much less need for &#8220;factories&#8221; or &#8220;<a href="http://en.wikipedia.org/wiki/Test_fixture">fixtures</a>&#8221; or &#8220;<a href="http://martinfowler.com/bliki/ObjectMother.html">object mothers</a>&#8220;.)</p>
<p>Given either test, the code is straightforward:</p>
<script src="http://gist.github.com/442327.js?file=gistfile1.clj"></script>
<p><b>Onward</b></p>
<p>No matter how satisfying the individually-tested pieces, the whole has to work, which is why everything ends by running at least one end-to-end test. A test like the one we started with:</p>
<script src="http://gist.github.com/434773.js?file=gistfile1.clj"></script>
<p>Because I&#8217;m making up my test notation as I go, I&#8217;ve been running all the tests manually in the REPL. Now I can run the whole file:</p>
<script src="http://gist.github.com/441265.js?file=gistfile1.sh"></script>
<p>If you look carefully, you&#8217;ll see that the test would fail because the locations are in the wrong order. But that&#8217;s a quick fix:</p>
<script src="http://gist.github.com/441267.js?file=gistfile1.clj"></script>
<p>Done. Ship it!</p>
<p><b>Development order - Test-down or REPL-up? </b></p>
<p>It&#8217;s often said that the Lisps are bottom-up languages, that you test out expressions in the REPL, discover good functions, and compose them into programs. A lot of people do work that way. A lot of people who use TDD to write object-oriented code also work that way: when implementing a new feature, they start at low-level objects, add whatever new code the top-level feature seems to demand of them, then use those augmented objects in the testing of next-higher-level objects.</p>
<p>For I guess about a year now, I&#8217;ve been experimenting with being strictly top-down in some projects. I find that leads to less churn. Too often, when I go bottom-up, I end up discovering that those low-level changes are not in fact what the feature needs, so I have to revisit and redo what I did. </p>
<p>I get less disrupted by rework when I go from the top down (or from user interface in). It&#8217;s not that I don&#8217;t blunder&#8212;we saw <a href="http://www.exampler.com/blog/2010/06/16/tdd-in-clojure-part-2-in-which-i-recover-fairly-gracefully-from-a-stupid-decision#clojure_44">one of those</a> in the previous installment&#8212;but those blunders seem easier to recover from. </p>
<p>That&#8217;s not to say that I don&#8217;t use the REPL. We saw that a little bit in this program, when I <a href="http://www.exampler.com/blog/2010/06/16/tdd-in-clojure-part-2-in-which-i-recover-fairly-gracefully-from-a-stupid-decision#clojure_neighbor_343">was writing <code>neighbors</code></a>. It&#8217;s perfectly sensible to do even more in the REPL. I think of the REPL as a handy tool for what XP calls a <a href="http://www.extremeprogramming.org/rules/spike.html">spike solution</a> and the Pragmatic Programmers call <a href="http://www.artima.com/intv/tracer.html">tracer bullets</a>. When I&#8217;m uncertain what to do next, the REPL is a tool to let me try out possibilities. So I might be stuck in a certain function and go to the REPL to see how it feels to build up parts of what might lie under it. After I&#8217;m more confident, I can continue on with the original function, test-driven, reusing REPL snippets when they seem useful.</p>
<p>I don&#8217;t claim everyone should work that way. I do claim it&#8217;s a valid style that you&#8217;d be wise to try.</p>
<p><b>Notation</b></p>
<p>I&#8217;m something of an obsessive about test notation, and I&#8217;ve been endlessly fiddling with a Clojure mock notation. I implemented its first version as a facade on top of  <a href="http://richhickey.github.com/clojure-contrib/mock-api.html">clojure.contrib.mock</a>. As I experimented, though, I found that keeping my facade up to date with my notational variants slowed me down too much, so I put the code aside until the notation settled down.</p>
<p>I&#8217;m pretty happy with what you&#8217;ve seen here. Are you? If so, I may start on another mock package. I&#8217;ve got the most important parts: a name and sketch of a logo. (&#8221;Midje&#8221; and someone flying safely between the sun [of abstraction without examples] and the sea [of overwhelming detail].)</p>
<p><b>Tests and code together</b></p>
<p>You can see the completed program <a href="http://gist.github.com/442435">here</a>. It mixes up tests and code. I&#8217;ve tried that on-and-off over the years and always reverted to separate test files. This time, it&#8217;s seemed to work better. I probably want an Emacs keystroke that lets me hide all tests, though. I&#8217;d also want alternate definitions of the test macros so that I can compile them out of the production system</p>
<p><b>What next?</b></p>
<p>I&#8217;ll write a web app in this style, using <a href="http://weavejester.github.com/compojure/">Compojure</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.exampler.com/blog/2010/06/17/tdd-in-clojure-part-3-one-wafer-thin-function-conclusions/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
