Revolution Systems specializes in web application development, Systems Administration services and commercial support of many Open Source Software systems.

Technique for improving code over time

I was talking with a friend of mine recently about an all too common problem in software development.  That problem is finding the time and resources to revisit working, but not perfect code.  For whatever your definition of "perfect" may be.

The developers feel this particular bit of code is just plain nasty. Maybe it is written in a confusing manner, poorly documented, or the landscape has changed so much that the entire architecture could use a rethink. The programmers may have thought up a better way, changed their style/best practices, or perhaps have just improved their skills since that code was written. But it works. It accomplishes the business goals.

Because it works, the management/marketing/sales folks are not very interested in making it better.  They would rather the programmers focus their efforts on new features, because they don't feel they can sell code quality. "Maybe next month/year/release we can do that, but right now go knock out some of these TODO list items...", is what you typically hear.

Both sides of this struggle need to realize that they both are correct and both incorrect. The developers are right in saying the code isn't perfect and could be improved.  They are also wrong, because sometimes what you have is "good enough".

The biz folks are correct in their thinking that they can't directly sell the results of the programmer's effort. They can't put it on brochure and it certainly won't get them talked about in FastCompany. But they are also wrong, because they are missing the long term impact the code quality/design will have on their future business. It is difficult for them to understand how changing, for example to a messaging oriented architecture, helps their modularity and scalability. How it might drastically reduce future development time, improve testing, etc, etc, etc.

Arguing this out could take forever. Not to mention you will have to argue each architecture change as you find/want them.

A technique I have used with great success in the past is what I have so cleverly named "Friday Afternoons".  Friday afternoons are probably the least productive part of an employee's week.  They are watching the clock in anticipation of the weekend. It happens to everyone.  Experienced sales people will tell you that it is basically impossible for them to get any real sales on Monday mornings and Friday afternoons.

As a compromise,  I suggest management give the developers free reign to make architecture, design, and code clean up changes on Friday afternoons. You may need to implement rules around this, such as the changes can't impact any deadlines, they can't create any new work for others, can't impact the product in adverse ways from the customer's perspective, all work must be done in a cleanup branch, etc.

Some of you managers out there are probably thinking, but "No way, that's 10% of our development time".  If you feel this way, you're really deluding yourself. No one is 100% productive, and I would estimate no one is even 25% productive on Friday afternoons, yourself included.

So why do this? There are several reasons:

  • Developers can cleanup the code, effectively making their workplace ( aka the code ) more enjoyable. And everyone knows that Great Code comes from Happy Coders.
  • The programmers feel their concerns are being heard. That management cares about about the quality and not just the dollar signs.
  • You eliminate the time drain of the meetings arguing about these issues.
  • The coders are self-motivated in their Friday afternoon sessions. You weren't going to get much out of them anyway, but at least there is a chance that you can reap future benefits from this work.

Maybe one of those architecture changes means that a requested new feature takes 2 days to implement rather than 2 weeks.  Or perhaps the code will run 5% faster or scale 2x as well.  Even if you just end up with better documentation and a slighly improved employee morale this is win.

If you end up using this technique for awhile, please send me an E-mail or leave a comment here.  I would love to see how this idea plays out in different environments.

Comments

This idea of yours is simply delusion!!
I liked a lot your article about the high cost of low cost programming, but this other idea of your will fail simply because people will not be that keen to work hard on Friday afternoons for code clean-up. As you already said, developers are lazy in that specific period of the day, so how many of them can fight their laziness just to do improvements on the code?
To be more clear, if a developer is so powerful and can control itself to work in Friday afternoons on improving the code, it will for sure be a disciplined man and can also work on new features. For this reason only, it is better to work on TODO's with such programmers since anyway the ones in the other category will fail making an improvement in any of these tasks.
I'm a developer and I agree that improving the code is a good ideea, but your idea of spending that particular period of time to do this is what will not work because if the human nature.

  Posted by Christian on Sep 1, 2007 at 9:42 AM

Christian,

The reason the programmers are, as I said self-motivated, to work hard during this cleanup afternoon is it is in their own best interest. They can fix that nasty little bit of code that has been bugging them for the last several months, without having to specifically justify it to anyone. Maybe it is just a little bit of refactoring to make their next TODO item easier or possibly just documenting that one thing that confuses everyone. It allows them to clean up their own mistakes.

Finishing up another TODO item doesn't have the same motivation. Sure, if you're way behind on a particular task or know that if you can just get one more TODO done then the boss buys the after work drinks, THEN maybe there is some motivation. But far too often finishing another TODO item is just finishing another TODO item, and on Friday afternoons that doesn't seem like much fun.

Another reason I found this to work is new features, subsystems, etc. are compartively large endeavors. Possibly so large that it can't be finished in an afternoon. Getting 20% done and then having to pick it back up on Monday wastes time, as the programmer has to reacquaint themselves with the task, where they left off, etc. Where many code cleanups are often very small projects that can easily be accomplished in a 2-4 hour timeframe. Obviously this doesn't work out 100% of the time. Would it make sense to change gears at lunch when you're 1 hour away from finishing up a large TODO item? No problably not, because of the cost of the context switching over the weekend.

Giving your programmers this small amount of freedom to make their workplace more enjoyable for themselves and their colleages pays dividends. Measuring those dividends is the hard part.

  Posted by Frank Wiles on Sep 5, 2007 at 1:48 AM