logo
  • Jobs
  • About Me
  • Contact
  • Home
« Resolving comment spam with MovableType
Model View Presenter »

Avoiding Failure

Posted January 7th, 2005 by Matt Berther

Yesterday, the UPS truck delivered my recent purchase of Code Complete, Second Edition.

Having never read the original Code Complete and having heard so much about it, I could hardly wait to open the box and immediately started skimming through some of the sections. Yesterday evening, I started at page 1 and am working my way through it. I’m now about 20% into the book and am thoroughly impressed with it.

This book is filled with many “why didnt I think of that” items, including one of the best things Ive heard in a while. In the chapter that talks about building your designs (Chapter 5, if you have the book), the author mentions a heuristic called ‘Avoid Failure’.

The idea is that design failures could be avoided if you consider the ways that the design might fail, rather than just copy the attributes of other successful designs.

This is a very intriguing idea, and one that can be taken outside of the realm of building design. A place that I saw an immediate benefit by thinking about avoiding failure is in testing (unit testing or quality testing).

For example, if I have a simple unit test that does this:

class MyMath
{
    public static int Divide(int dividend, int divisor)
    {
        return divident / divisor;
    }
}
 
[TestFixture]
class MyMathFixture
{
    [Test]
    public void TestDivide()
    {
        int expected = 6 / 2;
        int value = MyMath.Divide(6, 2);
        Assert.AreEqual(expected, value);
    }
}

Our test passes perfectly. However, what happens when we think about avoiding failure? Is there another test hiding in there? What if we pass 0 as the divisor?

The same idea can be used when testing a web page. Let’s say that we have a simple data entry form that takes a persons birthdate and saves it into the database.

A common testing scenario would be to enter the following information into the corresponding fields on the web page:

Name: John Doe
Birth Date: 1/2/73

Once this is done, look at the data in the database. Does it match? Yes! It must work… right?

Maybe! Now, if we think about avoiding failure, we may ask ourselves what happens if I type the persons name into the birth date field and the birth date into the name field.

These are trivial examples, but one can see how you might get a lot better test coverage when thinking about considering the way an application could fail, rather than the way it should work.

This entry was posted on Friday, January 7th, 2005 at 3:27 pm and is filed under Uncategorized. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Simon Harriyott
January 8th, 2005

I got the same book for Christmas. I’m not that far through it yet, but from what I’ve read so far, it seems excellent. I did skip to the section of personal character, which was very interesting, and not what I expected to find in the book. I’m looking forward to finishing it.

Elegant Code
January 9th, 2005

Healthwise Bloggers

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>
-->

Social
  • mattberther on twitter
Syndication
Archives
  • November 2008
  • September 2008
  • August 2008
  • June 2008
  • May 2008
  • April 2008
  • March 2008
  • February 2008
  • January 2008
  • December 2007
  • November 2007
  • October 2007
  • September 2007
  • August 2007
  • July 2007
  • June 2007
  • May 2007
  • April 2007
  • March 2007
  • February 2007
  • January 2007
  • December 2006
  • November 2006
  • October 2006
  • September 2006
  • August 2006
  • July 2006
  • June 2006
  • May 2006
  • April 2006
  • March 2006
  • February 2006
  • January 2006
  • December 2005
  • November 2005
  • October 2005
  • September 2005
  • August 2005
  • July 2005
  • June 2005
  • May 2005
  • April 2005
  • March 2005
  • February 2005
  • January 2005
  • December 2004
  • November 2004
  • October 2004
  • September 2004
  • August 2004
  • July 2004
  • June 2004
  • May 2004
  • April 2004
  • March 2004
  • February 2004
  • January 2004
  • December 2003
  • November 2003
  • October 2003
  • September 2003
  • August 2003
  • July 2003
  • June 2003
  • May 2003
  • April 2003
  • March 2003
Jobs
mattberther.com © 2003 - 2008