tag:blogger.com,1999:blog-38985343726691136332019-03-21T02:09:03.283-07:00The Clean CoderA notebook for software craftsmen and engineers.Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.comBlogger32125tag:blogger.com,1999:blog-3898534372669113633.post-58533114564548676692011-02-04T07:56:00.000-08:002011-02-04T07:56:30.610-08:00This Blog has Moved.I won't be posting here anymore.&nbsp; My new blog is at <a href="http://cleancoder.posterous.com/">http://cleancoder.posterous.com/</a>.Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com29tag:blogger.com,1999:blog-3898534372669113633.post-10751925031190555272011-02-03T09:11:00.001-08:002011-02-03T09:11:26.298-08:00FLASH: TPP<div class='posterous_autopost'><h1>Flash Cards: T-P Premise</h1> <p>I read a nice <a href="http://madcoderspeak.blogspot.com/2011/02/flash-cards-kata-and-transformation.html">blog</a> today exploring the <a href="http://cleancoder.posterous.com/the-transformation-priority-premise">Transformation Priority Premise</a> using the flash card kata. The author did it in both lisp and C#. Let&rsquo;s try it in Java.</p> <p>The flash card kata is pretty straightforward. Given a set of questions and answers, ask the user each question and solicit an answer. If the answer is correct, say so and count it. If the answer is wrong show the correct answer and count the error. At the end, print the number of right and wrong answers.</p> <p>The first test is wonderfully simple. Given an empty list of questions and answers, end the game immediately with a summary showing nothing right and nothing wrong.</p> <p>We begin with an empty test which passes:</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">flashCardTest</span> { <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> degenerateGame() <span class="di">throws</span> <span class="ex">Exception</span> { } }</pre></div> </div> <p>We get the test to fail by asserting the answer we want and by doing a couple of <strong>({}&ndash;>nil)</strong> transforms. (In this case -1 is the integer equivalent of nil, e.g. a degenerate value)</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardTest</span> { <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> rightAndWrongShouldBeZeroIfGamePlayedWithNoCards() { <span class="pt">List</span> emptyList = <span class="kw">new</span> <span class="pt">ArrayList</span>(); playGame(emptyList); assertEquals(<span class="i">0</span>, rightAnswers()); assertEquals(<span class="i">0</span>, wrongAnswers()); } <span class="di">private</span> <span class="ty">int</span> wrongAnswers() { <span class="kw">return</span> -<span class="i">1</span>; } <span class="di">private</span> <span class="ty">int</span> rightAnswers() { <span class="kw">return</span> -<span class="i">1</span>; } <span class="di">private</span> <span class="ty">void</span> playGame(<span class="pt">List</span> flashCards) { } }</pre></div> </div> <p>To get this to pass just need to do some <strong>(nil->constant)</strong> transforms.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">private</span> <span class="ty">int</span> wrongAnswers() { <span class="kw">return</span> <span class="i">0</span>; } <span class="di">private</span> <span class="ty">int</span> rightAnswers() { <span class="kw">return</span> <span class="i">0</span>; }</pre></div> </div> <p>This solution is a bit ugly since it couples the test and the solution. So let&rsquo;s refactor to create a class.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardTest</span> { <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> rightAndWrongShouldBeZeroIfGamePlayedWithNoCards() { FlashCardGame flashCardGame = <span class="kw">new</span> FlashCardGame(); <span class="pt">List</span> emptyList = <span class="kw">new</span> <span class="pt">ArrayList</span>(); flashCardGame.playGame(emptyList); assertEquals(<span class="i">0</span>, flashCardGame.rightAnswers()); assertEquals(<span class="i">0</span>, flashCardGame.wrongAnswers()); } }</pre></div> </div> <hr /> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardGame</span> { <span class="di">public</span> FlashCardGame() { } <span class="ty">int</span> wrongAnswers() { <span class="kw">return</span> <span class="i">0</span>; } <span class="ty">int</span> rightAnswers() { <span class="kw">return</span> <span class="i">0</span>; } <span class="ty">void</span> playGame(<span class="pt">List</span> flashCards) { } }</pre></div> </div> <p>For the next test, lets try a game with a single flash card, that the user gets right.</p> <div class="CodeRay"> <div class="code"><pre><span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> rightShouldBeOneIfOneRightAnswer() { FlashCard card = <span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">Q</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>); <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(card); flashCardGame.playGame(cards); assertEquals(<span class="i">1</span>, flashCardGame.rightAnswers()); assertEquals(<span class="i">0</span>, flashCardGame.wrongAnswers()); }</pre></div> </div> <p>This fails of course. We can make it pass by simply incrementing the right count in <code>playGame</code> if the list of cards is not zero. This is a <strong>(unconditional->if)</strong> transform. That, plus a little refactoring gives us:</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardGame</span> { <span class="di">private</span> <span class="ty">int</span> rightAnswers; <span class="di">public</span> FlashCardGame() { } <span class="ty">int</span> getWrongAnswers() { <span class="kw">return</span> <span class="i">0</span>; } <span class="ty">int</span> getRightAnswers() { <span class="kw">return</span> rightAnswers; } <span class="ty">void</span> playGame(<span class="pt">List</span> flashCards, FlashCardTest answerer) { <span class="kw">if</span> (flashCards.size() != <span class="i">0</span>) rightAnswers++; } }</pre></div> </div> <p>OK, so let&rsquo;s try a wrong answer.</p> <div class="CodeRay"> <div class="code"><pre><span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> wrongShouldBeOneIfOneWrongAnswer() { FlashCard card = <span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">QW</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>); <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(card); flashCardGame.playGame(cards); assertEquals(<span class="i">0</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">1</span>, flashCardGame.getWrongAnswers()); } <span class="di">public</span> <span class="pt">String</span> answerQuestion(<span class="pt">String</span> question) { <span class="kw">if</span> (question.equals(<span class="s"><span class="dl">&quot;</span><span class="k">QR</span><span class="dl">&quot;</span></span>)) <span class="kw">return</span> <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>; <span class="kw">else</span> <span class="kw">return</span> <span class="s"><span class="dl">&quot;</span><span class="k">W</span><span class="dl">&quot;</span></span>; }</pre></div> </div> <p>This forced us to create the <code>answerQuestion</code> function that pretends to be a user answering questions. If you pass in &ldquo;QR&rdquo; you get the right answer &ldquo;A&rdquo;. If you pass in &ldquo;QW&rdquo; you get the wrong answer &ldquo;W&rdquo;. To get this test to pass we&rsquo;re going to have to get this function called by <code>playGame</code>. We can do this by passing the test along in an argument using the Change Signature refactoring. Then we can use a <strong>(unconditional->if)</strong> transform to check the value of our new function.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardGame</span> { <span class="di">private</span> <span class="ty">int</span> rightAnswers; <span class="di">private</span> <span class="ty">int</span> wrongAnswers; <span class="di">public</span> FlashCardGame() { } <span class="ty">int</span> getWrongAnswers() { <span class="kw">return</span> wrongAnswers; } <span class="ty">int</span> getRightAnswers() { <span class="kw">return</span> rightAnswers; } <span class="ty">void</span> playGame(<span class="pt">List</span> flashCards, FlashCardTest answerer) { <span class="kw">if</span> (flashCards.size() != <span class="i">0</span>) { <span class="pt">String</span> question = flashCards.get(<span class="i">0</span>).getQuestion(); <span class="kw">if</span> (answerer.answerQuestion(question).equals(<span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>)) rightAnswers++; <span class="kw">else</span> wrongAnswers++; } } }</pre></div> </div> <p>Of course this is hideous, so we need to refactor alot.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">interface</span> <span class="cl">User</span> { <span class="pt">String</span> answerQuestion(<span class="pt">String</span> question); } ---- <span class="di">public</span> <span class="ty">class</span> <span class="cl">MockUser</span> <span class="di">implements</span> User { <span class="di">public</span> MockUser() { } <span class="di">public</span> <span class="pt">String</span> answerQuestion(<span class="pt">String</span> question) { <span class="kw">if</span> (question.equals(<span class="s"><span class="dl">&quot;</span><span class="k">QR</span><span class="dl">&quot;</span></span>)) <span class="kw">return</span> <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>; <span class="kw">else</span> <span class="kw">return</span> <span class="s"><span class="dl">&quot;</span><span class="k">W</span><span class="dl">&quot;</span></span>; } } ---- <span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardGame</span> { <span class="di">private</span> <span class="ty">int</span> rightAnswers; <span class="di">private</span> <span class="ty">int</span> wrongAnswers; <span class="di">public</span> FlashCardGame() { } <span class="ty">int</span> getWrongAnswers() { <span class="kw">return</span> wrongAnswers; } <span class="ty">int</span> getRightAnswers() { <span class="kw">return</span> rightAnswers; } <span class="ty">void</span> playGame(<span class="pt">List</span> flashCards, User user) { <span class="kw">if</span> (flashCards.size() != <span class="i">0</span>) { <span class="pt">String</span> question = flashCards.get(<span class="i">0</span>).getQuestion(); <span class="pt">String</span> answer = user.answerQuestion(question); <span class="kw">if</span> (answer.equals(<span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>)) rightAnswers++; <span class="kw">else</span> wrongAnswers++; } } } ---- <span class="di">public</span> <span class="ty">class</span> <span class="cl">FlashCardTest</span> { <span class="di">private</span> FlashCardGame flashCardGame; <span class="di">private</span> MockUser user = <span class="kw">new</span> MockUser(); <span class="at">@Before</span> <span class="di">public</span> <span class="ty">void</span> setUp() <span class="di">throws</span> <span class="ex">Exception</span> { flashCardGame = <span class="kw">new</span> FlashCardGame(); user = <span class="kw">new</span> MockUser(); } <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> rightAndWrongShouldBeZeroIfGamePlayedWithNoCards() { <span class="pt">List</span> emptyList = <span class="kw">new</span> <span class="pt">ArrayList</span>(); flashCardGame.playGame(emptyList, user); assertEquals(<span class="i">0</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">0</span>, flashCardGame.getWrongAnswers()); } <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> rightShouldBeOneIfOneRightAnswer() { FlashCard card = <span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">QR</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>); <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(card); flashCardGame.playGame(cards, user); assertEquals(<span class="i">1</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">0</span>, flashCardGame.getWrongAnswers()); } <span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> wrongShouldBeOneIfOneWrongAnswer() { FlashCard card = <span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">QW</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>); <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(card); flashCardGame.playGame(cards, user); assertEquals(<span class="i">0</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">1</span>, flashCardGame.getWrongAnswers()); } }</pre></div> </div> <p>Now let&rsquo;s do two questions, one right and one wrong.</p> <div class="CodeRay"> <div class="code"><pre><span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> countBothOneRightAndOneWrong() { <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(<span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">QW</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>)); cards.add(<span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">QR</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>)); flashCardGame.playGame(cards, user); assertEquals(<span class="i">1</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">1</span>, flashCardGame.getWrongAnswers()); }</pre></div> </div> <p>This fails, but we can make it pass with a <strong>(if->while)</strong> transform.</p> <div class="CodeRay"> <div class="code"><pre><span class="ty">void</span> playGame(<span class="pt">List</span> flashCards, User user) { <span class="kw">for</span> (FlashCard card : flashCards) { <span class="pt">String</span> question = card.getQuestion(); <span class="pt">String</span> answer = user.answerQuestion(question); <span class="kw">if</span> (answer.equals(<span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>)) rightAnswers++; <span class="kw">else</span> wrongAnswers++; } }</pre></div> </div> <p>One thing left. We need to actually compare the answer in the flashcard to the response from the user.</p> <div class="CodeRay"> <div class="code"><pre><span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> countThreeNewQuestionsTwoRightOneWrong() { <span class="pt">List</span> cards = <span class="kw">new</span> <span class="pt">ArrayList</span>(); cards.add(<span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">Q1</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">1</span><span class="dl">&quot;</span></span>)); cards.add(<span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">Q2</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">2</span><span class="dl">&quot;</span></span>)); cards.add(<span class="kw">new</span> FlashCard(<span class="s"><span class="dl">&quot;</span><span class="k">Q3</span><span class="dl">&quot;</span></span>, <span class="s"><span class="dl">&quot;</span><span class="k">wrong</span><span class="dl">&quot;</span></span>)); flashCardGame.playGame(cards, user); assertEquals(<span class="i">2</span>, flashCardGame.getRightAnswers()); assertEquals(<span class="i">1</span>, flashCardGame.getWrongAnswers()); }</pre></div> </div> <p>We need to make a small change to the Mock.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">MockUser</span> <span class="di">implements</span> User { <span class="di">public</span> <span class="pt">String</span> answerQuestion(<span class="pt">String</span> question) { <span class="kw">if</span> (question.equals(<span class="s"><span class="dl">&quot;</span><span class="k">QR</span><span class="dl">&quot;</span></span>)) <span class="kw">return</span> <span class="s"><span class="dl">&quot;</span><span class="k">A</span><span class="dl">&quot;</span></span>; <span class="kw">else</span> { <span class="kw">return</span> question.substring(<span class="i">1</span>); } } }</pre></div> </div> <p>And now we can make this pass with a simple <strong>(expression->function)</strong> transform.</p> <div class="CodeRay"> <div class="code"><pre><span class="ty">void</span> playGame(<span class="pt">List</span> flashCards, User user) { <span class="kw">for</span> (FlashCard card : flashCards) { <span class="pt">String</span> question = card.getQuestion(); <span class="pt">String</span> answer = user.answerQuestion(question); <span class="kw">if</span> (answer.equals(card.getAnswer())) rightAnswers++; <span class="kw">else</span> wrongAnswers++; } }</pre></div> </div> <p>There&rsquo;s more to do, of course, but the plumbing is all set up, and the algorithm looks right. There were several cases where we <em>could</em> have used a lower transform such as <strong>(variable->assignment)</strong> but there was no need, and the algorithm came out nicely.</p> <p>There is just the slightest chance that the one use of <strong>(if->while)</strong> could have been done with <strong>(statement->tail-recursion)</strong>, but since this is Java, that&rsquo;s probably not the best choice.</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com26tag:blogger.com,1999:blog-3898534372669113633.post-87897066890101136802011-02-02T07:44:00.001-08:002011-02-02T07:44:03.842-08:00Fib: The T-P Premise.<div class='posterous_autopost'><p>Guilherme Silveira wrote a lovely <a href="http://blog.caelumobjects.com/2011/01/13/evolving-software-and-improving-algorithms/">blog</a> exploring the <a href="http://cleancoder.posterous.com/the-transformation-priority-premise">Transformation Priority Premise</a> using the Fibonacci sequence. He posed a suite of tests similar to these:</p> <div class="CodeRay"> <div class="code"><pre><span class="at">@Test</span> <span class="di">public</span> <span class="ty">void</span> fibTest() <span class="di">throws</span> <span class="ex">Exception</span> { assertEquals(<span class="i">0</span>, of(<span class="i">0</span>)); assertEquals(<span class="i">1</span>, of(<span class="i">1</span>)); assertEquals(<span class="i">1</span>, of(<span class="i">2</span>)); assertEquals(<span class="i">2</span>, of(<span class="i">3</span>)); assertEquals(<span class="i">3</span>, of(<span class="i">4</span>)); assertEquals(<span class="i">5</span>, of(<span class="i">5</span>)); assertEquals(<span class="i">8</span>, of(<span class="i">6</span>)); }</pre></div> </div> <p>He found that the proposed list of transformations did not lead him to a good solution. At first he found that the transformations led him to a solution like this:</p> <div class="CodeRay"> <div class="code"><pre><span class="kw">switch</span>(n) { <span class="kw">case</span> <span class="i">0</span>: <span class="kw">return</span> <span class="i">0</span>; <span class="kw">case</span> <span class="i">1</span>: <span class="kw">return</span> <span class="i">1</span>; <span class="kw">case</span> <span class="i">2</span>: <span class="kw">return</span> <span class="i">1</span>; <span class="kw">case</span> <span class="i">3</span>: <span class="kw">return</span> <span class="i">2</span>; ... }</pre></div> </div> <p>Obviously this is the wrong approach, but the priority list presented in my original article did not prevent it. So I&rsquo;ve added the <strong>(case)</strong> transformation to the very bottom of the list. <em>This means that using a switch/case or an &lsquo;else if&rsquo; is always the last option to choose.</em></p> <p>Guilherme went on to rightly ignore the switch/case solution to see if he could get a good solution for fib by following the other priorities. I suggest you read his blog to see how that turned out. Meanwhile, let&rsquo;s try it here.</p> <p>The first test leads us to use the <strong>({}&ndash;>nil)</strong> and then the <strong>(nil->constant)</strong> transformations:</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">Fibonacci</span> { <span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">return</span> <span class="i">0</span>; } }</pre></div> </div> <p>The second test forces an <strong>(unconditional->if)</strong> transformation that we can refactor with a <strong>(constant->scalar)</strong>. This coincidentally makes the third test pass which is always nice.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">if</span> (n &lt;=<span class="i">1</span>) <span class="kw">return</span> n; <span class="kw">return</span> <span class="i">1</span>; }</pre></div> </div> <p>The fourth tests is tricky. How can we transform that &lsquo;1&rsquo; into something that maps 1->1, 2->1, and 3->2. We know that fib(n) = fib(n-1)+fib(n-2) so we could use recursion to solve the problem. That&rsquo;s the <strong>(statement->recursion)</strong> transformation.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">if</span> (n &lt;=<span class="i">1</span>) <span class="kw">return</span> n; <span class="kw">return</span> of(n-<span class="i">1</span>) + of(n-<span class="i">2</span>); }</pre></div> </div> <p>This makes all the tests pass. Hallelujah! And look how simple that was! What a pretty sight.</p> <p>Unfortunately there are three things wrong with this pretty solution. First, that algorithm has a horrific runtime complexity of something like O(n<sup>2)</sup> or worse. Secondly, the algorithm does not use tail-recursion, and so uses a lot of stack space. Thirdly, Java is not a great language for recursion anyway since the JVM simply <em>can&rsquo;t</em> optimize tail recursion (yet).</p> <p>It&rsquo;s a great shame that such a simple expression has so many problems! There are <em>ways</em> to address that, but they are beyond the scope of this article. For now we&rsquo;ll focus on the three problems mentioned above.</p> <p>Let&rsquo;s tackle them one at a time. Is there a transformation that will at least get us to tail recursion? Of course there is, but it was missing from my original list. So I&rsquo;ve modified that list as follows:</p> <ul> <li><strong>({}&ndash;>nil)</strong> no code at all->code that employs nil</li> <li><strong>(nil->constant)</strong></li> <li><strong>(constant->constant+)</strong> a simple constant to a more complex constant</li> <li><strong>(constant->scalar)</strong> replacing a constant with a variable or an argument</li> <li><strong>(statement->statements)</strong> adding more unconditional statements.</li> <li><strong>(unconditional->if)</strong> splitting the execution path</li> <li><strong>(scalar->array)</strong></li> <li><strong>(array->container)</strong></li> <li><strong>(statement->tail-recursion)</strong></li> <li><strong>(if->while)</strong></li> <li><strong>(statement->recursion)</strong></li> <li><strong>(expression->function)</strong> replacing an expression with a function or algorithm</li> <li><strong>(variable->assignment)</strong> replacing the value of a variable.</li> <li><strong>(case)</strong> adding a case (or else) to an existing switch or if</li> </ul> <p>So tail recursion is preferred over arbitrary recursion.</p> <p>Now, can we use tail recursion to tranform this?</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">if</span> (n &lt;=<span class="i">1</span>) <span class="kw">return</span> n; <span class="kw">return</span> <span class="i">1</span>; }</pre></div> </div> <p>Of course we can. It&rsquo;s not as pretty as the previous solution, but it captures the same semantics. And it&rsquo;s not ugly by any means.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">Fibonacci</span> { <span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">if</span> (n &lt;=<span class="i">1</span>) <span class="kw">return</span> n; <span class="kw">return</span> of(<span class="i">0</span>,<span class="i">1</span>,n); } <span class="di">private</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> a, <span class="ty">int</span> b, <span class="ty">int</span> n) { <span class="kw">if</span> (n == <span class="i">0</span>) <span class="kw">return</span> a; <span class="kw">return</span> of(b, a+b, n-<span class="i">1</span>); } }</pre></div> </div> <p>Of course we can clean this up by removing the redundant &lsquo;if&rsquo;.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">Fibonacci</span> { <span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">return</span> of(<span class="i">0</span>,<span class="i">1</span>,n); } <span class="di">private</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> a, <span class="ty">int</span> b, <span class="ty">int</span> n) { <span class="kw">if</span> (n == <span class="i">0</span>) <span class="kw">return</span> a; <span class="kw">return</span> of(b, a+b, n-<span class="i">1</span>); } }</pre></div> </div> <p>But now, how do we deal with the fact that Java doesn&rsquo;t do well with recursion? If we thought that n would always stay relatively small, we could just ignore it. But let&rsquo;s assume that &lsquo;n&rsquo; will be large; forcing us to unwind the recursion and replace it with iteration. This requires a <strong>(if->while)</strong> and a few <strong>(variable->assignment)</strong> transformations.</p> <div class="CodeRay"> <div class="code"><pre><span class="di">public</span> <span class="ty">class</span> <span class="cl">Fibonacci</span> { <span class="di">public</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> n) { <span class="kw">return</span> of(<span class="i">0</span>,<span class="i">1</span>,n); } <span class="di">private</span> <span class="di">static</span> <span class="ty">int</span> of(<span class="ty">int</span> a, <span class="ty">int</span> b, <span class="ty">int</span> n) { <span class="kw">while</span> (n != <span class="i">0</span>) { <span class="ty">int</span> s = a+b; a = b; b = s; n--; } <span class="kw">return</span> a; } }</pre></div> </div> <p>The list of priorities prevents this from being the direct outcome of TDD because it prefers the recursive solution. So my list of proposed priorities will necessarily create Java programs that are recursive, and therefore less than optimal for the language.</p> <p>That makes me think that the priority list is language specific. In Java, for example, we might move <strong>(if->while)</strong> and <strong>(variable->assignment)</strong> <em>above</em> <strong>(statement->tail-recursion)</strong> so that iteration is always preferred above recursion, and assignment is preferred above parameter passing.</p> <p>This makes sense because Java is not a functional language, and strongly resists a functional style. So any bias towards functional style will lead to suboptimal implementations.</p> <p>If the priority list is language specific, is it also application specific? Do different problem domains require different priority lists? I strongly doubt this. We are working at a level of detail so far below the problem domain that it is hard for me to see how different problems would require different solution styles.</p> <p>What about teams? Will teams tweak the priority list to match their styles? I hope not; but I have to say that I think this is not improbable.</p> <p>I think what this shows us is that the transformations and their priorities are a way to encode a particular programming style. So long as we have different languages and styles, we&rsquo;ll likely need different transformations and priorities.</p> <p>On the other hand, if we compare the Java list with the Clojure list (say), the difference is subtle. The recursive transformations would move <em>slightly</em> lower in the list relative to the iterative and assignment transformations. The effect is, of course, profound, but the difference in the lists is actually relatively small. All the other transformations seem to hold their positions.</p> <p>So the good news is that, although there may be different styles based on language type, the vast majority of the low level coding decisions remain similar irrespective of those styles.</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com14tag:blogger.com,1999:blog-3898534372669113633.post-34635728887675069062011-01-19T11:06:00.001-08:002011-01-19T11:06:38.187-08:00Brining Balance to the Force<div class='posterous_autopost'><p>I read Martin Fowler's <a href="http://martinfowler.com/bliki/CraftmanshipAndTheCrevasse.html">contribution</a> to the craftsmanship thread with interest.&nbsp; He spoke of the so-called "crevasse" between developers and customers.&nbsp; He reiterated Dan North's fear that the craftsmanship movement could widen this crevasse.</p> <p>We are programmers.&nbsp; We need to talk about programming from time to time. We need time and space to focus on our primary discipline: programming.&nbsp; That discussion, and that focus, is a very positive thing.&nbsp; It means we <em>care</em> about what we do.&nbsp; But have we gone too far?&nbsp; Are we too technical?&nbsp; Is the Software Craftsmanship movement a movement only about techical practice and details?&nbsp; Have we forgotten the customer?</p> <p><a href="manifesto.softwarecraftsmanship.org">The Software Craftsmanship Manifesto's</a> fourth statement: <em>"We value not only customer collaboration but also productive partnerships"</em> should be enough to quell those fears. Software Craftsmanship is a movement dedicated to <em>partnering</em> with customers.&nbsp; That means taking on the customer's problems as our own.&nbsp; That means putting ourselves in the position of our customers.&nbsp; Their pain becomes our pain, their problems our problems, their victories, our victories.&nbsp; <em>That's craftsmanship!</em>&nbsp; That's what we want.&nbsp; We want to be able to do our job with professionalism and skill, and to partner with our customers to achieve the best possible outcomes.</p> <p>Software Craftsmanship is <em>not</em>, as Martin said: "A place where programming can be front and central again."&nbsp; It is not a movement that "underplays the vital role of customer communication".&nbsp; After all, those of us in the Software Craftsmanship movement have not abandoned Agile.&nbsp; We still read the Agile papers.&nbsp; We still follow the Agile threads.&nbsp; We still go to the Agile conferences.&nbsp; We are still part of the Agile community.&nbsp; So we are steeped in "the vial role of customer communication."&nbsp; So much so that we amplified that role to one of <em>partnership</em>.&nbsp;</p> <p>No, the Software Craftmanship movement is not overplaying the technical role; rather it is trying to recapture the <em>balance</em> that the Agile movement has lost.&nbsp;</p> <p>Martin made an amazing point about this in his article.&nbsp; He said that the craftsmanship movement was spawned as a reaction to the rise of non-programming topics within agile.&nbsp; I completely agree.&nbsp; Indeed, I made exactly that point just a week ago while attending an Agile Coach Camp in Norway.&nbsp; I, for one, consider the agile movement to have been inundated by a vocal and enthusiastic cohort of project managers, waving their scrum-master certificates, or their Lean and Kanban books.&nbsp; They have overwhelmed the original movement and changed it into something new.&nbsp;&nbsp; Agile is no longer about a balance between the technical and non-technical parts of development.&nbsp; Rather it has become a discussion almost entirely dedicated to non-technical issues.&nbsp; Agile is no longer about healing the divide, or closing the crevasse.&nbsp; The agile movement now represents <em>one side of the crevasse</em>.&nbsp;</p> <p>The argument has been made that the technical issues are the <em>simple</em> part.&nbsp; That the real <em>hard</em> parts of software development are the people issues. So therefore we should focus on the people issues, on the customers and employers, and keep quiet about the technical stuff.&nbsp; If we talk too loudly about the technical stuff, then the customers may feel that we're not paying due attention to them.</p> <p>Bollocks!&nbsp; Bollocks I say!&nbsp; Yes, the people part is hard.&nbsp; The people part is complicated.&nbsp; The people part needs lots of work.&nbsp; We should be talking a lot about the people part.&nbsp; But anybody who thinks the technical stuff isn't just as hard, and just as <em>worthy of conversation</em>, is misguided.&nbsp; We need <em>both</em>.&nbsp; And we need both sides to listen to each other and to trust each other.&nbsp; We need balance!<em>&nbsp;</em></p> <p>The imbalance<em> is the crevasse!</em>&nbsp; One side thinks <em>their</em> issues are more important that the other's.&nbsp; One side thinks <em>their</em> issues should dominate.&nbsp; And when the other side tries to talk about their issues, they are told to shush because they might alienate the other side and "widen the crevasse".&nbsp;</p> <p>But neither side is more important than the other.&nbsp; Neither side should dominate.&nbsp; Neither side's issues should be toned down.&nbsp; Neither side should be told to shush for fear of what the other side might say.&nbsp; The only way to bring the crevasse together is to realize that both sides need each other, and need each other to be skilled and professional.&nbsp; Each side should be <em>glad</em> that the other is talking about their own issues.&nbsp; And each side should be willing to listen to the other side's issues. Each side must respect the other side's desire to increase their skill and professionalism.&nbsp; If we do that enough, maybe we'll realize that there's actually only one side.&nbsp;</p> <p>So the next time you see some programmers talking about code retreats or koans or katas or TDD or some other deeply techincal topic, <em>congratulate them</em> for giving due dilligence to their practice.&nbsp; The next time you see an agile coach talking about Kanban, or Lean, or Iteration length, or story points,<em> congratulate them</em> for their dedication to their discipline.&nbsp; Remember, <em>these are your team-mates</em>.&nbsp; You want them to be able to play their positions with skill and professionalism.&nbsp; You want them to be good at their jobs.&nbsp; And, if you want them to repect your role,&nbsp; you must first respect theirs.</p> <p>&nbsp;</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com25tag:blogger.com,1999:blog-3898534372669113633.post-46576828898706834642011-01-17T13:59:00.001-08:002011-01-17T13:59:55.230-08:00Software Craftsmanship: What it's all about.<div class='posterous_autopost'><p>TL;DR<a href='http://posterous.com/getfile/files.posterous.com/temp-2011-01-17/uEzpJoJJmtGBxuCuaiHFEtogGhHAofIHgiBffABEdxvffGCIsmHnEczihEvx/DSC04794.JPG.scaled1000.jpg'><img src="http://posterous.com/getfile/files.posterous.com/temp-2011-01-17/uEzpJoJJmtGBxuCuaiHFEtogGhHAofIHgiBffABEdxvffGCIsmHnEczihEvx/DSC04794.JPG.scaled500.jpg" width="500" height="527"/></a> </p> <p>I've gone from <a href="http://dannorth.net/2011/01/11/programming-is-not-a-craft/">Dan North's post</a>, to <a href="http://www.gilzilberfeld.com/2011/01/path-already-taken.html?utm_source=twitterfeed&amp;utm_medium=twitter&amp;utm_campaign=Feed%3A+gilzilberfeld+%28Geek+out+of+water%29">Gil Zilberfeld's</a> to <a href="http://michaelfeathers.typepad.com/michael_feathers_blog/2011/01/the-thing-of-software-development.html">Michael Feather's</a> to <a href="http://parlezuml.com/blog/?postid=992">Jason Gorman's</a> and back. And I'm at a loss.</p> <p>Why is there a software craftsmanship movement?&nbsp; What motivated it?&nbsp; What drives it now?&nbsp; <em>One</em> thing; and <em>one thing only.</em>&nbsp;</p> <p style="text-align: center;"><em>We are tired of writing crap.</em></p> <p>That's it.&nbsp; The fat lady sang.&nbsp; Good nite Gracy. Over and out.&nbsp;</p> <p>We're tired of writing crap. We are tired of embarrassing ourselves and our employers by delivering lousy software.&nbsp; We have had enough of telling our customers to reboot at midnight.&nbsp; We don't want bug lists that are a thousand pages long.&nbsp; We don't want code that grows more tangled and corrupt with every passing day.&nbsp; We're tired of doing a bad job.&nbsp; We want to start doing a good job.&nbsp;</p> <p>That's ... what ... this ... is ... about.&nbsp; Nothing else.</p> <p>What we are <em>not</em> doing:</p> <ul> <li>We are <em>not</em> putting code at the center of everything.</li> <li>We are <em>not</em> turning inward and ignoring the business and the customer.</li> <li>We are <em>not</em> inspecting our navels.</li> <li>We are <em>not</em> offering cheap certifications.&nbsp;</li> <li>We are <em>not</em> forgetting that our job is to delight our customers.&nbsp;</li> </ul> <p>What we will <em>not do anymore</em>:</p> <ul> <li>We will <em>not</em> make messes in order to meet a schedule.</li> <li>We will <em>not</em> accept the stupid old lie about cleaning things up later.&nbsp;&nbsp;</li> <li>We will <em>not</em> believe the claim that quick means dirty.</li> <li>We will <em>not</em> accept the option to do it wrong.</li> <li>We will <em>not</em> allow <em>anyone</em> to force us to behave unprofessionally.&nbsp; </li> </ul> <p>What we <em>will</em> do from now on:</p> <ul> <li>We <em>will</em> meet our schedules by knowing that the only way to go fast is to go well. </li> <li>We <em>will</em> delight our customers by writing the best code we can.</li> <li>We <em>will</em> honor our employers by creating the best designs we can.</li> <li>We <em>will</em> honor our team by testing everything that can be tested.</li> <li>We <em>will</em> be humble enough to write those tests first.</li> <li>We <em>will</em> practice so that we become better at our <em>craft</em>.&nbsp;&nbsp;</li> </ul> <p>We will remember what our grandmothers and grandfathers told us:</p> <ul> <li>Anything worth doing is worth doing well.</li> <li>Slow and steady wins the race.</li> <li>Measure twice cut once.</li> <li>Practice, Practice, Practice.</li> </ul> <p>I suppose that some people might look askance at our code katas and our code retreats, and our practice sessions.&nbsp; They might think that we're turning inwards and abandoning our customers.&nbsp; They might think that we've given up on the real world and have yielded to the temptation to entertain ourselves.&nbsp; I can see how someone might come to that conclusion.</p> <p>But they are as wrong as the day is long.&nbsp; We are doing this <em>because</em> we care about the customer.&nbsp; We are dedicating time and effort to being the <em>best that we can be</em> so that our employers will get the best possible value out of us.&nbsp;</p> <p>Do you think the only time musicians play their instruments is when they are on stage?&nbsp; Do you think the only time that batters hit balls is during games?&nbsp; Do you think the only time lawyers give a closing is at trial?&nbsp; Of course not.&nbsp; These people are professionals; <em>and professionals practice</em>!&nbsp; Professionals study the minutia of their disciplines.&nbsp; Professionals know all the little tricks and quirks.&nbsp; They know the history, the theories, the anecdotes.&nbsp; They know techniques and methods.&nbsp; They know good options and bad options and how to tell them apart.&nbsp; And they know all this stuff because they <em>practice, practice practice</em>.</p> <p>So when you see someone wearing a green wrist-band that says "Clean Code" or "Test First" or "Test Obsessed", it's not because they've joined a movement, or signed a manifesto, or that they somehow feel superior to everyone else.&nbsp; They aren't participants in a holy war.&nbsp; They aren't trying to join a tribe and huddle around a campfire.&nbsp; The green band is a <em>personal</em> thing.&nbsp; It's a promise made to one's self:&nbsp; "I will do a good job.&nbsp; I will not rush.&nbsp; I will write tests.&nbsp; I will go fast by going well.&nbsp; <em>I will not write crap</em>. And I will <em>practice, practice practice</em> so that I can be a professional."</p> <p>&nbsp;</p> <p>&nbsp;</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com163tag:blogger.com,1999:blog-3898534372669113633.post-38047824793769367862011-01-17T12:34:00.001-08:002011-01-17T12:34:19.003-08:00STUB5: Prolog, Midje, and Test Specifications.<div class='posterous_autopost'><p> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/odkwsxJetdjwhGwnrrwIrGmrtxBlrcBAoiChBywanuBsbuuCltHypsDqGIHm/p93.mov' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mov.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href="http://cleancoder.posterous.com/stub5-prolog-midje-and-test-specifications" style="color: #bc7134">watch on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/odkwsxJetdjwhGwnrrwIrGmrtxBlrcBAoiChBywanuBsbuuCltHypsDqGIHm/p93.mov' style='color: #bc7134;'>p93.mov</a></b> <span style="font-size: 10px; color: #424037;">(85043 KB)</span> <br style="clear: both;"/></div> </p>Fascinating equivalence of Midje and Prolog.</div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com16tag:blogger.com,1999:blog-3898534372669113633.post-87278795241929907002011-01-05T13:08:00.001-08:002011-01-05T13:08:48.189-08:00STUB4: MDA: A forlorn hope.<div class='posterous_autopost'><p> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/jbpivtxemjuAAxqyEIGevCAusBnjgAzihmqGCcnumpmyfsdhewoBHFjuCfaC/p80.mov' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mov.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href="http://cleancoder.posterous.com/stub4-mda-a-forlorn-hope" style="color: #bc7134">watch on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/jbpivtxemjuAAxqyEIGevCAusBnjgAzihmqGCcnumpmyfsdhewoBHFjuCfaC/p80.mov' style='color: #bc7134;'>p80.mov</a></b> <span style="font-size: 10px; color: #424037;">(60319 KB)</span> <br style="clear: both;"/></div> </p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com31tag:blogger.com,1999:blog-3898534372669113633.post-74053246448988838452011-01-01T12:25:00.001-08:002011-01-01T12:25:09.552-08:00Transformation Priority and Sorting<div class='posterous_autopost'><div> <div style="margin: 0px;"><span style="font-family: Helvetica; font-size: small;">Comic created with Comic Life from plasq - <a href="http://plasq.com">http://plasq.com</a></span></div> </div> <p><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/jPotr6Yd92j7O4SkEJcll5TpBMkNlrz7GPk2z4AS7zmSZ5Gb3C0TX7Y1ae1T/Page_1.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/TxB6hfoSKIkP9d6HuIkY1SYbXrGndkQM8djGzOsA33PhEMV0Xvbz06uNz1pA/Page_1.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/7Mugz99HfA4yQS6ZGncG7Ek6KEga58FbVUPexXEG8goN0Q6aoSPrsfJFVLAd/Page_2.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/bJwywnUP9th9FtB9yliDxQrvtxVeZzZ1m7dj2szSlYiFaoBdlpNNwcqXyZRK/Page_2.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/IykNJX6EepLgDEqoxebcB2neuYC40KLJ2SjC6Jc6UDHHILQq8CCQ5iBOM7R2/Page_3.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/LBOWwS2T2tSnKhhHm0noq8EkZbhHhUqxtMnFnnrVlanW8qqoQZuDKoH1cqZZ/Page_3.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/RGXCMYn8meNaGUbWedBoAEI7uHG1QZv7JYxCZ7cWKUSObNRRUEAHzgV5BwZT/Page_4.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/edsJZpu2HjOAkIoMxiwmykDbsGrnTYSz0EiuGcRWpoNf4DdgtXJg8fsgfv8c/Page_4.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/ZQNGN2NyjWabUUOwrQ6nzLWpMhlxahiIlAchK5OJBMxSfwuswGnU3Mt4last/Page_5.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/g1859NxzQmL7T0NyL2NHdP2XWZhFCUCYab8XoaZi1um1yaP9RncBJxwm9oEJ/Page_5.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/7zBNs7VxRcZPxflkMHXwuZzP4ff1UcxDF8I2wxlgdFTOo6FULOc4M9K0OCpE/Page_6.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/7ChJZky7iXWDI64Fwc6jq2ZZ7NvHS1xnPoF4IaUOxoTpw2GyxwGyZ8GfNb2R/Page_6.jpg.scaled.500.jpg" width="500" height="647"/></a> <a href='http://posterous.com/getfile/files.posterous.com/cleancoder/VEmOeFln9QdSsaikkO4cmPFlUCZ4jarUjpY7PLwzDxADSofnSUdbTMgtqr1T/Page_7.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/l2ayJZ1FzJypzYoP7agBCbqm5wLVQpX1NHa70tU0xR10a94uafj4lDvNAxM3/Page_7.jpg.scaled.500.jpg" width="500" height="647"/></a> <div><a href='http://cleancoder.posterous.com/transformation-priority-and-sorting'>See and download the full gallery on posterous</a></div></p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com26tag:blogger.com,1999:blog-3898534372669113633.post-91862057150790234962010-12-29T14:32:00.001-08:002010-12-29T14:32:13.482-08:00STUB3: Validating the Visitor<div class='posterous_autopost'><p> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/hxChGepoCwnazblrDGJychrbpCjIrjfwxFojwumkhrAnDcoIyjfjysHCssbn/p68.mov' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mov.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href="http://cleancoder.posterous.com/validating-the-visitor" style="color: #bc7134">watch on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/hxChGepoCwnazblrDGJychrbpCjIrjfwxFojwumkhrAnDcoIyjfjysHCssbn/p68.mov' style='color: #bc7134;'>p68.mov</a></b> <span style="font-size: 10px; color: #424037;">(36856 KB)</span> <br style="clear: both;"/></div> </p> <p>Why I like the much maligned visitor pattern.</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com12tag:blogger.com,1999:blog-3898534372669113633.post-72588387479745676432010-12-27T06:35:00.001-08:002010-12-27T06:35:30.234-08:00STUB2: K&R around the Campfire<div class='posterous_autopost'><p> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/xCGJjrwdirzoEpgfuGulitgHfhpvaFosmchEjrwrFCxgBjAkHptxJkkAwjkv/p56.mov' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mov.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href="http://cleancoder.posterous.com/stub2-kr-around-the-campfire" style="color: #bc7134">watch on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/xCGJjrwdirzoEpgfuGulitgHfhpvaFosmchEjrwrFCxgBjAkHptxJkkAwjkv/p56.mov' style='color: #bc7134;'>p56.mov</a></b> <span style="font-size: 10px; color: #424037;">(40711 KB)</span> <br style="clear: both;"/></div> </p>Fond memories of learning C.</div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com7tag:blogger.com,1999:blog-3898534372669113633.post-78259232926906341402010-12-24T04:53:00.001-08:002010-12-24T04:53:14.252-08:00Clean Code mug and luggage tag<div class='posterous_autopost'><p><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/lEkpeBECdfGBdudoiCwiucnEIrDjwhttAcgHuzujlsJwJyzxAxrIeikayHks/p50.jpg.scaled1000.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/lEkpeBECdfGBdudoiCwiucnEIrDjwhttAcgHuzujlsJwJyzxAxrIeikayHks/p50.jpg.scaled500.jpg" width="500" height="373"/></a> </p> <p>Watch for them on cleancodeproject.com</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com25tag:blogger.com,1999:blog-3898534372669113633.post-85986242651848558952010-12-23T07:05:00.001-08:002010-12-23T07:05:58.673-08:00STUB 1: SICP & Assignment<div class='posterous_autopost'><p><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/lgyIvmdhrgplCbHIcatyEyrpfHflIdfcrozhDmFGhqbocpyHzsigaGdumFdf/p36.jpg.scaled1000.jpg'><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/lgyIvmdhrgplCbHIcatyEyrpfHflIdfcrozhDmFGhqbocpyHzsigaGdumFdf/p36.jpg.scaled500.jpg" width="500" height="669"/></a> </p><p> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/ukFIDtwvljJxvlGnuIbqoJspaxCxqlnafbJjBDlEdGbsjvtzlovcnzEFBpDo/p39.mov' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mov.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href="http://cleancoder.posterous.com/stub-1-sicp-assignment" style="color: #bc7134">watch on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/ukFIDtwvljJxvlGnuIbqoJspaxCxqlnafbJjBDlEdGbsjvtzlovcnzEFBpDo/p39.mov' style='color: #bc7134;'>p39.mov</a></b> <span style="font-size: 10px; color: #424037;">(64778 KB)</span> <br style="clear: both;"/></div> </p>A very brief sojourn through Abelson's and Sussman's landmark book: "Structure and Interpetation of Computer Programs".</div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com9tag:blogger.com,1999:blog-3898534372669113633.post-85772813890784856142010-12-20T04:28:00.001-08:002010-12-20T04:28:05.098-08:00Snow and Pandemonium<div class='posterous_autopost'>These pictures are from Heathrow on Monday morning, 20 December after a light dusting of snow paralyzed flights on Friday night and Saturday morning. Though most people were cheerful in a "what can you do about it" way; there was also anger, frustration, and tears of desperation as people struggled to gain some modicum of control over their fate. <p /> I understand that there are times when events are beyond reasonable control. But this was just a little snow. I can even understand that Heathrow and the airlines had not planned properly for unexpected cold weather. What I can not understand is the breathtaking incompetence that has left thousands upon thousands of travelers without any kind of information. <p /> The British Air website was inaccessible until earlier today. The phone lines were so jammed that when she got through on her 41st call, my daughter was actually told by an automated attendant that the hold time would be 594 minutes. (That's 10 hours). How has this once great airline fallen so far that they are reduced to having mumbling women, with bull-horns that don't work, walk through a crowd of people telling them that their best option is to somehow get to customer service desk (an obviously hopeless task). I think it may be time to consider reducing Heathrow and British-air to third-world status. I would expect this kind of treatment in Central America.<p><img src="http://posterous.com/getfile/files.posterous.com/cleancoder/ocOvokLTxiYjVvziaEdleMO4BzmrkOOmM2lgFEHj01eQJSYgEykQVnqyWDxg/IMG_0311.jpeg" width="320" height="240"/> <img src="http://posterous.com/getfile/files.posterous.com/cleancoder/NOVdwWXrJqIZScAEgiKAgmB4M2G0EzzaQslzlgDGDpOwyoCr89DCHplQwcAE/IMG_0314.jpeg" width="320" height="240"/> <img src="http://posterous.com/getfile/files.posterous.com/cleancoder/LzSojkLIEmbVJRXrefmtuMIG0BPe7q7s2yD9f67vUo43SpTAQN7XbZToPCnT/IMG_0317.jpeg" width="320" height="240"/> <img src="http://posterous.com/getfile/files.posterous.com/cleancoder/8fQPwaqe3fYkIkuADoBFCTKFyMfbDrKmLRMrozRsZXscnBGBewBRxzCxHGbI/IMG_0312.jpeg" width="320" height="240"/> <div><a href='http://cleancoder.posterous.com/snow-and-pandemonium'>See and download the full gallery on posterous</a></div></p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com5tag:blogger.com,1999:blog-3898534372669113633.post-70440880524361371532010-12-19T07:17:00.001-08:002010-12-30T10:03:36.612-08:00The Transformation Priority Premise<a href="http://cleancoder.posterous.com/the-transformation-priority-premise">See this blog on Posterous, it doesn't render well here.</a>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com8tag:blogger.com,1999:blog-3898534372669113633.post-68918905643673165442010-12-17T12:24:00.001-08:002010-12-17T12:24:39.087-08:00Clean Code Course in Dallas.<div class='posterous_autopost'>I'll be teaching a three-day Clean Code course in Dallas on the 15th-17th of February. Come one, come all! <br />You can sigh up here: <a href="http://www.eventbrite.com/event/1019973769">http://www.eventbrite.com/event/1019973769</a></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com3tag:blogger.com,1999:blog-3898534372669113633.post-15079408060327072792010-12-16T03:30:00.001-08:002010-12-16T03:30:28.253-08:00test<div class='posterous_autopost'><i><span style="font-size: 14px;">italic</span></i><span style="font-size: 14px;"> </span><b><span style="font-size: 14px;">bold</span></b><span style="font-size: 14px;"> </span><span style="font-size: 14px;">monospaced</span><span style="font-size: 14px;">.</span><p /><div>This is two. &nbsp;<br /><div> <span style="">----<br />Robert C. Martin (Uncle Bob) | <a href="mailto:unclebob@cleancoder.com">unclebob@cleancoder.com</a><br />Uncle Bob Consulting LLC. &nbsp; &nbsp;| @unclebobmartin<br />847.922.0563 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | web: <a href="http://objectmentor.com">objectmentor.com</a><p /><p /></span> </div> <br /></div></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com4tag:blogger.com,1999:blog-3898534372669113633.post-15834821369259693192010-12-14T01:50:00.001-08:002010-12-14T01:50:17.371-08:00Too Lazy to "Type".<div class='posterous_autopost'>Loren Segal (@Islegal) in his blog (<a href="http://gnuu.org/2010/12/13/too-lazy-to-type/)">http://gnuu.org/2010/12/13/too-lazy-to-type/)</a> makes the interesting point that most dynamic programs are, in fact, not particularly dynamic. Even duck-typed ruby programs would require very little change to make them static. He includes a Rack example showing this transformation. <p /> class MyMiddleware <br /> def call(app) ... end <br />end <p /> To: <p /> class MyMiddleware <br /> include Callable <br /> def call(app) ... end <br />end <p /> He asks, in the end: "how often do you write Ruby code that can really not have some kind of class based inheritance type system? For me, I can’t think of many cases. How often do you pass arbitrary types to methods without at least having a well-defined set of types that can be accepted by the method?" <p /> He's quite correct that many (if not most) programs written in dynamic languages do not need to be dynamic. That with a very few simple changes we could add the hints that would make them static. And this would allow the compilers to optimize the programs in ways that are impossible for dynamic programs. However, there is a cost -- and the cost is not simply typing (and by that I mean keystrokes or LoC). <p /> The cost is _dependencies_. The simple "include" in Segal's example above is a _coupling_. That coupling adds complexity to the design of the application. It might not seem that such a simple statement would be very confounding, but the problem is not one simple statement. The problem is that nearly all our classes would suddenly require instrumentation with appropriate includes or extends statements. <br />Even that might not seem all that bad, but the problem is that the requirements for interfaces change. We often want to add new methods to existing interfaces. When we do, we must add those methods to all classes that implement those interfaces, whether they need it or not. If some of our derivatives don't need those methods we might be tempted to split the interface into one that has the new methods, and one that does not; but that forces us to find all the classes that implement that interface and decide, in each case, which interface it should now derive from. <p /> And of course interfaces depend on other interfaces which depend on other interfaces. And so the tangle grows. If you haven't been programming in a static language for awhile, it is easy to forget the complexities that these couplings lead to. But in the end, we like dynamic language not because we are too lazy to "Type". We like dynamic languages because we are tired of untangling couplings. <p /> ---- <br />Robert C. Martin (Uncle Bob) | <a href="mailto:unclebob@cleancoder.com">unclebob@cleancoder.com</a> <br />Uncle Bob Consulting LLC. | @unclebobmartin <br />847.922.0563 | web: objectmentor.com</div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com3tag:blogger.com,1999:blog-3898534372669113633.post-4620087747804960942010-11-28T16:14:00.001-08:002010-11-28T16:14:46.718-08:00Mentoring & Apprenticeship (A reading from: "The Clean Coder")<div class='posterous_autopost'> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/omANhadhZYd5xw0xDaYoFc3ZOIm5DkrPG8TM2cS1mCmPbjxZlLsiex487DdP/mentoring.mp3' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mp3.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;"><b>Mentoring</b> by Robert C Martin&nbsp;&nbsp;<br/>Download now or <a href='http://cleancoder.posterous.com/mentoring-apprenticeship-a-reading-from-the-c' style='color: #bc7134;'>listen on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/omANhadhZYd5xw0xDaYoFc3ZOIm5DkrPG8TM2cS1mCmPbjxZlLsiex487DdP/mentoring.mp3' style='color: #bc7134;'>mentoring.mp3</a></b> <span style="font-size: 10px; color: #424037;">(17930 KB)</span> <br style="clear: both;"/></div> <p>---- <br />Robert C. Martin (Uncle Bob) | <a href="mailto:unclebob@cleancoder.com">unclebob@cleancoder.com</a> <br />Uncle Bob Consulting LLC. | @unclebobmartin <br />847.922.0563 | web: objectmentor.com</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com3tag:blogger.com,1999:blog-3898534372669113633.post-72201125692980808642010-11-27T09:00:00.001-08:002010-11-27T09:00:04.630-08:00Mentoring & Apprenticeship (A reading from: "The Clean Coder")<div class='posterous_autopost'> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/omANhadhZYd5xw0xDaYoFc3ZOIm5DkrPG8TM2cS1mCmPbjxZlLsiex487DdP/mentoring.mp3' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/mp3.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;"><b>Mentoring</b> by Robert C Martin&nbsp;&nbsp;<br/>Download now or <a href='http://cleancoder.posterous.com/mentoring-apprenticeship-a-reading-from-the-c' style='color: #bc7134;'>listen on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/omANhadhZYd5xw0xDaYoFc3ZOIm5DkrPG8TM2cS1mCmPbjxZlLsiex487DdP/mentoring.mp3' style='color: #bc7134;'>mentoring.mp3</a></b> <span style="font-size: 10px; color: #424037;">(17930 KB)</span> <br style="clear: both;"/></div> <p>---- <br />Robert C. Martin (Uncle Bob) | <a href="mailto:unclebob@cleancoder.com">unclebob@cleancoder.com</a> <br />Uncle Bob Consulting LLC. | @unclebobmartin <br />847.922.0563 | web: objectmentor.com</p></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com1tag:blogger.com,1999:blog-3898534372669113633.post-31655884925457149352010-11-23T10:15:00.001-08:002010-11-23T10:15:35.969-08:00A Certification Worth Having.<div class='posterous_autopost'><ul> <li>If you spend months studying and working just for the <em>chance</em> of getting it; then it&rsquo;s worth having.</li> <li>If other people know that you had to work your ass off to get that piece of paper, then the piece of paper is worth showing.</li> <li>If well-recognized masters scrutinize and examine you after your study and effort, and then <em>sign their name</em>, then that piece of paper is <em>golden</em>.</li> <li>If only half the people who make the attempt achieve the goal, then that piece of paper is a competitive advantage.</li> </ul> <p>That&rsquo;s the long and short of it. A certification worth having is one that you have to work your ass off just to get a chance of receiving.</p> <ul> <li>It should take months or years.</li> <li>It should cost a lot, just to make the attempt.</li> <li>It should be backed by experts whose reputations are on the line.</li> <li>A sizable fraction should fail or drop-out.</li> </ul></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com3tag:blogger.com,1999:blog-3898534372669113633.post-14095458202367818642010-11-22T14:15:00.001-08:002010-11-22T14:15:32.725-08:00What Killed Waterfall Could Kill Agile.<div class='posterous_autopost'> <div style='padding: 5px 5px 10px 5px; margin-top: 5px; border: 1px solid #ddd; background-color: #fff;line-height: 16px;'> <div style="float: left; margin-right: 5px; overflow: visible;"><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/VsYK3gN8nEusY9lyM9DuNkXFlWoeDJTBBEzztb8TyJZUxKJGrdBdoA5J2wet/What_Killed_Waterfall_could_Ki.docx' style='color: #bc7134;'><img src='http://posterous.com/images/filetypes/doc.png' style='border: none;'/></a></div> <div style="font-size: 10px; color: #424037;line-height: 16px;">Download now or <a href='http://cleancoder.posterous.com/what-killed-waterfall-could-kill-agile' style='color: #bc7134;'>preview on posterous</a></div> <b><a href='http://posterous.com/getfile/files.posterous.com/cleancoder/VsYK3gN8nEusY9lyM9DuNkXFlWoeDJTBBEzztb8TyJZUxKJGrdBdoA5J2wet/What_Killed_Waterfall_could_Ki.docx' style='color: #bc7134;'>What Killed Waterfall could Kill Agile.docx</a></b> <span style="font-size: 10px; color: #424037;">(153 KB)</span> <br style="clear: both;"/></div> </div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com14tag:blogger.com,1999:blog-3898534372669113633.post-82679227580546817762010-11-09T12:44:00.000-08:002010-11-09T12:44:34.651-08:00Craftsman 63: Specifics and Generics.<style>@font-face { font-family: "Courier New"; }@font-face { font-family: "Wingdings"; }@font-face { font-family: "Verdana"; }@font-face { font-family: "Tahoma"; }p.MsoNormal, li.MsoNormal, div.MsoNormal { margin: 0in 0in 0.0001pt; font-size: 12pt; font-family: "Times New Roman"; }h3 { margin-right: 0in; margin-left: 0in; font-size: 13.5pt; font-family: "Times New Roman"; }p.MsoFootnoteText, li.MsoFootnoteText, div.MsoFootnoteText { margin: 0in 0in 0.0001pt; font-size: 10pt; font-family: "Times New Roman"; }p.MsoCommentText, li.MsoCommentText, div.MsoCommentText { margin: 0in 0in 0.0001pt; font-size: 10pt; font-family: "Times New Roman"; }span.MsoFootnoteReference { vertical-align: super; }span.MsoCommentReference { }p.MsoBodyTextIndent, li.MsoBodyTextIndent, div.MsoBodyTextIndent { margin: 0in 0in 6pt 0.25in; font-size: 12pt; font-family: "Times New Roman"; }p.MsoBodyTextFirstIndent2, li.MsoBodyTextFirstIndent2, div.MsoBodyTextFirstIndent2 { margin: 0in 0in 6pt 0.25in; text-indent: 10.5pt; font-size: 12pt; font-family: "Times New Roman"; }p.MsoBodyText3, li.MsoBodyText3, div.MsoBodyText3 { margin: 0in 0in 6pt; font-size: 8pt; font-family: "Times New Roman"; }a:link, span.MsoHyperlink { color: blue; text-decoration: underline; }a:visited, span.MsoHyperlinkFollowed { color: purple; text-decoration: underline; }em { }pre { margin: 0in 0in 0.0001pt; font-size: 10pt; font-family: "Courier New"; }p.MsoAcetate, li.MsoAcetate, div.MsoAcetate { margin: 0in 0in 0.0001pt; font-size: 8pt; font-family: Tahoma; }span.Heading3Char { font-weight: bold; }p.BODY3, li.BODY3, div.BODY3 { margin: 3pt 0in 0.0001pt; text-align: justify; text-indent: 0.25in; font-size: 10pt; font-family: "Times New Roman"; color: black; }p.CHAPTITLE, li.CHAPTITLE, div.CHAPTITLE { margin: 0in 0in 0.0001pt; text-align: right; font-size: 24pt; font-family: "Times New Roman"; color: black; font-weight: bold; }p.QUOTES, li.QUOTES, div.QUOTES { margin: 0in 0in 0.0001pt; text-align: right; font-size: 10pt; font-family: "Times New Roman"; color: black; font-style: italic; }p.Code, li.Code, div.Code { margin: 0in 0in 0.0001pt; font-size: 9pt; font-family: "Courier New"; color: black; }span.CommentTextChar { }p.ModCode, li.ModCode, div.ModCode { margin: 0in 0in 0.0001pt; font-size: 9pt; font-family: "Courier New"; color: red; font-weight: bold; }span.FootnoteTextChar { }span.BalloonTextChar { font-family: Tahoma; }span.HTMLPreformattedChar { font-family: "Courier New"; }span.BODY3Char { color: black; }span.CodeChar { font-family: "Courier New"; color: black; }span.ModCodeChar { font-family: "Courier New"; color: red; font-weight: bold; }span.meta { }span.fitlabel { font-family: Verdana; }span.StylefitlabelVerdana9ptItalicGray-80 { font-family: "Times New Roman"; color: gray; font-style: italic; }p.Pattern, li.Pattern, div.Pattern { margin: 3pt 0in 0.0001pt; text-align: justify; text-indent: 0.25in; font-size: 10pt; font-family: "Times New Roman"; font-variant: small-caps; color: black; }span.PatternChar { font-variant: small-caps; color: black; }span.fitgrey { }span.body { }span.pagetitle { }span.BodyTextIndentChar { }span.BodyTextFirstIndent2Char { }span.BodyText3Char { }div.Section1 { page: Section1; }ol { margin-bottom: 0in; }ul { margin-bottom: 0in; } </style> <div class="CHAPTITLE" style="margin: 34pt 0in;"><span>The Craftsman: 63<br />Specifics and Generics</span></div><div class="QUOTES"><span style="font-style: normal;">Robert C. Martin</span></div><div class="QUOTES"><span style="font-style: normal;">8 Nov, 2010</span></div><div class="QUOTES"><span><span> </span></span></div><div class="BODY3" style="text-indent: 0in;"><br /></div><div class="BODY3"><i>Sat, 18 Mar 2002, 13:00</i></div><div class="BODY3" style="margin: 3pt 0.5in 0.0001pt; text-indent: 0in;"><br /></div><div class="BODY3"><span class="body">I was sitting in the observation deck practicing some code katas when I saw Avery walk by.<span>&nbsp; </span></span></div><div class="BODY3"><span class="body">“Avery, come take a look at this.”<span>&nbsp; </span></span></div><div class="BODY3"><span class="body">Aver stopped and looked over my shoulder.<span>&nbsp; </span>“Ah, you’re doing the <i>Stack</i> kata.”</span></div><div class="BODY3"><span class="body">“Yes, this is the third time I’ve done it this morning, and I’ve noticed something interesting.<span>&nbsp; </span>Do you have a few minutes?”</span></div><div class="BODY3"><span class="body">Avery sat down next to me and chortled:<span>&nbsp; </span>“Most certainly and without the slightest hesitation.”</span></div><div class="BODY3"><span class="body">I didn’t want to get into the formal banter game that we often played, so I just said: “Do you remember one of Mr. C’s rules about TDD?<span>&nbsp; </span>The one about tests being specific and code being generic?”</span></div><div class="BODY3"><span class="body">“Indeed I do, Alphonse.<span>&nbsp; </span>Indeed I do.<span>&nbsp; </span>Let’s see. (Ahem): ‘<i>As the tests get more specific, the code get’s more generic</i>.’ Is that the one?”</span></div><div class="BODY3"><span class="body">“Yes, that’s the one.<span>&nbsp; </span>I always thought I knew what it meant, but this morning something kind of hit me.”</span></div><div class="BODY3"><span class="body">“And what was it that caught your attention, if I may ask?”</span></div><div class="BODY3"><span class="body">“Let’s walk through the <i>Stack</i> kata, and I’ll show you.”</span></div><div class="BODY3"><span class="body">“Very well, Alphonse, Shall I endeavor to write the first test?”</span></div><div class="BODY3"><span class="body">“Please do.”</span></div><div class="BODY3"><span class="body">And so Avery wrote the first test of the <i>Stack</i> kata:</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class StackTest {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void newStackShouldBeEmpty() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>Stack stack = new Stack();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.size(), equalTo(0));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3"><span class="body">I responded with the standard ritual.<span>&nbsp; </span>“OK, now I can make that fail with this…”</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class Stack {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public int size() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return -1;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3"><span class="body">“…and I can make it pass with this.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int size() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return 0;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="BODY3" style="text-indent: 0in;"><br /></div><div class="BODY3"><span class="body">“Excellent, Alphonse. Nicely done!<span>&nbsp; </span>Now for the next test, we’ll ensure that the size, after a push, is one.”<span>&nbsp; </span></span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void sizeAfterPushShouldBeOne() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>Stack stack = new Stack();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(0);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.size(), equalTo(1));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“OK, and I can make that pass with a simple increment.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class Stack {</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>private int size;</span></div><div class="Code"><span class="body"><span>&nbsp; </span></span></div><div class="Code"><span class="body"><span>&nbsp; </span>public int size() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return </span><span class="ModCodeChar">size</span><span class="body">;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="ModCode"><span class="body"><span>&nbsp; </span>public void push(int element) {</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>size++;</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Oh, well done, well done, Avery old chap…”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">I interrupted him.<span>&nbsp; </span>“OK, Avery, this is what I wanted to show you.<span>&nbsp; </span>Notice that I changed the </span><span class="CodeChar"><span style="font-size: 9pt;">size</span></span><span class="body"> method to return a variable instead of a constant?” </span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Indeed!”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Right, so that’s taking something very specific and making it more general.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Indeed.<span>&nbsp; </span>Indeed.<span>&nbsp; </span>What could be more specific than a constant? And certainly a variable, by its very nature, is more general than a constant.<span>&nbsp; </span>After all a constant has only one value, whereas a variable can have many different values.<span>&nbsp; </span>An astute observation that!”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“But now,” he continued,<span>&nbsp; </span>“I must insist that after a pop, the size should be zero once again.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">Had he really understood my point?<span>&nbsp; </span>If not, I had more to show him.<span>&nbsp; </span></span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Right.” I said.<span>&nbsp; </span>“And don’t forget to refactor the tests to eliminate the duplication.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Oh, I shan’t forget, Alphonse.<span>&nbsp; </span>I shan’t forget.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class StackTest {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>private Stack stack;</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Before</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void setUp() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack = new Stack();</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>…</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void sizeAfterPushAndPopShouldBeZero() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(0);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.pop();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.size(), equalTo(0));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“OK, and now I can make this pass with a simple decrement.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int pop() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>size--;</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return -1;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Capital, old sport!<span>&nbsp; </span>Capital!<span>&nbsp; </span>But now, I’m afraid that it’s quite necessary to prevent you from popping an empty stack.<span>&nbsp; </span>I do hope that doesn’t inconvenience you too much.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test(expected=Stack.Underflow.class)</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void shouldThrowUnderflowWhenEmptyStackIsPopped() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.pop();</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Good.” I said, still ignoring his patois, “Now I can make that pass by checking for zero.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int pop() {</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == 0)</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Underflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>size--;</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return -1;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">…</span></div><div class="Code"><br /></div><div class="ModCode"><span class="body"><span>&nbsp; </span>public class Underflow extends RuntimeException {</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Outstanding!<span>&nbsp; </span>Simply outstanding!<span>&nbsp; </span>You clearly have mastery over your medium.<span>&nbsp; </span>But now, alas, I must further impose upon you.<span>&nbsp; </span>You see, you must not allow the stack to exceed the specified size.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Before</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void setUp() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack = new Stack(</span><span class="ModCodeChar">2</span><span class="body">);</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body">…</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test(expected=Stack.Overflow.class)</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void shouldThrowOverflowWhenFullStackIsPushed() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(1);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(2);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(3);</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Good.<span>&nbsp; </span>Now I can make that pass by creating the constructor and then comparing the size against the capacity in the </span><span class="CodeChar"><span style="font-size: 9pt;">push</span></span><span class="body"> method.</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class Stack {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>private int size;</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>private int capacity;</span></div><div class="ModCode"><br /></div><div class="ModCode"><span class="body"><span>&nbsp; </span>public Stack(int capacity) {</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>this.capacity = capacity;</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body">…</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void push(int element) {</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == capacity)</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Overflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>size++;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body">…</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public class Underflow extends RuntimeException {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="ModCode"><span class="body"><span>&nbsp; </span>public class Overflow extends RuntimeException {</span></div><div class="ModCode"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Sheer brilliance, old sport, old coot, old sod!<span>&nbsp; </span>But enough of these mundane machinations.<span>&nbsp; </span>It’s time to make this sad excuse of a program begin to act like a stack.<span>&nbsp; </span>So when you push an element, I must require that you pop that self-same element!”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void shouldPopZeroWhenZeroIsPushed() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(0);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.pop(), equalTo(0));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“I’m afraid, dear Avery, that I can make that pass rather trivially.”<span>&nbsp; </span>I cursed myself under my breath for succumbing to his banter.</span></div><div class="BODY3" style="margin-right: 0.5in;"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int pop() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == 0)</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Underflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>--size;</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return </span><span class="ModCodeChar">0</span><span class="body">;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Devilishly clever my boy!<span>&nbsp; </span>You parried my thrust with just a flick of your wrist!<span>&nbsp; </span>But can you flick this away just as casually?”</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void shouldPopOneWhenOneIsPushed() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(1);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp; </span><span>&nbsp;</span>assertThat(stack.pop(), equalTo(1));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">I forced myself to avoid the banter.<span>&nbsp; </span>“This one is going to require a variable. And once again, notice that we are replacing something specific, with something more general.”</span></div><div class="Code"><br /></div><div class="Code"><span class="body">public class Stack {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>…</span></div><div class="Code"><span class="body"><span>&nbsp; </span>private int element;</span></div><div class="Code"><br /></div><div class="Code"><span class="body">…</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public void push(int element) {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == capacity)</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Overflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>size++;</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>this.element = element;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int pop() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == 0)</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Underflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>--size;</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return element;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">…</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Oh, ho!<span>&nbsp; </span>Yes, again, the constant is replaced with a variable.<span>&nbsp; </span>Specifics become generics.<span>&nbsp; </span>Well done, Alphonse!<span>&nbsp; </span>Well done!<span>&nbsp; </span>But as yet this beast behaveth not as ought a stack.<span>&nbsp; </span>Therefore shall I maketh you to perform a true FIFO operation!”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">Why did he add that old-english twist?<span>&nbsp; </span>Was I distracting him?<span>&nbsp; </span>Was he looking ahead to the end-game and losing concentration?</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>@Test</span></div><div class="Code"><span class="body"><span>&nbsp; </span>public void PushedElementsArePoppedInReverseOrder() <span>&nbsp;</span>{</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(1);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>stack.push(2);</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.pop(), equalTo(2));</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>assertThat(stack.pop(), equalTo(1));</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“OK, Avery, now watch this carefully.”<span>&nbsp; </span></span></div><div class="BODY3" style="margin-right: 0.5in;"><br /></div><div class="Code"><span class="body">public class Stack {</span></div><div class="Code"><span class="body"><span>&nbsp; </span>…</span></div><div class="Code"><span class="body"><span>&nbsp; </span>private int elements</span><span class="ModCodeChar">[]</span><span class="body">;</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public Stack(int capacity) {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp; </span><span>&nbsp;</span>this.capacity = capacity;</span></div><div class="ModCode"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>elements = new int[capacity];</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public void push(int element) {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == capacity)</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Overflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>element</span><span class="ModCodeChar">s[</span>size++<span class="ModCodeChar">]</span><span class="body"> = element;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><br /></div><div class="Code"><span class="body"><span>&nbsp; </span>public int pop() {</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>if (size == 0)</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>throw new Underflow();</span></div><div class="Code"><span class="body"><span>&nbsp;&nbsp;&nbsp; </span>return element</span><span class="ModCodeChar">s[</span>--size<span class="ModCodeChar">]</span><span class="body">;</span></div><div class="Code"><span class="body"><span>&nbsp; </span>}</span></div><div class="Code"><span class="body">…</span></div><div class="Code"><span class="body">}</span></div><div class="Code"><br /></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Do you see what happened Avery?<span>&nbsp; </span>We transformed that </span><span class="CodeChar"><span style="font-size: 9pt;">element</span></span><span class="body"> variable into something more general than a variable.<span>&nbsp; </span>We transformed it into an array.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">Avery just looked at the code with his brows knitted together. <span>&nbsp;</span>His normally bulging eyes bulged even further.<span>&nbsp; </span>I could see the wheels turning in his head.</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Alphonse, do you realize that you didn’t delete that </span><span class="CodeChar"><span style="font-size: 9pt;">size</span></span><span class="body"> code?<span>&nbsp; </span>You just moved it around.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“What do you mean?”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“I mean that all that silly code that we wrote at first, the code for the </span><span class="CodeChar"><span style="font-size: 9pt;">size</span></span><span class="body"> variable in order to pass the initial tests.<span>&nbsp; </span>I usually think of that as throwaway code – just something to do to get the early tests to pass.<span>&nbsp; </span>But we didn’t delete that code; we <i>moved</i> it.<span>&nbsp; </span>We moved the </span><span class="CodeChar"><span style="font-size: 9pt;">size++</span></span><span class="body"> and </span><span class="CodeChar"><span style="font-size: 9pt;">--size </span></span><span class="body">into array subscripts.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Yeah.” I said. “Maybe that code wasn’t so silly after all.<span>&nbsp; </span>It certainly wasn’t throwaway.<span>&nbsp; </span>But did you notice the <i>transformations</i>, Avery?<span>&nbsp; </span>We transformed specific code like constants, into generic code like variables and arrays.” </span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Yeah, I <i>did</i> notice that Alphonse, and that means that from one test to the next we were generalizing and moving code.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“We also <i>added</i> code like the constants, and the </span><span class="CodeChar"><span style="font-size: 9pt;">if</span></span><span class="body"> statements for the exceptions, and the increments and decrements.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Yeah!<span>&nbsp; </span>So the process of changing the production code from test to test is not one of rewriting so much as it is of adding, moving, and generalizing.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“That’s cool!” I said. “It means that none of the code we write to pass the early tests is wasted code; it’s just code that’s incomplete, not properly placed, or not general enough.<span>&nbsp; </span>It’s not that the code is wrong, it’s just – what’s the word?”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“Degenerate!” Avery said.<span>&nbsp; </span>“The early code is degenerate.<span>&nbsp; </span>It’s not silly or wasted; it just young!<span>&nbsp; </span>It needs to evolve.<span>&nbsp; </span>That earlier code is the <i>progenitor</i> of the latter code.”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“I wonder.”<span>&nbsp; </span>I said.<span>&nbsp; </span></span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“What?”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“I wonder if this is <i>always</i> true.<span>&nbsp; </span>Can you always evolve code, from test to test, by adding, moving, or generalizing it?<span>&nbsp; </span>Is the process of TDD really just a set of successive generalizations constrained by tests?”</span></div><div class="BODY3" style="margin-right: 0.5in;"><span class="body">“I don’t know.<span>&nbsp; </span>Let’s try the Prime Factors kata…”<span>&nbsp;&nbsp; </span></span></div><div class="BODY3" style="margin-right: 0.5in; text-indent: 0in;"><br /></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com7tag:blogger.com,1999:blog-3898534372669113633.post-36591327178134358532010-10-21T10:58:00.000-07:002010-10-21T10:58:48.149-07:00Danger! Software Craftsmen at Work.On October 12, 2010 at QCon <a href="http://www.teamsandtechnology.com/dh/">David Harvey</a> gave a talk entitled <a href="http://www.infoq.com/presentations/Danger-Software-Craftsmen-at-Work">Danger! Software Craftsmen at Work</a>.&nbsp; This talk was nicely summarized and expanded upon by <span class="author"><a href="http://www.sharpcrafters.com/blog/author/Gael-Fraiteur.aspx">Gael Fraiteur</a> in his blog: <a href="http://www.sharpcrafters.com/blog/post/Why-Should-We-Care-About-Software-Craftsmanship-Part-2.aspx">Why Should We Care About Software Craftsmanship?&nbsp; Part 2</a>.&nbsp; But I have a few things to add.&nbsp;&nbsp; </span><br /><span class="author"><br /></span><br /><span class="author">Harvey makes the following points (as described by Fraiteur):</span><br /><ol><li>The Manifesto for Software Craftsmanship is empty of content because it is not refutable, i.e. it is not possible for a reasonable person to disagree.<br /></li><li>The opposition of software craftsmanship to software engineering is pointless and may even give permission to software developers to ignore the lessons of software engineering. <br /></li><li>Metaphors, and the language we are using to describe ourselves and our activity, do matter. The people around us think of a craftsman as someone producing leather bags, not items you can rely on. Although software developers have their own definition of craftsmanship, what eventually matters is the perception of our customers. By choosing inappropriate metaphors, we are increasing the gap between those who build software, and those who use it.&nbsp;</li></ol><b><span style="font-size: small;">The Empty Manifesto</span></b><br />Is the Manifesto for Software Craftsmanship empty because it is irrefutable?&nbsp; I think the notion is absurd.&nbsp; That's like saying that the Hippocratic Oath, or the Golden Rule are empty because they are irrefutable.&nbsp; The Manifesto is not a scientific hypothesis that requires experimental verification.&nbsp; Rather the Manifesto is a statement of beliefs and values that the signatories adhere to and promote.&nbsp; The Manifesto contains articles of <i>belief</i>, not statements of measurable fact, and is therefore not required to be falsifiable.<br /><br />Is the Manifesto irrefutable?&nbsp; Would that it were so!&nbsp; Unfortunately the Manifesto is regularly refuted in both word and deed.&nbsp; For example, the first article of the Manifesto states that we value well-crafted software over working software; yet there continues a significant debate on the topic of "good-enough software".&nbsp; There is a large cohort of software developers who contend that well-crafted code is antithetical to time-to-market.&nbsp; <br /><br />The second article of the Manifesto is more interesting still.&nbsp; It promotes the steady addition of value over simply responding to change.&nbsp; What value does this refer to?&nbsp; It refers both to the value of the software's function, and the value of it's structure.&nbsp; That is, we as craftsman, will continue to steadily improve both the structure and function of the software, rather than simply responding to change.&nbsp; This kind of responsible behavior is refuted daily by the actions of developers who release changes that damage both structure and function.&nbsp; If you doubt that this happens, consider <a href="http://vimeo.com/9981123">this</a> video of bad code that I posted a few months ago.&nbsp; Believe it or not, this is deployed production code.<br /><br /><b>Engineering vs. Craftsmanship.</b><br />Is craftsmanship antithetical to engineering?&nbsp; Harvey suggests this possibility based on some of the statements in <a href="http://www.mcbreen.ab.ca/">Pete McBreen</a>'s classic book <a href="http://www.amazon.com/exec/obidos/ASIN/0201733862/mcbreenconsul-20/nosim">Software Craftsmanship</a> in which he derides some of the more egregious, high-ceremony and high-documentation practices associated with Software Engineering.&nbsp; Harvey suggests that this may give "permission" to budding software craftsmen to ignore the good software engineering work that has been done over the decades.&nbsp; <br /><br />I agree that this would be a bad thing.&nbsp; We don't want anyone in the Software Craftsmanship community to dismiss Software Engineering out of hand.&nbsp; The problem I have with Harvey's&nbsp; suggestion, however,&nbsp; is that none of the leaders in the Software Craftsmanship movement espouse the view that the history of Software Engineering is worthless.&nbsp; Indeed, quite the opposite is true.&nbsp; Software Craftsmen see themselves <i>as</i> <i>Software Engineers</i>.&nbsp; That does not mean we accept all of the Software Engineering dogma that has accumulated over the decades.&nbsp; It also doesn't mean that we reject it.&nbsp; It <i>does</i> mean that we <i>learn</i> it.<br /><br />The Software Craftsmanship community is deeply committed to learning the lessons of the past.&nbsp; That means studying the things we did right, <i>and</i> the things we did wrong.&nbsp; Software Craftsmen <i>immerse</i> themselves in their craft.&nbsp; We continue to read the old books by DeMarco, Yourdon, Parnas, Dijkstra, Hoare, Weinberg, and their brethren.&nbsp; We study at the feet of the old masters so that we can learn how to be the next masters.&nbsp; <br /><br />It is true that we have currently tabled some of the older practices that have been associated with Software Engineering; <i>but we do not disrespect</i> those practices, nor the people who at one time proposed and adopted them.&nbsp; They were pioneers who led the way and who, in some cases, showed us the paths to avoid.<br /><br /><b>The Craftsman Connotation</b><br />Harvey advises us to take care with the metaphors we choose.&nbsp; He makes the point that terms like craft, dojo, kata, apprentice, master etc., can have negative connotations.&nbsp; The word "craft" for example, may bring to mind the kind of quality one experiences at a flea-market or a craft fair.&nbsp; The martial-arts terms that are sometimes common in craftsmanship circles may bring to mind the notion of the "omnipotent loner" like Bruce Lee, or Neo.&nbsp; The terms "Master", "Journeyman", and "Apprentice" may bring to mind the secretive guilds of the middle ages with all their ritual, mysticism, and intrigue.&nbsp;<br /><br />I think this is a legitimate concern.&nbsp; I also think it's easily dealt with.&nbsp; The strategy I've been using is "guilt by association".&nbsp; When I talk about Software Craftsmanship, I also talk about Software Professionalism.&nbsp; I use the terms interchangeably in order to enforce the association in my listeners' (and readers') minds.&nbsp; When I talk about dojo's and kata's, it is always in the connotation of "practice'.&nbsp; I use the terms together so that there is no doubt about what the terms actually mean.<br /><br />Harvey is right in that we don't want to create a "secret language".&nbsp; There is nothing wrong with the memes we've chosen to communicate amongst ourselves; but we have to be careful to make sure we associate those memes with concepts like <i>professionalism</i>, <i>practice</i>, and <i>seniority</i> that our customers and employers understand and appreciate.&nbsp;&nbsp; We want these people's support.&nbsp; We want them to believe and trust in the values that we espouse.&nbsp; We will not accomplish that by disrespecting the metaphors that they depend upon.<br /><br /><br /><br /><br /><span class="author"></span>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com4tag:blogger.com,1999:blog-3898534372669113633.post-11968621383704074562010-10-17T10:59:00.000-07:002010-10-17T10:59:40.067-07:00The Cost of Code?In a panel at #scna yesterday, @chadfowler asked the question: "How many projects fail because of the code?"&nbsp; I think the point he was trying to make was that the primary causes of project failure are business issues, not technical issues.<br /><br />I posed this question on twitter earlier today.&nbsp; The responses came quickly, and virtually all of them agreed that business issues are the more significant causes of project failure. <br /><br />It's certainly true that projects fail because of cost, requirements, schedule, management. etc.&nbsp; It's also true that we seldom trace the cause of failure back to something as mundane as code.&nbsp; So Chad's point, if that's what it was, certainly has merit.<br /><br />The conclusion that we might make from this is that code just isn't very important in the long run, and the the craftsmanship movement might just be a load of Yak Shaving.&nbsp; Indeed, Chad asked us to consider just that in his talk at #scna.&nbsp; If we follow that reasoning, then we should decrease our emphasis on technological prowess and skill, and increase our emphasis on business, requirements, budgets, schedules, and management.&nbsp;<br /><br />Before I counter this argument, let me say that I <i>do</i> know of projects that have failed because of the code.&nbsp; Indeed, I know of <i>companies</i> that have failed because of the code.&nbsp;<br /><br />This isn't actually very difficult to believe or understand.&nbsp; We all know that when the code is a mess, it becomes more and more costly to maintain and improve.&nbsp; If that cost exceeds what the project can afford, the project fails.&nbsp; If that cost exceeds what the company can afford, the company fails.&nbsp; In the cases that I am aware of, this is precisely what happened.&nbsp; The code was simply too costly for the business model to support.&nbsp;<br /><br />So let's try a simple thought experiment.&nbsp; What fraction of projects would fail if the code was <i>infinitely</i> expensive to produce and maintain? Clearly <i>all</i> projects would fail because the code would be too expensive for any finite business model to support.&nbsp; <br /><br />OK, so what if the code cost <i>nothing</i> to produce and maintain?&nbsp; What fraction of those projects would fail because of the code?&nbsp; Again, the answer is clear.&nbsp; No project would fail because of the code, if the code costs nothing to make.&nbsp;<br /><br />What does it mean to cost nothing to make?&nbsp; It means that you would have the code you needed the instant you needed it.&nbsp; The code would simply be there, instantly, fully functional,&nbsp; free of defects.&nbsp; Any time you needed a change, the change would instantly be in effect, fully deployed, fully operational.<br /><br />So let's say you are thrown into a cave&nbsp; by some thieves.&nbsp; In that cave you find a old beat-up PC jr, complete with the IR chicklet keyboard.&nbsp; You pick up that keyboard and rub a smudge off the enter key.&nbsp; Wooosh!&nbsp; a genie appears on the screen and grants you the ability to have zero cost code for the rest of your life!&nbsp; Would any of your projects ever fail from that point on?<br /><br />Remember, nobody else has your ability.&nbsp; Nobody else can produce the code they want, instantly, and without defect.&nbsp; Nobody else can make and deploy changes in zero time.&nbsp; So you have a tremendous competitive advantage.&nbsp; Is there any way you could fail?&nbsp; I think my dog Petunia might fail, but anyone smarter than that should become a multi-trillionaire.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_McaZb7v3tS4/TLslFMtIPBI/AAAAAAAAABg/nD0wMjJ1wC8/s1600/petunia.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="239" src="http://1.bp.blogspot.com/_McaZb7v3tS4/TLslFMtIPBI/AAAAAAAAABg/nD0wMjJ1wC8/s320/petunia.JPG" width="320" /></a></div><br />If we had that magic PC jr, there wouldn't be any schedule or budget issues.&nbsp; The cost of mismanagement and/or bad requirements would be close to zero.&nbsp; So all those things that cause projects to fail would become irrelevant. &nbsp;<br /><br />But we don't have that magic PC jr.&nbsp; Code <i>does</i> cost money to produce and maintain.&nbsp; But if I, as a craftsman, can&nbsp; invoke a fraction of the power of that Genie to reduce the cost of producing and maintaining code, then I simultaneously reduce the cost and risk of mismanagement, of bad requirements, of tight schedules, and of tight budgets.&nbsp; By reducing the cost of the thing that's being managed, we reduce the cost of error and increase the chances of success!<br /><br />Why is it that projects fail due to bad requirements, bad management, bad schedules, and bad budgets?&nbsp; They fail because the cost of error is <i>huge</i>.&nbsp; Why is the cost of error huge?&nbsp; Because the cost of the code is so horribly large.&nbsp; If code cost nothing to produce, the cost of error would be close to zero.<br /><br />This realization has not been lost on the business community.&nbsp; They tried to solve it by reducing the hourly rate of programmers.&nbsp; They set up horrifically expensive and risky mechanisms in order to hire programmers who lived half a world away in a wildly different culture.&nbsp; They faced the issues of time zones and languages, and cultural mismatch in order to reduce the cost of code.&nbsp; They did this because they understood that the it is <i>that cost </i>that drives the cost of management error.&nbsp; They did this because it is <i>that cost</i> that makes projects fail. <br /><br />Unfortunately this strategy didn't work as well had been hoped.&nbsp; Some folks have made it work; more or less.&nbsp; But the majority of the off-shoring efforts have been disappointing.&nbsp; And so the cost of code remains high, and therefore the risk of error is also high.<br /><br />And that brings us back to the question at hand.&nbsp; How many projects fail because of the code?&nbsp; The argument above suggests that <i>all</i> failures are a direct result of the cost of code.&nbsp; How many projects fail because of code?&nbsp; <i>All of them!</i><br /><br />More importantly, what is the single most effective way to increase the chances of project success?&nbsp; Is it improving requirements?&nbsp; Management?&nbsp; Schedules and budgets?&nbsp; All those things would help, but they are all secondary to the thing that truly drives project failure:&nbsp; The cost of the code.Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com28tag:blogger.com,1999:blog-3898534372669113633.post-22195912699344097012010-10-17T07:12:00.000-07:002010-10-17T07:12:59.074-07:00Be a good one. #scna 2010I didn't expect it, but something profound happened at #scna this week.&nbsp; I expected the conference to be good.&nbsp; I expected it to be fun.&nbsp; I expected to see many old and new faces and have stimulating conversations.&nbsp; And in all these things my expectations were met.&nbsp; What I didn't expect was the <i>gelling</i>.<br /><br />There was a meme at this conference that pervaded every talk and every session.&nbsp; Doug Bradbury (<strong><a class="screen-name screen-name-dougbradbury pill" href="http://twitter.com/#%21/dougbradbury"><strong>@dougbradbury</strong></a>)</strong> coined it in the title of his talk: <i>Made to Make</i>.&nbsp; His point was that we are <i>makers</i>.&nbsp; We love to <i>make</i>.&nbsp; There is something within us drives us to create. &nbsp; Doug opened his talk with a story from his childhood.&nbsp; He was eight, hanging out with his grandfather in the workshop.&nbsp; His grandfather saw him leaning over his child-sized workbench and asked him what he was doing.&nbsp; "<i>I'm making stuff.</i>" was his reply.&nbsp;<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://1.bp.blogspot.com/_TVhFMT7oEd0/TLmDuaQ0BdI/AAAAAAAAJ_0/_-Z5dM4ZI8I/0072.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://1.bp.blogspot.com/_TVhFMT7oEd0/TLmDuaQ0BdI/AAAAAAAAJ_0/_-Z5dM4ZI8I/0072.jpg" width="320" /></a></div><br /><br />Keavy McMinn (<a class="screen-name screen-name-keavy pill" href="http://twitter.com/#%21/keavy"><strong>@keavy</strong></a>), in her talk <i>Artist to Programmer</i>, reiterated this meme more directly when she quoted one of her friend's tweets: "<i>I just want to make stuff, I don't really care if its Flash or objective-C or <span class="query-token">fuzzy</span> felt</i>" and again later: "<i>The future belongs to the few of us still willing to get our hands dirty</i>".&nbsp; One of the most moving moments in Keayv's presentation was her description of daily refactoring a one-ton tower or bricks during an art show.&nbsp; She showed pictures of this tower from day to day.&nbsp; Each different.&nbsp; Each telling a different story.&nbsp; Each lovingly built.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://scna.softwarecraftsmanship.org/assets/42/keavy_bio_pic_86x100_thumbnail.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="http://scna.softwarecraftsmanship.org/assets/42/keavy_bio_pic_86x100_thumbnail.png" /></a></div><br />Michael Norton (<a class="screen-name screen-name-DocOnDev pill" href="http://twitter.com/#%21/DocOnDev"><strong>@DocOnDev</strong></a>) talked about the history of medicine, medical education, and medical certification.&nbsp; He placed it all on a time line and showed how medicine transitioned through phases of empirical observation, to the canonization of an initial body of knowledge, to rapid theoretical and technological development, to the intensely supervised and collaborative learning model of today.&nbsp; And throughout this long history and transition, medicine began as, and remains, a craft developed by people who <i>love what they do</i>.&nbsp;<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_TVhFMT7oEd0/TLmCzCkFNLI/AAAAAAAAJ6k/CF63DQpFqIo/0160.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://3.bp.blogspot.com/_TVhFMT7oEd0/TLmCzCkFNLI/AAAAAAAAJ6k/CF63DQpFqIo/0160.jpg" width="320" /></a></div><br /><br />I (<strong><a class="screen-name screen-name-unclebobmartin pill" href="http://twitter.com/#%21/unclebobmartin"><strong>@unclebobmartin</strong></a></strong>) and Michael Feathers (<a class="screen-name screen-name-mfeathers pill" href="http://twitter.com/#%21/mfeathers"><strong>@mfeathers</strong></a>) both gave talks about functional programming, showing us new (old) ways to make our stuff.&nbsp;&nbsp; <span class="query-token">Enrique</span> Comba Riepenhausen (<strong><a class="screen-name screen-name-ecomba pill" href="http://twitter.com/#%21/ecomba"><strong>@ecomba</strong></a>)</strong> gave an impassioned talk about fostering partnerships with our customers, reiterating the pleas and advice from both Ken Auer and Chad Fowler (<a class="screen-name screen-name-chadfowler pill" href="http://twitter.com/#%21/chadfowler"><strong>@chadfowler</strong></a>) reminding us that: <i>We make things for others</i>.<br /><br />There were lots of open-space sessions about all kinds of things.&nbsp; Laptops were always open, Code was never far away.&nbsp; There were "randori" coding sessions on stage.<br /><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlOlhSjteI/AAAAAAAAJhw/1GjGgF0IY5s/0539.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlOlhSjteI/AAAAAAAAJhw/1GjGgF0IY5s/0539.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlOrB5mwUI/AAAAAAAAJiU/SiMO391EQ0c/0531.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlOrB5mwUI/AAAAAAAAJiU/SiMO391EQ0c/0531.jpg" width="320" /></a></div><br /><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><a href="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlN_M5-UII/AAAAAAAAJeM/VshUpAEnA0w/0592.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="213" src="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLlN_M5-UII/AAAAAAAAJeM/VshUpAEnA0w/0592.jpg" width="320" /></a></td></tr><tr><td class="tr-caption" style="text-align: center;"><div style="text-align: center;"><span style="font-size: xx-small;">&nbsp; Me exhorting Adewale Oshineye (<strong><a class="screen-name screen-name-ade_oshineye pill" href="http://twitter.com/#%21/ade_oshineye"><strong>@ade_oshineye</strong></a></strong>) to "Write a Test".</span></div></td></tr></tbody></table><br />There were impromptu coding sessions and lessons and discussions.&nbsp; <br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_TVhFMT7oEd0/TLmCVHigtpI/AAAAAAAAJ30/5I72WjMkQf4/0202.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://2.bp.blogspot.com/_TVhFMT7oEd0/TLmCVHigtpI/AAAAAAAAJ30/5I72WjMkQf4/0202.jpg" width="320" /></a></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><div class="separator" style="clear: both; text-align: center;"></div><table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody><tr><td style="text-align: center;"><img border="0" height="240" src="http://yfrog.com/4c1zkbj.th.jpg" style="margin-left: auto; margin-right: auto;" width="320" /></td></tr><tr><td class="tr-caption" style="text-align: center;">Improptu Clojure Coding Session</td></tr></tbody></table><div class="separator" style="clear: both; text-align: center;"><a href="http://yfrog.com/4c1zkbj.th.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"></a></div><div class="separator" style="clear: both; text-align: center;"><a href="http://2.bp.blogspot.com/_TVhFMT7oEd0/TLmCB1abZvI/AAAAAAAAJ2E/QwCEpERROk4/0228.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://2.bp.blogspot.com/_TVhFMT7oEd0/TLmCB1abZvI/AAAAAAAAJ2E/QwCEpERROk4/0228.jpg" width="320" /></a></div><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://3.bp.blogspot.com/_TVhFMT7oEd0/TLlQGEcxOpI/AAAAAAAAJrU/lmDTSfw00SU/0393.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://3.bp.blogspot.com/_TVhFMT7oEd0/TLlQGEcxOpI/AAAAAAAAJrU/lmDTSfw00SU/0393.jpg" width="320" /></a></div><br />Corey Haines (<a class="screen-name screen-name-coreyhaines pill" href="http://twitter.com/#%21/coreyhaines"><strong>@coreyhaines</strong></a>) gave the closing talk, and it summarized the tone perfectly.&nbsp; The message, set amongst stories of cats, and cows, and redwoods, was simple: <i>We are makers</i>.&nbsp; We love what we do.&nbsp; We are happiest doing what we do.&nbsp; So we need to do the things that make us happiest.<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLmEe_mwZhI/AAAAAAAAKEE/zGIIb6ReVVo/0014.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="213" src="http://4.bp.blogspot.com/_TVhFMT7oEd0/TLmEe_mwZhI/AAAAAAAAKEE/zGIIb6ReVVo/0014.jpg" width="320" /></a></div><br /><br />Yes, there was a <i>gelling</i> at #scna 2010.&nbsp; It was a gelling around a meme.&nbsp; It was the consolidation of an idea.&nbsp; It was a group of people who found themselves to be in violent agreement over a central organizing notion.&nbsp;<br /><br />Abraham Lincoln said it over 100 years ago.&nbsp; Had he been at #scna 2010 he might have gotten up on stage after Corey's talk and sent us home with the following exhortation:<br /><br /><div class="separator" style="clear: both; text-align: center;"><a href="http://www.sonofthesouth.net/slavery/abraham-lincoln/pictures/lincoln-sitting.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="http://www.sonofthesouth.net/slavery/abraham-lincoln/pictures/lincoln-sitting.jpg" width="237" /></a></div><br /><div style="color: #6aa84f; text-align: center;"><i><span style="font-size: x-large;">"Whatever you are, be a good one."</span></i></div><div style="text-align: center;"><br /></div><br /><div style="text-align: right;"><span style="font-size: x-small;">(Thanks to </span><span style="font-size: x-small;">Monty Ksycki for taking all those great pictures!)</span><b><br /></b></div><br /><br /><br /><div style="text-align: center;"><br /></div>Uncle Bobhttp://www.blogger.com/profile/02481406139679244157noreply@blogger.com7