Getting Started with Test-Driven Development - My Left Hand

If you’ve done any amount of programming that wasn’t test-driven, the entire notion of writing a test before writing any code may sound odd. I can tell you from my own experience in late 2000 and early 2001 that it certainly seemed like a strange way to build software. When I first tried writing code in a test-driven manner, it felt more than odd or strange - it felt as if I was using my "wrong" hand to write my signature.

While some people are ambidextrous, most of us aren’t and have a decided preference to one hand or the other. I’m right-handed, and my first attempts at TDD felt like I was trying to write something with my left hand. I noted, though, that it wasn’t the first time I had encountered that feeling.

So, About My Left Hand

I was born and raised in the same town that James Naismith, the inventor of basketball, was raised. I even lived on Naismith Drive for over 15 years! Needless to say, basketball was a big thing in our town. I played during high school and even into my late 30’s in recreational leagues. We had a park with a basketball court right outside our back yard, and a bunch of us played constantly from when the snow melted in the spring until almost when it fell again in late fall.

My Dad also loved basketball and on a few occasions he came over to the park with me to shoot some hoops. One of those times, we played a little one on one. Dad noticed that I dribbled mostly with my right hand and all my shot attempts - even layups - were right handed as well.

For those of you who’ve met me in person, I’m not what you would call the prototypical basketball player. I’m a whopping 5 feet, 6 inches (165cm) tall and was blessed with endurance more than speed. Dad pointed this out and said that I needed to find other advantages when playing, since most (OK, all) of the players defending me would be taller and probably faster. That advantage would be to be able to use my left hand as in addition to my right when dribbling, passing and shooting. Other players wouldn’t be expecting someone right handed to use their left hand as much.

Dad was never one to give a lot of advice, so when he did I usually listened. I believe it was June when he suggested that, and I proceeded to spend the next two months of the summer trying to use my left hand as much as possible. And I sucked at it. I could hardly dribble, passing with my left hand was a joke, and shooting simply wasn’t happening. I was able to start making layups pretty quickly, though, which gave me some hope.

By the end of the summer, not only was I making layups but I was comfortable dribbling with either hand, I could make passes using my left hand that I had never been able to do before, and I could make shots with my left from almost anywhere within 10 feet of the hoop.

Let’s jump ahead now to the basketball season the following winter, when I was the starting point guard. I was much more effective because I was no longer limited to dribbling with my right hand. I could dribble away from defensive pressure and my new capability to pass with my left hand helped get me out of trouble when I couldn’t dribble. It also allowed me to make passes that the players on defence weren’t expecting.

To that point, I clearly remember one playoff game where I drove to the basket with a defender right behind me. When I went up for the shot his hand and arm were over my right shoulder, expecting a right-handed shot. I simply used my left hand instead and sank the layup. It was exactly what my Dad had said would happen the previous summer.

I actually had progressed to the point that I was more comfortable using my left hand on fast break layups than I was my right. That was in the early 80’s and it stayed with me right up until I hung up my Converse’s in the mid–2000’s.

Plasticity

Our brains are incredible - they have a capability called brain plasticity. You will hear about people who’ve suffered a brain injury, a stroke, or have had tumours removed and lost control of some part of their body. Through physical therapy they are able to regain some, if not all of their previous ability because their brain re-learned how to do whatever function had been lost.

Learning to play basketball with my left hand used the same concept, although I hadn’t lost anything. Our brains are capable of rewiring themselves to allow us to do things we hadn’t been able to do before. This isn’t a fast process, though. It takes time and repetition. It took me over two months of practice and repetition to have my brain create new pathways to provide the coordination to use my left hand.

Learning Test-Driven Development is very much the same. It takes time, practice and repetition for your brain to transform it from feeling like trying to write with your opposite hand to being the natural way to do things. From being almost impossible to me preferring to do layups with my left hand.

The question now is, how do you get started?

Don’t Be Embarrassed

The first time you try TDD, it will feel awkward. You will probably be quite self-conscious if others are present because you’ve been used to writing code and shipping systems using a traditional approach. Don’t worry about that - any new technique will feel odd, and this has no bearing on your ability to program. If someone asks why you seem to be going more slowly, tell them you’re using your “wrong hand”!

Use the Buddy System

Probably the most important thing for me when I learned TDD was that I had a “buddy” doing it with me. We shared our discomfort, laughed at each other, and learned together. We also pushed each other. I wasn’t going to give up if he wasn’t!

This concept is actually pretty standard for any behaviour changing activity. Weight loss programs like Weight Watchers use the buddy system. Alcoholics Anonymous has sponsors who work with a person. Those people have “been there” and can relate their experiences.

Do the same with TDD. Find someone who wants to learn as well. Pair with them. Make mistakes together and laugh! Learn together, knowing that you both will get better at it.

Practice Makes Perfect

Over the summer that I learned to use my left hand in basketball, I would be on the court almost every day, sometimes twice a day if I had the time. There were a bunch of us who just showed up each night when the weather cooperated. We played a ton of basketball that summer (and many others as well)! You can do the same while learning TDD.

There are code practice sessions called Katas that are extremely helpful when you’re starting out. You can spend 15–30 minutes working on one of the kata programming exercises such as Prime Factors, Fizz Buzz and a String Parser among others. That practice will take you from that awkward, uncoordinated, “using my wrong hand” feeling to a natural flow.

Conclusion

Test-Driven Development is a development technique that comes with what I call a “learning cliff”… it’s simply too steep to call a curve! However, using these steps can help you scale that cliff relatively easily.

Find someone to scale the TDD cliff with you. Try it out, practice and compare your experiences. Most of all, though, be patient! It will take some time and you likely become frustrated at some point. Remember that the outcome of clean, well-factored, well-designed code that happens to have a comprehensive set of tests describing its behaviour is more than worth the effort.

More on that in later posts!

Comments