Back from Öresund Agile 2008

Wednesday, June 11, 2008 11:36:20 PM (Romance Standard Time, UTC+01:00)

Yesterday Jesper and I was doing an agile workshop as part of the Öresund Agile 2008 conference in Malmö, Sweden. I have to admit we had set out being pretty ambitious about the content of the workshop. We stuffed everything from Release planning, charting, coding, test-driving, continuously integrating, doing reviews, retrospectives, scrum meetings, planning poker, and discussing engineering practices and process improvement into just one day. I think we can conclude the workshop fully lived up to it's name -- Accelerated Agile!

With Malmö filled with swedish football fans, students celebrating final exams, and of course a lot of skilled people from the agile software community, we had some great days. Not only was it cool doing the workshop itself, but being at a smaller software conference where you actually get a chance to chat with most of the attendees I think is really valuable. I hope everyone else enjoyed it as much as we did (in time the feedback forms will tell!).

As promised during the workshop, we have of course put the latest (and hopefully greatest) version of all the slides online. You can download them from here.

After browsing through the pictures that was taken during the day, I selected some that you'll find below.

Notice the red and green lava lamps in the background. These were controlled by the CruiseControl CI server! I personally think that this was actually more than just a gadget. It brought great visiblity into the project. With these lamps connected to the build system, everyone who entered the conference room (or even looked through the door) could immediately spot if there was currently a problem. Now that is TRULY surfacing problems fast!


The self-organizing team working towards a common goal?


Some laid back discussions of interesting engineering practices.


Our one-day iteration ended with a retrospective, that judging from the smiles were rather positive.


All sorts of important stuff on the wall. Tasks, burn-down, WIP chart, and standard work sheets.

A big thanks to all the dedicated attendees, conference coordinator Gustav Bergman from Softhouse who invited us in the first place, and also Sonny, Lars and Thomas Lundström who assisted us during the entire day!

By Sune Gynthersen

Is TDD Controversial?

Tuesday, October 16, 2007 8:27:51 PM (Romance Standard Time, UTC+01:00)

If you attended the JAOO 2007 conference, or follow the Test-Driven Development community you may have heard of Jim Coplien and his arguments about why you should not use TDD. I believe that Jim said something like "TDD will deteriorate your design", and it made me ask myself -- Is TDD a controversial topic?

So is it? Not if you ask me. If you rewrite the original Red-Green-Refactor mantra from TDD, into "Spec. the feature" > "Implement it" > "Reduce technical debt", it seems to make quite a lot of sense. In fact, I don't really see any other way you could work and maintain your professional integrity!

So is there any risk of bad design or architecture as a result of using Test-Driven Development? Well, only if you neglect that refactoring is a continuous activity of TDD. If you refactor (small and large refactorings) on a continuous basis, I simply do not see how you could have a design- or architectural meltdown. If anyone experience this, I seriously doubt that TDD is the root cause of their problem.

Check out Roy Osherove's blog entry on the topic here.

By Sune Gynthersen

Test Driven Thread Safety

Friday, September 14, 2007 6:22:46 PM (Romance Standard Time, UTC+01:00)
The other day I needed a thread safe collection class. Since .NET 2.0 lack thread safe generic collection classes and because I wanted a ReaderWriterLock for best throughput I decided to write it myself.
Being a TDD-kind of guy, I wanted to start with some failing tests, and focusing on the thread safety of the class I wanted the tests to fail because of lacking thread safety. In this way I would know for sure when the added thread safety mechanisms was actually working.
But how do you write a test that fails because of lacking thread safety? Well, in this case I could start up some threads, make sure that they used the collection methods simultaneously and then assert that only one thread was allowed to do so at a time.
That turned out to be more easy to think than to code. Lets look at the two problems and their solution:
"Making sure that the threads used the collection methods simultaneously". The collection methods are typically so fast that it is practically impossible to arrange for two threads to try to enter a method simultaneously. However, I decided that for testing purposes, I could slow down the methods and thereby ensure that the first thread was still inside the method when the next thread came around. So inside the Collection.Add()-method I added:
   if (assertEnabled)
{
Thread.Sleep(100);
}

"Asserting that only one thread at a time is allowed to execute a method". A thread cannot know whether other threads are running the same method body. However, inside the method body, we can count the number of threads entering and exiting. And then we can add Assert-statements stating the required restriction on the number of concurrent threads in the method. So again, inside the Collection.Add()-method I added:
   if (assertEnabled)
{
Interlocked.Increment(ref writerCount);
Thread.Sleep(100);
Assert.AreEqual(1, writerCount);
Assert.AreEqual(0, readerCount, "trying to write while reading");
}
// the implementation of the method go here
if (assertEnabled)
{
Interlocked.Decrement(ref writerCount);
}

Having these mechanisms in place I could write a test that failed because of the "trying to write while reading"-exception being thrown.
   [Test]
public void WriterWaitForReader()
{
Thread r1 = CreateReader();
Thread w1 = CreateWriter();
r1.Join();
w1.Join();
Assert.That(exception, Is.Null);
}

Now having a failing test, allowed me to add the actual thread safety mechanism using the ReaderWriterLock in the Collection.Add()-method:
   rwLock.AcquireWriterLock(InfiniteTimeOut);
if (assertEnabled)
{
Interlocked.Increment(ref writerCount);
Thread.Sleep(100);
Assert.AreEqual(1, writerCount);
Assert.AreEqual(0, readerCount, "trying to write while reading");
}
// the implementation of the method go here
if (assertEnabled)
{
Interlocked.Decrement(ref writerCount);
}
rwLock.ReleaseLock();

Bringing me a succeeding test. Then I could add tests for the actual functionality of my collection class and the corresponding implementation.
Depending on the project in which this code is being used I could keep asserEnabled==true in production as well as when running the tests (this requires another condition to avoid enabling the Sleep()). Another choice could be to entirely avoid the overhead of the assertEnabled condition by surrounding it with #if DEBUG ... #endif, so the tests only run in debug mode.
Take a look at the example source code (for Visual Studio 2008). By Lars Thorup