Repitition is Good for the Soul

Posted by Berin Loritsch Wed, 03 Oct 2007 11:56:00 GMT

In martial arts, we perform kata (also known as Hyung or just simply forms). Contained in the kata are a selection of techniques, stances, transitions, etc. to help train your body to move properly. There’s usually a general focus of the kata, and as you progress each kata builds on the lessons from before. According to the rules of progressing through the belt ranks in Tae Kwan Do, they explicitly say you should have performed the kata 300 times that are prerequisites for the next belt. That’s a lot of repetition. Essentially, you really have to know the kata inside and out before you can progress.

If you do it right, you learn the areas you have problems with and you work on fixing those issues. Each repetition of the kata shouldn’t be a mindless action because you will never have reached perfection. There’s always something to improve. You learn subtle nuances as you slow down and visualize your opponent attacking. You learn that minor changes in your stance, shifting of your weight, etc. will have a profound impact on the power you can deliver and the ease of moving into the next technique. You’re constantly learning and improving.

As software writers, we tend to have to solve the same solutions over and over again. Each time through, we learn from our past experience and seek to improve on what we’ve done in the past. It’s one of the reasons why I think pattern chasers have missed the boat. If all you do is mindlessly slap together some patterns you learned from a book or an online resource, you never learn. You never can appreciate what the technique buys you, and how much (or little) of it you have to do for the application at hand. Some parts of the problem are so ingrained you really don’t have to think about it. That’s OK, and that’s expected. However, the corner cases, the challenging parts are where you have to focus a little extra mental effort. Following a recipe book isn’t going to get you over the hump.

In martial arts, physics is our friend. When we apply force to one part of the problem (the body), it will move in predictable ways—even if that problem is resisting. When we’ve gone through the repetition of performing the forms, one-steps, etc. we can instinctively apply the right force to get the problem to move in a way that we want. If we do our job right, that problem will be in subjection in short order.

In software, logic is our friend. When we apply control to one part of the problem (the software), it will move in predictable ways—even if system events try to throw a monkey-wrench in it. Each time we deal with the issues that a machine can throw at us, we can instinctively know which system events we can ignore and which we need to control. If we do our job right, the application will be finished in short order.

Unit tests are the best way we have to understand how the code works in an application. The goal of a good unit test is to express in as few lines as possible how the code should behave under specific circumstances. If you put too much in your unit tests, you never know just quite what might be going wrong. With unit tests, you can ensure a certain amount of predictability in the system.

Integration tests are the best way we have to understand how the application works in its environment. The goal of a good integration test is to express in as few lines as possible how the system should behave as a whole under specific circumstances. The integration tests should simulate or force certain system events to ensure the application handles it robustly.

The best way to describe it with a good mental picture is again with the forms. As we are performing our forms, we can focus on each technique one at a time. Some techniques are going to be particularly troublesome for you (one I’m learning right now is kicking my but with some jumping techniques). However, you can isolate parts of the whole kata and focus on just that technique (or two if you are having problem with a transition from one technique to the other). These are like unit tests. However, your training is incomplete if you never put it all together and perform the kata as a whole. Your sensei may have people attacking you as the kata is designed, but it doesn’t change the form itself. The practice of performing the whole kata is like the integration tests.

Repetition provides you with several advantages over cookie cutter approaches: deeper understanding of the problem, better understanding of your weaknesses, and more confidence in the solution you chose. Another, more subtle, advantage is that for the parts you know well your brain does disengage allowing you to move “in the flow” for longer stints.