If you want to practice, delete your code
This Saturday I participated in a Code Retreat, facilitated by Drew Shefman. It was an opportunity to practice good habits for software development. The retreat was composed of a series of sessions, each with a different flavored challenge. But all had a similar basis. We were working to implement Conway’s Game of Life, using Pair Programming and TDD. But there was a catch. For best results, we had to delete our code after each session was over.
As soon as Drew mentioned this you could hear an audible groan from the room. ‘Delete our code?’ I thought ‘But we’ll never finish’. This was precisely the point. When we started the day, I felt this was going to hurt. I take some pride in the work of my hands, and discarding that felt wrong. But as the day progressed, my feelings changed.
After deleting my code for the third time, I noticed a pattern. At the start of each new session, I was able to start a little faster. I was able to discern a meaningful test case a little faster. I was able to align with my new partner a little faster. And I didn’t ever once have to ‘catch up’ with someone else’s code, nor anyone with mine. More interestingly though, I never had to use the same approach to Conway’s Game of Life more than once. And each session’s design was a little different.
By deleting my code, I released myself from it’s assumptions, requirements and shortcomings. This is what allowed me to practice the design, pairing, and testing habits of development. I had never felt burdened by my own code before. But I’ve joined some existing projects, and had to deal with the constraints those who came before put on it. Without this CodeRetreat forcing me to delete my code, I likely never would have.
Looking back at my other side projects, I realize these were never the best practice. I was always building towards something. I was never merely building code, to practice the building of it. I had always sought a something. Looking at it that way, it might be like expecting the free-throw shot in practice to get you some points. Which would be silly. But what about soldering, or woodworking? Is it practice if you are soldering the transistor into a hobby project? Is it practice if you are cutting this board to make a table with it?
Maybe it is a kind of practice, but not the most effective kind. You know that research that says you need something like 10000 hours to become a world-class expert{1}? The practice they talk about there, isn’t the kind you get by playing the game or working a project. Those experts pursue a ‘deliberate practice’, focusing on specific elements of their technique. A little like what we did at the Code Retreat. So if you want to practice, maybe you should try deleting your code first.
{1} - I happened on a TED talk about 3 years ago, which touched on this idea. The talk suggests that it is possible to learn any skill with about 20 hours of work.