Archive

Archive for the ‘Agile’ Category

Candles, by the Micro ISV

October 11th, 2008 No comments

An almost burnt-down lit candle on a candle ho...Image via Wikipedia

Required materials:

  • Plain Paraffin Wax (about 1/2 pound)
  • Double Boiler
  • Wooden spoon
  • Bowls for cold water
  • Candle thermometer
  • Kitchen Stove
  • Wick

And the instructions:

  1. Cut the wax into small pieces.
  2. Bring the water gently to the boil. Place wax in the double boiler.
  3. Stir until the wax is melted. Once melted, try to keep the wax at 71C / 160F.
  4. Cut the wick to the desired length, then dip into the wax. Allow the wax to cool between dippings for a minute or two.
  5. Continue the dipping and cooling process. After a few dippings, you can speed up the process by dipping in cold water.
  6. Repeat the process until the candle reaches the desired thickness.
  7. When finished and cooled, cut a flat base on the candle.

Et voila.

So what’s so interesting about candle dipping from the perspective of software development?
Well, after 1 dip, what do you have? Well, you have a piece of string
covered in wax, neither use nor ornament. But after just a few dips,
you will have the beginnings of a candle, albeit at this stage, a very
slim one. So very quickly, we have something that could function as a
working candle.

Then, over time, we add layers, additional wax, additional
functionality. In time, this candle willl become an impressive church
candle, with a good 4 or 5 inches in diameter. Just as your app, with
very humble beginnings, will, with proper technique, become a very
impressive app.

The use of candle dipping as a metaphor for software development is not new in the world of Agile Software Development.
The essence is that we work in very small iterations, and we keep a
working application available at all times, just as our candle could
function as a candle at all times throughout its creation.
Functionality, business value, mojo, whatever you want to call it, is
added in vertical strips, just like in candle dipping.

If mojo is added in the order of business value, this process will,
at all times, mean that your application will yield the highest return on investment possible at any given time.

  • Share/Bookmark
Categories: Agile, Micro ISV, Uncategorized Tags:

Code As A Liability

March 11th, 2008 1 comment

Img_debt
Jim Shore
asked recently about what metric might be used to measure technical debt.
Now, sigh and groans over the word ‘metric’ aside, his first suggestion
prompted some thought; namely, SLoC. This was interesting, mostly
because SLoC was once used as a measure of productivity, but here it
was something different. I didn’t like this idea, simply because it
meant that no matter how hard you worked, how mercilessly you
refactored, you would always be increasing technical debt. In other
words, no matter what, you lose. I don’t find this appealing. We went
around the houses a bit talking about using SLoC per feature, or SLoC
per story point, but something very interesting came out of the
discussion.

As software developers, and particularly as a micro ISV, we would
think of our code base as our biggest asset, but how often do we think
of it as potentially our biggest liability? Why a liability? Because it
costs money. It costs money for others to spend time understanding it
(if you aren’t a 1 man band), it costs money to change it, it costs
money to test it, to bugfix it, to refactor it, to add to it, to
integrate it. These are the times that you will notice the interest
payments on your technical debt.

As a micro ISV, technical debt payments can be crippling. Imagine
not being able to make use of you’re new employee because your code is
too hard to understand, because it does not clearly express intent.
Imagine not being able to add a new feature because you’re too worried
about the impact on the stability of your codebase.

The solution is clear. Don’t let technical debt accumulate to a
level such that the interest paments become a barrier to progress. Your
code is your greatest asset, don’t let it become your greatest
liability.

  • Share/Bookmark
Categories: Agile, Uncategorized Tags:

Executable Specifications – Part 2

March 7th, 2008 1 comment

OK, it’s time to get our hands dirty with a little coding. Following
a strong tradition of contrived examples, I’m going to develop a simple
stack class to demonstrate some of the techniques of using executable
specifications to drive the functionality and design of the code base.
For this example I’m going to use NSpec as the specification framework.
We all know what a stack class is, right? It’s sort of a last in, first
out (LIFO) collection.

For the purposes of today, I’m going to say that the interface our stack class will support is as follows: 

public
class
Stack<T>

{


public
Stack();


public
void
Clear();


public
bool
Contains(T item);


public T Peek();


public T Pop();


public
void
Push(T item);

 


// Properties


public
int
Count { get; }

}

 

Now, clearly we’re not going to win any awards for the class, but it should serve its purpose.

So what are the first things we could say about it? Well, when the
stack is empty, its Count should be zero, and trying to call Pop or
Peek should cause an exception. So how might we write that in an
executable specification? Well, let’s take the first one as an example:

using NSpec.Framework;

 

namespace Stack.Specs

{

 [Context]

 public
class
WhenTheStackIsEmpty

    {

  Stack<int> _stack = new
Stack<int>();

 

        [Specification]

  public
void CountShouldBeZero()

        {

   Specify.That(_stack.Count).ShouldEqual(0);

        }

    }

}

That’s the simplest way of expressing that piece of behaviour. And
I’ll need to implement just enough to make that code compile, and the
spec fail. Here’s what I’m starting with:

namespace Stack

{


public
class
Stack<T>

{

 public
int Count

    {

  get

  {

   return -1;

        }

    }

}

}

And firing up the spec runner, I get:

But making the test pass is trivial, by changing the Count property to:

public
int Count

{
 get
 {
  return 0;

 }

}

Don’t cry foul, we’re not done yet. What else did we say about an
empty stack? We said calling pop or peek should cause an exception.
Taking a bit of a short cut, specifying these two bits of behaviour:

[Specification]

public
void PeekShouldThrowException()

{

 MethodThatThrows mtt = delegate()

    {

        _stack.Peek();

    };

 

 Specify.ThrownBy(mtt).ShouldBeOfType(typeof(InvalidOperationException));

}

 

[Specification]

public
void PopShouldThrowException()

{

 MethodThatThrows mtt = delegate()

    {

        _stack.Pop();

    };

 

 Specify.ThrownBy(mtt).ShouldBeOfType(typeof(InvalidOperationException));

}

 

These requirements can easily be met with:

public T Peek()

{

 throw
new
InvalidOperationException();

}

 

public T Pop()

{

 throw
new
InvalidOperationException();

}

 

Now we have 3 passing specs. What else could we say? Well, when the
stack has stuff in it, we’d like the count to be correct, we’d like to
know whether it contains a particular item, we’d like to be able to
clear it, and we’d like things to Pop and Peek in the right order. So
let’s get started by adding a new Context, and a new spec method:

using NSpec.Framework;

 

namespace Stack.Specs

{

    [Context]

 public
class
WhenTheStackContainsItems

    {

  Stack<int> _stack;

 

        [SetUp]

  public
void SetUp()

        {

            _stack = new
Stack<int>();

 

            _stack.Push(0);

            _stack.Push(1);

            _stack.Push(2);

        }

 

        [Specification]

  public
void CountShouldBeCorrect()

        {

   Specify.That(_stack.Count).ShouldEqual(3);

        }

    }

}

Now we’ve got some work to do. This doesn’t compile because we don’t have a Push method yet, so let’s add one:

using System;

 

namespace Stack

{

 public
class
Stack<T>

    {

  int _current = -1;

        T[] _items = new T[10];

 


// Snip

 

  public
void Push(T item)

        {

            _current++;

            _items[_current] = item;

        }

    }

}

 

But shock! We have a failure.

What went wrong? Oh that’s right, we cheated in our initial
implementation of Count, so now it’s time to do it right. In the spirit
of YAGNI (You Aint Gonna Need It) it’s almost always best to fake a
method until you are forced to do it right.

public
int Count

{

 get

    {

  return _current +1;

    }

}

 

4 green dots and 1 happy camper. So let’s move on to checking whether it contains a certain item:

[Specification]

public
void ShouldNotContain999()

{

 Specify.That(_stack.Contains(999)).ShouldBeFalse();

}

 

[Specification]

public
void ShouldContainZeroOneAndTwo()

{

 Specify.That(_stack.Contains(0)).ShouldBeTrue();

 Specify.That(_stack.Contains(1)).ShouldBeTrue();

 Specify.That(_stack.Contains(2)).ShouldBeTrue();

}

 

And some implementation:

public
bool Contains(T item)

{

 foreach (T t in _items)

    {

  if (t.Equals(item))

        {

   return
true;

        }

    }

 

 return
false;

}

 

And we’re good, 8 green dots. What next? Let’d add support for clearing:

[Specification]

public
void ClearShouldEmptyTheStack()

{

    _stack.Clear();

 Specify.That(_stack.Count).ShouldEqual(0);

}

 

Red dot.

public
void Clear()

{

    _current = -1;

}

 

Green dot. Now on to the fun bits, peeking and popping:

[Specification]

public
void ShouldPopThemInTheRightOrder()

{

 Specify.That(_stack.Pop()).ShouldEqual(2);

 Specify.That(_stack.Pop()).ShouldEqual(1);

 Specify.That(_stack.Pop()).ShouldEqual(0);

}

 

Again, our earlier short cuts are biting us, red dot. Let’s iron out the wrinkles:

public T Pop()

{

 if (_current > -1)

    {

        T popped = _items[_current];

        _current–;

 

  return popped;

    }

 else

    {

  throw
new
InvalidOperationException();

    }

}

 

And for the peeking:

[Specification]

public
void PeekShouldReturnTopItem()

{

 Specify.That(_stack.Peek()).ShouldEqual(2);

    _stack.Pop();

 Specify.That(_stack.Peek()).ShouldEqual(1);

    _stack.Pop();

 Specify.That(_stack.Peek()).ShouldEqual(0);

}

 

This gives us the same problem as before, so, ironing again:

public T Peek()

{

 if (_current > -1)

    {

  return _items[_current];

    }

 else

    {

  throw
new
InvalidOperationException();

    }

}

 

There, 15 shiny green dots. We have a rudimentary stack class with
some pretty sever limitations, but in terms of the specifications,
every time we build this code, every time we add to it, or refactor,
every time we fix a bug, these specifications will be here, ready to be
run. Don’t underestimate the confidence these kind of tests can bring
to your micro ISV. Time is precious, and believe me, writing these
specs once, will pay you back very quickly, as it drastically reduced
repetitive, error prone manual checking later.

kick it on DotNetKicks.com

  • Share/Bookmark
Categories: Agile, Uncategorized Tags: