<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Tag what</title>
    <link>http://blog.objectmentor.com/articles/tag/what</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>TDD is how I do it, not what I do</title>
      <description>&lt;blockquote&gt;
&amp;#8220;Do not seek to follow in the footsteps of the men of old; seek what they sought.&amp;#8221; ~Basho
&lt;/blockquote&gt;

	&lt;p&gt;That quote resonates with me. I happend across that a few days after co-teaching 
an &amp;#8220;advanced &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; course with Uncle Bob. One of the recurring themes during the week
was that &lt;span class="caps"&gt;TDD&lt;/span&gt; is a &amp;#8220;how&amp;#8221; not a &amp;#8220;what&amp;#8221;. It&amp;#8217;s important to remember that &lt;span class="caps"&gt;TDD&lt;/span&gt; is not the
goal, the&lt;i&gt; &lt;b&gt;results&lt;/b&gt;&lt;/i&gt; of successfully applying &lt;span class="caps"&gt;TDD&lt;/span&gt; are.&lt;/p&gt;


	&lt;p&gt;What are those results?&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;You could end up writing less code to accomplish the same thing&lt;/li&gt;
		&lt;li&gt;You might write better code that is less-coupled and more maleable&lt;/li&gt;
		&lt;li&gt;The code tends to be testable because, well, it IS tested&lt;/li&gt;
		&lt;li&gt;The coverage of your tests will be such that making significant changes will not be too risky&lt;/li&gt;
		&lt;li&gt;The number of defects should be quite low&lt;/li&gt;
		&lt;li&gt;The tests serve as excellent exampls of how to use the various classes in your solution&lt;/li&gt;
		&lt;li&gt;Less &amp;#8220;just in case&amp;#8221; code written, which typically doesn&amp;#8217;t work in those cases that they targeted&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Right now I do not know of a better way to accomplish all of these results more effectively
than practicing &lt;span class="caps"&gt;TDD&lt;/span&gt;. Even so, this does not elevate &lt;span class="caps"&gt;TDD&lt;/span&gt; from a &amp;#8220;how&amp;#8221; to a &amp;#8220;what.&amp;#8221; 
&lt;span class="caps"&gt;TDD&lt;/span&gt; remains a technique to accomplish thigns I value. It is not a self-justifying
practice. If someone asks me &amp;#8220;why do we do it this way&amp;#8221;, saying something like
&amp;#8220;we practice &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; or &amp;#8220;well you don&amp;#8217;t understand &lt;span class="caps"&gt;TDD&lt;/span&gt;&amp;#8221; is not a good answer.&lt;/p&gt;


We had an interesting result during that class. One group was practicing Bob&amp;#8217;s three rules of &lt;span class="caps"&gt;TDD&lt;/span&gt; (paraphrased); 
	&lt;ul&gt;
	&lt;li&gt;Write no production code without failing tests&lt;/li&gt;
		&lt;li&gt;Write only enough test code so that it fails (not compiling is failing)&lt;/li&gt;
		&lt;li&gt;Write only enough production code to get your tests to pass.&lt;/li&gt;
	&lt;/ul&gt;


But they ended up with a bit of a mess. Following the three rules wasn&amp;#8217;t enough. These rules are guiding principles, but those three rules mean nothing if you forget about clean code, refactoring and basic design principles (here are a few):
	&lt;ul&gt;
	&lt;li&gt;S.O.L.I.D.&lt;/li&gt;
		&lt;li&gt;F.I.R.S.T.&lt;/li&gt;
		&lt;li&gt;Separation of Concerns (Square Law of Computation)&lt;/li&gt;
		&lt;li&gt;Coupling/Cohesion&lt;/li&gt;
		&lt;li&gt;Protected Variation&lt;/li&gt;
		&lt;li&gt;...&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; is a means to an end but it is the end we care about. What is that end? 
Software that has few defects and is easy to change. Tests give us that. Not 
testing generally does not give us that. And testing in a common &amp;#8220;QA over the wall&amp;#8221; configuration typically does not cut it.&lt;/p&gt;


	&lt;p&gt;Since I do not know how to so easily produce those results in any other way. &lt;span class="caps"&gt;TDD&lt;/span&gt; becomes the defacto means of implementation for me. That doesn&amp;#8217;t mean I should turn a blind eye to new ways of doing things. In lieu of any such information, however, I&amp;#8217;ll pick &lt;span class="caps"&gt;TDD&lt;/span&gt; as a starting point. This is still a &amp;#8220;how&amp;#8221; and not a &amp;#8220;what&amp;#8221;.&lt;/p&gt;


It turns out that for me there are several tangible benefits I&amp;#8217;ve personally 
experienced from practicing &lt;span class="caps"&gt;TDD&lt;/span&gt;:
	&lt;ul&gt;
	&lt;li&gt;Increased confidence in the code I produce (even more than when I was simply test infected)&lt;/li&gt;
		&lt;li&gt;Less worrying about one-off conditions and edge cases. I&amp;#8217;ll get to them and as I think about then, they become tests&lt;/li&gt;
		&lt;li&gt;Fun&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Fun?&lt;/p&gt;


Yes I wrote fun. There are several aspects of this:
	&lt;ul&gt;
	&lt;li&gt;I seem to produce demonstrable benefits sooner&lt;/li&gt;
		&lt;li&gt;I actually do more analysis throughout&lt;/li&gt;
		&lt;li&gt;I get to do more OO programming&lt;/li&gt;
	&lt;/ul&gt;


&lt;h4&gt;Demonstrable Benefits Sooner&lt;/h4&gt;
Since I focus on one test at a time, I frequently get back to running tests. I&amp;#8217;m able to see results sooner. Sure, those results are sometimes disjoint and piecemeal, but over time they organically grow into something useful. I really enjoy teaching a class and moving from a trivial test to a suite a tests that together have caused what students can see is a tangible implementation of something complex.

&lt;h4&gt;More Analysis&lt;/h4&gt;
Analysis means to break into constituent parts. When I practice &lt;span class="caps"&gt;TDD&lt;/span&gt;, I think about some end (say a user story or a scenario) then I think about a small part of that overall work and tackle it. In the act of getting to a test, I&amp;#8217;m doing enough analysis to figure out at least some of the parts of what I&amp;#8217;m trying to do. I&amp;#8217;m breaking my goal into a parts, that&amp;#8217;s a pretty good demonstration of analysis.

&lt;h4&gt;More OO&lt;/h4&gt;
I like polymorphism. I like lots of shallow, but broad hierarchies. 
I prefer delegation to inheritance. But often, the things I&amp;#8217;m writing 
don&amp;#8217;t need a lot of this &amp;#8211; or so it might seem.

	&lt;p&gt;When I try to create a good unit test, much of what I&amp;#8217;m doing is trying 
to figure out how the effect I&amp;#8217;m shooting for can be isolated 
to make the test fast, independent, reliable &amp;#8230; To do so, I 
make heavy use of test doubles. Sometimes I hand-roll them, sometimes 
I use mocking libraries. I&amp;#8217;ve event used &lt;span class="caps"&gt;AOP&lt;/span&gt; frameworks, but not nearly as extensively.&lt;/p&gt;


	&lt;p&gt;Doing all of this allows me to use polymorphism more often. And that&amp;#8217;s fun.&lt;/p&gt;


&lt;h3&gt;Conclusion&lt;/h3&gt;
Am I wasting time writing all of these tests? Is my enjoyment of my work
an indication that I might be wasting the time of my product owner?

	&lt;p&gt;Those are good questions. And these are things you might want to ask yourself.&lt;/p&gt;


Personally, I&amp;#8217;m pretty sure I&amp;#8217;m not wasting anyone&amp;#8217;s time for several reasons:
	&lt;ul&gt;
	&lt;li&gt;The product owner is keeping me focused on things that add value&lt;/li&gt;
		&lt;li&gt;Short iterations keep me reigned in&lt;/li&gt;
		&lt;li&gt;I&amp;#8217;m only doing as much as necessary to get the stories for an iteration implemented&lt;/li&gt;
		&lt;li&gt;The tests I&amp;#8217;m writing stay passing, run quickly and over time remain (become) maintainable&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;Even so, since &lt;span class="caps"&gt;TDD&lt;/span&gt; is a how and not a what, I still need to keep asking myself
if the work I&amp;#8217;m doing is moving us towards a working solution that will be
maintainable during its lifetime.&lt;/p&gt;


	&lt;p&gt;I think it is. What about you?&lt;/p&gt;</description>
      <pubDate>Mon, 21 Jul 2008 14:32:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:b4795a7f-9544-422c-bb60-8cf16917afbd</guid>
      <author>Brett Schuchert</author>
      <link>http://blog.objectmentor.com/articles/2008/07/21/tdd-is-how-i-do-it-not-what-i-do</link>
      <category>Schuchert's Scattered Synapses </category>
      <category>TDD</category>
      <category>how</category>
      <category>versus</category>
      <category>what</category>
    </item>
  </channel>
</rss>
