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.

247 comments

  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 Lord+Bitman · · Score: 2

      and creating code which can be easily refactored is, itself, the key to maintainable code.

      --
      -- 'The' Lord and Master Bitman On High, Master Of All
    2. 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...

    3. Re:Maintainable... by Anonymous Coward · · Score: 0

      Developer hours are a lot more expensive than a hardware upgrade on the production site. Code organization techniques which cost a teeny bit of CPU or memory, but wind up saving developer hours, is totally worth it (in most cases).

    4. Re:Maintainable... by invictusvoyd · · Score: 1

      It's quite similar (philosphically) to this old japanese thing http://en.wikipedia.org/wiki/K...

    5. 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?!

    6. Re:Maintainable... by MrKaos · · Score: 3, 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.

      Exactly, and that good way is reliability which is something I observe the study doesn't measure so whilst it's good to challenge the current wisdom, there seems to be a few holes here.

      First up I don't think 4500 lines of code is a good was to asses the interaction complexity of applications where the codebase exceeds 10 or 20 times that number. Second I may write a functional prototype of code knowing full well that I or someone else will refactor later when we have a better idea of how things are functioning.

      Unexpected failure modes are going to exist in the software. The whole point of doing things the 'Agile' way is to provide incremental improvement so things get better. The paper talks of XP but what if you are using DSDM instead of programming pairs, in that case you are *expecting* to refactor often as you explain the domain or new concepts are introduced. That's not scope creep, it's being honest and admitting you don't know everything.

      In my experiences the most powerful concept is the vocabulary you build as you begin to understand the domain better. I've found refactoring is the opportunity to 'put things in the right place' to define the vocabulary which makes things easier on myself and my colleagues a year or two later when someone asks if they can have this extra feature. Sure we should be using certain design patterns when implementing code from the beginning however I'm certain I'm not alone in confronting a codebase and wondering why certain methods are implemented in the controller instead of an information expert and spending the next week refactoring to avoid peoples heads exploding when methods are duplicated...but they don't work the same.

      that's my 2 cents...

      --
      My ism, it's full of beliefs.
    7. Re:Maintainable... by rtb61 · · Score: 4, Interesting

      The biggest problem with the study is it seems to miss the whole point of refactoring code http://en.wikipedia.org/wiki/C.... It is not about one project, it is all about a coding company and the code it produces over the life time of it's existence, about all of it's projects, past present and future. Is refactoring a technical waste for one project, depends upon the qualities of the initial code produced. Is refactoring a waste over 100 different projects over ten years, of course not and often because far less refactoring effort will be required for latter projects than earlier projects and those latter projects will be far more efficient.

      It is much like the principles of TQM http://en.wikipedia.org/wiki/T.... Does Total Quality management work for one project, rarely the administrative costs will readily out weigh the benefits because there is little or no opportunity to apply the improvements provided by TQM. Will TQM provide benefits for hundred projects over ten years, of course because. As there is plenty of opportunity to apply the benefits gained from the administrative efforts expended on TQM.

      --
      Chaos - everything, everywhere, everywhen
    8. Re:Maintainable... by Anonymous Coward · · Score: 1

      My thoughts exactly. If it isn't easier to analyze and change, it isn't easier to maintain. that's nuts.

      Implicit in definition of "refactor" is that the refactored code is functionally equivelent to the original, so it's hardly a surprise that refactoring alone doesn't substantially affect performance or resource usage.

      I consider refactoring a professional courtesy, like commenting and good naming. I'd be embarrassed leaving obvious refactorizations in my code.

    9. Re:Maintainable... by LifesABeach · · Score: 1

      Maybe Sri Lanka's coders chant that Refactoring is evil, and that only new code from them will save us all? Otherwise their logic makes no sense.

    10. Re:Maintainable... by LostMyBeaver · · Score: 1

      hahah well said... I wrote 4500 lines of code this weekend. It was a virtual machine runtime engine proof of concept. I am rewriting it now that I have proven the API

    11. Re:Maintainable... by Anonymous Coward · · Score: 0

      "The summary is badly worded with a weird bias."

      Badly worded? The biggest clown is the one that's running the show. It is stupid or there's money involved. Or BOTH.

      One click made me dumber and dumber.

    12. Re:Maintainable... by Anonymous Coward · · Score: 0

      No kidding - "maintainable" is the main aspect of "code quality". Performance, design and architecture issues are a different game entirely.

    13. Re:Maintainable... by Boronx · · Score: 1

      It's important, and it's always been the main reason to re-factor. It's also strange to say that Maintainability is improved, but changing the code is not, since code maintenance isn't really maintenance, it's just changing the code. It's not like code wears out over time through too much use.

    14. Re:Maintainable... by Anonymous Coward · · Score: 0

      Depends on the language.

      4500 lines in some languages can get you an app with a lot of useful features while in others(*cough* Java *cough* C++) will get you a hello world app.

    15. Re: Maintainable... by prefec2 · · Score: 1

      Maintainability is a measure used to determine how easy it is to change and adapt code to modify existing featuers, add new one and remove obsolete ones. Changing code is the task you have to do to change the feature set.

    16. Re:Maintainable... by Anonymous Coward · · Score: 0

      Yes ... components need to be upgraded and interfaces changed to work with new versions of operating systems (and other software it interfaces with).
      Which isn't really changing the code as it still does the same thing.
      There's a *LOT* of this to do, ime

    17. Re:Maintainable... by theshowmecanuck · · Score: 1

      And by being maintainable, it should also extend, ahem, to extensible.

      --
      -- I ignore anonymous replies to my comments and postings.
    18. Re:Maintainable... by laurencetux · · Score: 1

      the biggest thing to do during a refactor is to figure out that a block of dew crazed code can be cooked off into a much smaller (and more readable) block by grouping exceptions and figuring out if the main "class" just needs to be expanded.

      its the code version of replacing that 3d printed super widget with a properly made metal version (that has the correct bends and bobs in it)

    19. Re:Maintainable... by Anonymous Coward · · Score: 0

      Perhaps what they say is:

      One of the main reasons refactoring is done, is having to make as less modifications as possible when evolving requirements arrive. These usually follow some pattern which regards only a relatively small part of the application. Making this small part simpler and more configurable will ease the maintenance tasks, while on the whole the program may continue to have bad "software engineering" metrics, and its design continues to be fragmented and not uniform across its various parts. In this case, this very much corresponds to my experience (I work in a medium sized company with continuously changing software requirements).

    20. Re:Maintainable... by gbjbaanb · · Score: 1

      creating code that doesn't need to be refactored is the key to maintainable code.

    21. Re:Maintainable... by multi+io · · Score: 1

      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??!?!

      Refactoring means code gets written anew, so it becomes more maintainable because it was written by the same people who have to do the maintaining. Before the refactoring, you have to maintain crappy code written by some dude that quit last year. After the refactoring, you have to maintain crappy code written by yourself. Definitely easier.

    22. Re:Maintainable... by Immerman · · Score: 1

      I'd say it's more "real" than that - personally I'd regard the "optimal refactoring situation" the one where you have a piece of code that originally did one thing, then had years of frankensteinesque new functionality hurriedly bolted on to it until it barely resembles it's original self and is likely to blow up if you look at it wrong. At some point rewriting the code with the complete current functionality, and likely future expansion, in mind is going to make it much clearer and easier to modify further without random bits interfering with each other.

      --
      --- Most topics have many sides worth arguing, allow me to take one opposite you.
    23. Re:Maintainable... by BreakBad · · Score: 1

      Once upon a time inherited a project where every time it had to access the database, it created a new connection object, rather than using an existing session. It was horribly slow, and prone to crash, and difficult to maintain. I re-factored by simply implementing the singleton pattern on the class and removing redundant instantiations. Now the application is faster, utilizes less resources, and is easier to maintain. WTF is the article smoking?

      FTA:

      According to the Fowler’s definition (Fowler, 2000), refactoring is the change made to the internal structure of the software system by removing bad smells or problematic places in the source code.....

      Oh....IC.

    24. Re:Maintainable... by tlhIngan · · Score: 1

      I'd say it's more "real" than that - personally I'd regard the "optimal refactoring situation" the one where you have a piece of code that originally did one thing, then had years of frankensteinesque new functionality hurriedly bolted on to it until it barely resembles it's original self and is likely to blow up if you look at it wrong. At some point rewriting the code with the complete current functionality, and likely future expansion, in mind is going to make it much clearer and easier to modify further without random bits interfering with each other.

      Well, refactoring also is the opportunity to apply previous experience to the new code as well.

      When refactoring, you can trim out the fat - the original code may have been written to satisfy features X, Y and Z, but as it evolved, Y and Z were never used, yet its code exists and often has to ve special cased to support real use cases of Y1 and Z3 (Z1/Z2 were old requirements that were obsoleted).

      Also, decisions may have been made because the system may have added possibilities for X1, X2 and X3 as they were planned into the requirements, but real business operations deemed there was no practical use case in the end.

      So refactoring to current spec simply say you need to support X, Y1 and Z3. But experience has taught you that X is unlikely to ever change, Y was revised so maybe make it possible to revise it should it be necessary, and Z needs to be flexible because it's Z3 now, but past experience shows Z4 and Z5 are likely so that code should be made as adaptable as possible. And maybe redesigned since Z needs the flexibility, while X is static and Y changes are limited.

    25. Re:Maintainable... by GargamelSpaceman · · Score: 1

      Refactoring IS evil. It's time you spend to make your code more maintainable by others. So it makes you look bad by taking your time, and makes others look good when they work on your code, by making their job easier. And you're probably a temporary who won't get the opportunity to eat your own dogfood if you're a Sri-Lankan coder, anyway....

      Also, 4,500 lines of code was used in this study. That is TINY. Who works on 4,500 lines of code? It's possible to analyze that much code without too much troubley ( unless it was written by kindergarteners maybe ) no matter how it was factored. There is a little overhead in abstraction - not much, but enough that maybe 4,500 lines of ok code doesn't benefit all that much in some ways from the abstractions they tested. Whatever. It doesn't invalidate the abstractions, and it's likely down to a matter of opinion whether in a tiny project the abstractions are worth their weight.

      --
      ...
    26. Re:Maintainable... by kmoser · · Score: 1

      No. Creating code that doesn't need to be created is the key to maintainable code.

    27. Re:Maintainable... by Anonymous Coward · · Score: 0

      lmao their study participants is laughable.
      A student wouldn't know how to properly architect a simple tic tac toe game let alone a real world problem with 10 different stake-holders 200 different data classes and 5 different storage engines.

      great article... burn it.

    28. Re:Maintainable... by Anonymous Coward · · Score: 0

      ...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.

      And make myself replaceable? Not in today's employment environment. I want my management to know that if I walk out that door and don't come back, at least two years of my salary worth of functionality is going with me, and let them do the ROI. They might come to the wrong answer, but it's the right thing for me to do.

    29. Re:Maintainable... by MrBigInThePants · · Score: 1

      Students from a uni?
      You can guess what language. Almost certainly C# or java.

      Not that I OR ANYONE ELSE should rate languages based on the number of lines of code.

      While Java IS verbose it is also tends to be very clear, readable and obvious comparatively which helps on many fronts.(to play devil's advocate - I am fully aware of Java's deficiencies)
      What you SHOULD measure is the time required to write, refactor and maintain that codebase using typical tools for a typical codebase using freely available libraries.
      I would pit java against any language on that front although I doubt it would be the overall top.

      There are also the Java based variants now (e.g. the scripting ones) which help with that also.
      An experienced java developer (for example) rarely writes all of the code in a class as the IDE helps.

      But this always needs to be coupled with library support. Yes coding in XXX language may be more efficient in terms of lines of code. But what about the support/community? Do you have access to 1000 upon 1000 of mature OS libraries again with vibrant communities?
      So your language requires 1/2 the lines of code, you will have to end up writing and maintaining 100x(+) the code if there is no community to back it up.

      This is has been the true strength of Java for the last 10 years. It will die one day but this the thing that will keep it going long after "better" alternatives become mature.

    30. Re:Maintainable... by LifesABeach · · Score: 1

      I just thought that they, the Sri Lankans, didn't have numbers past 4,500. When I saw their group photo my reactioin was, "thats what they think humans dress like?" I wonder why their mothers made them put on those clothes?

    31. Re:Maintainable... by eric_harris_76 · · Score: 1

      Absolutely. More than once I've heard one of our developers say that, as part of a fix, the code will have to be refactored first.

      Otherwise, we'd be going from a chunk of unmaintainable code to a larger chunk of more unmaintainable code. If it gets 10% and 10% more unmaintainable (using my handy-dandy unmaintainability-meter), it is now 21% worse, overall.

      Sort of the opposite of the old joke about the restaurant: "The food is terrible. And the portions are too small."

      --
      There's no time like the present. Well, the past used to be.
  2. Obviously... by Anonymous Coward · · Score: 1

    They employed inbred butt monkeys to refactor their code.

  3. This should not be on the front page by Anonymous Coward · · Score: 1

    The "study" looked at a single, 4500-line program, with no way to properly define a baseline for any of the measurements. (Yes, they have "pre-refactoring" scores, but who's to say the initial version hadn't been refactored before? Maybe that refactoring was awesome.) This is not even close to news.

    1. Re:This should not be on the front page by Anonymous Coward · · Score: 0

      I've seen many files at 10k+ lines, overall program size over 500million lines. 4500 is nothing. I turned in bigger programs for homework assignments in school. (Which is probably what the guys actually analyzed)....

      I want to see them analyze 20 year old spaghetti code.

    2. Re:This should not be on the front page by dgatwood · · Score: 1

      Seriously. I've written single functions longer than that. If your code is so confusing that you can't maintain it without refactoring it by the time the entire app hits 4500 lines, either your code is some of the worst in the universe or you have insufficient working memory. Just saying.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    3. Re:This should not be on the front page by Danga · · Score: 2

      Single functions with more than 4500 lines? Sounds like a good time to do some refactoring, that sounds hard to follow and probably should be broken down. We have a 100 line max standard where I am at now.

      --
      Hey, there is only one Return and it's not of the King, it's of the Jedi.
    4. Re:This should not be on the front page by LostMyBeaver · · Score: 1

      You've written single functions with 4500 lines of code? I think I would passionately hate working with you. I throw a fit when I am over 45 lines of code in a function.

    5. Re:This should not be on the front page by lgw · · Score: 4, Interesting

      10,000 line functions are shockingly common in industry. Shit grows over time, and is so poorly written that you can't safely refactor it, and management lacks the balls to let you clean it up, so it just festers and festers.

      I hear PayPal had 90% of their processing business logic in a single, multi-million-line class! Thankfully, I don't know that one first hand.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    6. Re:This should not be on the front page by AJWM · · Score: 1

      I could believe 10 kloc (kilo lines of code) functions being created by some front-end automated code generator (like a gui builder or parser generator, etc). If anyone is hand-coding 10 kloc functions they should be taken out and shot, or at least have their fingers broken so they don't do it again.

      And while a multi-million-line class certainly seems excessive, that says nothing about how it's broken down into members and methods and inner classes.

      --
      -- Alastair
    7. Re:This should not be on the front page by dgatwood · · Score: 4, Interesting

      About 5600 lines. However, because it was a glorified case statement, you were really only debugging a single case at a time, each of which was about the length of a sane function, so splitting it into functions would do little to improve readability. I like to trot out that example to terrify people, but the function itself was really quite sane and easy to maintain.

      You did, however, have to fully understand the state machine as a whole, which in total was almost twenty kloc, had almost 200 instance variables in the state object, and leaned heavily on a tree object with about 30 instance variables. That's the point at which most people's heads exploded.

      Either way, 4,500 lines is the size of a fairly straightforward iOS app. Most folks can dig into that and figure out enough to maintain it without spending a huge amount of time, even if the organization isn't ideal. When you hit tens of thousands of lines, that's where you have to start thinking about how you organize it and document it, because with such large projects, if you jump into the middle without a complete picture, you're likely to be hopelessly lost.

      --

      Check out my sci-fi/humor trilogy at PatriotsBooks.

    8. Re:This should not be on the front page by narcc · · Score: 2

      I'd rather have a readable and maintainable 4500-line function than an unreadable and unmaintainable 45-line function.

      I remember, years ago, standard advice to students to break up code in to functions when some process got over some number of lines. Know what we got? A lot of really odd functions of similar length, as they broke things apart at seemingly random boundaries! I'm still deeply suspicious when I hear people talk about a proper length for functions.

      It's time to let that one go, and teach students that while shorter is often better, length doesn't really matter that much. They ought to factor out functions when they see them and when it makes the program more readable. I'll suggest this as a new rule-of-thumb: functions should do just one thing and be named accordingly.

      (Still, 4500 lines? Damn, that's big.)

    9. Re:This should not be on the front page by edtice1559 · · Score: 1

      I hate to take the side of management, but I don't think it's lack of "balls." If you have 10k LoC function, it's pretty much impossible to test and/or maintain so it seems like a great idea to "clean it up." But since nobody an possibly really know all of the boundary cases for a 10k LoC function, chances are that, when you "clean it up" you introduce regressions. There probably are some interesting things that you could do in this situation, but would probably be a project in and of itself. Something that wouldn't be "cleaning it up." It might even be a good idea to do, but you're still looking at a significant undertaking and it seems that the tools we have today just aren't up to the task.

    10. Re:This should not be on the front page by Anonymous Coward · · Score: 0

      I'll suggest this as a new rule-of-thumb: functions should do just one thing and be named accordingly.

      "New"? I learned this rule over 20 years ago, and I'm pretty sure it wasn't new then.

    11. Re:This should not be on the front page by Cederic · · Score: 1

      I disagree.

      You don't rewrite 10k loc, you rewrite four of them. It's pretty easy to isolate four lines of code, put extensive testing in place and extract method (or some other refactoring).

      You don't need to do that too often to start to see benefits.

    12. Re:This should not be on the front page by lgw · · Score: 2

      Tech debt is like credit card debt: the interest is a bitch. I worded for a while at one company that nearly folded because the time required for emergency bug fixes grew to, then past 100% of development time for the team. Horrible code doesn't just require more bug fixes in the first place, each change grows progressively more expensive and unsafe.

      10k lines of shipped, production code is only of value if it's working bug free and without complaint. 10k lines of buggy code, that you have to add a week to any project that modifies in any way, that has negative value.

      That being said, if the code is "cleaned up" by the same team that wrote it in the first place, you likely don't come out ahead. The only reason that company "nearly" folded was monuments willingness to hire about 10 senior guys like me to rescue what we could - 6 of them quite within a few weeks, but the 4 of us who stayed managed a few core fixes that kept it limping along for enough time to find a buyer for the company before it went under.

      --
      Socialism: a lie told by totalitarians and believed by fools.
    13. Re:This should not be on the front page by lgw · · Score: 1

      Wow, auto-correct had a blast with that code. "Monuments" indeed!

      --
      Socialism: a lie told by totalitarians and believed by fools.
    14. Re:This should not be on the front page by Anonymous Coward · · Score: 0

      I've seen the single function which controlled at the time most of the telephone calls in the US. It had a comment warning that the compiler **would** choke if you made it bigger than 65535 lines.

      Refactoring that was complicated by the fact that "goto" won't jump to other functions.

  4. Well DUH... by Anonymous Coward · · Score: 0

    The compiler is what makes the final decision on the code, not the programmer.

    Just refactoring a poor algorithm will still result in a poor performance, though the code might look better.

    1. Re:Well DUH... by Anonymous Coward · · Score: 1

      No fair, i wasn't taught that during my ruby on rails bootcamp. i'll check my local ninja maker coder dojo. maybe we can disrupt this together and raise awareness.

    2. Re:Well DUH... by sysrammer · · Score: 1

      Bingo!

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    3. Re:Well DUH... by Anonymous Coward · · Score: 0

      What's a compiler or an algorithm?

      - Average Ruby/Javascript developer

    4. Re:Well DUH... by Boronx · · Score: 1

      Refactoring a good algorithm that's written in spaghetti code on the other hand...

    5. Re:Well DUH... by readin · · Score: 3, Insightful

      The compiler is what makes the final decision on the code, not the programmer.

      Just refactoring a poor algorithm will still result in a poor performance, though the code might look better.

      The whole point of refactoring in most cases is to make the code look better, not to improve performance. Very rarely do people change an algorithm as part of refactoring. The goal is instead to make the code easy to understand, easy to change, and easy to debug. Creating consistent names and API patterns, re-ordering statements to group them based on the task they're performing, finding code that is the same in many different methods and moving it into its own method, reducing dependencies between classes.... these are common refactoring techniques and have almost nothing to do with performance.

      --
      I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
    6. Re:Well DUH... by TapeCutter · · Score: 3, Interesting

      Yes, after 25yrs in the industry I have come to the conclusion that "what is it supposed to do?" is invariably the most difficult question to answer.

      --
      And did you exchange a walk on part in the war for a lead role in a cage? - Pink Floyd.
    7. Re:Well DUH... by edtice1559 · · Score: 1

      I wish I could mod you up, but I basically already posted the same thing only in a less succinct way.

  5. Refactoring done right happens as you go by GoodNewsJimDotCom · · Score: 2

    When you code, the most important thing to do is get your memory architecture built right, then methods just write themselves. Come back later and want to make a better method, you can use your old code as a partial refactor. It is an agile sort of run and gun approach and it works.

    Refactoring for the sake of refactoring is often wasted time for the original author for there is ways of understanding code past just nice variable names and indentation. Sometimes even badly formatted code stands out and reminds you what it did to remind you of how it works. But when you code in a group, this doesn't hold true and a refactor can help.

    1. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 2, Insightful

      I'm not sure I can trust the coding advice from a person who thinks all the predictions in the bible have been, or will be proven to be 100% true (meanwhile claiming all other belief systems have been proven to be fakes). There are a lot of "religious" programmers out their who are sure that their preferred language, design pattern, or style is the only good one, and all others are terrible, even without bringing in actual religion.

      If a scientist were to tell me he is 100% sure that the planes that crashed on 9/11 where flown by the US government via remote control, and that the people that were supposed to be on those planes are held in some secret facility, I might question their ability to think critically. It's possible that their is really good evidence to support this, and I've just never seen it, but I think it is far more likely that this scientist has horrible intuition and is probably a terrible scientist as a result.

    2. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 1

      You might as well be deriding a programmer for being gay, or a woman. Rewrite your post using one of them, and you clearly come off as a bigot.

      Ummm. Being gay or a woman aren't conscious choices.*
      Unless you are arguing that religiosity is a form of congenital brain damage, then there is a difference. You definitely can deride people for holding silly views, and the world would be better if it happened more often.

      * Obvious transgender critique being sidestepped here for brevity.

    3. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Not sure I can trust someone with your last name. Sounds like a terrorist.

    4. Re:Refactoring done right happens as you go by ranton · · Score: 1

      I'm not sure I can trust the coding advice from a person who thinks all the predictions in the bible have been, or will be proven to be 100% true

      One of the smartest men to ever live (Isaac Newton) was deeply religious, believed in scientific studying of the Bible, alchemy, and plenty of other ridiculous things. I'm as atheist as they come, but I still understand that very smart people can still have very ridiculous beliefs. Being religious in no way means you cannot refactor code properly.

      --
      -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
    5. Re:Refactoring done right happens as you go by BarbaraHudson · · Score: 1

      What do you mean by "memory architecture"? I am willing to suspend my disbelief that someone who believes they have directly communicated with a metaphysical entity couldn't give me advice concerning programming.

      From the context, I gather that maybe what he meant to say was "data structures"?

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    6. Re:Refactoring done right happens as you go by Bill+Dog · · Score: 1

      You might as well be deriding a programmer for being gay, or a woman.

      No, because in today's world sexual preference and gender bigotry are disdained, but religious bigotry is not only acceptable, it's considered fully warranted. (Well, except against Muslims, because it could lead to harassment and discrimination. And they don't deserve that. *cough*Unlike Christians. And those among Jews who are religious and pro-Israel.)

      The human race never progresses enlightenment-wise, we just periodically change what groups it's acceptable to hate.

      --
      Attention zealots and haters: 00100 00100
    7. Re:Refactoring done right happens as you go by Bite+The+Pillow · · Score: 1

      WTF does this have to do with the bible? There are SO MANY things wrong with this that you could attack, but you chose prior posts?

      Go fuck yourself with a sideways with a rusty rake.

      When you code, the most important thing to do is get your memory architecture built right, then methods just write themselves. Come back later and want to make a better method, you can use your old code as a partial refactor. It is an agile sort of run and gun approach and it works.

      Refactoring for the sake of refactoring is often wasted time for the original author for there is ways of understanding code past just nice variable names and indentation. Sometimes even badly formatted code stands out and reminds you what it did to remind you of how it works. But when you code in a group, this doesn't hold true and a refactor can help.

    8. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      You don't get the data structure right without also thinking about the algorithm being used...

      They are so tightly bound together that you can't DO them separately.

    9. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      It's only racist and bigoted if it comes out of the mouth of a male, white, christian.

      Otherwise, it's perfectly acceptable.

      Don't judge and force your viewpoint on gays! While they force cake shops to close for not agreeing with their viewpoint...
      Don't judge and force your religion on Muslims! Although it's okay for them to kill gays and Christians everywhere else...
      Don't disagree with the President, otherwise that makes you racist. If you are black? that makes you a traitor, and uncle tom and racist.

    10. Re:Refactoring done right happens as you go by AJWM · · Score: 2

      "Memory architecture" -- you mean data structures?

      As the title of my old intro CS text put it, "Algorithms + Data Structures = Programs". Yep, one is clearly going to influence the other, and sometimes a minor tweak in one will vastly simplify (or complicate, if you do it wrong) the other.

      Refactoring isn't merely reformatting -- a prettyprinter can do that -- but it can help give you insight into the code. After getting the code right I like to refactor to see how much code or useless variables I can get rid of, but that's partly a hangover from my old APL one-liner days. (grin)

      --
      -- Alastair
    11. Re:Refactoring done right happens as you go by AJWM · · Score: 1

      Hence the title of Wirth's book, Algorithms + Data Structures = Programs. I think it was my second semester CS text (nigh on nearly forty years ago).

      --
      -- Alastair
    12. Re:Refactoring done right happens as you go by readin · · Score: 1

      When you code, the most important thing to do is get your memory architecture built right, then methods just write themselves. Come back later and want to make a better method, you can use your old code as a partial refactor. It is an agile sort of run and gun approach and it works. Refactoring for the sake of refactoring is often wasted time for the original author for there is ways of understanding code past just nice variable names and indentation. Sometimes even badly formatted code stands out and reminds you what it did to remind you of how it works. But when you code in a group, this doesn't hold true and a refactor can help.

      But I never write badly formatted code.

      Of course part of the reason is that I refactor as I write. Like battle plans never surviving contact with the enemy, software designs rarely survive contact with the code. As I'm writing the code I find holes in requirements that force a new plan. I refine method signatures to reduce dependencies. In short, I'm learn more about what I'm writing as I write it. It only makes sense refactor as I go. And sometimes I have to finish writing something before I can do certain refactorings.

      --
      I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
    13. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      You are not using logic. You only think you are

      I am expressing an opinion.

      In actuality, you are cherry-picking to discredit him to fulfill your own bias.

      I'm not sure what "fulfilling one's bias" means, but at no point did I claim to be unbiased. In fact I think it was pretty clear that I was presenting my bias openly.

      If you actually gave a shit about him, you'd read through his other posts, not just a simple click of his signature.

      It's not just his signature. It's also his username and his domain name. It seems pretty clear that he wants to be identified with the statement on his website.

      In short, using someone's religion or other personal choices to detract from their words is the act of a petty, scared individual, incapable of debating in professional terms.

      I wasn't using his religion detract from his words. I am using his words to detract from his credibility as a person with good analytical ability.

      You might as well be deriding a programmer for being gay, or a woman. Rewrite your post using one of them, and you clearly come off as a bigot.

      That's ironic considering that he is the one who basically claimed that all other worldviews are proven to be fakes. Which I consider to be much more offensive than anything I've said.

      I'm not a bigot. It's not like I am not trying to pass laws preventing him from getting married or anything. I am not prejudiced against him for anything he can not control. I am judging his worldview to be one that sucks, which is exactly what he is doing to non-Christians.

      So maybe I am just as bad as he is. But I'll bet I'm a better software engineer.

    14. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      Christians love to be the victim...

    15. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      I hope I didn't give the impression that I think being religious necessarily makes you stupid. I know lots of very smart religious people. I will say that I think it's harder to be a very smart person with an especially intolerant and IMHO naive religious view (e.g. all other religions have been proven fake except mine), especially nowadays (as compared to when Newton lived).

      It does certainly seem that the proportion of smart people that are religious has been dropping over time.

      I would also say that I think that religious views fall on a spectrum of being quite thought-provoking, to dim-witted to absolutely abhorrent. That is I don't believe all religious views should be treated as equally valid, profound. And no idea should be above criticism.

    16. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      I am not the one that brought it up. He has his domain name as his username and a link to his website in his signature. It's not like I'm digging around for his private religious views. He chooses to publicly advertise this view in every comment he posts.

    17. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Great, so now we're bashing Christians for not liking being bashed.

    18. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Certain religious claims about society fall apart when we finally can access information about other places.

      e.g. the idea that with your chosen religious book being followed, everyone will end up fornicating in the streets, raping, murdering and looting like there's no tomorrow. Maybe this is easy to believe if you're Amish or something, but we, who can read about or visit other places, can test this prediction by looking at countries like Japan or Sweden, which are both over 80% athiest, yet aren't falling apart at the seams. In fact, they're emininently peaceful and well-ordered places to live. I've had people tell me, "yes but that's over there, it's different here, we need Christianity here". I just wonder if they're telling me Americans are just naturally more barbaric or something, it doesn't make any sense as a comeback.

    19. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Newton was brilliant, no doubt about that. Religion does, however, cripple your critical thinking by way of indoctrination; and since the bible is supposedly the "infallable" word of god, the extent of your critical thinking is limited because you're not allowed to contradict scripture (oh the irony) as it makes you a heretic. You can overcome this limitation as a christian if you simply don't take the bible literally, if you compartmentalize your beliefs or if you stick to fields of research that doesn't conflict with scripture. Imagine how far Newton might have gone if he wasn't a christian? It's possible he was too limited by the lack of instruments to get any further than he did, but it's also likely that he might have gone much further if he had let go of certain unhealthy (from a scientific perspective) ideas.

      My point is that critical thinking can be deeply affected by beliefs, and a scientist has a much greater potential without this limitation. I doubt this is a problem for a programmer refactoring code - on that we agree, but it's still tragic to see a scientist cling to ridiculous and crippling ideas. /M

    20. Re:Refactoring done right happens as you go by narcc · · Score: 1

      So maybe I am just as bad as he is. But I'll bet I'm a better software engineer.

      That doesn't make sense to me. Why would a persons beliefs about religion (or politics, race, potato chip flavors) have any influence on their ability to write computer programs?

      Do you think Buddhists write better code than Hindus? Are Raeliens better developers than Shintoists? What could possibly compel you to put forward such a silly belief?

    21. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      The issue is always with caches versus scratch pads, isn't it? ;)

    22. Re:Refactoring done right happens as you go by narcc · · Score: 4, Interesting

      Of course part of the reason is that I refactor as I write.

      I'm not sure what that has to do with writing "badly formatted code", but I'd still caution against that. Some of the best advice I ever received: "There are no good writers, only good rewriters." I've found this to be true for code as well. It's amazing how much you can improve your code once you've distanced yourself from it a bit.

    23. Re:Refactoring done right happens as you go by TheRaven64 · · Score: 1

      Newton looked at the spectrum and saw that it contained six distinct colours to the human eye: red, orange, yellow, green, blue, purple. But his alchemist beliefs considered 7 to be a magic number and so wanted the spectrum to have seven colours. He decided that purple should be split into indigo and violet to reflect this, but didn't split any of the others (even where the difference is at least as pronounced) because it contradicted his mystical thinking.

      If even Newton 'One of the smartest men to ever live' couldn't manage to keep his science separate from his mysticism, what hope do you think other religious people have?

      --
      I am TheRaven on Soylent News
    24. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      That doesn't make sense to me. Why would a persons beliefs about religion (or politics, race, potato chip flavors) have any influence on their ability to write computer programs?

      Most of those things don't have any influence (e.g. race, potato chip preferences). Political views (e.g. democrat vs. republican) probably don't have any influence either, but that doesn't mean that political views can't have an influence. Let's say you are part of a political movement that believes people who draw pictures of the prophet Muhammad should be killed. Maybe your biases in regard to free speech would affect your ability to be a good journalist.

      Race and food preferences don't have any significant affect on your worldview. Politics and religion are belief systems which can certainly affect your abilities to do certain jobs depending on what they are.

      Do you think Buddhists write better code than Hindus? Are Raeliens better developers than Shintoists? What could possibly compel you to put forward such a silly belief?

      I didn't put forward that belief that members of one religion write better code than members of another religion. I do think a person who is sure that their religion and holy book is 100% true and that every other belief system has been proven to be fake, is not a person who thinks logically. And logical thinking is an essential skill to writing good code, and understanding code other people write.

      I'm not saying he can't be a good programmer, I'm only saying I think people with good logic skills tend to have a better chance at being good software developers.

    25. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      No the opposite. I am bashing Christians for liking to be "bashed" because it makes them more like Jesus and the suffering he had to endure.

    26. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Christians do like to being kshed, I have heard.

    27. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      in today's world sexual preference and gender bigotry are disdained, but religious bigotry is not only acceptable, it's considered fully warranted.

      Statistics show atheists face more prejudice than other minority groups. (Don't believe me; google it.) *That* is the religious bigotry in the world today.

      The human race never progresses enlightenment-wise, we just periodically change what groups it's acceptable to hate.

      And yet we have progressed because now, as you say, it is not okay to mock or ridicule someone for their gender or sexual orientation.

      It is and should remain acceptable to critique (not hate) adults who believe in fairy tales whether they be Santa Claus, the Easter Bunny, or Jesus-as-son-of-god.

    28. Re:Refactoring done right happens as you go by BarbaraHudson · · Score: 1

      But you still have to start with the data. Algorithms by themselves are meaningless. The data structure can be modified to accommodate more efficient algorithms, but without the original data structures, you've no real place to start, whether it's a census database or the attributes of a character in an RPG.

      And the problem with making your data too tightly coupled to the algorithms is that because they are now more tightly coupled, you might find yourself in a jam when changes have to be made to the data structures.

      They should NOT be "so tightly bound together that you can't DO them separately".

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    29. Re:Refactoring done right happens as you go by david_thornley · · Score: 1

      People often don't think consistently. It's entirely possible to believe objectively false things as part of religion, and be logical in other areas. In that case, religion would be something he doesn't actually reason about, and he might reason well about software. but I would regard it as suspicious. (In my opinion, that's also a very bad sort of religion, and can easily turn dangerous and diabolical, but that isn't the issue here.)

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    30. Re:Refactoring done right happens as you go by david_thornley · · Score: 1

      How ridiculous were those things in his day? There was a belief at the time that the Bible was true, and that we could learn about the world both from the Bible and from looking at the world. This lasted about as long as the Bible didn't clearly disagree with science, at which point scientists dropped Bible study as part of science. IIRC, the science that discredited the Bible as objective truth about the world was geology, and I think that considerably post-dates Newton.

      I'm less sure about alchemy, but until we developed an actual theory of chemistry there was no way to rule out, say, transmutation of the elements. Obviously, it wasn't easy to accomplish, but was it possible? (I do know someone who did transmute very small amounts of one element into another, actually, but not with traditional alchemical techniques.)

      There was a large body of information of varying quality, and Newton was responsible for sorting a lot of it out. He invented gravitational theory, thereby giving Kepler's laws a sound theoretical foundation, and made great advances in optics. Had there been a lot of truth hidden in alchemy (and there was no solid evidence against it then), he doubtless would have found some of it.

      What I wish he hadn't devoted so much time to is Royal Mint business.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    31. Re:Refactoring done right happens as you go by narcc · · Score: 1

      I do think a person who is sure that their religion and holy book is 100% true and that every other belief system has been proven to be fake, is not a person who thinks logically. And logical thinking is an essential skill to writing good code, and understanding code other people write.

      So you think a persons religious beliefs affect their ability to program.

      That's ridiculous. Even more ridiculous is your "reasoning".

    32. Re: Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      for fuck sakes, are you dense narcc? you are putting words in his mouth. stop it with this strawman bullshit. you know damn well what he meant.

    33. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      I agree that some people don't seem to have cognitive dissonance (when they should). All I am saying is that a person who has a higher proportion of illogical beliefs is more likely to have a particular illogical belief. Like for example if someone drives drunk frequently, they are more likely to be in a car accident. This doesn't mean that drunk drivers will always have accidents and sober drivers never have accidents, but I still don't want to be on the road with a drunk driver..

    34. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      I think illogical beliefs are an indication of the lack of ability to think logically, and I think that ability is crucial to good programming.

      And no I don't think all religious beliefs are illogical. The beliefs of GoodNewssJimDotCom are not the craziest I've ever seen, but they are still in the category of me questioning his ability to program well.

    35. Re:Refactoring done right happens as you go by narcc · · Score: 1

      Just so you know, when Spock used the word 'logical', he was using it incorrectly. Consequently, you are using it incorrectly as well. Please stop.

      Back on topic, so you're saying that a persons religious beliefs affect their ability as a developer.

      So .. Do Buddhists write better code than Hindus? Are Raeliens better developers than Shintoists? Why or why not?

    36. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      I'm not a bigot. It's not like I am not trying to pass laws preventing him from getting married or anything. I am not prejudiced against him for anything he can not control. I am judging his worldview to be one that sucks, which is exactly what he is doing to non-Christians.

      +1 =)

    37. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      (yawn)
      you either don't or can't get it.
      stop making up bullshit he's not saying.

    38. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      When you code, the most important thing to do is get your memory architecture built right,

      Spoken like a divine commandment with the dogmatism and conviction of a religious zealot. =)

      Oh wait, and we were just wondering why being a religious freak could affect your ability to code?!

    39. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      tuskegee experiment ... there are more... you just need to understand nation-states are evil.

    40. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      Why would a persons [sic] beliefs about religion (or politics, race, potato chip flavors) have any influence on their ability to write computer programs?

      He has provided the answer for you himself with hints of his dogmatic thinking right there:

      When you code, the most important thing to do is get your memory architecture built right,

      Said with the certainty of a modern day Moses sharing the little known 11th commandment that only he and other enlightened ones are privy to!

      I've worked with religious people, and I've worked with developers who hold religious beliefs about coding. The latter are worse for your productivity.

    41. Re:Refactoring done right happens as you go by Anonymous Coward · · Score: 0

      straw man! straw man!

    42. Re:Refactoring done right happens as you go by BarbaraHudson · · Score: 1

      And there's no dogmatism here? It should be called GNU/linux, With open source, all bugs are shallow, Vi vs Emacs, systemd, $WHOEVER is evil, This will be the year of the linux desktop, Ubuntu yadda yadda yadda, anything to do with ruby or ruby on rails...

      Really?

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    43. Re:Refactoring done right happens as you go by david_thornley · · Score: 1

      I think we need to classify "illogical" beliefs better. A belief can be said to be illogical if it contravenes evidence, or when there's simply no evidence for it.

      To give an example, a belief in Christianity would be supported by no objective evidence, but it can't be falsified either. A belief that one's own religion had been proven correct, or that other people's religions had been proven false, would contravene a whole lot of evidence.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
    44. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      Just so you know, when Spock used the word 'logical', he was using it incorrectly. Consequently, you are using it incorrectly as well. Please stop.

      I am not using the word incorrectly. I picked the word "logic" specifically because of it's pertinence to software development. The fact you you think I *must* be using it in what you think is the "Spock" sense is your problem.

      Back on topic, so you're saying that a persons religious beliefs affect their ability as a developer.

      It depends if that person's religious beliefs are illogical. And if you had read what I said, you'd see that I specifically said that I do not think all religious beliefs are logical.

      If you used some logic you would have been able to easily infer my positions which is "I think a person's belief's (religious or otherwise), if they are illogical, can affect their ability to program".

      So .. Do Buddhists write better code than Hindus? Are Raeliens better developers than Shintoists? Why or why not?

      I already answered this question the first time you asked it. I said "I didn't put forward that belief that members of one religion write better code than members of another religion."

      Members of the same religion don't necessarily share exactly the same beliefs.

      Maybe you need to work on your reading comprehension.

    45. Re:Refactoring done right happens as you go by TsuruchiBrian · · Score: 1

      I do think defining "logical" vs. "illogical beliefs" is important in general. I don't think we need a really good definition for GoodNewsJimDotCom.

      Being able to label something as illogical objectively involves getting someone to agree to all your premises and then showing them that based on those premises your conclusion is right and their's is wrong (or maybe you might find youself to be wrong), and everyone who is logical will eventually arrive at the same correct conclusion.

      If I were GoodNewsJimDotCom, I would probably just dispute the evidence against my point of view. I could say that the evidence for noahs ark is really good and the evidence for evolution is really bad. You might say that according to X, Y, Z rules, the evidence for noahs ark is bad and evidence for evolution is good, and then I would just say that I think rules X, Y, Z are bad. And then you just end up not agreeing on any premises.

  6. 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?

  7. 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.

    1. Re:New study shows taking medicine is ineffective. by Anonymous Coward · · Score: 0

      It's worse. They used students' code.

    2. Re:New study shows taking medicine is ineffective. by BreakBad · · Score: 1

      +1

    3. Re:New study shows taking medicine is ineffective. by BreakBad · · Score: 1

      -1

      Now, statistically, with only me as a sample pool, your post is not effectively insightful.

  8. Summary makes no sense... by Anonymous Coward · · Score: 1

    Here's the short version of their findings: Refactoring doesn't make code easier to analyze or change

    Contrasted with:

    But it may make code more maintainable.

    This makes no sense...

  9. Whathuh? by neminem · · Score: 4, Insightful

    Isn't the very *definition* of making code more "maintainable" that it makes the code "easier to analyze or change"?

    1. Re:Whathuh? by TsuruchiBrian · · Score: 1

      Maybe they mean the source code is less susceptible to bitrot after refactoring...

    2. Re:Whathuh? by Wrath0fb0b · · Score: 1

      Or it makes the developer's intimately aware of all the different places it can break and the places you need to make changes. And since they wrote large portions of it they grok the flow from a high-level ...

      That is to say, you can make the code more maintainable without changing a single line. Another example is documentation changes or environment/setup like dev instances.

    3. Re:Whathuh? by cascadingstylesheet · · Score: 1

      Isn't the very *definition* of making code more "maintainable" that it makes the code "easier to analyze or change"?

      No, judging from common usage, "maintainable" actually means "my favorite flavor of 'object oriented'".

      It has no real world correlation with actual ease of maintenance.

    4. Re:Whathuh? by Anonymous Coward · · Score: 0

      No.
      The "maintainable" in this paper use the ill-minded ISO definition.

  10. No shit by RightwingNutjob · · Score: 1

    If the logic itself is convoluted, roundabout, or inefficient (ie n^2 sort onstead of n log n, exhaustive search instead of bisectioon search or kd-tree), prettying up the code won't help.

    1. Re:No shit by Anonymous Coward · · Score: 0

      Refactoring is not "prettying up the code".

      Refactoring would be replacing inefficient algorithms, that give the correct answer, with faster algorithms, that also give the correct answer.

    2. Re:No shit by narcc · · Score: 1

      "Refactor" implies simplification, not optimization. Given all the disagreement here, maybe we should stop using such an imprecise term and just go with "rewrite".

    3. Re:No shit by TsuruchiBrian · · Score: 1

      I don't think refactoring implies simplification. I think ideally it would simplify something about the code (e.g. semantics, interoperability, etc), but it will likely make some parts of the code more complex (e.g. more levels of abstraction, or a more complex design patterns, etc)

      Refactoring definitely doesn't imply optimization.

      from wikipedia

      Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior. Refactoring improves nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve source code maintainability, and create a more expressive internal architecture or object model to improve extensibility.

    4. Re:No shit by sysrammer · · Score: 1

      Shh. Don't say "rewrite". Managers heard that was a dirty word. That's why we give them a vague, important sounding "methodology" called "refactoring".

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    5. Re:No shit by sysrammer · · Score: 1

      ^^^ Ok, here's the definition people. Mod this up so the arguments can stop over what it is.

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    6. Re:No shit by Anonymous Coward · · Score: 0

      Ya, so we can waste time on another useless task when there is real code to be written. Why not just add a process so we have to track and log time on our time tracking and logging time. After that one I have a couple of reviews to do and I need to take some security training that looks like it was written by the authors of Tron.

    7. Re:No shit by Anonymous Coward · · Score: 0

      Don't know if you're being sarcastic or not but that's exactly how I would define code refactoring. It's a direct analogy to factoring in algebra, e.g. changing (x + y)^2 - 2y(x + y) to (x + y)(x - y) or x^2 - y^2. There's more to refactoring code than there is in algebra but the idea is similar: changes that don't affect the meaning but are more clearly expressed.

    8. Re:No shit by readin · · Score: 1

      If the logic itself is convoluted, roundabout, or inefficient (ie n^2 sort onstead of n log n, exhaustive search instead of bisectioon search or kd-tree), prettying up the code won't help.

      Quite often when I'm refactoring, thus making it simple enough to be understood, I discover code that is inefficient that wasn't noticed before because it was too difficult for anyone to really see what was going on.

      --
      I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
    9. Re:No shit by readin · · Score: 1

      I don't think refactoring implies simplification. I think ideally it would simplify something about the code (e.g. semantics, interoperability, etc), but it will likely make some parts of the code more complex (e.g. more levels of abstraction, or a more complex design patterns, etc)

      Refactoring definitely doesn't imply optimization.

      from wikipedia

      Code refactoring is the process of restructuring existing computer code – changing the factoring – without changing its external behavior. Refactoring improves nonfunctional attributes of the software. Advantages include improved code readability and reduced complexity to improve source code maintainability, and create a more expressive internal architecture or object model to improve extensibility.

      Occasionally you may be refactoring the code to give it more capabilities so you'll move to a higher level of abstraction. But I think in most cases the goal is to make the code simpler even if doing so makes some portions of the code more complex. A design pattern that reduces coupling between two classes can make the overall code simpler even if the code that implements the design pattern is complex. If you have a program that, for example, prints a custom driver's license for each of the fifty states, you may put complexity into certain parts of the code so that the parts of the code that focus on the differences between each state can be simple.(instead of 50 mildly complex pieces of code have one more complex piece of code and a list of 50 calls to that code with each call having unique parameters).

      --
      I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
    10. Re:No shit by TsuruchiBrian · · Score: 1

      I think the view of refactoring as redistribution of complexity is a pretty useful one.

    11. Re:No shit by Anonymous Coward · · Score: 0

      If the logic itself is convoluted, roundabout, or inefficient (ie n^2 sort onstead of n log n, exhaustive search instead of bisectioon search or kd-tree), prettying up the code won't help.

      Or, as in most cases for me, the end users have no idea what they want; and/or the specs for the code are sketchy and superficial; and/or the person requesting the code has no idea what the end users want or need. Can we refactor middle management?

  11. WTF by Anonymous Coward · · Score: 0

    Firstly, I'm not sure what they think "more maintainable" means, if not "easier to analyze or change". Secondly, refactoring isn't supposed to make the code faster or less resource-intensive. So they're basically saying that it doesn't do what it's not supposed to do, and it both does and doesn't do what it is supposed to do.

  12. Refactoring is busy work by Anonymous Coward · · Score: 0

    Look at me, I'm so busy earning my pay! I'm a coder, bro!

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

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

    1. Re:car by caseih · · Score: 1

      I can think of plenty of car repairs that can make your car faster and more comfortable. Fixing broken A/C would make most people more comfortable. As would fixing a bad power steering pump, fixing warped rotors, etc. And if your engine isn't running, then your car is by definition not fast, so repairing that will make your car faster.

      But "repair" and "refactor" are hardly the same thing. I'm sure automotive companies refactor their car systems all the time.

    2. Re:car by ClickOnThis · · Score: 1

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

      Well, sometimes it can. An engine or transmission in poor condition can slow down a car's uphill performance. A broken heater will make a car less comfortable in the winter. Repairs will correct these problems.

      And so it goes with software refactoring. Removing redundant calculations and data-reads (e.g., out of loops) where possible will improve performance. Changing names of variables, functions, classes, etc., to reflect their use more closely will improve readability (or "comfort" if you will.)

      Good car analogy, though.

      --
      If it weren't for deadlines, nothing would be late.
    3. Re:car by Duhavid · · Score: 1

      You don't usually do car repair unless something is not working..

      --
      emt 377 emt 4
    4. Re:car by Ravaldy · · Score: 1

      The car repair analogy isn't a good one. A better analogy would be to compare it to the engineering design process to make the car.

      Refactoring is the action of reviewing the code and re-writing it (internally only). Refactoring is in most cases done to increase readability and reusability (once again, internally only) which usually results in better maintainability. A by products of refactoring is detecting defects and optimization opportunities.

      Key here is that the process may reveal optimization opportunities and software issues.

    5. Re:car by RightwingNutjob · · Score: 1

      Refactoring is like re-arranging the deckchairs. If you need to make room for something, or get visibility into something you plan to work on, or be able to walk the length of the ship multiple times an hour without tripping over a chair, then you need to rearrange the deckchairs. If your ship is sinking, it generally won't help. If you have a ship and you need a train locomotive, rearranging won't help.

    6. Re:car by cowwoc2001 · · Score: 1

      Oh my god. If I could up-vote this answer a thousand times, I would! You made my day :)

    7. Re:car by Anonymous Coward · · Score: 0

      Repair is by definition not refactoring. Refactoring would be something like changing the engine layout so it's easier to access the parts in the future. As soon as performance is affected by a change, it's not refactoring.

    8. Re:car by Anonymous Coward · · Score: 0

      And yes, refactoring makes a car more comfortable, but not for the driver or passengers. It makes it more comfortable for the mechanics, IF it's done with some practical sense, instead of mindlessly applying ten "rules" like in this useless study.

    9. Re:car by Anonymous Coward · · Score: 1

      washing your car makes it use less fuel.

      That's why the first thing I do is remove all the comments from my coworker's source code.

    10. Re:car by readin · · Score: 1

      oooh, a car analogy :)
      Refactoring isn't repairing the car. Refactoring is moving the battery a little to the left so that next time you have to do a jump start the cables have room to grip the nodes.
      No that's not quite it either.

      Refactoring is the engineer changing the design of the car so that that instead of connecting the power steering to the front axle by using a wire that runs from the steering column to the roof to the trunk to underneath the seats and finally to the axle, the wire goes forward and down to the axle. This will make diagnosing problems with the steering easier (won't have to wonder if roof damage is problem) and will make future design work easier. However the customer is unlikely to notice any immediate difference.

      --
      I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
    11. Re:car by naris · · Score: 1

      Here is a more appropriate car related comparison to the study in question: We studied rebuilding automobiles and found that after a complete overhaul of a 2012 Chevy with 30K miles that it did not improve any aspects of it...

  14. A study just to support its own hypothesis by Imagix · · Score: 2

    Let's see... of the 5 main conclusions, 4 were statistically insignificant, and the 5th showed an improvement in maintainability. Thus the conclusion is don't do it. Sure, that makes sense.

    1. Re:A study just to support its own hypothesis by ClayDowling · · Score: 1

      And this, my friend, is why it's a bad idea to subcontract your software development to undergrads in Sri Lanka.

  15. May, may, may ... by fahrbot-bot · · Score: 1

    But it may make code more maintainable.

    ... and I may bring you a pony. Or I may not.

    Stating that something "may" do something, without additional qualifiers, is really no statement at all.

    --
    It must have been something you assimilated. . . .
  16. Procedural to Object Code by xfade551 · · Score: 4, Informative

    The test case basically converted procedural/structural code (structs and test cases) to object oriented code (classes and polymorphism) for a small, 4,500 line project. What they basically added was extensibility at the expense of overhead and traded individual-line complexity with architectural complexity.

    1. Re:Procedural to Object Code by Anonymous Coward · · Score: 0

      Well that seems simple enough, but makes the entire thing seem foolish IMHO. Of course refactoring should only be done when it's worth the time, and if your program is a black box with no expectation of becoming obsolete there's no reason to ever look in there again. Why on earth there are people out there getting paid huge sums more than me who fail to grasp these simple concepts eludes me :P

    2. Re:Procedural to Object Code by Anonymous Coward · · Score: 0

      I don't even understand why efficiency was even something they tested. None of the refactoring techniques they set out to test should affect run times or memory utilization in any significant way.

    3. Re:Procedural to Object Code by sysrammer · · Score: 1

      Correct. And now they have the data points to prove that. Might as well since they were testing, as recording the timings is a fairly trivial task.

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    4. Re:Procedural to Object Code by Anonymous Coward · · Score: 0

      > I don't even understand why efficiency was even something they tested.

      Because that's the scientific method.

      > None of the refactoring techniques they set out to test ***should*** affect run times or memory utilization in any significant way.

      Emphasis yours and mine. "Should" implies that it's an assumption of outcome, and that is subject to being tested.

    5. Re:Procedural to Object Code by sysrammer · · Score: 1

      ^^^ mod up. This is a good summary of what actually happened.

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    6. Re:Procedural to Object Code by sysrammer · · Score: 1

      xkcd has a good strip where zombie Feynman extolls the virtues of Mythbusters, stating that experimentation is at the core of science. And I notice in astronomy various projects are still confirming various parts of Relativity, even ones that have been proven before in different circumstances.

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    7. Re: Procedural to Object Code by Anonymous Coward · · Score: 0

      While that is true in the general case, at some point one must stop testing for foregone conclusions. Example: changing the location of an elementary tabletop Newtonian ballistics experiment by a couple of meters should have no effect on the result, so it's probably safe to skip calculating nanovariances in Earth's gravity.

    8. Re:Procedural to Object Code by xfade551 · · Score: 1

      If you take a bit of well-constructed procedural/structural code, then convert it to OOP, you'll find you tend to wind up with a few extra memory loads and jump/branch instructions. You also tend to spend a bit more runtime doing data initialization with classes rather than structs.

      Most of the time, these changes insignificant, but if you're doing something intensely iterative it can add up.

  17. Re:Easier to Analyze or Change == More Maintainabl by blue+trane · · Score: 1

    Isn't refactoring when you start doing the optimizations that were premature before, when you just wanted something that ran?

  18. empirical evidence by Andy+Smith · · Score: 1

    Refactoring is the process of improving the design of existing code by changing its internal structure without affecting its external behaviour, with the main aims of improving the quality of software product. Therefore, there is a belief that refactoring improves quality factors such as understandability, flexibility, and reusability. However, there is limited empirical evidence to support such assumptions.

    If my code looks scruffy then I refactor it. When I come back to it, I can read it better. That's all the empirical evidence I need.

  19. Re:Easier to Analyze or Change == More Maintainabl by cheesybagel · · Score: 4, Insightful

    Yeah. The conclusions are nonsense piled on more nonsense. Plus it is plain bullshit. Imagine I only refactor by removing duplicated code across functions or different compilation units. Will the compiled code size become smaller? Yep. Will be easier to read (less LOC to read)? Yep. Will it be more maintainable? Of course you have less code to bother with.

  20. Re:Easier to Analyze or Change == More Maintainabl by Wraithlyn · · Score: 4, Insightful

    My thoughts exactly. More maintainable code IS higher quality code, in my opinion.

    Making code run faster has a completely different name, it's called optimization (and is frequently the root of all evil). And it often involves the exact opposite of things you do when refactoring. Eg, unrolling a loop to make it run faster is pretty much the exact opposite of refactoring for maintenance & readability.

    --
    "Mind, as manifested by the capacity to make choices, is to some extent present in every electron." -Freeman Dyson
  21. Re:Easier to Analyze or Change == More Maintainabl by narcc · · Score: 2

    I hope not.

  22. If you hire coders in Sri Lanka... by PRMan · · Score: 1

    ...don't be surprised if you end up with unmaintainable code..

    --
    Peter predicted that you would "deliberately forget" creation 2000 years ago...
    1. Re:If you hire coders in Sri Lanka... by Anonymous Coward · · Score: 0

      Consider it "write once" code.

    2. Re:If you hire coders in Sri Lanka... by BarbaraHudson · · Score: 1

      That's because they've finally grasped the concept of "job security for coders 101."

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  23. Re:Easier to Analyze or Change == More Maintainabl by Anonymous Coward · · Score: 0

    Isn't refactoring when you start doing the optimizations that were premature before, when you just wanted something that ran?

    That's certainly one type. "Premature optimization is the root of all evil." - Knuth

  24. Re:Easier to Analyze or Change == More Maintainabl by rgmoore · · Score: 2

    No. Refactoring is when you take the awful, unmaintainable spaghetti code you produced when you were in a deadline crunch and convert it into something maintainable. The goal is to restructure the source code without changing the functionality at all.

    --

    There's no point in questioning authority if you aren't going to listen to the answers.

  25. Totally meaningless paper by Kjella · · Score: 2

    Sorry, but it has absolutely nothing to do with the real world. They're giving twenty people - ten in experiment group and ten in the control group 30 minutes to do a bit of analysis. And they measure minutes to apply a few changes, without any qualitative measure on how the code is growing. There's very little proof that the refactoring they did made any sense, the sample size is so low you'd never get reliable results and pretty much what you can conclude is that refactoring doesn't make hackjobs easier. Never thought so, that just involves finding the place something's happening and hack it. If it's a good idea, well... it works there and then.

    --
    Live today, because you never know what tomorrow brings
  26. 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."

    1. Re:Not significant - ignore by sysrammer · · Score: 1

      Well, it's a first step. Industry can take it from there if they want, and adapt the experiment to their particular situations.

      --
      His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
    2. Re:Not significant - ignore by Anonymous Coward · · Score: 0

      To reinforce this observation: I am the sole compiler developer for our architecture, and our LLVM - based compiler has 12,650 Lines of target specific code.
      Furthermore, it would be better if the C# nitwits can have an experimental setup which can be executed in a non-trivial environment

    3. Re:Not significant - ignore by avandesande · · Score: 1

      I will take well written procedural code over poorly implemented OO any day... not to mention that I can't remember a single time where I refactored and the LOC wasn't significantly reduced.

      --
      love is just extroverted narcissism
    4. Re:Not significant - ignore by Anonymous Coward · · Score: 0

      " I've seen single class files that have thousands of lines of code (and vomited when I saw it)"

      There is nothing intrinsically bad about a class with thousands of lines of code. Classes should reflect logical structure. Lines of code reflect actions and functionality, so it's entirely possible for a class to be large, broad, and long, but still belong to a very clear logical structural element within the entire software architecture.

      But perhaps you vomited due to the code quality?

    5. Re:Not significant - ignore by Anonymous Coward · · Score: 0

      Its not uncommon for class files to have more than a 1000 lines of code. There isn't anything wrong with that as long as it is cohesive.

  27. Sample size of zero by Anonymous Coward · · Score: 0

    > The researchers selected a small-scale application (about 4,500 lines of C# code) used by the academic staff at the University of Kelaniya for scheduling events and managing online documents for evaluation.

    My personal anecdotes have orders of magnitude more evidence than this study.

  28. Needs a larger sample size by CODiNE · · Score: 3, Insightful

    The researchers selected a small-scale application (about 4,500 lines of C# code) used by the academic staff at the University of Kelaniya for scheduling events and managing online documents for evaluation.

    That's hilarious, I have web apps (I'm stuck with) having individual pages larger than that, including tons of other crap. Refactoring allows following the DRY principle and removing duplicated code. It allows moving SQL statements all the heck over the place into single places where they can easily be tested and updated when bugs are found.

    They're basically working with a program that's not really that awful in the first place and making it a little bit nicer. How about starting with absolute junk and making it useable? Unmaintainable code is a consequence of technical debt, refactoring pays that debt down and keeps things manageable. Sure you may not need to refactor right now, but taking the time to do it once in a while keeps things from getting out of control.

    --
    Cwm, fjord-bank glyphs vext quiz
  29. Sample Size by Anonymous Coward · · Score: 0

    The study group size is 19 students. Does that bother anyone else? 19? Students?

    1. Re:Sample Size by ledow · · Score: 1

      19 students, one codebase, 4500 lines.

      Hell, my HOBBY project has something like 120,000 lines and that's not including any of the huge open-source libraries that I suck in to do the interesting stuff. And that's just the stuff I tinker with when I have a spare day or so.

      I wrote more than 4500 lines (not including bracketing and whitespace) for my first set of Introduction To Programming coursework answers, for the first week, for the course I took in my first year of my degree, in Java, that was designed for the people on the maths courses who'd never touched a computer.

  30. The paper is BS... by Anonymous Coward · · Score: 2, Insightful

    There are so many problems with that study.

    First, they use C#. There is no reason to think that it's not language independent.

    Second, All the code was from one code base with 4500 lines! How can you extract anything statistically significant from basically 1 data point!

    Third, supposedly 10 canonical re-factoring techniques were used. Could it be that these re-factoring techniques are useless? Of course, they are not discussed at all in the article. We don't know what re-factoring techniques they used (out of a big set from a different paper).

    Fourth:

    In order to apply 10 refactoring techniques a small scale project with bad smells was selected as
    the source code. The selected application was a system which was implemented in the
    Department of Industrial Management, University of Kelaniya and used by academic staff at the
    department to schedule their personal and professional events and to manage their online
    documents repository. The source code contained around 4500 lines of codes. The relevant bad
    smells were identified and all the selected refactoring techniques were applied to the source code.

    What?? They sniffed the code??? Makes absolutely no sense. I'd say the authors are idiots...

    Oh yea, neither of the authors have background in CS. They're MIS (i.e. trained to be PHB).

    1. Re:The paper is BS... by AJWM · · Score: 1

      "Bad smell" is a (silly, I'd agree) term of art. You know it when you look at code, wrinkle up your nose and go "eww".

      I just call it ugly code.

      --
      -- Alastair
    2. Re:The paper is BS... by Verdatum · · Score: 1

      The refactoring techniques they used were from Fowler's book, Working Effectively with Legacy Code. But it seems like they didn't actually bother to read his book. They are good techniques, and it is an excellent book, I recommend it to anyone stuck working on old crummy codebases. But the book tries to stress that the specific techniques are not nearly as important as determining when it is appropriate to use which technique. It further stresses that the most important thing is to get as much of the codebase covered by well written unit tests as is reasonably achievable. But there was no mention of either of these concepts in this paper. The article made it sound like they just gave a bunch of undergrads the list of techniques and instructed them to apply them. Undergrads generally have zero experience working on legacy code. Most of them only work on assigned programming projects from scratch. The only time I worked with legacy code was tweaking the Linux Kernel for my OS class.

    3. Re:The paper is BS... by DickMardy · · Score: 1

      The techniques were from 14% of Fowler's book (10 out of 72 refactoring techniques). One of the techniques that was chosen was "Extract Subclass". One of the quality measures they used was "Depth of Inheritance". Quality went down. Go figure.

  31. on *average* by microbox · · Score: 1

    The title is dying for "ON AVERAGE" on the end. The framing strongly suggests that it is a simple issue.

    --

    Like all pain, suffering is a signal that something isn't right
    1. 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.
    2. Re:on *average* by LifesABeach · · Score: 1

      Sri Lanka, and simple in the same sentence; well maybe they are eager to learn more of the H1B ways?

    3. Re:on *average* by BarbaraHudson · · Score: 1

      The framing strongly suggests that it is a simple issue.

      It is a simple issue - "this 'study' is crap."

      --
      "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
    4. Re:on *average* by LostMyBeaver · · Score: 2

      The paper itself is a crap read to begin with. It's just screaming for a Fox News headline model like this. I think Slashdot really summarized itwbennet summarized it pretty well.

      I read a bit of it looking for actual meaningful numbers, but it was clear to me that none of the people involved or focused worked on multi-million line projects. I am almost choking on my tongue thinking "Imagine the code quality of a web browser if the code wasn't regularly refactored to reduce the number of possible bugs?

      Every single thing test they ran and used as proof, I can personally contradict from experience being part of implementing CSS 3 in a browser. There are thousands of contexts in CSS alone where it is business critical to refactor.

    5. Re:on *average* by Anonymous Coward · · Score: 0

      Agreed, LOC needs to be balanced with cyclomatic complexity and maintainability index. If the average method cyclomatic complexity is above 100, then a refactor will improve morale. Better yet, some code has dead logic to remove. New language features allow thousands of lines of boilerplate to be replaced with templates.

      They should try refactoring a 11,000 line C++ file then do a new report.
      This report is one for the bin.

    6. Re:on *average* by grahamtriggs · · Score: 1

      Bigger qualifier would be - what is measurable software quality? The only measures that really matter are how few bugs are there, how non-serious are the bugs, how easy are the bugs to fix in reality, how quickly and reliably can new features be added, or old ones removed, and how efficient is the code?

      You can't genuinely measure software quality in the static. You can't measure it against the unknowns of the future.

      Refactoring to meet some arbitrary definition of software quality is a red herring. But refactoring tools and techniques are an invaluable part of addressing the challenges of the future - of being able to address bugs / isolating code for testing, being able add/remove features, increasing code reuse instead of duplication for maintenance and predictability.

    7. Re:on *average* by Anonymous Coward · · Score: 0

      LOC is an issue. It's more of a personal thing but once a java file is over 2000 lines long, I start getting dizzy. That usual means that I need to break it into a model and something else (usually a controller).

  32. Re:Easier to Analyze or Change == More Maintainabl by blue+trane · · Score: 1

    So I have a method that brute forces something, then I go back and figure out how to do it with a better big 0, and the functionality doesn't change, but that still isn't refactoring, because ... ?

  33. 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.
    1. Re:Improving crap code by Anonymous Coward · · Score: 0

      "Good coder" is contradictory. "Crap coder" is redundant. Get it straight.

    2. Re:Improving crap code by Anonymous Coward · · Score: 0

      good thing i can keep him employed because im one of those coders that turns gold to crap.

    3. Re:Improving crap code by Murdoch5 · · Score: 1

      If the code does preform like Gold after being re-factored then it wasn't needed, period!

    4. Re:Improving crap code by davidwr · · Score: 1

      If you misunderstood my to mean "gold, the relatively inert chemical element used for teeth fillings, expensive paperweights, electrical circuits, and as a financial hedge against inflation" then I take your point.

      If you understood me correctly to mean "high quality code" then I don't understand your comment, please elaborate.

      --
      Knowledge is how to play a game, intelligence is how to win, wisdom is knowing what game to play.
  34. Re:Easier to Analyze or Change == More Maintainabl by Dutch+Gun · · Score: 4, Insightful

    Nope, it's when I take the awful, unmaintainable spaghetti code someone else produced when they were in a deadline crunch and convert it into something maintainable.

    Sigh... I wish I could say that with a straight face.

    Interestingly, in my experience, poorly structured code seems to come about often less often because of "rushed code" but instead a lack of foresight in the original structure of a system to deal with continuously evolving features (which happens in most projects), along with a lack of willingness to refactor those systems as soon as it's apparent it's starting to break down.

    This is the "golden time" to refactor code, because it's just now become apparent where the structural flaws are in the architecture, but it's still early enough to refactor without causing a significant amount of pain. It's often hard to justify, because you've only got a couple of ugly special cases that complicate things here and there. However, if you procrastinate too long, you're going to start piling on more and more "ugly special cases", and the code is going to get harder and harder to read and maintain.

    --
    Irony: Agile development has too much intertia to be abandoned now.
  35. Re:More like Duh by sysrammer · · Score: 1

    Refactoring is more than changing names.

    --
    His ignorance covered the whole earth like a blanket, and there was hardly a hole in it anywhere. - Mark Twain
  36. Apples and Oranges by Anonymous Coward · · Score: 1

    This paper is an introductary/exporitory look into the topic so I'll forgive the tiny sample sizes, but I'd really like to see appenicies showing the code before-and-after refactoring, and some discussion of the participants' skill level (besides mentioning in the conclusion that "expert developers would constitute a better evaluation"). I'll also point out that while C# is comparable to Java, refactoring one language is not the same as refactoring another; with C++ you have a lot more rope to hang yourself and the language is very much alive and kicking; for instance refactoring code to use smart pointers can prevent future bugs. You also have a lot more tools for refactoring the code such as lambdas and proper templates. C# is designed to be simple and is slow as a result, and I'd not be surprised if refactoring C# code does not improve either of these things a lot, although using proper data structures for the right job would be important. I don't mean to bash C# as I actually find some parts of it pretty nifty; I just want to point out that it's vastly different from C++ and that no study aiming to undertstand the impact of some good refactoring upon code maintainence metrics can focus on a single language.

  37. Re:Easier to Analyze or Change == More Maintainabl by Ravaldy · · Score: 1

    Refactoring is the action of reviewing the code and re-writing it (internally only). Refactoring is in most cases done to increase readability and reusability (once again, internally only) which usually results in better maintainability. A by products of refactoring is detecting defects and optimization opportunities.

  38. Or maybe their refactoring was poor... by Anonymous Coward · · Score: 0

    The paper does not mention who actually did the refactoring in the first place and how much was done, besides from:
    "The relevant bad smells were identified and all the selected refactoring techniques were applied to the source code."

    It then mentions showing the un-refactored source code to one group and the refactored to another group, then comparing results on a questionnaire.

    So my conclusion could just as well be that this particular refactoring was done incorrectly

  39. Comment removed by account_deleted · · Score: 1

    Comment removed based on user account deletion

  40. Refactoring does not mean superior - it depends... by CraigCruden · · Score: 1

    Refactoring does not necessarily mean superior code.... it depends on the coder doing the coding and the refactoring as well as many other factors such as the history of the source itself.

    Refactoring is something you should think of whenever you revisit your code to make changes as you are developing. Can I do this better? I don't know many programmers that write something once and it is perfect. Sure you can come back to it and make some changes that are necessary and do no thinking about anything other than just hacking in a change to make it work.... but that leads to worse and worse code, longer development cycles to deal with the repercussions of aging unmaintainable code etc. People have to start thinking of their source code as a depreciable asset not as an investment. A good percentage (depending on technology and industry the software is written for) of the cost of developing the system should be written off each year, and you require a certain amount of additional investment just in upkeep.

    Of course to be able to properly refactor, your system cannot be a fragile system (lacks unit tests). If it is then refactoring may cause more problems than it solves. To properly refactor, you really need to have taken the time to write a full slate of unit tests as you were developing the system. This allows developers to be able to focus on the changes and be reasonable assured that if the tests say everything works, that the changes have not caused problems elsewhere in the system. If someone tries to measure refactoring as separate from all of the other good practices - you won't necessarily be able to measure much difference....

  41. Study: This Study Is BS by engineerErrant · · Score: 3, Insightful

    Making a judgment about "refactoring" as a single, simplistic concept is like making a judgment about "food" or "government" without going into any further detail. Umm, it's kind of not that simple.

    Refactoring in real life is a whole array of different, nuanced activities. Any of them can be wise or foolish depending on the situation. Well-written code requires less of it, but some degree of it will always be needed as we can't tell the future. Each instance is a judgment call with no concrete right answer.

  42. Re:Easier to Analyze or Change == More Maintainabl by anonymous_echidna · · Score: 1

    I would describe refactoring as increasing the level of abstraction involved in the code. This makes the code more robust and potentially reusable. However, a higher level of abstraction will take more time for a person new to the code to understand. I think this is why "more maintainable" and "easier to analyse and change" seem to be at odds with each other in the study, as students aren't going to have the ability to readily deal with the higher levels of abstractions as well as, say, more seasoned programmers. I don't count optimisation (dealing with specific bottlenecks) as refactoring (abstracting and generalising the code). They are totally different approaches.

    --
    In most times, most places, by most people, liars are considered contemptible. - Ursula Le Guin
  43. Narrow Subject by Art3x · · Score: 1

    The study was over a single application. From the article:

    The researchers selected a small-scale application (about 4,500 lines of C# code) used by the academic staff at the University of Kelaniya for scheduling events and managing online documents for evaluation. 10 common refactoring techniques were applied to the code (e.g., Replace Type Code with Subclasses, Replace Conditional with Polymorphism).

    Not only did they study just one application, but they limited refactoring to these 10 fancy techniques specific to object-oriented programming (from the research paper itself):

    R1- Introduce Local Extension
    R2- Duplicate Observed Data
    R3- Replace Type Code with Subclasses
    R4- Replace Type Code with State/Strategy
    R5- Replace Conditional with Polymorphism
    R6- Introduce Null Object
    R7- Extract Subclass
    R8- Extract Interface
    R9- Form Template Method
    R10- Push Down Method

    In contrast, here are some things I do when refactoring:

    - escape HTML in variables before embedding them in HTML, to seal against scripting attacks
    - rewrite database queries to use parameters, instead of variables directly from user input, to seal against SQL injection
    - move repeated code into functions
    - Make app use just one database connection library instead of two. Yes, that's right, the app made two connections to the same database, through two different PHP libraries, on the same page. The only reason I can guess is that the last programmer meant to move from one library to the other, but left the company when he was right in the middle of doing so.

    and a dozen other basic programming techniques. You had better believe that such refactoring improved code quality. Typically the code shrinks down to 30-70% its original size. Often it runs several times faster. For sure it is safer. And having merged code that was copy and pasted all over the palce, it is a lot easier to make changes to thereafter.

    Theoretically, I shouldn't have to do these kinds of things, because a professional programmer should not strew such code behind them. But every single one of my fellow programmers or forebears here has committed these atrocities. For what it's worth, I work on a corporate intranet. So I probably see worse acts than at companies dedicated to software.

  44. shit can coders in third world by Anonymous Coward · · Score: 0

    IT's the third world , if your coders are crap - of course you are going to have issues.

  45. Bullshit. by Anonymous Coward · · Score: 0

    EOM

  46. Re:Easier to Analyze or Change == More Maintainabl by Anonymous Coward · · Score: 0

    It can make code more "shareable". A tangled mess of globals can't be shared with anything.

    It's hard to prove this with 4,500 SLOC.

  47. Re:More like Duh by BarbaraHudson · · Score: 1

    ... and removing duplicate code, turning some code into a reusable library that can be used in other projects, de-obfuscating "cute" code that you wrote in a midnight caffeine-fueled "in the zone" blur of clarity (you know this is not a contradiction if you've been there), calling an existing library that you found does the same job as your code but is more flexible, adding cross-platform #ifdefs, etc.

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  48. Re:Easier to Analyze or Change == More Maintainabl by OzPeter · · Score: 1

    who in the world ever though that refactoring would make code run faster?

    Well if you were refactoring a brain dead method into something that had more smarts it is possible for the refactored code to run faster.

    --
    I am Slashdot. Are you Slashdot as well?
  49. Completely misses the point by WinstonWolfIT · · Score: 2

    The #1 reason to refactor is to make code testable. The standard recipe is dependency injection with an IOC container, resulting in no live constructor calls, no dependency issues when a constructor changes, and decoupled dependencies. It's not a magic bullet but it's a big step in the right direction. Interestingly, testable code can have no tests and still be higher quality as a result.

  50. To which I say, "duh?" by acroyear · · Score: 2

    from my blog on this, just now:

    Proponents of refactoring have never ever said otherwise (unless they themselves are confused on the matter). Code is only readable if it is either simple, or clearly follows design patterns, or is clearly commented and the comments are up to date with the current version of the code. Code is only easy to change when it is readable and when all external dependencies are well known. That last part is a key thing that metrics aren't necessarily able to capture.

    A refactoring project, if not refactoring to the right design patterns to address what was wrong with the structure in the first place, is not going to improve it. One must know clearly why the current structure is making a bug-fix or a new feature difficult to implement.

    And while some refactorings are 'good' in that they reduce a lot of copy-paste code, others are good because they add code, or add classes (an alternative increase in complexity). Different refactorings have different effects, and are used in different situations.

    And as always, if you don't need to refactor, don't. A refactoring is to improve the design, not to rewrite for its own sake.

    And there-in lies the great flaw of the whole idea of such a study: you can't measure the quality of a software design. Some things you just have to judge for yourself, based on experience and attention, and no arbitrary metrics number will ever differentiate between a good design and a rubbish heap.

    Disclaimer: I hate software metrics.

    --
    "But remember, most lynch mobs aren't this nice." (H.Simpson)
    -- Joe
  51. Re:Easier to Analyze or Change == More Maintainabl by ranton · · Score: 2

    So I have a method that brute forces something, then I go back and figure out how to do it with a better big 0, and the functionality doesn't change, but that still isn't refactoring, because ... ?

    That is generally considered optimizing, not refactoring. By some definitions of refactoring I guess all optimizations are a form of refactoring, but that is almost never what someone means when they say refactoring.

    --
    -- All that is necessary for the triumph of evil is that good men do nothing. -- Edmund Burke
  52. Re:Easier to Analyze or Change == More Maintainabl by BarbaraHudson · · Score: 2

    This is the whole problem with "narrow and deep" vs "wide and shallow." Too deep a hierarchy is just bad practice.

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  53. Refactoring often done for understanding by laughingskeptic · · Score: 1

    Most refactoring that I have observed over the last 30+ years was done primarily because the person handed the code did not understand it as it was. The refactoring process is very often the process through which a new developer figures out how old code works. Everyone likes to think that their refactoring was some sort of improvement over the previous code base, but the truth is this is only likely to be true about half the time. Considering that inexperienced engineers do more refactoring than experienced engineers, refactoring probably only brings actual improvement of any form to the code base less than half the time. The big plus is you now have a new guy that has ownership of something in the product. This benefit is hard to quantify, but should not be underestimated.

  54. Two birds, one stone by duck_rifted · · Score: 1

    I don't buy the conclusion in the article at all, period.

    1. When you refactor, you look over your source.

    Programming is like any other kind of writing. The more you proofread, the more error-free your resulting work will be. While refactoring if all you're doing is copying and pasting code around, then sure, it does no good. But if you're paying attention to the code you're working with then you're also proofreading.

    2. Improved interface = improved code.

    The end functionality is not all that matters. Whether other programmers can use your code also has an impact upon how its quality will be perceived. When you refactor to improve an interface, you make your code more readable and more easily reused. That is most certainly an improvement.

    3. Things change.

    It wasn't that long ago that in C++, an insane number of malloc calls lurked behind every return. One could see this with callgrind, easily. Copies were copied and copied again just to get a return out of its function scope. Now we have move semantics. While you're refactoring, take a look and see if you can improve your performance with new language features.

    4. Errors are not always obvious.

    While refactoring, proofreading, and implementing new paradigms and patterns enabled by new language features, never stop compiling and running your code in your head. Sometimes ugly bugs don't show up until weird corner cases come around, but if you can think of that corner case ahead of time then you can nip it in the bud.

    5. Get reacquainted.

    While you're there, you might as well get to know your code well, once again. It has been a while since you've seen it, and hey, people forget. This is an excellent time to cozy up with a cup of coffee or hot cocoa and get to know the code you were once one with long ago.

    If the conclusions drawn from a single case are generalized and promoted as gospel, be suspicious. Your competitors have a vested interest in teaching you to do things the wrong way. Should they ever succeed, may they be struck down by the fury of a thousand days maintaining the crap code they helped create by being underhanded.

  55. Re:Easier to Analyze or Change == More Maintainabl by Anonymous Coward · · Score: 0

    A quote unfortunately used by a bunch of second rate coders to justify their lack of planning. I always get a chuckle when someone brings it out.

  56. Re:Easier to Analyze or Change == More Maintainabl by hey! · · Score: 3, Interesting

    I once took over 30,000 lines of code that had been written by a subcontractor and trimmed it to around 4000 LOC. And you better believe it ran faster! Not because refactoring is magic, but because once all the mind-numbing almost-repetition was mucked out you could actually see what the code was doing and notice that a lot of it wasn't really necessary. Ever since then I have always maintained that coders should never ever copy and paste code. I've had people disagree, saying that a little bit of copying and pasting won't hurt, but I say if it's really such a little bit then you shouldn't mind re-typing it. Of course if you do that very soon you start putting more effort into devising ways to stop repeating yourself, which is exactly the point. Repeating yourself should be painful.

    That's I think a reliable litmus test for whether you should refactor a piece of software. If it's an area of code that's been receiving a lot of maintenance, and you think you can reduce the size significantly (say by 1/3 or more) without loss of features or generality you should do it. If it's an area of code that's not taking up any maintenance time, or if you're adding speculative features nobody is asked for and the code will get larger or remain the same size, then you should leave it alone. It's almost common sense.

    I don't see why anyone would think that refactoring for its own sake would necessarily improve anything. If an automotive engineer on a lark decided to redesign a transmission you wouldn't expect it to get magically better just because he fiddled with it. But if he had a specific and reasonable objective in the redesign that's a different situation. If you have a specific and sensible objective for reorganizing a piece of code, then it's reasonable to consider doing it.

    --
    Post may contain irony: discontinue use if experiencing mood swings, nausea or elevated blood pressure.
  57. Re:Easier to Analyze or Change == More Maintainabl by Bite+The+Pillow · · Score: 1

    Who? Quants?

    That is, Quantitative Analysts. And it's kind of their job to say whether we, as coders, improve things by refactoring.

    Should we bill the client those hours, or suck them up as something we were initially paid to do? Lots of arguments here, but there is a study that claims to have an answer.

    How can anyone say?

    Obviously, stats. How? Depends on stats.

    You shut your mouth, How can you say I go about things the wrong way? I am human and I need to be loved Just like everybody else does.

  58. Re:Please don't tell my boss! by Anonymous Coward · · Score: 0

    r u a coder bro?

  59. Re:Easier to Analyze or Change == More Maintainabl by Yaztromo · · Score: 2

    So I have a method that brute forces something, then I go back and figure out how to do it with a better big 0, and the functionality doesn't change, but that still isn't refactoring, because ... ?

    Because it violates the standard definition of "refactoring".

    Refactoring is about changing the structure of the code, and not the algorithms used within the code. The goal is typically to reduce coupling, increase cohesion, and (frequently) to improve testability.

    Replacing an algorithm with a better algorithm isn't "refactoring", it's "rewriting".

    Taking your giant brute-force method and breaking it into smaller parts in a cohesive unit (source file, class, package, etc.) with lowered coupling (perhaps by genericizing previously tightly-coupled bits), in such a way that the individual units have a smaller testing surface -- but is otherwise the same algorithm -- then you've refactored the code, by definition.

    Yaz

  60. Re:Not true by MrBigInThePants · · Score: 0

    Thanks for that irrelevant and very retarded comment.

    I am completely in awe of your obvious level of experience and wisdom in this area...

  61. Re:Easier to Analyze or Change == More Maintainabl by Kobun · · Score: 1

    Here's probably the best things I've seen written on refactoring: http://www.joelonsoftware.com/... & http://www.joelonsoftware.com/...

  62. What? by Anonymous Coward · · Score: 0

    Are you fucking serious? That's pretty subjective. If you're talking about taking

    string s = "";
    s += "a";
    s += "b";

    to

    string s = string.Format("{0}{1}", "a", "b");

    Yeah, no difference. It looks prettier. How does that encompass all rafactoring. I've refactored sites and found major structural problems. Load times from 30 seconds down to 250 ms. Terrible use of recursion. Calling a method in a loop instead of once before the loop.

    Like almost anything, YMMV.

  63. Re:Easier to Analyze or Change == More Maintainabl by readin · · Score: 2

    This is the "golden time" to refactor code, because it's just now become apparent where the structural flaws are in the architecture, but it's still early enough to refactor without causing a significant amount of pain.

    It can also be the golden time because the original writers are still around and know why certain things were done a certain way, and know what dependencies need to be addressed.

    Interestingly, in my experience, poorly structured code seems to come about often less often because of "rushed code" but instead a lack of foresight in the original structure of a system to deal with continuously evolving features...

    In my opinion poorly structured code too often comes from individual developers who just don't care. They show up to do a job and get paid; they got into CS because it was a way to make money; they don't really care about doing things elegantly. Or perhaps they care about quality but just don't understand the benefits of refactoring.

    --
    I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
  64. Re:Easier to Analyze or Change == More Maintainabl by readin · · Score: 1

    I would describe refactoring as increasing the level of abstraction involved in the code.

    I would say that refactoring can also be decreasing the level of abstraction. The goal isn't to create the highest level of abstraction, the goal is to create the right level of abstraction.

    --
    I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
  65. Refactoring requires context, NEWS at ELEVEN. by Anonymous Coward · · Score: 0

    There is a small wrinkle with the study: namely, that it makes *zero* sense to blindly apply refactorings. Each refactoring in the Martin Fowler book has an *exact* mirror refactoring, also found in the book. You have too many classes? He shows how to move away from it by using conditionals. You have too many conditionals? He shows how to use classes to get rid of 'em. If you apply each refactoring in his book, you will arrive at your original code!

    Did the "study" authors fail basic reading comprehension, or are they being dull on purpose?

  66. Re:Easier to Analyze or Change == More Maintainabl by readin · · Score: 1

    Ever since then I have always maintained that coders should never ever copy and paste code.

    If you're just copying and pasting and leaving it unchanged then you're probably right. But I've certainly had cases where I needed to copy and paste a few lines of code maybe even 100 times and then tweak each instance to put in the data values or validations I want. Making a loop or making it somehow generic would have made the code unreadable and I would have had to put in a lot of extra code to handle a few special cases. That said, I'm only talking about a few lines of code beint repeated. If 15 or more lines are being copied then that does suggest a need for reusing the code.

    --
    I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
  67. One example is all you need, right? by CBravo · · Score: 1

    What about the case where all java classes are named the same (but in different packages)? I think refactoring would help quality.

    --
    nosig today
  68. depends ? by Tom · · Score: 1

    Doesn't it depend a lot on what you refactor, when and how?

    I have 3 year old code that I would like to refactor because I've since switched framework (from CodeIgniter to Symfony 2) and it would bring it in line with all my other projects, allowing me more easy code-reuse and not maintaining two frameworks both on servers and in my mind. But it's largely a convenience factor and I would agree that it will probably not improve code quality very much.

    But I also have 12+ year old code written in plain PHP with my own simple database abstraction layer. I'm quite certain that refactoring that would do a world of good.

    --
    Assorted stuff I do sometimes: Lemuria.org
  69. Re:Easier to Analyze or Change == More Maintainabl by narcc · · Score: 1

    Indeed. By introducing abstractions, you exchange performance and flexibility for simplicity (of one kind or another). More than one unmaintainable mess has been made by abstraction-hungry developers layering one leaky abstraction on top of another in a vein attempt to restore some of that flexibility.

    This is why I'm a fan of top-down design. It tends to find the right balance almost automatically.

  70. It didn't need to be refactored by Anonymous Coward · · Score: 0

    1. Take a small application that didn't need to be refactored.
    2. Refactor it badly anyway.
    3. Analyse the refactoring poorly with questionable metrics.
    4. Conclude refactoring is rubbish.

    If you want the opposite conclusion hire a new professor with a vested interest in proving refactoring works. Better yet make it a CIO at a commercial company. There will be all kinds of meetings about the new wonderful improvements and all sorts of wacky metrics to back that up.

  71. Re:Not true by TheRaven64 · · Score: 3, Interesting

    Code runs. It continues to run. And, over time, the requirements change. Maintenance is adapting the code to the new requirements. If you don't understand why this is important, then I can only assume that no one is using code that you've written.

    --
    I am TheRaven on Soylent News
  72. Tuxedo Code vs Sloppy Code by Ugmug · · Score: 1

    Sloppy Code works just as well as "Tuxedo Code" i.e. refactored code......

  73. Fish Rights Now! by SpeedBump0619 · · Score: 1

    Why is this tagged Cod Equality? I mean, I'm all for fish rights, but that's just sil...heh.

  74. more maintainable? by Anonymous Coward · · Score: 0

    it doesn't make code run faster; and it doesn't result in lower resource utilization. But it may make code more maintainable.

    So, a research project that proved that refactoring does what it is supposed to do. What morons. That's the whole point. Maintainability. Take a piece of software that is going to have a 20 year life span written like hell and refactor it. Over the long term, the new devs that continually are tasked to work on it will have an easier time when actual OO techniques are used instead of the original spaghetti code.

    Refactoring: Many small changes made without effecting functionality (that means no changes for performance improvements unless it is a mess and the result is a better performing unit of code) over the long term make a better product.

  75. Always go back to C and ASM by Murdoch5 · · Score: 1

    Maintainability, Readability, Object Oriented and all the other catch words associated with software development are all just lipstick on pigs. Software development isn't beautiful and you don't write software to win a beauty pageant. At the end of the day your software needs to be fast, stable, secure, expandable and dependable, anything that doesn't assist those goals needs to go.

    What did this study think it was going to achieve? You can have the most readable and maintainable code in the world but if doesn't preform, then who cares. It's time to stop wasting time on catch phrases and return to the time when software development meant getting good code out.

  76. WTF? Ease of analysis =/= ease of maintenance??? by luis_a_espinal · · Score: 1

    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.

    From the OP, how the fuck do we reconcile this:

    Refactoring doesn't make code easier to analyze or change

    with this:

    But it may make code more maintainable.

    Seriously, those two statements conflict with one another. And since when refactoring was done primarily to make things run faster or more efficient resource-wise? Optimization is typically an architectural issue, or a point of local optimization in changing algorithms and data structures. Refactoring for the most part has always been about structural changes to enable analysis, re-usability and replacement and to ensure correctness (or at least to avoid introducing new fuck-ups.)

    On The Onion News at 11, refactoring does not make code more eco-friendly/gmo-free.

  77. So Much Wrong by Zalbik · · Score: 1

    There is so much wrong with the study, I can hardly decide where to begin...

    1) They used a single project of 4500 lines of code. That's quite small. The project may have been fairly easy to analyze/debug/maintain even if the code quality is crap.

    2) No objective measure was given of the "bad code smells" identified in the selected project.

    3) It is possible they did a very bad job refactoring the code base. In addition to refactoring, they should have had other software professionals evaluate whether the "refactored" code was more maintainable in order to control for this.

    4) There is no indication that they controlled for variability in the student's skill sets. The students who worked on the original code may have been much better students than those that worked on the refactored code.

    5) The student group sizes were far too small to get meaningful results.

    6) The "quiz" to determine analyzability consisted of 15 questions. This is far too small a size to determine how analyzable the code is.

    7) The mean analyzability scores were 7 vs 6.63. This suggests the student's in both sets may have poor understanding of the code bases.

    8) 10 refactoring techniques were not chosen based on applicability to the system in question, but were instead chosen based on previous studies that ranked the impact of refactoring on code quality. i.e. they treated refactoring as a "silver bullet" rather than deciding what types of refactoring were most applicable to the project in question.

    There are so many flaws in the methodology that the results are meaningless. The only reason to waste time with this sort of nonsense is publicity.

  78. Study: Refactoring Doesn't Improve Code Quality by Anonymous Coward · · Score: 0

    Then you're doing it wrong.

    Also how is improved maintainability not improved quality?

    That's probably the number one reason I will refactor code - because someone who had more clever coding tricks than understanding of how other people read and parse code wrote some deep voodoo full of magic numbers that only they know what it all means.

  79. Re:Easier to Analyze or Change == More Maintainabl by jdschulteis · · Score: 1

    But I've certainly had cases where I needed to copy and paste a few lines of code maybe even 100 times and then tweak each instance to put in the data values or validations I want.

    This leads to bugs where a tweak gets missed in one of the copies (copy, paste, do tweak 1, interruption!, forget tweak 2). It also causes maintenance problems when the person coding a bug fix doesn't know there are a bunch of other places that need to be fixed.

  80. Isn't that what refactoring /is/? by Anonymous Coward · · Score: 0

    "it doesn't make code run faster; and it doesn't result in lower resource utilization. But it may make code more maintainable."

    I thought maintainability is the whole point of refactoring. If you want your code to run faster or use fewer resources, I'd say you need to optimize, not refactor.

  81. ... in other news by Anonymous Coward · · Score: 0

    any improvement done by the same group did not improve anything... coincidence? I think not

  82. Re:Easier to Analyze or Change == More Maintainabl by readin · · Score: 1

    But I've certainly had cases where I needed to copy and paste a few lines of code maybe even 100 times and then tweak each instance to put in the data values or validations I want.

    This leads to bugs where a tweak gets missed in one of the copies (copy, paste, do tweak 1, interruption!, forget tweak 2). It also causes maintenance problems when the person coding a bug fix doesn't know there are a bunch of other places that need to be fixed.

    You're right that forgetting to do the tweak can be a problem. But as for not knowing there are a bunch of other places that need fixing, I guess I wasn't clear enough. The repetition gets centralized in a single file so that you can look over all the locations at once.

    --
    I often don't like the choices people make, but I like the fact that people make choices. That's why I'm a conservative.
  83. Maintainability by carys689 · · Score: 0

    "But it may make code more maintainable." -- in my experience this is usually the primary motivation for refactoring.