<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Object Mentor Blog: Category Michaels Musings</title>
    <link>http://blog.objectmentor.com/articles/category/michaels-musings</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>UI Test Automation Tools are Snake Oil</title>
      <description>&lt;p&gt;It happens over and over again.  I visit a team and I ask about their testing situation.  We talk about unit tests, exploratory testing, the works.  Then, I ask about automated end-to-end testing and they point at a machine in the corner.  That poor machine has an installation of some highly-priced per seat testing tool (or an open source one, it doesn&amp;#8217;t matter), and the chair in front of it is empty.  We walk over,  sweep the dust away from the keyboard, and load up the tool.  Then, we glance through their set of test scripts and try to run them.  The system falls over a couple of times and then they give me that sheepish grin and say &amp;#8220;we tried.&amp;#8221;  I say, &amp;#8220;don&amp;#8217;t worry, everyone does.&amp;#8221;  

&lt;p&gt;It&amp;#8217;s a very familiar &amp;#8216;rabbit hole&amp;#8217; in the industry.  It&amp;#8217;s sort of like the old days when you&amp;#8217;d find a couple of classes generated by a &lt;span class="caps"&gt;CASE&lt;/span&gt; tool in every code base you visited if you  looked hard enough.  People started with the merry notion that they were going to round-trip code with some &lt;span class="caps"&gt;CASE&lt;/span&gt; tool and they learned (like most lucky teams do) that it just doesn&amp;#8217;t pay for itself, it&amp;#8217;s not worth the time or the frustration.  UI Test Automation tools are in the same category.  Personally, I think that in this day and age selling them is irresponsible.  Developing them open-source?  Well, let your conscience be your guide, but really, even though people can use them responsibly, they hardly ever do because these tools are sold with a dream, a very seductive and dangerous one.

&lt;h2&gt;The Dream&lt;/h2&gt;

&lt;p&gt;Janet comes into work in the morning and she sits down at her super-duper testing console.  She presses a button and the testing system springs to life.  The application comes up all at once across ten monitors.  Cursors move, selections are made (silently) and tests run against the user interface magically, as if some eager set of ghost elves took control, mischievously burrowing through the nooks and crannies of the application, running scripts to completion, and making little notes whenever there is a failure.  Janet sits back in her chair, waiting for the elves to report back to her.  She stirs her coffee gently.

&lt;h2&gt;The Reality&lt;/h2&gt;

&lt;p&gt;Janet hasn&amp;#8217;t gone home yet.  It&amp;#8217;s 2AM and she has to report completion of all her test cases at a meeting in the morning.  She thinks she&amp;#8217;s past the last configuration issue but she&amp;#8217;s not sure.  For the last hour, she&amp;#8217;s been trying to make sure that a particular button is pressed at step 14 of her script, but quirky latency on the server is preventing it from happening consistently.  Sadly, she has to run the script from the beginning each time.  Oh, and five hours ago she discovered UI changes which invalidated 30% of the regression tests.  Most of the changes were easy but she still has 12 cases to go and her 9AM meeting looms ahead of her.

&lt;p&gt;This gap between the dream and the reality is not a matter of flawed execution, it&amp;#8217;s endemic.  Here&amp;#8217;s the scoop.

&lt;h2&gt;UI Test Automation Tools are Brittle&lt;/h2&gt;

&lt;p&gt;You might not think this is fair but it is, really.  I haven&amp;#8217;t seen one of these tools yet which isn&amp;#8217;t susceptible to missed events or timing madness.  It just happens.  The fact of the matter is, it is hard to sit on the outside of an application an instrument it.  It&amp;#8217;s a very technology sensitive problem.  You need to hook into either the OS or the browser or both.  Neither are ever really built from the ground up for that sort of access.

&lt;h2&gt;UI Based Testing Is Not the Solution That Vendors Imply It Is&lt;/h2&gt;

&lt;p&gt;This is the big issue, the one which really hurts the industry.  The fact of the matter is that UI based testing should be used for UIs: that&amp;#8217;s it.  You should not be testing your full application end-to-end through a UI Testing tool.  First of all, that sort of testing couples some of the most important tests in your system to one of the most volatile parts of it.  It&amp;#8217;s easy for us to see business logic as volatile, but really, the UI is the thing which twists and ripples in the winds of change. When customers want new features, often those features involve new workflows.  When usability experts discover better ways of models of interaction, an agile business seizes upon them and makes the changes&amp;#8212;if they can.  You&amp;#8217;d be surprised at the number of applications which continue to sport out of day user interfaces simply because the development organization is terrified of throwing away all of their regression tests which (by the way) go through the UI.  Even if you&amp;#8217;re not a consultant like me, visiting teams and seeing their development processes, you can see hints from the outside.  Think of every website or shrink-wrap application which has &amp;#8220;the same old workflow&amp;#8221; and a UI that has become more cluttered over the years.  Often it&amp;#8217;s because of that lock-in.

&lt;h2&gt;UI Based Testing Takes More Staff and Time Than You Expect&lt;/h2&gt;

&lt;p&gt;This, really, is the most common failure case.  It&amp;#8217;s the case which explains the dust on the testing box&amp;#8217;s keyboard.  Someone, usually disconnected from the development organization, decides that &amp;#8220;hey, we need to solve the testing problem.  We have too many people doing manual testing.  It&amp;#8217;s taking forever.&amp;#8221;  So, they do their research, find a vendor with with a good licensing model and a good pitch and then they push it on the development organization.  They are, of course, looking to reduce staff so when they realize that translating all of those manual tests to the tool is very labor-intensive, they are taken aback.  But, of course, it is just a temporary cost, right? But, then it takes far longer than they expect.  Remember Janet&amp;#8217;s story?  It&amp;#8217;s really hard to catch up with a UI-Based testing tool.  It&amp;#8217;s hard to even stay in place with one.  Typically it takes a number of people to do UI-Based automated testing for a development team in sync with an iteration and worse, they&amp;#8217;ll always lag behind a bit because you can&amp;#8217;t really write UI-based tests ahead of time the way you can with &lt;span class="caps"&gt;FIT&lt;/span&gt; and other beneath-the-UI testing tools. From what I&amp;#8217;ve seen UI-based testing, done diligently, takes the effort of about one tester for every two to three developers.  That&amp;#8217;s what it seems to cost amortized across all of the maintenance of UI-induced test breakage. Oh, and by the way, if think you are going to save labor using record and playback?  Nope, you aren&amp;#8217;t.  It doesn&amp;#8217;t work.

&lt;h2&gt;Solutions&lt;/h2&gt;

&lt;p&gt;The fact of the matter is, you can use these tools effectively, but in a very narrow space.  It&amp;#8217;s nice to be able to test the UI&amp;#8212;by itself.  However, this sort of thing &lt;a href=http://www.computer.org/portal/web/csdl/doi/10.1109/MS.2005.110&gt;requires an architectural change&lt;/a&gt;. 

&lt;p&gt; In general, UIs are too volatile for end-to-end testing.  Teams that do it well, typically develop a small task-focused scripting layer and build tests on top if it so that the actual tests don&amp;#8217;t touch the UI directly.  But, if they happen across that technique, they are lucky. Still, it isn&amp;#8217;t an ideal solution. You really want to be &lt;i&gt;below&lt;/i&gt; the UI working against an &lt;span class="caps"&gt;API&lt;/span&gt; which exposes the business logic.  And, because of that nearly mystical synergy between testability and good design, that &lt;span class="caps"&gt;API&lt;/span&gt; layer is often useful for many things other than testing.

&lt;h2&gt;Conclusion/Challenge&lt;/h2&gt; 

&lt;p&gt;I recognize that I&amp;#8217;ve been rather vicious in the this blog.  If you develop these tools for a living, you might not think it&amp;#8217;s fair. But consider this.  If you don&amp;#8217;t think I&amp;#8217;m being fair, take a look at how your tools are marketed.  In particular, show me where the product literature discourages end-to-end testing through the tool.  Otherwise, well, you know, you are probably developing snake-oil.</description>
      <pubDate>Mon, 04 Jan 2010 05:35:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:b8d700fd-4c7c-4e3c-8d6f-d91710d990d4</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2010/01/04/ui-test-automation-tools-are-snake-oil</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>vih</title>
      <description>&lt;p&gt;Over the past few days, I&amp;#8217;ve been tinkering with a little project I&amp;#8217;ve called vih &amp;#8211; it&amp;#8217;s a vi clone written in Haskell.  Here&amp;#8217;s the &lt;a href=http://github.com/michaelfeathers/vih/tree/master&gt;git repo&lt;/a&gt;.  

&lt;p&gt;The way I&amp;#8217;ve started it is rather naive, and frankly I&amp;#8217;m surprised I that I had gotten as far as I did without curses and with the simple data structure I choose.  Rather than using a clever representation for a buffer, I decided to just use a &lt;code&gt;String&lt;/code&gt;.  What this means is that every time a character is inserted into a buffer, the whole thing is split and reconstituted.  I&amp;#8217;m not using &lt;code&gt;Data.ByteString&lt;/code&gt; or &lt;code&gt;Data.ByteString.Lazy&lt;/code&gt; either.  I suppose that I&amp;#8217;ll move toward a more sensible data structure in a while but right now typing is comfortable even with all of that work going on.

&lt;p&gt;My intention in doing this was to start to get a sense of how data structures evolve in Haskell by growing something large from a small seed. The primary data structure that I&amp;#8217;m using right now is called &lt;code&gt;EditBuffer&lt;/code&gt; and I notice that quite a few of my functions translate an &lt;code&gt;EditBuffer&lt;/code&gt; to another &lt;code&gt;EditBuffer&lt;/code&gt;.  This seems to work fine, however I find that I almost always have to label the buffer in the argument list and deconstruct it.  I haven&amp;#8217;t seen pervasive use of labels like that in Haskell code I&amp;#8217;ve looked at, so I&amp;#8217;m wondering if my mapping of functions to data structures is odd.

	&lt;p&gt;Right now, vih supports insert and command mode (toggled with &amp;#8216;i&amp;#8217; and &amp;#8216;ESC&amp;#8217;), the h, j, k, l cursor movements, line deletion with &amp;#8216;dd&amp;#8217;, home with &amp;#8216;gg&amp;#8217;, end of file with &amp;#8216;G&amp;#8217;, `in line&amp;#8217; positioning with &amp;#8216;0&amp;#8217; and &amp;#8217;$&amp;#8217;, insert new line after with &amp;#8216;o&amp;#8217;, and delete current char with &amp;#8216;x&amp;#8217;.  No file I/O yet.&lt;/p&gt;


	&lt;p&gt;Have a look, fork or contribute.&lt;/p&gt;</description>
      <pubDate>Fri, 14 Aug 2009 00:31:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:f3bac35e-0d49-47f6-b231-e95ad3293df1</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/14/vih</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Over the next month..</title>
      <description>&lt;p&gt;I&amp;#8217;m off on a round of conferences, classes and talks soon, so I figured I&amp;#8217;d list them here.

&lt;p&gt;In about 2 weeks, I&amp;#8217;ll be at Agile2009.  While there, I&amp;#8217;ll be doing a workshop called &lt;a href=http://agile2009.agilealliance.org/node/1953&gt;Treating Errorhandling as a First Class Consideration in Design&lt;/a&gt;.  This might be as much tutorial as workshop.  I&amp;#8217;ve been collecting a lot of material on error handling over the past few years and it will be nice to present some of it.

&lt;p&gt;I&amp;#8217;ll also be doing a talk called &lt;a href=http://agile2009.agilealliance.org/node/864&gt;Test Driven Development: Ten Years Later&lt;/a&gt; with Steve Freeman on the main stage.  We gave this talk at QCon London last year. It&amp;#8217;s chock-full of history and reminiscences.  

&lt;p&gt;Some people in the Software Craftsmanship community pulled a sneaky and organized &lt;a href=http://scna.softwarecraftsmanship.org/&gt;Software Craftsmanship North America (SCNA)&lt;/a&gt;, a one-day conference during Agile2009 across the street.  I&amp;#8217;ll be speaking there as well.   

&lt;p&gt;Later in the week at Agile, I&amp;#8217;ll be doing a workshop with Naresh Jain called &lt;a href=http://agile2009.agilealliance.org/node/2257&gt;
Styles of &lt;span class="caps"&gt;TDD&lt;/span&gt;: First Test&lt;/a&gt;.  Naresh has had a long-standing interest in the different ways that different people approach &lt;span class="caps"&gt;TDD&lt;/span&gt;, and we hope to throw the spotlight on that aspect in the workshop. Brett Schuchert and I will also be doing something terrifying with legacy code in public early one morning during the conference.  Details as it finalizes.

&lt;p&gt;It should come as no surprise to readers of this blog that I&amp;#8217;m interested in functional programming.  I&amp;#8217;ve had a casual interest for a while, but recently, I&amp;#8217;ve decided to go full bore and dedicate whatever spare time I have to it &amp;#8211; to the exclusion of the other design and programming topics I spend time investigating/thinking about.  So, the week after Agile, I&amp;#8217;m going to &lt;a href=http://www.cs.nott.ac.uk/~gmh/icfp09.html&gt;&lt;span class="caps"&gt;ICFP&lt;/span&gt;&lt;/a&gt; and its companion practitioner conferences &lt;a href=http://www.defun2009.info/blog/tutorial-schedule/&gt;&lt;span class="caps"&gt;DEFUN2009&lt;/span&gt;&lt;/a&gt; and &lt;a href=http://cufp.galois.com/&gt;&lt;span class="caps"&gt;CUFP&lt;/span&gt;&lt;/a&gt;.  I&amp;#8217;m looking forward to meeting some of the people who&amp;#8217;ve been helping me on and off and chatting with me on irc and mailing lists.  

&lt;p&gt;A week or so after that, I&amp;#8217;ll be teaching a &lt;a href=http://www.crisp.se/tdd/feathers/20090915&gt;Three-day &lt;span class="caps"&gt;TDD&lt;/span&gt;/Refactoring course in Stockholm&lt;/a&gt;.  There are still sign ups available. I&amp;#8217;m looking forward to that trip as well.

&lt;p&gt;Looking out past September, I&amp;#8217;ll be speaking at &lt;a href=http://jaoo.dk/aarhus-2009/&gt;&lt;span class="caps"&gt;JAOO&lt;/span&gt;&lt;/a&gt; in Aarhus, and &lt;a href=http://agilevancouver.ca/&gt;Agile Vancouver&lt;/a&gt;. More about those later as the talk times and topics finalize.</description>
      <pubDate>Thu, 13 Aug 2009 09:50:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:4ef72785-1549-4b79-977b-d482ba9acd71</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/13/over-the-next-month</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Naming and Body Language in Functional Code</title>
      <description>&lt;p&gt;I wrote a blog the other day about functional refactoring and I had what I thought was a good example:

&lt;code&gt;&lt;pre&gt;
absPosition :: Buffer -&amp;gt; Int
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    foldr ((+).length) 0 . take y . terminatedLines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;Almost immediately, I saw replies on a couple of forums (including this one) which pointed out that I could&amp;#8217;ve written the code this way:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    sum . map length . take y . terminatedLines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;It&amp;#8217;s funny, I thought of using &lt;code&gt;sum&lt;/code&gt; instead of &lt;code&gt;foldr&lt;/code&gt; back when I was using Haskell&amp;#8217;s line function.  The code I had looked like this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = 
    foldr ((+).((+1).length)) 0 . take y . lines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;But, I realized that the code wasn&amp;#8217;t in great shape for &lt;code&gt;sum&lt;/code&gt;, so I created &lt;code&gt;terminatedLines&lt;/code&gt;, used it and promptly forgot to do the refactoring I set out to do.

&lt;code&gt;&lt;pre&gt;
terminatedLines :: String -&amp;gt; [String]
terminatedLines = map (++ "\n") . lines
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;From an imperative point of view, &lt;code&gt;terminatedLines&lt;/code&gt; looks a bit silly: &lt;i&gt;What?? You&amp;#8217;re going to append a newline to each line in a list of lines you just created just so that you can count it??&lt;/i&gt; But, I suspect 
that it isn&amp;#8217;t that bad.  The evaluator pulls values from each line and as it reaches the end of one it should just put a newline at the end of it.  If I&amp;#8217;m wrong about this, please let me know.

&lt;p&gt;In any case, I agree that the code looks better with &lt;code&gt;sum&lt;/code&gt; that it does with &lt;code&gt;foldr (+) 0&lt;/code&gt;.  The big question is &amp;#8211; should we refactor any more?

&lt;p&gt; Someone with the handle &lt;i&gt;sterl&lt;/i&gt; suggested a very cool trick.  I could drop the where clause like this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = 
  x + (sum . map length . take y . terminatedLines) contents
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;And then move on to this:

&lt;code&gt;&lt;pre&gt;
absPosition (Buffer (x, y) contents) = 
  sum . (x:) . map length . take y . terminatedLines $ contents
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;What&amp;#8217;s going on here?  Well as &lt;i&gt;sterl&lt;/i&gt; put it, we&amp;#8217;re summing anyway so why not prepend the &lt;code&gt;x&lt;/code&gt; onto the list that we are already summing? 

&lt;p&gt;Part of me likes this and part of me doesn&amp;#8217;t.  One the one hand, it&amp;#8217;s brief, but on the other hand, the code isn&amp;#8217;t telling us why it is doing what it is doing anymore. In the original code, there is an algorithm:
&lt;blockquote&gt;To get the absolute position, add the x position of the location to the sum of the lengths of all of the previous lines.&lt;/blockquote&gt;

&lt;p&gt;In the new code, the algorithm is:
&lt;blockquote&gt;To get the absolute position, sum the current x position with the lengths of all of the previous lines.&lt;/blockquote&gt;

&lt;p&gt;Wait, that&amp;#8217;s sort of the same, isn&amp;#8217;t it?

&lt;p&gt;This example points to a fundamental dilemma that I have with naming in Haskell.  I&amp;#8217;m used to introducing names in lower-level languages to bridge the gap between intention and mechanism, but what happens when your mechanism is so high-level that it can speak for itself?  Maybe we don&amp;#8217;t need names as much?

&lt;p&gt;Now, I know as I write this that someone is going to look at this as an extreme statement.  It isn&amp;#8217;t. Names are useful, and indispensable, but really they are only one of several ways of communicating meaning.  In each case, we have to pick the right tool for the job.  With Haskell, I think that programmers communicate with structure as much as they communicate with names.  It&amp;#8217;s the body-language of their code.</description>
      <pubDate>Tue, 11 Aug 2009 12:25:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:571c0f66-0389-492d-93c5-2992eedf53af</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/11/naming-and-body-language-in-functional-code</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Imposing the Edges Later</title>
      <description>&lt;p&gt;Here&amp;#8217;s what wikipedia has to say about lazy evaluation: 

&lt;blockquote&gt;The benefits of lazy evaluation include: performance increases due to avoiding unnecessary calculations, avoiding error conditions in the evaluation of compound expressions, the ability to construct infinite data structures, and the ability to define control structures as regular functions rather than built-in primitives.&lt;/blockquote&gt;

&lt;p&gt;It&amp;#8217;s all true, but I think it misses a point.  One of the nicest things about lazy evaluation is that it enables a different form of abstraction.  Take a look at &lt;a href=http://www.physics.emory.edu/~weeks/software/mandel.c&gt;this code&lt;/a&gt;.  It computes the &lt;a href=http://en.wikipedia.org/wiki/Mandelbrot_set&gt;Mandelbrot Set.&lt;/a&gt;  There are many ways to code up this algorithm, but the code I just linked to is very typical &amp;#8211; it&amp;#8217;s a doubly nested loop which iterates over a specific rectangle in the complex plane.  It&amp;#8217;s hard to see anything that&amp;#8217;s awkward about its iteration strategy in a procedural language &amp;#8211; the algorithm does require starting and ending points in the plane.

&lt;p&gt;Let&amp;#8217;s look at a different way of approaching this.  Here&amp;#8217;s part of a Mandelbrot Set generator in Haskell:

&lt;code&gt;&lt;pre&gt;
mandelbrot :: Double -&amp;gt; [[Int]]
mandelbrot incrementSize =
  [[ escapeIterations $ translate offset . translate (x,y) . mandel
    | x &amp;lt;- increments]
    | y &amp;lt;- increments] 
   where increments = [0.0, incrementSize .. ]

window :: (Int, Int) -&amp;gt; (Int, Int) -&amp;gt; [[a]] -&amp;gt; [[a]]
window (x0, x1) (y0, y1) = range y0 y1 . map (range x0 x1)
  where range m n = take (n-m) . drop m

&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;The interesting bit is the &lt;code&gt;mandelbrot&lt;/code&gt; function.  It contains a doubly-nested list comprehension which, essentially, mimics the behavior of a doubly-nested loop in the procedural algorithm.  However, there is one interesting difference.  This list comprehension actually represents the mandelbrot computation across a full quarter of the infinite plane &amp;#8211; it goes from zero to infinity in x and y.  All we have to do is pass it an increment size and it is configured to create that grid. If we want to zoom in to a particular place in the Mandelbrot Set, we can use the &lt;code&gt;window&lt;/code&gt; function like this:

&lt;code&gt;&lt;pre&gt;
-- compute the mandelbrot from (10,10) inclusive to
-- (20,20) exclusive with an increment of 0.05 

window (10, 20) (10, 20) $ mandelbrot 0.05
&lt;/pre&gt;&lt;/code&gt;   

&lt;p&gt;The trick to this code is in &lt;code&gt;window&lt;/code&gt;&amp;#8217;s &lt;code&gt;range&lt;/code&gt; computation.  It takes a starting position, an ending position, and a list and it drops all of the elements of the list before the starting position, without evaluating them, and then it takes, from the front of the new list, &lt;code&gt;end - start&lt;/code&gt; elements, giving us a sub-range from the original list.  When that elements of that sub-list are evaluated, the computation for each point in the window occurs.    

&lt;p&gt;This code yields the computation that we want and the neat thing is, we are really only computing the piece we specified with &lt;code&gt;window&lt;/code&gt;.  We&amp;#8217;ve essentially formed a general computation and imposed the edges later.

&lt;p&gt;Looking back now at the imperative mandelbrot code, it&amp;#8217;s easy to see that it was, in a way, mixing two concerns.  The code which determined the range was mixed with the code which generated the set.  Laziness allows us to separate the two concerns.  

	&lt;p&gt;&lt;i&gt;Note: There are much more direct ways of computing the Mandelbrot Set in Haskell.  Here&amp;#8217;s one which is &lt;a href=http://warp.povusers.org/MandScripts/haskell.html&gt;particularly brief.&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Sat, 08 Aug 2009 11:12:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:04c166b9-ce54-4fda-8121-7e8898845702</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/08/imposing-the-edges-later</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Functional Refactoring and &amp;quot;You Can't Get There From Here&amp;quot;</title>
      <description>&lt;p&gt;I&#8217;ve been working in Haskell recently, and I find myself doing much less refactoring.  In fact, I rewrite more than I refactor.  
&lt;p&gt;I&#8217;m not talking about massive refactoring, but rather the sort of micro-refactoring that I do to move from one algorithm to another.  If you are working in an imperative language, you can often make micro waypoints &amp;#8211; little testable steps along the way as you change your code from one shape to another.  You can add a variable, confident that behavior won&#8217;t change because you haven&#8217;t used it yet, and you can move one statement down below another, changing the order of a calculation if (again) you are confident that the overall computation is order in variant.  As &lt;span class="caps"&gt;I TDD&lt;/span&gt; my code, I do those sorts of things.  I often refactor by introducing a parallel computation in the same method as the old one, and if the test passes, I knock out the old way of doing things and leave the shiny new one.
&lt;p&gt;In Haskell, however, I don&#8217;t do that, and it reduces the amount of time that I spend refactoring.  Yes, I rename variables, add parameters, and introduce where-clauses, etc. But, refactoring in Haskell seems different, and I think I know why now.  There are two reasons and they sort of intermingle.

&lt;p&gt;Imperative programs are built of little state changing variables, and one of the effects is that you can have lots of little bits changing independently. It&#8217;s rather easy to add mutating state variables and have &#8220;several calculations in the air&#8221; in a method while you are along the way toward reducing it to one. In functional programming, however, you use bigger pieces. Instead of looping, you use map or fold &amp;#8211; you end up with terse code which packs a lot of punch.  
&lt;p&gt;Here&#8217;s a function which determines a position within a document from a column/row coordinate (affectionately named x and y here):
&lt;code&gt;&lt;pre&gt;absPosition :: Buffer -&amp;gt; Int
absPosition (Buffer (x, y) contents) = x + lenPreviousLines contents
  where lenPreviousLines = foldr ((+).length) 0 . take y . terminatedLines
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;The thing to get from this example if you don&#8217;t read Haskell is that it is fully compositional.  Each of the dots in the definition of lenPreviousLines is a composition operation.  We apply the terminatedLines function to a string, and take its output and pass it to the function &#8216;take y&#8217;, then we pass its output to &#8216;foldr ((+).length) 0&#8217;.  The net effect (take my word for it) is that we end up with the sum of the lengths of a set of text lines.
&lt;p&gt;That small piece of code performs a rather large chunk of work.  It takes a string, splits it into lines, appends a newline to each line, takes y of the lines and then sums the count of their characters.  But, to me, that&#8217;s not the interesting part.  The interesting part is that it is tight.  There is no space for a parallel computation, no place where you can perform some computation off to the side and progressively move toward a different algorithm.  If you want to change the algorithm you essentially rewrite it &amp;#8211; you replace some chunk of that code with another chunk of code.
&lt;p&gt;One of the beautiful things about pure functional programming is that it eliminates side effects.  That, by itself, might not impress you, but the thing that it enables is very powerful, when you remove side effects you lose all barriers to composability.  It&#8217;s easy to make little tinker-toy-like parts which you piece together to do your work, and, in fact, that&#8217;s exactly what has happened in Haskell.  Most of the time, you can find a little function which will do what you want.  You don&#8217;t often have to drop down into primitive list operations or recursion.  Instead, you have this substrate of little composable bits.  We don&#8217;t have anything like that in traditional languages.  We drop down to loops, assignment and mutable variables all the time.  
&lt;p&gt;The end result, I think, is that a lot of refactoring in Haskell is more like rewriting, or (to be precise) it is more like the &#8216;Substitute Algorithm&#8217; refactoring in Martin Fowler&#8217;s Refactoring book.  In pure code, there isn&#8217;t any extra bandwidth for building up parallel computations.  The pieces are bigger, so many refactorings are more like leaps than micro-adjustments toward a goal.
&lt;p&gt;Is this good or bad?  I don&#8217;t know.  I think it is just different.  Personally, I&#8217;m happy to have higher level pieces, although, I have to admit, I sometimes miss the fluidity of work with more granular primitives.  It&#8217;s a place you can always drop down to and build back up from.  In Haskell, at the micro-level, you have to fix your sights on a new target and rebuild.</description>
      <pubDate>Wed, 05 Aug 2009 11:18:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:0190c2b3-dfec-498a-8439-cf9b701fabef</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/08/05/functional-refactoring-and-you-cant-get-there-from-here</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Static Typing vs. Dynamic Typing</title>
      <description>&lt;p&gt;Some sculptors prefer clay and some prefer marble.  Some choose on a piece by piece basis, depending upon what the work demands.  The important thing is to respect the medium and understand its affordances and limitations.&lt;/p&gt;</description>
      <pubDate>Mon, 27 Jul 2009 14:13:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:737ffb08-f063-4828-a40f-b3fe03464860</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/07/27/static-typing-vs-dynamic-typing</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Ending the Era of Patronizing Language Design</title>
      <description>&lt;p&gt;Earlier this year, I was asked to speak at a Ruby Conference.   I was happy to go, but I also felt a bit out of place.  I haven&#8217;t done much Ruby, but I&#8217;ve admired the language from afar.  I have a number of friends who&#8217;ve left C++ and Java to jump toward Ruby and Python and for the most part, they are happy. They do great work, and they enjoy it.  They are living proof that the nightmare scenarios that people imagine about dynamic languages aren&#8217;t inevitable.  You can program safe, secure, high quality applications in dynamically typed languages. People do it all the time, but that&amp;#8217;s cultural knowledge. If you are in a culture, you hear about all of the things which are normal which appear odd from outside. If you aren&amp;#8217;t, you don&amp;#8217;t.&lt;/p&gt;

&lt;p&gt;This is pretty much the situation I&#8217;ve been in with Ruby, up to a point.  I haven&#8217;t written a large Ruby application.  I&#8217;ve tinkered around with the language and written utilities but as far as total immersion goes &#8212; no, I&#8217;ve never been totally immersed in the language but that hasn&#8217;t kept me from learning noticing interesting things at the edge. One of the striking things that I&#8217;ve noticed is that the attitude of Rubyists toward their language is a bit different.  They seem to have an &lt;i&gt;ethic of responsibility&lt;/i&gt; that I don&#8217;t see in many other language cultures.&lt;/p&gt;

&lt;p&gt;Ethic of responsibility?  What do I mean by that?&lt;/p&gt;

&lt;p&gt;I guess I can explain it this way.  In many language communities, people are very concerned with the &#8220;right way&#8221; to do things.  They learn all of the warts and edges of the language and they anticipate the ways that features could be misused.  Then, they starting writing advice and style guides &#8212; all the literature which tells you how to avoid problems in that language.  The advice goes on and on. Much of it centers around legitimate language defects.  Some languages make you work hard to use them well.  Other bits of advice, though, are really extensions of culture.  If a language gives you mechanisms to enforce design constraints, it doesn&#8217;t feel quite right to not use them.  As an example, consider &lt;code&gt;sealed&lt;/code&gt; and &lt;code&gt;final&lt;/code&gt; in C# and Java.  Both of those constructs do pretty much the same thing and people do go out of their way to advise people on how they should be used to protect abstractions.  It&#8217;s interesting, however, that languages like Ruby, Python, and Groovy don&#8217;t have anything similar, yet people do write solid code in those languages.&lt;/p&gt; 

&lt;p&gt;Let&#8217;s leave aside, for a minute, the debate over static and dynamic typing.  What I think is more important is the issue of tone.  In some languages you get the sense that the language designer is telling you that some things are very dangerous, so dangerous that we should prohibit them and have tools available to prohibit misuse of those features.  As a result, the entire community spends a lot of time on prescriptive advice and workarounds.  And, if the language doesn&#8217;t provide all of the features needed to lock things down in the way people are accustomed to, they become irate.&lt;/p&gt;

&lt;p&gt; 
I just haven&#8217;t noticed this in Ruby culture.&lt;/p&gt;

&lt;p&gt;  
In Ruby, you can do nearly anything imaginable.  You can change any class in the library, weave in aspect-y behavior and do absolutely insane things with meta-programming.  In other words, it&#8217;s all on you.  You are responsible.  If something goes wrong you have only yourself to blame.  You can&amp;#8217;t blame the language designer for not adding a feature because you can do it yourself, and you can&amp;#8217;t blame him for getting in your way because he didn&amp;#8217;t.&lt;/p&gt;

&lt;p&gt;
So, why aren&#8217;t more people crashing and burning?  I think there is a very good reason.  When you can do anything, you have to become more responsible.  You own your fate.  And, that, I think, is a situation which promotes responsibility.&lt;/p&gt;

&lt;p&gt;For years, in the software industry, we&#8217;ve made the assumption that some language features are just too powerful for the typical developer &#8212; too prone to misuse.  C++ avoided reflection and Java/C# avoided multiple-inheritance. In each case, however, we&#8217;ve discovered that the workarounds that programmers apply when they legitimately need a missing feature are worse than what the omission was meant to solve.  Blocks and closures are good immediate example.  There are tens of thousands of applications in the world today which contain duplication that you can really only remove with the template method design pattern or by creating a tiny class which encapsulates the variation.  If blocks or closures were available, programmers would be more likely to tackle the duplication and arrive at much less cluttered design.&lt;/p&gt;

&lt;p&gt;Meta-programming features are yet another example.  Business applications are rife with situations where you need to know the value, type, and name of a piece of data, yet we use languages in which these sorts of capabilities have to be hand-coded and over and over again. The fact that it took decades for the industry to arrive at something as useful as ActiveRecord in Rails is due primarily to the attitude that some language features are just too powerful for everyone to use.&lt;/p&gt;

&lt;p&gt;
We&#8217;ve paid a price for that attitude.  Fortunately, I think we are getting past it.  The newer breed of languages puts responsibility back on the developer.  But, language designers do persist in this sort of reasoning &#8212; this notion that some things should not be permitted.  If you want to see an example of this style of reasoning see the metaprogramming section in this blog of Bruce Eckel&#8217;s  ( &lt;a href=http://www.artima.com/weblogs/viewpost.jsp?thread=260578&gt;http://www.artima.com/weblogs/viewpost.jsp?thread=260578&lt;/a&gt; ).  I respect Bruce, and I realize he isn&#8217;t speaking as a language designer, but I offer that as a example of that type of reasoning &#8212; reasoning about what should be permitted in a language rather than what puts a bit more control and responsibility in the hands of programmers.  Maybe decorators work in 95% of the cases where you would want to do metaprogramming in an application, but there is a price to that choice, and it isn&#8217;t just the workarounds in 5% of the cases.  The additional price is a decreased sense of responsibility and ownership.  I think that those human dimensions have far more impact on software than many people suspect.&lt;/p&gt;

&lt;p&gt;
The fact of the matter is this: it is possible to create a mess in every language.  Language designers can&#8217;t prevent it. All they can do is determine which types of messes are possible and how hard they will be to create.  But, at the moment that they make those decisions, they are far removed from the specifics of an application.  Programmers aren&#8217;t.  They can be responsible. Ultimately, no one else can.&lt;/p&gt;</description>
      <pubDate>Mon, 13 Jul 2009 13:44:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:69e0768a-edc0-45fd-ac0c-38c8c7ff9cc5</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/07/13/ending-the-era-of-patronizing-language-design</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>X Tests are not X Tests</title>
      <description>&lt;p&gt;Testing is a slippery subject, and it&#8217;s reasonably hard to talk about for one simple reason: the nomenclature is chaotic.  Years ago, I went to a summit with some testing gurus.  I was one of the lone developers there and I asked about the taxonomy of testing.  Cem Kaner, Bret Pettichord,  Brian Marick, and James Bach went through it for us on a flipchart, and it was a nightmare.  You can name tests after their scope: (unit, component, system), their place in the development process (smoke, integration, acceptance, regression), their focus (performance, functional) their visibility (white box, black box), the role of the people writing them (developer, customer).. The list goes on.  There are far more than I can remember.&lt;/p&gt;

&lt;p&gt;Why is it so confusing?  There are are a couple of reasons.  One is that different communities have developed different nomenclature over time.  But, let&#8217;s face it, that&#8217;s true in most fields.  The thing which makes testing nomenclature worse is that the tests themselves aren&#8217;t all that different, or at least, they are often not different enough for us to for us to distinguish them without being told.  Yes, we can tell the difference between a unit test and an acceptance test in most systems, but really there is no force which prevents tests of different types from bleeding through into each other.  Often the &#8220;type&#8221; of a test is more like an attribute: &#8220;here I have a blackbox smoke test, written by a developer for component integration.&#8221;  In the end, all we have are tests and each of them can serve purposes beyond the purpose we originally intended.&lt;/p&gt;

&lt;p&gt;Earlier today, I read a blog by Stephen Walther: &lt;a href=http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx&gt;&lt;span class="caps"&gt;TDD&lt;/span&gt; Tests are not Unit Tests&lt;/a&gt;.  In it, he draws some distinctions between various types of testing.  It&#8217;s great that he wrote it because it&#8217;s nice for us to have mental categories for these things, but we have to remember is that they really are just categories.  We get to choose how distinct they will be.  When I write code, most of my &lt;span class="caps"&gt;TDD&lt;/span&gt; tests end up being the same as my unit tests.  I find value in forcing that overlap, and in general, I think overlapping test purposes are great to the degree that the purposes don&amp;#8217;t conflict. You get more for less that way.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t see any remedy for the muddle of test types.  We will continue to make up terms to distinguish tests.  We&amp;#8217;ll just have to remember that the types are labels, not bins.</description>
      <pubDate>Mon, 13 Apr 2009 11:48:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:198bd544-9462-4558-9212-989882ced158</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/04/13/x-tests-are-not-x-tests</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>A Brief Collection of Convenient Lies about Functional Programming</title>
      <description>&lt;p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;i&gt;A value is the instantaneous state of an object.&lt;/i&gt; &amp;#8211; In OO languages, we have objects. In FP languages, we throw out the object and instead manipulate the values it would take on over time.
&lt;li&gt;&lt;i&gt;Algebraic data types are classes.&lt;/i&gt; &amp;#8211; Every case in an &lt;span class="caps"&gt;ADT&lt;/span&gt; is a state that an &#8220;object&#8221; can be in.

&lt;code&gt;&lt;pre&gt;
data Tree = Empty 
          | Leaf Int 
          | Node Tree Tree
&lt;/pre&gt;&lt;/code&gt;

When we write functions over ADTs, we are obliged to cover all of the cases.  So, for instance, if we define depth for Empty, we have to define depth for the Leaf and Node cases as well.  When we do, we can evaluate &lt;i&gt;depth t&lt;/i&gt; for any tree value and have a well-defined result.
&lt;li&gt;&lt;i&gt;The functions which we define over an &lt;span class="caps"&gt;ADT&lt;/span&gt; can be considered its public interface.&lt;/i&gt; &amp;#8211; There&#8217;s a school of thought which says that encapsulation doesn&#8217;t matter in an functional programming language because values are immutable and corruption can&#8217;t happen.  Nothing could be further from the truth.  If we add or remove a case from an &lt;span class="caps"&gt;ADT&lt;/span&gt; all of the functions which pattern match against it are impacted.  While we don&#8217;t need to have an encapsulation boundary as tight as we might have in an OO language &amp;#8211; it pays to be conscious of how far ADTs travel in a program.  Encapsulation is the act of forming a boundary by transforming an &lt;span class="caps"&gt;ADT&lt;/span&gt; into some other form of data.
&lt;/ol&gt; 
&lt;/p&gt;
&lt;p&gt;
Each of these statements is a lie, an artful simplification, but they are a convenient and not entirely false way of thinking about functional programming until it becomes second-nature.&lt;/p&gt;</description>
      <pubDate>Mon, 23 Mar 2009 10:19:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:96dfa233-e7b6-4c3c-b5e4-6f2d4ff07191</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/03/23/a-brief-collection-of-convenient-lies-about-functional-programming</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>The Successor Value Pattern</title>
      <description>&lt;p&gt;Functional programming is in the air.  It&amp;#8217;s nearly unavoidable. Even if you haven&#8217;t heard people talk about it or haven&#8217;t read a blog about it, you&#8217;ve probably seen its influence in your project.  People are taking ideas that they learned in functional programming and applying them in straight object-oriented code.  In Java, where there are no closures, today you are much more likely to encounter someone&#8217;s hand-rolled fold or map abstraction, and even if they haven&#8217;t gone that far, you are likely to find attempts to replace mutable data with immutable data.  It&#8217;s part of the learning process, and there are some interesting patterns which occur along the way.
&lt;/p&gt;

&lt;p&gt;OO programmers often think in terms of entities.  They imagine objects with identity and  changeable local state; messages sent to objects alter their local state and trigger further message sends.  Classic OO is intrinsically time-oriented.  How do we pull this into a functional world?  One thing that we can do is choose to see an entity as a series of values over time.  Here&#8217;s one way to do it.  If we have an entity like this:
&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
public class EventDay {
    private LocalDate date;

    ...

    public void advance() {
        do {
            date = RegionalEventCalendar.nextValidDate(date)
        } while (!fitsLocalCalendar(date));
    }

    ...
}

&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;We can change it to this:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
public class EventDay {
    private final LocalDate date;

    ...

    public EventDay next() {
        return new EventDay(prospectiveDay(date));
    }

    ...
}

&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;This is the &lt;i&gt;successor value pattern&lt;/i&gt;.  The notion is that you model state change as a series of value transformations.  Is this good?  Well, successor value is extremely common in functional programming languages.  In Haskell, for instance, you don&#8217;t have mutation so you are always constructing new values.  When Scala and F# are used in a functional style, you do the same thing; but is this a good idea in Java, C#, and C++?  One concern is that the runtimes and libraries of those languages might not be as well tuned for continual reconstruction of value representations of the larger domain objects that we often see in OO designs.  On the surface, however, &lt;i&gt;successor value&lt;/i&gt; is nice; it gives us a mapping to immutable values and a dose of referential transparency.
&lt;/p&gt;

&lt;p&gt;&lt;i&gt;Successor Value&lt;/i&gt; has an interesting quality from a type perspective.  You compute successor values using a function which takes a type to another value of that same type.  In the example above, &lt;code&gt;next&lt;/code&gt; is a function like that.  It maps from &#8216;this&#8217;, which has the type EventDay, to a new EventDay. In category theory, this is called an endomorphism.  It&#8217;s a relationship with some cool characteristics.  One of them is closure. You can chain any number of endomorphic operations and still end up with the type you started with:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
LocalDate next  = date.nextDay().nextWeek().fridayAfter();
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;
This is really about as encapsulated as you can get.  Endomorphic chains don&#8217;t betray their representations and they don&#8217;t force users to use new types.  In a way, you can look at an endomorphic chain as a state machine over an entity, spread out over time.
&lt;/p&gt;

&lt;p&gt;If you are used to thinking in terms of entities, you can mechanically translate entities into values and mapping functions.  However, the better thing is to rethink your data types a bit. Sometimes the mapping from entities to values is clean but often with a bit of thought you can end up with representations which are better tuned for functional work.&lt;/p&gt;</description>
      <pubDate>Sun, 22 Mar 2009 11:03:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:9069d8ed-dd87-4cb4-8252-180bea0aad4d</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/03/22/the-sucessor-value-pattern</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>10 Papers Every Programmer Should Read (At Least Twice)</title>
      <description>&lt;p&gt;I spent most of yesterday afternoon working on a paper I&#8217;m co-writing.  It was one of those days when the writing came easy.  I was moving from topic to topic, but then I realized that I was reaching too far backward &amp;#8211; I was explaining things which I shouldn&#8217;t have had to explain to the audience I was trying to reach.&lt;/p&gt;

&lt;p&gt;When I first started writing, one of the pieces of advice that I heard was that you should always imagine that you are writing to a particular person.  It gets your juices going &amp;#8211; you&#8217;re automatically in an explanatory state of mind and you know what you can expect from your audience.  I was doing that, but I noticed that I was drifting.  I was losing my sense of audience. I started to explain one thing, and then I realized that I would have to explain something else to help it make sense. I couldn&#8217;t imagine that person any more. How could I know what they know and what they don&#8217;t?&lt;/p&gt;

&lt;p&gt;
The problem I was experiencing is only getting worse. People come into programming from many different directions.  Some started in other fields, and others started programming as teens.  Some started with &lt;span class="caps"&gt;BASIC&lt;/span&gt;, others started with Ruby or C.  The industry is filled with knowledge, but it isn&#8217;t common knowledge. It isn&#8217;t knowledge that we all share. We have to dig for it because of a peculiar fact about our industry: we reinvent our languages and notations every ten years.  It&#8217;s hard to find deeply technical books and articles which stand the test of time in software: they are all Latin within 20 years.&lt;/p&gt;

&lt;p&gt;So, I was thinking about this and trying to not to get too glum.  I realized that instead of complaining, I could help by pointing to some papers which are easily available online and which (to me at least) point to some of the most interesting ideas about software.  To me, these are classic papers which contain deep &#8220;things you oughta know&amp;#8221; about code &amp;#8211; the material you work with.&lt;/p&gt;

&lt;p&gt;
We&#8217;ve taken an interesting turn in the industry over the past ten years.  We&#8217;ve come to value experiential learning much more, and we&#8217;ve regained a strong pragmatic focus, but I think it would be a shame if we lost sight of some of the deeper things which people have learned over the past 50 years.  Rediscovering them would be painful, and (to me) not knowing them would be a shame.&lt;/p&gt;

&lt;p&gt;Here&#8217;s the original list.  It&#8217;s a rather personal list of foundational papers and papers with deep ideas. I wrote it &amp;#8220;off the cuff&amp;#8221; and threw it into a tumblr blog the other day and I got responses from people who suggested others.  I&#8217;ll add those in a later blog.&lt;/p&gt;

&lt;p&gt;Most are easy to read but some are rough going &amp;#8211; they drop off into math after the first few pages.   Take the math to tolerance and then move on. The ideas are the important thing.&lt;/p&gt; 

	&lt;ol&gt;
	&lt;li&gt;&lt;a href="http://sunnyday.mit.edu/16.355/parnas-criteria.html"&gt;On the criteria to be used in decomposing systems into modules&lt;/a&gt; &amp;#8211; David Parnas&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://research.sun.com/techrep/1994/abstract-29.html"&gt;A Note On Distributed Computing&lt;/a&gt; &amp;#8211; Jim Waldo, Geoff Wyant, Ann Wollrath, Sam Kendall&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://portal.acm.org/citation.cfm?id=365257"&gt;The Next 700 Programming Languages&lt;/a&gt; &amp;#8211; P. J. Landin&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://portal.acm.org/citation.cfm?id=359579"&gt;Can Programming Be Liberated from the von Neumann Style?&lt;/a&gt; &amp;#8211; John Backus&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://cm.bell-labs.com/who/ken/trust.html"&gt;Reflections on Trusting Trust&lt;/a&gt; &amp;#8211; Ken Thompson&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.6083"&gt;Lisp: Good News, Bad News, How to Win Big&lt;/a&gt; &amp;#8211; Richard Gabriel&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.29.363"&gt;An experimental evaluation of the assumption of independence in multiversion programming&lt;/a&gt; &amp;#8211; John Knight and Nancy Leveson&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.50.7565"&gt;Arguments and Results&lt;/a&gt; &amp;#8211; James Noble&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://c2.com/doc/oopsla89/paper.html"&gt;A Laboratory For Teaching Object-Oriented Thinking&lt;/a&gt; &amp;#8211; Kent Beck, Ward Cunningham&lt;/li&gt;
		&lt;li&gt;&lt;a href="http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.31.562"&gt;Programming as an Experience: the inspiration for Self&lt;/a&gt; &amp;#8211; David Ungar, Randall B. Smith&lt;/li&gt;
	&lt;/ol&gt;


&lt;p&gt;&lt;i&gt;(edit: Added a brief synopsis of each of them and why I think they are special):&lt;/i&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;On the criteria to be used in decomposing systems into modules &amp;#8211; Parnas&lt;/b&gt;&lt;/p&gt;
&lt;p&gt;This is a very old paper, but it is more than a classic.  In in it, Parnas introduces a forerunner to the &lt;i&gt;Single Responsibility Principle&lt;/i&gt;.  He introduces the idea that we should use modularity to hide design decisions &amp;#8211; things which could change.  People still don&amp;#8217;t consider this as often as they should.&lt;/p&gt;

&lt;p&gt; Another thing I really like in the paper is his comment on the &lt;span class="caps"&gt;KWIC&lt;/span&gt; system which he used as an example.  He mentioned that it would take a good programmer a week or two to code. Today, it would take practically no time at all.  Thumbs up for improved skills and better tools.  We have made progress.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;A Note On Distributed Computing &#8211; Waldo, Wyant, Wollrath, Kendall&lt;/b&gt;&lt;/p&gt;&lt;p&gt; Abstraction is great but it can only go so far.  In this paper, the authors lay to rest what was once a pervasive myth &amp;#8211; that we could design a distributed system and make distribution transparent.  Ever wonder why you had to implement specific interfaces to do remoting in Java?  This is why. &lt;/p&gt;&lt;p&gt; In the aftermath it might seem hard to believe that people thought this was possible.  I think we can we partially thank this paper for that.
&lt;/p&gt;
&lt;p&gt;&lt;b&gt;
The Next 700 Programming Languages &amp;#8211; Landin&lt;/b&gt;&lt;/p&gt;&lt;p&gt; Most of us have spent a lot of time working in traditional programming languages, but functional programming languages are slowly seeing an uptick and many OO languages are gaining functional features. This paper (which reads like a tutorial) makes an argument for an expression-oriented style of programming. It also lays the foundation for lazy evaluation. &lt;/p&gt;
&lt;p&gt;One of the other neat things about this paper, from a historical point of view, is that there is a discussion section at the end in which there a number of questions and comments about whether making indentation significant in a language is a good idea.  I was thrown to see people asking whether or not this would be a problem for functions which span over several pages(!).&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Can Programming Be Liberated from the von Neumann Style? &#8211; Backus&lt;/b&gt;&lt;/p&gt;&lt;p&gt; John Backus is known for a number of achievements in computer science.  He received the &lt;span class="caps"&gt;ACM&lt;/span&gt; Turing Award for his work on Fortran.  This paper, which he presented at the award ceremony was rather shocking at the time because it said, in essence, &#8220;we got it wrong.&#8221;  Backus took the opportunity to make a plea for pure functional programming.  His arguments were convincing and they helped to set a research agenda which is just now starting to make some waves in the mainstream.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Reflections on Trusting Trust &#8211; Thompson&lt;/b&gt;&lt;/p&gt;&lt;p&gt; I once heard that when this paper was presented, people in attendance rushed back to de-compile their C compilers and look for, er, problems.  This paper unveiled a hard problem at the heart of computer security.  If you&#8217;ve spent any time at all thinking about security, you need to read it.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Lisp: Good News, Bad News, How to Win Big &#8211; Gabriel&lt;/b&gt;&lt;/p&gt;&lt;p&gt; This paper is a bit atypical in this list.  It&#8217;s aimed at the Lisp community and it comes off as a bit of a lament.  But, hidden deep within it is the Gabriel&#8217;s description of the &#8216;Worse is Better&#8217; philosophy &amp;#8211; an idea with profound implications for the acceptance and spread of technology.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;An experimental evaluation of the assumption of independence in multiversion programming &#8211; John Knight and Nancy Leveson&lt;/b&gt;&lt;/p&gt;&lt;p&gt; Behind this dry title lies something very interesting. I first heard about this paper from Ralph Johnson in a newsgroup discussion about program correctness.  It turns out that one of the avenues that engineers in other disciplines take to make their products stronger &amp;#8211; redundancy &amp;#8211; doesn&#8217;t really work in software.  Multi-version programming was the idea that you could decrease faults in critical systems by handing the spec to several teams, having them develop the software independently, and then having the systems run in parallel.  A monitoring process verifies their results and if there is any discrepancy it picks the most common result.  Sounds like it should work, right? Well..&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Arguments and Results &#8211; Noble&lt;/b&gt;&lt;/p&gt;&lt;p&gt; I think that all of the other papers in this list are rather well known in some circles. This one isn&#8217;t, or if it is, I just haven&#8217;t found that circle yet.  What I like about this paper is that it takes something which we deal with every day &amp;#8211; the set of arguments and results of functions &amp;#8211; and it works them through a series of variations which just don&#8217;t occur to many people.  The fact is, every function that you work with has a number of possible directions if could evolve in.  Not all of them are appropriate, but if you know the possible directions, you&#8217;re richer for it.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;A Laboratory For Teaching Object-Oriented Thinking &#8211;  Beck, Cunningham&lt;/b&gt;&lt;/p&gt;&lt;p&gt; There are an incredible number of papers about there about object orientation.  The thing which makes this one great is its directness.  OO went through a number of stages.  It was once fresh and novel, then it was ornate, and then it became matter-of-fact.  This paper hits upon key ideas which many people don&#8217;t talk about much any more: anthropomorphism and dropping the top/down perspective.  It also shows you how you can design with index cards. It may not sound cool but it is incredibly effective.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Programming as an Experience: the inspiration for Self &#8211; Ungar, Smith&lt;/b&gt;&lt;/p&gt;&lt;p&gt; How many people know about the Self Project? Not enough in my opinion.  Self was an attempt to take two ideas in computing and push them as far as humanly possible.  The first was minimalism: the Self programming language was thoroughly in the Lisp and Smalltalk vein &amp;#8211; everything was defined in terms of the smallest number of primitives possible.  The other idea was direct manipulation &amp;#8211; the idea that the object metaphor could be pushed all the way in the user interface &amp;#8211; the programmer and user sit with a mouse in a sea of directly clickable objects and use them for everything.  If they could&#8217;ve gotten away with dropping the keyboard, I think they would&#8217;ve.&lt;/p&gt;

&lt;p&gt;The amount of technology which the Self project threw off is terrifying also.  Self broke ground in dynamic language optimization and VM design.  Chances are, your VM uses technology it pioneered.  It&#8217;s also one of the more perverse ironies that the most widely distributed programming language today (JavaScript) is a prototype-based programming language which borrowed ideas from the hyper-research-y Self.&lt;/p&gt;

&lt;p&gt;What would you add to the list?&lt;/p&gt;</description>
      <pubDate>Thu, 26 Feb 2009 20:49:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:2a8b62cf-d3ae-4c95-9105-32548762637b</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/02/26/10-papers-every-programmer-should-read-at-least-twice</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>The Bloat at the Edge of Duplication Removal (The Orange Model)</title>
      <description>&lt;p&gt;
There are times when I sit down to work on some piece of code and I see a bit of duplication.  I remove it. Then I see a bit more, and a bit more. When I&#8217;m done with all of my extractions, I look back at the code and notice that it&#8217;s increased in size about 20 or 30 percent.  If I&#8217;m working with someone else, it&#8217;s often a shock for them.  After all, we are used to thinking that code gets smaller when we remove duplication. Often it does, but not always.
&lt;/p&gt;

&lt;p&gt;Let&#8217;s take a look at an example:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
private void adjustPaths() {
  pathNew = pathNew.removeFirstSegments(1).removeFileExtension()
                  .addFileExtension("class");
  pathOld = pathOld.removeFirstSegments(1).removeFileExtension()
                  .addFileExtension("class");
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That&amp;#8217;s six lines of code with obvious duplication.  Now let&amp;#8217;s remove it.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
private void adjustPaths() {
  pathNew = adjustPath(pathNew);
  pathOld = adjustPath(pathOld);
}

private IPath adjustPath(IPath path) {
  return path.removeFirstSegments(1).removeFileExtension()
               .addFileExtension("class");
}
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;
Now we have 9 lines.&lt;/p&gt;
&lt;p&gt;
What&#8217;s going on here?  Well, when we extract duplication, we have to put it someplace, and that operation isn&#8217;t free.  In all languages, there is a cost in space for separate functions.  In Java, the cost includes method declaration line and lines for the curly braces.  In Python, the cost is (again) the declaration line and some whitespace to separate the function from other functions.&lt;/p&gt;

&lt;h2&gt;Code is like an Orange&lt;/h2&gt;
&lt;p&gt;The mental model I have for this is that code can be separated into two parts.  One part is structural.  It gives form to the code.  It consists of all of the cruft that we use to declare a method.  The stuff inside is the meat &#8212; the pure computational code which is held in place by the structural bits. 
&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
/* cruft */ private IPath adjustPath(IPath path) { 
/* meat  */    return path.removeFirstSegments(1).removeFileExtension()
/* meat  */                .addFileExtension("class");
/* cruft */ } 
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;This pattern is rather common.  In fact, you&#8217;ll see it in most living things.  The muscle tissue in your body (the meat) is held in place by a sheath called fascia.  The same pattern occurs in fruit and vegetables.  The pulp in an orange is held in place by fascia too, it&amp;#8217;s the white part between the sections:&lt;/p&gt;

	&lt;p&gt;&lt;a href="http://www.flickr.com/photos/92231089@N00/3289039006/" title="P2170002 by mfeathers256, on Flickr"&gt;&lt;img src="http://farm4.static.flickr.com/3455/3289039006_e1d1c2a3a7.jpg" width="500" height="375" alt="P2170002" /&gt;&lt;/a&gt;&lt;/p&gt;


&lt;p&gt;Here&#8217;s what duplication removal does, structurally.  It allows you to pull out redundant bits of pulp from big sections, yielding smaller sections, but the side effect is that you end up with more fascia.  Duplication removal increases the ratio of fascia to pulp.  If the amount of pulp you are able to remove exceeds the size of the fascia you introduce, the net amount of code decreases, otherwise it might increase.&lt;/p&gt;

&lt;p&gt;In general, I think that a high fascia to pulp ratio is better for maintenance.  It gives us is a higher surface area to volume ratio for our code.  This can enhance testability and make it easier to compose new software &amp;#8211; we already have smaller more understandable pieces.&lt;p&gt;

&lt;p&gt;The cost of fascia, however, can be disturbing. In the normal formatting convention for C++ a new method will give you at least 5 lines.  You need the line for the method declaration in the header, one for the definition in the source file, a line apiece for the beginning and ending braces and a newline to separate the method from next one.  In Haskell, you can get away with 2 if the method is a one-liner and you forgo type declarations. The thing to notice is that it is never zero.  There&#8217;s always some space overhead when we create a new method.  The question is whether the amount of code that we remove as duplication swamps the addition overhead or not.&lt;/p&gt;

&lt;p&gt;
We can model duplication removal this way &#8212; the number of lines T&#8217; after removing n stretches of x contiguous lines is:&lt;/p&gt;
&lt;p&gt;
T&#8217;  = T &amp;#8211; (n &amp;#8211; 1)x + c + n&lt;/p&gt;

&lt;p&gt;We start with T, the original number of lines in the program and we remove n &amp;#8211; 1 stretches of x lines.  We leave in the nth x (as the method we extract) and we add in c which is the number of lines of fascia for a method in our language.  We also add in n again since we will need to leave in a line for the call at each of the n sites where the code was originally duplicated.&lt;/p&gt;
&lt;p&gt;
According to the equation, we can end up with more code if c is large or if n and x are small.  Aggressive refactoring with a c of 3 or 4 and and an n of 2 and an x of 1 will definitely increase code size.&lt;/p&gt;
&lt;p&gt;
Again, is this bad? No, I think it&#8217;s just something to be aware of.  Removing duplication increases the ratio of fascia to pulp.  To me, it&#8217;s only annoying when I&#8217;m working in a language with a high c value.
&lt;/p&gt;</description>
      <pubDate>Tue, 17 Feb 2009 21:51:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:e1985d6a-2bb3-46b9-8491-d1085b55c5a7</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2009/02/17/the-bloat-at-the-edge-of-duplication-removal-the-orange-model</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>A Wish List for the Next Mainstream Programming Language</title>
      <description>&lt;p&gt;It&amp;#8217;s been fun watching the reactions to new features in C# 4.0.  Some people love them.  Others wonder, legitimately, where it is all going to end.  The argument for feature addition is simple: over time we find better ways of doing things and our languages, as tools, should allow us that flexibility.  The only downside to this strategy is that you end up with sprawling, complex languages over time &#8211; you never get to revisit the foundations.&lt;/p&gt;

&lt;p&gt;Fortunately, however, people design new languages all the time and some of them do eventually enter the mainstream.  We get a chance to start over and address foundational problems. And, that&amp;#8217;s nice because we can do better than Java and C# for mainstream development and I don&#8217;t think there is any way to mutate either language into a better foundation.&lt;/p&gt;

&lt;p&gt;
Before I launch into the wish list, however, I want to set the context.&lt;/p&gt;

&lt;p&gt;When I say &#8220;mainstream language&#8221; I am talking about languages which are in the Java/C#/VB market space &#8211; languages which are light on rocket science, seen as suitable for large-scale development, and don&#8217;t scare people.  So, I&#8217;m not going to suggest dynamic typing or (on the other side of the coin) tight Hindley-Milner type systems and lazy evaluation.  I love those approaches and I&#8217;m happy (in particular) that Ruby is gaining widespread acceptance, but I&#8217;m not going to fight that fight here.  In the immediate future, for whatever reason, there will be development shops which feel much more comfortable with traditional static typing &amp;#8211; the kind found in Java, C#, and VB.  Given that, the question becomes: what can we do to make that sort of language better?&lt;/p&gt;

&lt;p&gt;Here&#8217;s my list:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;i&gt;Immutability by Default&lt;/i&gt; &amp;#8211; Over the past few years, a rather broad consensus has emerged around the idea that code is easier to understand and maintain when it has less mutable state.  This isn&#8217;t a new idea; it&#8217;s been around for as long as functional programming, but our recent concerns with concurrency and our move toward multi-core computing just underscore the state problem.  A mainstream language should, at the very least, make mutable data something special.  References should be immutable by default and mutable state should be marked by a special keyword so that its use leaps out at you. It&#8217;s too late for the current crop of languages to make such a pervasive change, but the next mainstream language could.

&lt;li&gt;&lt;i&gt;Support for Components&lt;/i&gt; &amp;#8211;  In large-scale development, teams have to manage usage and dependency across an organization.  The notions of &lt;i&gt;public&lt;/i&gt;, &lt;i&gt;protected&lt;/i&gt;, and &lt;i&gt;private&lt;/i&gt; are too coarse as protection mechanisms, and we really need scopes larger than class, assembly, and package.  In the end, this sort of protection is a social issue, so we should have mechanisms which make use very easy within a team (3-10 people working together) and somewhat more manageable between teams.  It&#8217;s odd that language-based support for this work stopped with Ada and the Modula family of languages.  Java&#8217;s recent move toward support for modules seems to be an exception.

&lt;li&gt;&lt;i&gt;Support for Scoped and Explicit Metaprogramming&lt;/i&gt; &#8211; In the past, language designers avoided adding meta-programming support to their languages because they were scared it would be abused.  However, we&#8217;ve learned that without meta-programming support, people create yet another distinctive type of mess.  If there is a middle ground for mainstream languages it probably involves scoping the use of metaprogramming and making it far more detectable.  If, for instance, all of the code which modifies a given component had to be registered with some easily locatable component-specific construct, maintenance would be much easier.

&lt;li&gt;&lt;i&gt;Support for Testing&lt;/i&gt; &#8211; This one is only a matter of time, I think.  In the last 10 years we&#8217;ve seen an explosion of mocking tools and testing frameworks.  It&#8217;s not clear to me that we&#8217;ve reached any sort of consensus yet, but I suspect that at the very least we could add constructs to a language which make mocking and stubbing much easier.  It&amp;#8217;s also about time that languages attempt to solve the problems that dependency injection addresses.

&lt;li&gt;&lt;i&gt;Imposed I/O Separation&lt;/i&gt; &#8211; This is the controversial one.  The more I work with Haskell, the more I notice that there is a beneficial discipline that comes from factoring your program so that its points of contact with the outside world can not be mixed with the pieces doing the work.  When you first start to work that way, it feels like a straitjacket, but I think the benefit is apparent to anyone who has had to go on a spelunking expedition in an application to find and mock parts of the system which touch the outside world.  Is that discipline too much for a mainstream language?  I hope not.
&lt;/ol&gt;

&lt;p&gt;So, that&#8217;s my list.   There is no &#8220;grand language planning board&#8221; which decides these things.  We will move forward chaotically like ever other industry, but I  do hope that some of these features make it into the next mainstream programming language.&lt;/p&gt;</description>
      <pubDate>Mon, 29 Dec 2008 20:06:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:08858466-5200-453c-aa91-8efe4ed44032</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/12/29/a-wish-list-for-the-next-mainstream-programming-language</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Speaking in Russia</title>
      <description>&lt;p&gt;The week after next, I&amp;#8217;ll be visiting Russia to do some training and some University lectures.
&lt;/p&gt;
&lt;p&gt;
The lectures will be at Ural State University, Ekaterinburg.  Each starts at 18:30:
&lt;/p&gt;
&lt;p&gt;
Monday, Dec 8th
&lt;u&gt;Recovering a Code Base&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;Wednesday, Dec 10th
&lt;u&gt;Error Handling as a First Class Consideration in Design&lt;/u&gt;
&lt;/p&gt;
&lt;p&gt;
Thursday, Dec 11th
&lt;u&gt;Design Sense &amp;#8211; Reaching Consensus on Excellence&lt;/u&gt;
&lt;/p&gt;&lt;p&gt;
I&amp;#8217;ll also be speaking to the Agile Russia group in Moscow Friday, Dec 12th.
&lt;/p&gt;&lt;p&gt;
The internet tells me it might be colder than Miami.  I will probably bring a jacket.
&lt;/p&gt;</description>
      <pubDate>Thu, 27 Nov 2008 13:50:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:106ff73e-d30d-4d5c-936c-0e8924837761</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/11/27/speaking-in-russia</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Exploding Link Stubs in C</title>
      <description>&lt;p&gt;When you&#8217;re working in a batch of legacy C code, it&#8217;s often hard to build and test just a part of it.  You may want to build some set of functions, but then you discover that they call other functions, and those functions call yet other functions.   When link dependencies are very bad, you may discover that you&#8217;re linking in the entire system.&lt;/p&gt;
&lt;p&gt;Fortunately, there is a way out of this.  
Pick a set of files that appear to be a &#8220;component&#8221; and attempt to build them into an executable along with a simple main function.&lt;/p&gt; 
&lt;p&gt;You will get link errors.&lt;/p&gt;
&lt;p&gt;Create a file called &lt;code&gt;&amp;lt;componentname&amp;gt;_stubs.c&lt;/code&gt;  and then go through each of the link errors.  Look up the full declaration of the variable or function the error describes.  Create a stub for each of them in the stub file.&lt;/p&gt;  &lt;p&gt;Here&#8217;s an example of a function stub:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
int irc_send_ppr(struct ppr *pprn, int nSize)
{
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;
The only problem with this is that you have to place something in the stub function.  For functions which return values you need to, at the very least, provide a return value.  But what should it be?&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
int irc_send_ppr(struct ppr *pprn, int nSize)
{
  /* is negative -1 okay?   If it isn&#8217;t, how will we know? */
  return -1;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;There is alternative ++:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
int irc_send_ppr(struct ppr *pprn, int nSize)
{
  assert(!&#8221;irc_send_ppr boom!!&#8221;);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This is an &lt;i&gt;exploding link stub&lt;/i&gt;.  When you have it in place, you &lt;i&gt;will&lt;/i&gt; know when a function you&amp;#8217;re testing calls a stub.  When you see the boom you go to the code and replace the assert with a better stub implementation.&lt;/p&gt;

&lt;p&gt;When you use link stubs, you have to be able to build your component two different ways.  Production builds link to the rest of the code. Test builds link to the stubs and a testing main. There&amp;#8217;s no need to stub out all of the external functions that a component uses.  Many low level functions can remain direct calls, but stubbing out calls to other high level components can give you a decent amount of leverage as you try to get an area under test.&lt;/p&gt; &lt;p&gt;Fortunately, for any given component you only have to go through the massive grunt work once.  Once you do, you can reap the reward of easier testing in that component forever.&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;++ Note: If you are using &lt;span class="caps"&gt;C99&lt;/span&gt;, you can genericize this code by using the &lt;code&gt;__func__&lt;/code&gt; predefined macro.  In any function, &lt;code&gt;__func__ &lt;/code&gt; expands to the name of the enclosing function.&lt;/i&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 07 Nov 2008 19:33:00 -0600</pubDate>
      <guid isPermaLink="false">urn:uuid:b4de149a-1d4a-417e-8846-e967259ea38c</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/11/07/exploding-link-stubs-in-c</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Data Rattle</title>
      <description>&lt;p&gt;Take a look at this code:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;public static int findPositionInInterval(int [] content, int start, int end) {
  for(int n = 0; n &amp;lt; content.length; n++) {
    int current = transform(content[n]);
    if (start &amp;lt;= current &amp;#38;&amp;#38; current &amp;lt;= end) {
      return n;
    }
  }
  return -1;
}
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;How does it look?  Great? Poor? Is it code with a glaring problem?&lt;/p&gt;

&lt;p&gt;Hold that thought for a second and then take a look at this code:&lt;/p&gt;

&lt;code&gt;&lt;pre&gt;
public static int findPositionInInterval(final int [] content, final int start, final int end) {
  for(int n = 0; n &amp;lt; content.length; n++) {
    final int current = transform(content[n]);
    if (start &amp;lt;= current &amp;#38;&amp;#38; current &amp;lt;= end) {
      return n;
    }
  }
  return -1;
}
&lt;/pre&gt;&lt;/code&gt;

&lt;p&gt;I like it better.&lt;/p&gt;

&lt;p&gt;The fact of the matter is: mutable state hurts.  Unless you&#8217;ve done some functional programming you might not realize that it hurts, but it does.  It may feel okay to walk barefoot, but if some gives you a comfy pair of shoes you quickly learn that, well, your feet &lt;i&gt;were&lt;/i&gt; irritated by pebbles and twigs and there was a better way of walking around, you just didn&amp;#8217;t know about it.  Fixing state and making it immutable is just like that.  When you become used to that style, you notice that it&amp;#8217;s easier to reason about your code.&lt;/p&gt;

&lt;p&gt; 
In my mind&#8217;s eye, the first snippet is a like a box containing loose parts.  If you shake it, it rattles.  Parts that don&#8217;t need to move are fixed in place by &lt;i&gt;final&lt;/i&gt;.  In code as brief as this, it doesn&amp;#8217;t smell mightily, but it smells nonetheless.&lt;/p&gt;

&lt;p&gt;
So mutable data is a smell and we can fix it. However, there&amp;#8217;s a problem.  I&#8217;d argue that the second snippet is just a little noisier than the first one.   Java forces us to do something special to make data immutable.  C# and C++ are the same way: mutable is the default and immutability requires special keywords.  There are some languages which make immutability the default, or least make don&amp;#8217;t make you pay the price of an extra token to make something immutable.  Haskell, OCaml, Scala, and F# all fit into this category.   In the older languages, however, we&#8217;ll continue to have a lot of rattling data.&lt;/p&gt;

&lt;p&gt;Listen for it.&lt;/p&gt;</description>
      <pubDate>Tue, 28 Oct 2008 01:01:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:ad99a0ad-7f85-4d40-9d24-6179e07bf4b8</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/10/28/data-rattle</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>The Fact/Intention Gap</title>
      <description>&lt;p&gt;The other day, I was browsing some code with a team and we came across a cluster of static methods.  I looked at them and asked whether they were used someplace else without an object reference. I could&amp;#8217;ve done a &lt;i&gt;find references&lt;/i&gt; in the &lt;span class="caps"&gt;IDE&lt;/span&gt;, but one of the team members had the answer: &amp;#8220;No, they&amp;#8217;re just used here.&amp;#8221;&lt;/p&gt;

&lt;p&gt;&amp;#8220;Okay, so why are they static?&amp;#8221;, I asked.&lt;/p&gt;

&lt;p&gt;&amp;#8220;Well, the &lt;span class="caps"&gt;IDE&lt;/span&gt; pointed out that they don&amp;#8217;t refer to any instance data, so I made them static.&amp;#8221;&lt;/p&gt;

&lt;p&gt;Technically, there&amp;#8217;s nothing wrong with that.  I do the same thing sometimes.  I make a method static to document its independence of instance data. But, this scenario highlights something important about static and a few other keywords: their uses can be seen as &lt;i&gt;statements of fact&lt;/i&gt; or &lt;i&gt;statements of intention&lt;/i&gt;. Static can be read as &amp;#8220;Hey, this function doesn&amp;#8217;t use any instance data, and you should know that.&amp;#8221; Or, it can be read as &amp;#8220;I am making this static so that it can be used easily anyplace without an instance.&amp;#8221;  When you&amp;#8217;re trying to read a pile of unfamiliar code, it&amp;#8217;s nice to know whether you can count on one meaning or the other.&lt;/p&gt;

&lt;p&gt;I don&amp;#8217;t think I&amp;#8217;ve ever heard anyone articulate this directly, but there&amp;#8217;s a tendency in a lot of &lt;i&gt;best practice&lt;/i&gt; literature to close the gap between fact and intention.  Joshua Bloch&amp;#8217;s advice to use make fields final whenever you can in Java is a good example.  The traditional advice to make methods private whenever they are not used outside of a class is another.&lt;/p&gt;
&lt;p&gt;Part of me feels that closing the gap is a good practice but the fact is, there are holes in it.  If you are developing a library or a framework, you do have to write code that may not reflect the facts of your code, but rather will reflect the facts of your code &lt;i&gt;and&lt;/i&gt; the code that people write to use it or extend it.  Beyond that, it might be overly conservative to reduce visibility of things that aren&amp;#8217;t used beyond a particular scope.  For instance, imagine a method that is used only by other methods of a class.  We understand the invariant of the class and we see that the method could be public.  We could make it private now, but that means that anyone who wants to make it public later would have to do some re-analysis to arrive at the answer that we have right now.&lt;/p&gt;

&lt;p&gt;The Fact/Intention Gap is a very real thing.  Whether we know it or not, we confront it every time we try to understand unfamiliar code.  I think there&amp;#8217;s only one way to solve it, and that&amp;#8217;s to try to separate fact from intention in our languages and tooling.  Imagine what it would be like if your &lt;span class="caps"&gt;IDE&lt;/span&gt; gave you a visual indicator for all methods which didn&amp;#8217;t use instance data. If it did, you could use static on methods only when you want to indicate that the intention is to use them without an instance.&lt;/p&gt;

&lt;p&gt;It seems that &lt;span class="caps"&gt;IDE&lt;/span&gt; developers are moving in this direction. I wonder if any language designers will follow suit.&lt;/p&gt;</description>
      <pubDate>Tue, 21 Oct 2008 11:57:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:400b7f15-fb95-44b9-b56c-a00edba13d71</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/10/21/the-fact-intention-gap</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>If-Methods Redux</title>
      <description>&lt;p&gt;So was looking over my blog on &lt;a href=http://blog.objectmentor.com/articles/2008/09/23/if-methods&gt;If-Methods&lt;/a&gt; this morning and I realized that I fell into a trap.  I was solving one problem but thinking about another.&lt;/p&gt;  
&lt;p&gt;There I was working on lexer code and I thought &amp;#8220;Hmm&amp;#8230; I&amp;#8217;d really like to extract these if-blocks.&amp;#8221; I mulled it over a bit, and while thinking about the &lt;i&gt;general&lt;/i&gt; problem of naming if-blocks, I settled on a naming scheme that I thought would be good in general, but it ended up being a bit odd in particular.  The comments on the blog show this.  Many of them offer good suggestions for dealing with the particular case I showed, but I was really after something different, a good general-purpose naming scheme for methods extracted around conditional.&lt;/p&gt;
&lt;p&gt;I&amp;#8217;m going to try this again and see if I can come up with a case which motivates a generic naming scheme a bit better.&lt;/p&gt;
&lt;p&gt;Consider this chunk of code.&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    if (sensorTripped) {
        ...
        alarm.sound();
    }
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We could extract the body of the if-block, but in a long method, we might want to extract the entire concern.  What should we call it?&lt;/p&gt;  
&lt;p&gt;One option is to call it &lt;code&gt;soundAlarm()&lt;/code&gt;.  It&amp;#8217;s not quite true, however.  The sounding is conditional.&lt;/p&gt;  
&lt;p&gt;We could, on the other hand, get explicit: &lt;code&gt;soundAlarmIfSensorTripped()&lt;/code&gt;.  This smacks more of implementation than intention, however.  Now, having said that, I do think that in legacy code these names are great reminders as you make your first cut.. slicing and dicing a long method.  They help you remember what is going on as you plan your next move.&lt;/p&gt;
&lt;p&gt;Here&amp;#8217;s another option: &lt;code&gt;handleAlarmActions()&lt;/code&gt;.  I don&amp;#8217;t like this one very much.  The word &lt;i&gt;handle&lt;/i&gt; is nice, but the name makes it sound like the alarms are an event.&lt;/p&gt;
&lt;p&gt;How about this one? &lt;code&gt;handleSensorStateChange()&lt;/code&gt;.  Much better in my opinion.  I&amp;#8217;m not quite sure how to justify this but I think that it is better to name these sorts of methods after their condition rather than their action. In the legacy code situation, at least, it helps to accent conditions.  In not-so legacy code, it separates concerns at a deeper level.&lt;/p&gt;
&lt;p&gt;Are there exceptions?  Of course.  Null pointer checks, guards.. the conditions that indicate errors rather than problem domain conditionality.. code surrounded by these can be safely extracted into methods named for their primary action.&lt;/p&gt;
&lt;p&gt;This:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    if (alarm != null) {
        ...
        alarm.sound();
    }
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;becomes this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    ...
    soundAlarm();
    ...
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with this definition:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
    void soundAlarm() {
        if (alarm == null) {
            // handle error, throw exception, etc.
        }
        ...
        alarm.sound();
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That code still has problems, but that extraction was a way forward.&lt;/p&gt;
&lt;p&gt;All this is good, as far as it goes, but there is still a problem.  The &lt;i&gt;handle&lt;/i&gt; naming idiom seems to always call for generalization when I use it in real cases.&lt;/p&gt;
&lt;p&gt;Imagine a condition like this:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;
if (sensor != null 
        &amp;#38;&amp;#38; sensor.isTripped() 
        &amp;#38;&amp;#38; configFlag == X_MODE 
        &amp;#38;&amp;#38; usingBasicIO) {
    ...
}
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;It would be &lt;i&gt;handle&lt;/i&gt;.. what?&lt;/p&gt;
&lt;p&gt;Sometimes you have a good name for a condition, sometimes you don&amp;#8217;t.  A convention would be nice, however.&lt;/p&gt;</description>
      <pubDate>Fri, 26 Sep 2008 12:05:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:e78814ad-1bb5-4247-892e-a12920149635</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/09/26/if-methods-redux</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>If-Methods</title>
      <description>I was working on some lexical analysis code this morning and I was stumped by a name.  Or, rather, the lack of a good name.  The code was a long series of if-statements, each of which tested for a lexical condition and then handled it:
&lt;pre&gt;&lt;code&gt;
if (Character.isLetter(ch) &amp;#38;&amp;#38; identCharCount &amp;gt; MIN_IDENT_LEN) {
    currentToken.append(ch);
}

if (Character.isWhitespace(char ch) {
    tokens.add(new Token(tokenBuffer.toString(), TokenType.IDENT));
    currentToken = new StringBuilder();
}
&lt;/code&gt;&lt;/pre&gt;
The list of ifs went on and on.  Each of them did something distinct and I wanted to break the method down into a set of meaningful sub-methods, but how?

The typical pattern to use is to extract the bodies of the if-statements into separate methods, provided you can find good names for them.   However, when I imagined what the code would look like after that refactoring, I didn&#8217;t really like it.  It was still rather wordy:
&lt;pre&gt;&lt;code&gt;
if (Character.isLetter(ch) &amp;#38;&amp;#38; identCharCount &amp;gt; MIN_IDENT_LEN) {
    appendToCurrentToken(ch);
}

if (Character.isWhitespace(char ch) {
    addToken(currentToken.toString(), TokenType.IDENT);
}
&lt;/code&gt;&lt;/pre&gt;
So, I thought that I&#8217;d extract each of the if-statements into its own method:
&lt;pre&gt;&lt;code&gt;
void onIdentChar(char ch) {
    if (Character.isLetter(ch) 
            &amp;#38;&amp;#38; identCharCount &amp;gt; MIN_IDENT_LEN) {
        currentToken.append(ch);
    }    
}

void onWhitespace(char ch) {
    if (Character.isWhitespace(char ch) {
        tokens.add(new Token(tokenBuffer.toString(), 
                             TokenType.IDENT));
        currentToken = new StringBuilder();
    }
}
&lt;/code&gt;&lt;/pre&gt;
The calling code would certainly look cleaner:
&lt;pre&gt;&lt;code&gt;
    onIdentChar(ch);
    onWhitespace(ch);
&lt;/pre&gt;&lt;/code&gt;
&lt;p&gt;The only problem is that the method names are a bit of a lie.  When we use an &#8220;on&#8221; prefix we&#8217;re writing in &lt;i&gt;event style&lt;/i&gt;.  We expect that a method like &lt;code&gt;onWhitespace&lt;/code&gt; is called only when we have whitespace.  It shouldn&#8217;t have to check for it.&lt;/p&gt;

&lt;p&gt;I&#8217;ve run into this situation before.  How do you name a function which consists of a single if-block?  The situation crops up frequently in legacy code.  You want to break up a large method into several smaller ones and you&#8217;re left with a dilemma: do you extract the entire if-statement or just its body?&lt;/p&gt;

&lt;p&gt;Here&amp;#8217;s another example.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;
if (replyFlag == RE_SEND) {
    ...
    // code that sends a mail message
    ...
}
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;I once asked a friend what he&amp;#8217;d name a method for that if-block if we extracted it and he said &amp;#8220;sendEmailIfNeeded.&amp;#8221;  We both flinched and moved on to other things, but let&amp;#8217;s think about that name a bit.  Part of it talks about intention and part of it talks about implementation.  Maybe we can pull the implementation bit out and concentrate on the condition:&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
if (needResend()) {
    ...
    // code that sends a mail message
    ...
}
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;Better.  Now, how about extracting it like this?&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
ifNeedsResend();
&lt;/pre&gt;&lt;/code&gt;

	&lt;p&gt;It&amp;#8217;s sort of like the &lt;i&gt;event style&lt;/i&gt; I wrote about earlier.  The method is a handler for a condition and the condition is checked in the method. Violation of the &lt;i&gt;Single-Responsiblity Principle&lt;/i&gt;?  Perhaps, but I do know that I&amp;#8217;m looking at some code now that has been clarified by this idiom.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
public List&amp;lt;Token&amp;gt; getTokens() {
    onStart();
    for (int n = 0; n &amp;lt; text.length(); n++) {
        char ch = text.charAt(n);

        ifLetter(ch);
        ifWhitespace(ch);
        ifLeftParen(ch);
        ifRightParen(ch);
        ifVerticalBar(ch);
        ifColon(ch);
        ifDigit(ch);
    }
    onFinish();
    return tokens;
}
&lt;/code&gt;&lt;/pre&gt;
What do you think?</description>
      <pubDate>Tue, 23 Sep 2008 18:26:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:2b495fb7-ffcc-4a75-8661-24ae960f5f1c</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/09/23/if-methods</link>
      <category>Michaels Musings</category>
    </item>
    <item>
      <title>Type Scum</title>
      <description>&lt;p&gt;Getting existing code under test is hard work, but it is fruitful.  Yes, you get code that is easier to change, but more importantly, you get knowledge &amp;#8211; you learn things about programming which make you better at avoiding common traps.  Sadly, many of these traps aren&amp;#8217;t well recognized yet.&lt;/p&gt;


	&lt;p&gt;The trap that I am going to write about today is one that I call &lt;i&gt;type scum&lt;/i&gt;.  It&amp;#8217;s most prevalent in C and C++ but it can attack in any of the traditional statically typed languages.&lt;/p&gt;


	&lt;p&gt;&lt;i&gt;Type Scum&lt;/i&gt; is the cruft in a code base which makes it impossible to compile a single file without an entire sub-stratum of defined types.  I&amp;#8217;m not talking about the primary, or even the secondary abstractions in your system, but rather the 200 or so basic types and structs that your abstractions depend upon.&lt;/p&gt;


	&lt;p&gt;Again, the problem is worst in C++ and C. At some point, every C or C++ developer feels the urge to isolate him or herself from the basic types of the language.  The &lt;i&gt;unsigned int&lt;/i&gt; type becomes &lt;i&gt;uint32&lt;/i&gt; and &lt;i&gt;unsigned char *&lt;/i&gt; becomes &lt;i&gt;uchar16_ptr&lt;/i&gt;. And, if that was all, it would be okay.  But no, people define &lt;i&gt;data transfer objects&lt;/i&gt; which aggregate these type pseudonyms together into large muddles. No file can compile without bringing in a world of types which cushion the code from dangerous things like the platform and testing harnesses.&lt;/p&gt;


	&lt;p&gt;No wait, testing harnesses are good. What can we do?&lt;/p&gt;


	&lt;p&gt;The unfortunate thing is that it is very hard to pull &lt;i&gt;type scum&lt;/i&gt; out of a system once it&amp;#8217;s been infected, but we can learn how to avoid it or at least manage it better:&lt;/p&gt;


&lt;ol&gt;
&lt;li&gt;If you must provide a sub-stratum of basic types in your system, do it in one place.  There should be a single library (and associated headers) that you include whenever you need it.  This library (and headers) should contain nothing else.
&lt;li&gt;If you must create &lt;span class="caps"&gt;DTO&lt;/span&gt; (Data Transfer Object) types, minimize them.  A good general purpose structure can carry a wide variety of different types of data and simplify testing.
&lt;li&gt;Push the DTOs to the edges.  There are some systems where you really do care whether an internal computation happens in &lt;i&gt;unsigned long int&lt;/i&gt; or &lt;i&gt;unsigned long long int&lt;/i&gt; but they are rare.  Basic data types and tolerances matter when two systems need to agree upon them, and that happens at component boundaries.  In many systems, the internal code can use platform types directly.
&lt;/ol&gt;

	&lt;p&gt;There you go.  &lt;i&gt;Type scum&lt;/i&gt; bad.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m sure that some people reading this will say &amp;#8220;Hey, isn&amp;#8217;t this the exact opposite of the advice that people give for a system with the &lt;i&gt;primitive obsession&lt;/i&gt; code smell?&amp;#8221;  The answer is &amp;#8220;yes.&amp;#8221;  But, to me, &lt;i&gt;primitive obsession&lt;/i&gt; is a different problem.  It&amp;#8217;s something which is the result of a lack of real behavioral abstractions in a system, not the lack of larger data holders.&lt;/p&gt;


	&lt;p&gt;Different problem.&lt;/p&gt;


	&lt;p&gt;&lt;i&gt;Type scum&lt;/i&gt; bad.&lt;/p&gt;</description>
      <pubDate>Mon, 08 Sep 2008 17:43:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:71bb9d92-6aa0-4899-bbc0-e912321d06cc</guid>
      <author>Michael Feathers</author>
      <link>http://blog.objectmentor.com/articles/2008/09/08/type-scum</link>
      <category>Michaels Musings</category>
      <category>Clean Code</category>
    </item>
  </channel>
</rss>
