Monday, February 16, 2009

Developing With Smaller Steps


My son has been learning to ice skate over the past months. I was lucky enough to use some of my software development skills, to help him become more successful. Here is the story of how my four year old learned how to skate and how you can build better software.

After getting my son all suited up and ready for the ice, he had his first lesson standing by himself. His second lesson started almost immediately: getting back on his feet after falling. His third lesson was how to move his feet. This was where it got more challenging: as soon as one foot moved, he needed to try and regain his balance. He would then move the next foot as quickly as possible to “fix” things; unfortunately, this caused him to fall faster.

He was persistent and kept trying as hard as he could. Eventually, I convinced him to take smaller steps; this allowed him to keep his balance throughout the movement and never need to react to any major changes. He moved slower like this, but he spent a lot less time getting up off the ice.

Somewhere there must be a lesson in developing software solutions:
  • Small steps allow you to be in control. 
  • Large steps expose many possibilities for failure.
So when I started coding my most recent project I started thinking about taking smaller steps. Instead of doing two or three things in my code or test, I just focused on doing one thing. I make a change and immediatly validate the outcome. If it didn't work I need to rework that modification. Once I am satified I have met my expectations, I move on to the next task.

Small steps allow you to get from project start to the other end of the ice without falling. Don't be tempted to code in “big steps” just because you are on a creative roll. Instead, try writing down some “small steps” on index cards; if these steps are written as tests, you will have the start of a TDD solution.

Take those index cards and start coding the solution to the first test. When you can prove that the first tests passes, you can then move onto the next test with confidence. If you suddenly realize you need a new test while coding a small step, write it down on a card. Don't stop working on that small step until it is complete.

If I coded a solution for eight hours without any validation, I can assure you the solution would have bugs. Trying to validate those changes, certainly would take longer then the original solution. Obviously, coding for one hour (a smaller step) followed by some testing would be a better, more efficient practice. Shorten that time to less then five minutes and you will be on your way to success.

How big are your steps? Can you make them even smaller?

Friday, February 6, 2009

What my Xbox taught me about agile

I have spent a large portion of my career trying to develop new code faster than before. This sounded like a really easy goal to accomplish. I guess my original plan was always flawed. The more I tried to develop fast, the more I needed to fix bugs. When something from 6 months past becomes a problem, things would come to a really frustrating halt.

The first time I played Forza Motorsport 2 on my Xbox 360, I drove as fast as I could crashing into every wall. This caused my car to get turned around backwards and start driving in the wrong direction. The game seemed impossible. Then I tried something crazy. I slowed down!!! What slow down in a video game. I did and do you know what happened? My time was significantly better. Eventually I was able get better control of the car at higher speeds. Still I needed to control how fast I drove, you can't go through a hair pin turn at full speed.

Why am I talking about video games?? Well we can learn a lot about software development from this same problem. If you are constantly pushing out as much code regardless of the quality, you will hit walls. You will need to stop what you are doing and rework code. The addition of new features will take longer because things are not stable or testable. Fixing defects requires hours of debugging sessions.

I realize no one wants to create a mess, it just happens. The faster you go the more technical debt you build up. Does your manager have sleepless nights about the debt you are building? I doubt it, this debt is usually very hidden. It only resurfaces in defects or the inability to make changes to existing code. I can assure you that you will spend more time fixing the mess then it took to create it.

One of my favorite techniques for delivering quality code is automated tests. Unit testing are the safety net that we need to prove what we are doing. If you are practicing TDD you are proving that your intentions are realized in code properly. Think back to before you had these tools. Has anyone wasted a day looking for a solution to a boolean expression of (variable = false). Yes it is an assignment not a boolean expression and it will always come back true. Unit testing is important.

So why FasterSlowerBetter? I think it says a lot about how I want to develop software. I want to be faster, but experience has taught me how to get my goal accomplished. Going slower and having better deliverables sets you up for a more productive future.