<?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>8th Light Blog: Lessons of a Craftsman: Are you Test Driving, or just writing tests?</title>
    <link>http://blog.8thlight.com/articles/2008/01/07/lessons-of-a-craftsman-are-you-test-driving-or-just-writing-tests</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>In the minds of the craftsmen...</description>
    <item>
      <title>Lessons of a Craftsman: Are you Test Driving, or just writing tests?</title>
      <description>&lt;p&gt;Recently I wrote the beginnings of a blackjack game in Java, and I found myself making what I believe is a common error.  The Java gameplay mechanic uses a state machine to manipulate the deck.  As I was implementing the state machine I found I needed a Card object, in addition to my Card3DObject which actually drew the card, a look-up table for the 3D cards, an interface for the Deck and an object representing the Deck (so I could mock it out), and when I came across the situation for an Ace I decided a needed an object responsible for computing a Total in order to handle the situation of an Ace being a 1 or 11.&lt;/p&gt;

&lt;p&gt;Apparently an if statement would cause an irreversible hand cramp, ending my programming career.&lt;/p&gt;

&lt;p&gt;If you&amp;#8217;ve ever done the bowling game, and really why haven&amp;#8217;t you, there&amp;#8217;s more than a few ways to skin that particular cat.  Ron Jefferies has done it about [four thousand different ways] (http://www.xprogramming.com/xpmag/index.htm), whereas Bob Martin typically teaches a simple one.  While none of them are wrong, I&amp;#8217;m partial to the Martin version because it&amp;#8217;s a simple problem, and it deserves a simple solution.  I can give that version to a college student, and he can understand it.  Furthermore in that version the tests &lt;em&gt;drive&lt;/em&gt; the design.  Let&amp;#8217;s go back and look at my blackjack game to see what I mean.&lt;/p&gt;

&lt;p&gt;When writing the game I decided blackjack would be a FSM.  I drew a couple of diagrams, then used the Java state machine generator to make my state machine.  The problem, as I see it, is that I did this without writing a line of code.  Furthermore as I was coding I was thinking two steps ahead, and making design decisions before I needed to.  I did a mini-version of the BDUF, and it&amp;#8217;s something I see people do all the time.  I was writing test first but I wasn&amp;#8217;t always letting tests drive that design.  Frankly that&amp;#8217;s not necessarily a bad thing, and virtually all large systems need some design as a sort of guide, but what I should have done is wait until the code forced me into the state machine, forced me into other objects, etc.  It&amp;#8217;s not the end of the world, and in the end I may even have made the same decisions I would have anyway, but given that I didn&amp;#8217;t let my tests drive my design I probably won&amp;#8217;t end up with the simplest thing that could possibly work.  That&amp;#8217;s a shame.&lt;/p&gt;</description>
      <pubDate>Mon, 07 Jan 2008 21:58:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:189f4cb4-6eca-4b18-822f-ce3016f36272</guid>
      <author>Eric</author>
      <link>http://blog.8thlight.com/articles/2008/01/07/lessons-of-a-craftsman-are-you-test-driving-or-just-writing-tests</link>
      <category>Coding</category>
      <category>Eric</category>
    </item>
  </channel>
</rss>
