Alex Rivera | Logout

What is a good ratio of refactoring time versus development time?

Asked 2009-09-16T15:33:21.530
9

I'm trying to build a plan on how we could spend more time refactoring. So I wanted to compare with the industry standards but I have hard time to find studies or metrics on that.

I feel that 20% of dev time spent on refactoring seems a good ratio, but I don't have anything to show for it.

In my mind, for 100% or dev time:

  • 50% is spent writing code, debugging, etc...
  • 30% is spent writing unit-tests
  • 20% is spent refactoring code

So around 1 line of code for 2 written end up being in the shipped product. Obviously design time, documentation time, etc is integrated in these percentages.

What is an industry standard? As a rule of thumb, what is your team using? Thanks, Olivier

Edit
Report

2 Answers

4

Your comment says that you have millions of lines of code but no unit tests, and that you are having a hard time convincing management that unit tests are worth it. According to Fowler's book, refactoring needs to be accompanied by unit tests to provide the confidence that you're not breaking anything while you refactor. I would agree, and I'd suggest that unit tests are going to provide more value than anything else at this stage, so aim first for that goal. I strongly recommend Michael Feathers' book "Working Effectively with Legacy Code" for suggestions as to how to do this. You don't even have to write more than a few unit tests to make it a worthwhile effort, just get the framework running.

Step 0: get an automated unit testing framework harnessed into your code.

You're not going to try to accomplish this alone, are you? This is a big project, and I expect you are part of a senior technical team who shares the pain with you. You need to get all of them to buy into this 100%. You'll need their backing when you go to your boss, you'll need their expertise to share in creating the design, and you'll need their total agreement on the design.

Step 1: gather a posse.

Without a plan and a goal, refactoring isn't going to help much. Are you hoping to just to chop the code up and make modules smaller? Are you going to get code organized into domains? Are you going to try to wedge some service interfaces into it? Are you going to refactor to an n-tier architecture? What do you and the posse think needs doing? And how are you going to communicate this design and refactoring plan to the SEs?

Step 2: get the posse to do some initial architectural design and planning of the end state.

Now for the hard part. You're asking for 20% of 30 engineers' time, which is probably over $500,000 per year. You're going to need a lot more justification than "accumulated technical debt." You're going to need to show ret

answered 2009-09-17T02:42:13.510
2

I doubt there are any norms.

To your breakdown: most teams do not write unit tests and do not refactor (until something breaks or stalls development). Most commonly, refactoring time allotment is < 1 %.

If you're interested in good practice then....

  • Refactoring may be an ongoing activity as part of the development process. You see an improvement potential and you personally assign some small time to make things better. Here refactoring time < 5%.

  • You perform regular code reviews. Say, once in a few months. Then you can dedicate a few days exclusively for the team to only review their code and improve it. Here also < 5%.

answered 2009-09-16T15:38:40.417

Your Answer