This post originated from an RSS feed registered with Agile Buzz
by Laurent Bossavit.
Original Post: Code it twice
Feed Title: Incipient(thoughts)
Feed URL: http://bossavit.com/thoughts/index.rdf
Feed Description: You're in a maze of twisty little decisions, all alike. You're in a maze of twisty little decisions, all different.
Have you ever lost a significant chunk of code to carelessness or accident, and had to rewrite it from scratch ?
Earlier this year, I conducted an informal survey of my colleagues on the french XP mailing list. (A biased sample - this post is in part to continue the survey with a slightly larger sample.) The consensus seems to be that when that happens,
Rewriting the code takes much less time than the first time around
Rewriting the code is a lot easier than the first time around
The rewritten code is better factored, more readable than that lost
Consensus is very strong on the first two points, less so on the last.
I've been wondering what to make of this regularity. It has to mean something, but what ?
I suspect that whenever we code something, we also learn something, and that repetition might reinforce the learning.
I'm wondering if people who do "up front design" (by which I mean something like work out the problem, algorithm, and so on on paper, then code more or less mechanically from their design) have similar or differing experiences.
I'm wondering, too, what might happen if we made a systematic habit of throwing away our first attempt at coding any given chunk of functionality, and made a habit of only committing rewrites to CVS. Would the increased quality offset the drop in productivity ?
I suspect that most programmers would respond with strong negative feelings to the suggestion of deliberately throwing away code - perhaps an impassioned reaction, more than a reasoned one. How would you react ?
Some of us, I suppose, have more frequent opportunities to write the same code over and over. The Dojo is where I'm finding my own opportunities for multi-coding. I suppose there are others - teachers, trainers, people who demo frameworks or APIs, I don't know who else... If you know something about it, please email me or comment here.