Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Is the time spent refactoring a code base worth it in the long run, in terms of developer productivity?

It seems pretty clear to me that modifying a clean, well designed system is much simpler and faster than working on a poorly designed one, but I'm after some solid evidence. Are there any studies around this topic?

share|improve this question

2 Answers

Empirically, software with higher complexity metrics, such as cyclomatic complexity, are harder to maintain. There is research supporting this dating back to the 1970s. There is also work that suggests that complexity density, which is cyclomatic complexity over size of the system also relates to maintenance time. Unfortunately, an IEEE subscription is necessary to access both of those papers, but you can try to look them up on other sources if you're interested.

From a quality perspective, it's often worth it to spend some time refactoring, assuming you have a test framework in place to prevent the introduction of new defects. This will allow you to more easily implement new features to your system, add additional tests, and train new developers to work.

Ultimately, however, there is the pressure to deliver new functionality and added value. You need to balance refactoring with the implementation of new functionality and repair of defects.

share|improve this answer
+1, but would you consider posting a rash/critical/short post sometime? It would make you seem more human ;) – Demian Brecht Sep 15 '11 at 3:27
1  
another point to add is that when you refactor, you also likely implement features in a better/more efficient/cleaner manner. There's an adage I've heard myriad times to the effect of "in 5 years you'll cringe that you thought your code was 'good'" – warren Sep 15 '11 at 6:49
Or you can choose to ignore the lack of any concrete evidence and trust the hoards of acclaimed developers when they say it pays off to clean up before expanding your code base further. I'm sure you have examples of your own based on which you can provide proof for their claims. Hell, we all do. – Filip Dupanović Sep 15 '11 at 10:37
@Filip We all have stories, but empirical evidence that shows correlation or other relationships between any two measures or metrics is important to further software engineering as an engineering discipline. – Thomas Owens Sep 15 '11 at 10:44

I'm after some solid evidence

Then stop wasting your time here.

  1. Find some code that's expensive to maintain. It's easy. Look at your organization's trouble tickets.

  2. Find some code that's cheap to maintain. Find code that's run frequently, but has few or no trouble tickets.

  3. Measure the complexity with any of the widely available complexity tools.

  4. Bask in the evidence.

You have now provided numbers to confirm the obvious.

share|improve this answer
Not really. the complexity of the task performed by the software must be distinguished from the added complexity caused by the implementation chosen. – reinierpost Jan 24 at 23:14

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.