Slashdot Mirror


Study: Refactoring Doesn't Improve Code Quality

itwbennett writes: A team of researchers in Sri Lanka set out to test whether common refactoring techniques resulted in measurable improvements in software quality, both externally (e.g., Is the code more maintainable?) and internally (e.g., Number of lines of code). Here's the short version of their findings: Refactoring doesn't make code easier to analyze or change (PDF); it doesn't make code run faster; and it doesn't result in lower resource utilization. But it may make code more maintainable.

9 of 247 comments (clear)

  1. Maintainable... by pokoteng · · Score: 5, Insightful

    ...is pretty important, and you should refactor when needed if only just for that. It'll spread all over rest of the code in many ways, in good ways.

    --
    the game
    1. Re:Maintainable... by MrBigInThePants · · Score: 5, Insightful

      The summary is badly worded with a weird bias.

      For most software projects maintainability is THE most important thing for TCO (over 90% as per the article) and thus the MOST important thing. Also I find it hard to believe for your average "REAL" project (i.e. far more than 4.5k of code) changeability and maintainability are not intertwined. Any study arguing otherwise needs it methodology closely inspected.

      Technical Debt is real, obvious and accumulates exponentially with the amount of code involved over time. This is what we are talking about here when we talking about being able to change it and maintain it. There is lots of research on this and any experienced enterprise developer will have seen this in action.

      MAJOR problems with this study:
        - They used Students. If you don't know why this is bad there is no hope for you.
        - 4500 is barely a code base at in the real world.
        - Debt accumulation is worst over long periods of time and many iterations/changes. This is not commented on at all when describing the example. (NB: From my speed read)

      So take this all with a grain of salt. This is a very limited academic paper and not at all definitive or real world applicable in of itself...

    2. Re:Maintainable... by monkeyzoo · · Score: 5, Insightful

      The study sounds like nonsense (at least as presented in this post).

      Refactoring doesn't make code easier to analyze or change.... But it may make code more maintainable.

      What is code maintenance, if not analyzing and changing the code??!?!

      Does code in Sri Lanka need to have its oil changed and tires rotated?!

  2. Easier to Analyze or Change == More Maintainable by medv4380 · · Score: 5, Insightful

    How any anyone say, or write, that refactoring doesn't make code easier to analyze or change, and then follow up with it can make it more maintainable? Also, who in the world ever though that refactoring would make code run faster?

  3. New study shows taking medicine is ineffective. by TsuruchiBrian · · Score: 5, Insightful

    We gave random medicines to groups of random people, and there was no statistical improvement in their health. Some people became healthier, but many people actually became ill.

  4. car by bmimatt · · Score: 5, Insightful

    Car repair does not make car faster, nor more comfortable.

  5. Not significant - ignore by jareth · · Score: 5, Insightful

    I wouldn't call that study publish worthy.

    It certainly isn't statistically significant. 4,500 lines of C# code is nothing. I work with systems that have millions of lines of code. I've seen single class files that have thousands of lines of code (and vomited when I saw it). An important question here would be whether the volume of code in a system is a significant factor in the value of refactoring.

    Based on their own statistics the refactoring was poorly done. Their result was more code, more complexity, and more coupling. Certainly not the work I would expect from an experienced software developer, but certainly something I would expect to see from undergraduate students who don't fully understand what they are doing.

    I think the last sentence in the actual study sums it up pretty well - "Furthermore, it would be better that the same
    experimental setup can be executed in industry environment with the industry experts and with
    the industry level matured source code."

  6. Improving crap code by davidwr · · Score: 5, Insightful

    I've seen the before-and-after when crap code was rewritten and refactored by hand by a good coder.

    The improvement was huge.

    Was it better than if the same coder wrote the code "from scratch" from the problem-description or design document? I don't know, but my point is that crap can be turned into gold by a good coder, and that refactoring can be part of the cleanup.

    --
    Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  7. Re:on *average* by Anonymous+Brave+Guy · · Score: 5, Insightful

    It needs a lot more qualifiers than that.

    For a start, as with an unfortunate number of academic studies, it appears that the sample population consisted of undergraduates and recent graduates. That alone completely invalidates any conclusions as they might apply to experienced professionals with better judgement about when and how to use refactoring techniques.

    Even without that, there seem to be a number of fundamental concerns about the data.

    One obvious example is that they consider lines of code to be a metric that tells you anything useful beyond the width you need to allow for the line number margin in your text editor. I doubt most experienced programmers would agree that a LOC count in isolation tells us anything useful about maintainability or that the mere fact that LOC went up or down after a change necessarily meant the code had become better or worse in any useful sense.

    Another concern is that they talk about "analysability", but this seems to be measured only by reference to a brief examination of a small code base in one of two versions, unrefactored and refactored. I'd like to know what the actual code looked like before I read anything at all into that data -- what refactoring was performed, what was the motivation for each change, and how do they know those two small code bases were representative of either refactoring in general or the effectiveness of refactoring on larger code bases or code bases that developers have more time to study and work with?

    I'm all for empirical data -- goodness knows, we need more objective information about what really works in an industry as hype-driven and accepting of poor quality as ours -- but I'm afraid this particular study seems to be so flawed that it really tells us very little of value.

    --
    If you disagree, post your argument. (-1, Overrated) isn't your personal censorship tool for views you don't like.