Know Your Next Commit

From WikiContent

Revision as of 15:59, 24 November 2008 by Kevlin (Talk | contribs)
Jump to: navigation, search

I tapped a programmer on her shoulder and asked what she was doing. "I am refactoring these methods," she answered. I tapped a second programmer on his shoulder and asked what he was doing. "I am adding some parameters to this web action," he answered. The third answered, "I am working on this user story."

It might seem that numbers one and two were focused on the details of their work and that the third was focused on the bigger picture, and that the latter should be better. However, when I asked when and what they would commit, the picture changed dramatically. The first two where pretty clear over what files would be involved and would be finished within an hour or so. The third programmer answered, "Oh, I guess I will be ready within a few days. I will probably add a few classes and might have to change those services some way."

The first two programmers did not lack consideration of the overall goal of what they where doing. But they had selected tasks that they could get to grips with, that led in a productive direction, and that they thought could be finished within a couple of hours. Once they had finished those tasks, they would select a new change or refactoring. In that way all the code they wrote was written with a clear purpose and a limited and achievable goal in mind.

The third programmer had simply not been able to break down the problem and was working on all of it at one go. He had no idea of what it would take, and was basically doing speculative programming, hoping that he would arrive at some point where he would be able to commit. Most probably the code written in the start of this long session was poorly directed for the solution that came out in the end.

What would the two programmers do if the task they had selected came out to take more than two hours? They would simply realise that they had taken too big a bite, throw away their changes, define a smaller task, and start over. To keep working would have been speculative, and you do not want speculative code in your repository. So, the changes where thrown away, but the insights where kept.

On the other hand, the third programmer would probably just keep guessing with less and less clue and desperately try to patch together his changes to something that could be committed. After all, you cannot throw away code changes you have done — that would be wasted work, wouldn't it? Unfortunately, that causes a lot of strange code changes without a clear purpose to enter the repository.

At some point of time even the commit-hard-ass programmers could not find something they thought could be finished in two hours and would lead in a productive direction. Then, they would go directly into speculative mode and play around with the code: trying some wild refactoring just to see how the code would move, or patching on some functionality to see if it would fit in the structure — and of course throwing away the changes whenever they had gained some insight leading them on track. Even these seemingly unstructured hacking sessions have purpose: to learn about the code to be able to define a task that would constitute a productive step.

Know your next commit. If you cannot finish, throw away your changes and define a new task you believe in with the insights you have gained. Do speculative experimentation whenever needed, but do not let yourself slip into speculative mode without noticing. And never let speculative code enter your repository.

By Dan Bergh Johnsson

This work is licensed under a Creative Commons Attribution 3


Back to 97 Things Every Programmer Should Know home page

Personal tools