More Software posts
November 20, 2003
Too Much Code?

Kimbly has a post about Code Inertia talking about how the programmers in her shop write large amounts of code, with much copy and paste, to solve problems that could be solved more compactly. She's interested in trying to change this. To which I say:

What about the old reward and punishment routine? I'd say that it's very unlikely that the programmers will change their behavior on their own. The way they work now is fine by them, I'd go so far as to say that the way they work now is being rewarded. Producing a lot of code is probably regarded as a sign of being a code stud. Kimbly's comments imply that it might be. Are the people who write more lines looked up to, are stats maintained about how many lines each person wrote? If lines of code per programmer is tracked, even if no formal reward is associated with it, then I suggest stopping. Instead track something associated with the behavior you want to promote. One thing would be to track number of tests created and have some target for number of tests per lines of code, the more code written the more tests required. Unfortunately it's very difficult to directly measure the thing you want to promote, code reuse.

Another angle is to make it easier to do the right thing. If you use Java then IntelliJ IDEA or Eclipse with their refactoring support make it easier to reuse than to copy and paste. Instead of copying the code for a method from one subclass to another it's easier to automatically move the method to the superclass.

One suggestion, that of introducing XP, might work, but not if you continue to track lines of code per programmer. It's a way of adding a set of rewards and punishments that favour a particular style of development. I'd take a good look at the programming culture in your shop and see how it could be tweaked so that reuse becomes seen, and rewarded, as more important and valuable than lines of code.

Posted by Alex at November 20, 2003 08:38 AM
Comments
So what's the system where you work? How do you encourage code reuse? And isn't there a corollary? People who steal a bit of code because it's close to what they want, throw in a condition to switch between uses, and end up making it difficult to modify the original code because it affects so many things. When I worked problem reports and was debugging, I found this to often be the case. Don't get me wrong. I believe strongly in code reuse, but you have to understand what is really similar and what looks close but is actually different. Posted by: M Sinclair Stevens on November 21, 2003 11:30 AM
Copy and Paste programming is a cultural problem, and it is *serious*. The real tragedy is that the coders who behave like this don't see that they have a problem, and may resist attempts to change their coding practices. The mindset of Copy-n-Paste coders is usually, "We don't need any of that fancy theory stuff! I can turn out an app in three days by copying that other one!" If they're willing to change, great. If not, they have to go. Posted by: Chris on December 4, 2003 11:42 AM
Chris, I agree. I wonder if these are the same people who resist most changes? Sometimes it can be difficult to descern what's going to turn out to be a fad and should be ignored and what actually represents progress. That's no excuse for dismissing all possible advances though, it just makes it a bit more difficult. On the other hand people who jump from bandwagon to bandwagon can sometimes be just as much trouble as they constantly rewrite stuff to match the latest thing they read on the net. Posted by: Alex on December 11, 2003 10:27 PM
Post a comment
Name:


Email Address:


URL:


Comments:


Remember info?