Know Your Next Commit
I tapped three programmers on their shoulders and asked what they where doing. "I am refactoring these methods," the first answered. "I am adding some parameters to this web action," the second answered. The third answered, "I am working on this user story."
It might seem that the first two were focused on the details of their work and that the third 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 a vision of the overall goal. They had selected tasks they thought led in a productive direction, and that they thought could finish 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, achievable goal in mind.
The third programmer had not been able to break down the problem and was working on all at once. He had no idea of what it would take, and was basically doing speculative programming, hoping to 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 it took more than two hours? They would simply realise that they had taken on too much, 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 kept.
The third programmer might keep on guessing 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 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, play around with the code, 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, 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.
This work is licensed under a Creative Commons Attribution 3
Back to 97 Things Every Programmer Should Know home page