2022-11-17 20:48

Coding is like Fencing*

Two people in white fencing gear against a dark backdrop practicing foil fencing.

Image by Cottonbro Studio

I had the pleasure of watching fencing practice a couple days ago. It was only three people - the coach, and two participants. One of them started only recently, the other one has some years of practice under his belt. While I was listening to the coach, I couldn't help but think about coding exercises. Her words could have been used almost verbatim to introduce a coding dojo. Is coding like fencing, then? There is quite an overlap, yes. But I think there's still room for improvement. Let me walk you through what I witnessed that evening, and where I think coding practice falls short.

Practice started with a relaxed bout for warm-up. After a while, the coach stopped them. You did well, but your movements are sloppy, she said. So here's what you're going to do: You will repeat a sequence of attack - parry, riposte - parry, riposte - parry, disengage, riposte. Yes, it feels artificial, and it is. But I want you to go through these movements over and over again. Do them slowly. It's not your goal to go fast, but to carry out these movements as precisely as possible. Over and over again. You want to commit them to muscle memory, so you have them at the ready when you need them during play.

At first she held on to the blades of the participants' foils and led them through the movements, naming them along the way: Attack, parry, riposte, parry, riposte, parry, disengage, riposte. They repeated the sequence a few times under her guidance, then the participants continued by themselves. Veeeerrryyyy sloooowlllyyy at first, almost stopping after each element. Attack. Parry, riposte. Parry, riposte. Parry, disengage and riposte. The coach corrected them where necessary, and didn't hold back with encouragement and praise either. There's a lot to concentrate on - legs, balance, arms, weapons. The movements became more fluid, then faster. After a number of repetitions they took a quick break, then switched back to bouts.

It's time now to confess that - barring choreographies with swords in films - I haven't seen any fencing since Gianna Bürki's olympic competitions in Atlanta, 1996. But even to these untrained eyes the difference between the bouts before and after this exercise was ... striking. (SCNR!) Where there had been a tangle of foils and arms and bodies before, there where now determined, well-defined movements. It looked quite elegant, really!

Now that I have shared the entirety of my fencing knowledge (and I even had to pester people for terminology), let's return to the more familiar waters of deliberate practice in coding. We do our katas to practice certain movements. Instead of attack, parry, disengage, riposte, we have our red-green-refactor. Write a failling test, make it pass, refactor. We repeat these movements, focussing on doing it right, not doing it fast. The code we practice on is usually not production code, but something artificial. And we do this kind of practice to become better developpers. To avoid falling into the trap of everyday sloppiness. So, in this sense, coding is exactly like fencing.

But there's one thing I'm missing in our practice. It's the direct comparison between the before and the after. Even though I feel like katas help me be a better developer, I'm not quite sure what I get better at. And I can't gauge my improvements after a session.

I'd like to take the red-green-refactor cycle to a higher level. I'd like to see myself fail, then succeed, then analyse and adjust.

Now this is getting longer than I expected, so I will save the rest for another day. Watch this space for part two.

* Hat tip to Emily Bache who inspires me to think more about how and why we practice, and whose blog inspired this title.