“Refactor,” what a dumbass term!

When did “rewrite” become “rewrite from scratch?!” In my 30 years of writing code, rewrite never meant rewriting from scratch — until the programming cults arrived on the scene at the beginning of the century, that is. Before them, “rewrite from scratch” meant — lo and behold — rewrite from scratch, and a plain “rewrite” meant what the cultists successfully have named “refactor.”

What a classic textbook example from Lifton’s list of 8 factors of thought reform: #6 - make them speak your secret language!

Bah.

Similar Posts:

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Reddit
  • Slashdot
  • StumbleUpon
  • Technorati
  • LinkedIn

9 Comments »

  1. podcat said,

    August 31, 2008 @ 10:48 pm

    Wait, what? Since when did refactor mean rewrite from scratch? Its just “somehow” changing code for the better without breaking too much of the interface. You know, like breaking out common functionality from that 2000 line function, or just breaking it up into logical pieces so someone can understand it.

    If some “agile guy” went and told you otherwise hes most probably wrong. I’ve had agile courses and practiced it quite a bit at work and there has never been any throwing away of huge parts of code for a rewrite.

  2. podcat said,

    August 31, 2008 @ 10:50 pm

    oh, and I totally missed the point… never post before morning coffee…

  3. Simeon said,

    August 31, 2008 @ 11:44 pm

    Why? - Mostly likely because the term rewrite got abused, stretched and morphed into “rewrite from scratch” by teams, and project managers learnt what it could mean so treated it always as such.

    You must admit, “full rewrite”, “partial rewrite”, “rewrite from scratch” and “rewrite” are all quite close sounding, so in the minds of managers, your fighting a battle of misunderstanding.

    Therefore a new clean word was needed.

  4. tristan said,

    September 1, 2008 @ 1:05 am

    Well, out comes Fowler with a book called refactoring, and then every monkey with a design patterns book has to start using the word everywhere to sound responsible. This way, they can Refactor to Patterns.

    I happen to like the word “revise” myself, instead of rewrite. Most folks seem to not associate revise with “from scratch”.

    Otherwise, “refactoring” is crap an IDE will do. Which is really useful about %0.00001 of the time. Usually when you’re staring at a mountain of poorly organized Java code, and you need to start by renaming everything.

  5. Paul Sinnett said,

    September 1, 2008 @ 4:49 am

    Well put. What puzzles me is why he didn’t just use “factor”. That has a well understood meaning in mathematics and is exactly equivalent to the intended meaning within programming.

    Regarding “revise” my understanding is that it means specifically a correction or change of meaning (which would be a different kind of change.)

  6. Paul Sinnett said,

    September 1, 2008 @ 4:58 am

    Apparently this is where the name came from:

    http://www.martinfowler.com/bliki/EtymologyOfRefactoring.html

  7. Andrew Lauritzen said,

    September 1, 2008 @ 3:05 pm

    I’ve personally not heard “refactoring” be used to contrast “rewriting from scratch”; rather I’m used to it meaning something more along the lines of “improve its readability, or simplify its structure, while preserving its existing functionality“, which is suitably different than the scope of “rewrite” to warrant a more specific term I think. As tristan mentions, “refactoring” is something that can be done purely at the semantic level of a program, and is honestly quite comparable to mathematical factoring (say transforming code in the form of ABABAB… to (AB)* or similar) that I think the term is fairly well-chosen.

    Certainly ideally most refactoring work can be handled by a clever IDE, perhaps with some user direction. Perhaps more importantly, it can often be handled by more junior programmers as knowledge of the intricate details of the program operation typically isn’t required.

    So while I do agree with you that it’s not a useful term as far as people use it to mean “rewrite not from scratch”, it does have a useful meaning if its definition is suitably restricted to “factoring” code (at the syntactic/semantic/smart IDE level) rather than changing it.

  8. supzi said,

    September 6, 2008 @ 5:12 pm

    I agree, refactor is mostly used as “clarify” or “re adapt” the code. It means you are going to change the code without really changing its existing structure.

    Rewrite means you are going “to change” the code and its structure.

    I think refactor was first introduced as “isolation of (copy/pasted) redundant code”. Source #1 of bloated software. Nobody uses it anymore.

  9. juancn said,

    October 2, 2008 @ 10:34 am

    Mhh… I always associated the term “refactor” with a mechanical code transformation that does not change the behavior of the code.

    Similar to factoring a polynomial (is that the word in english?).

    Refactoring the code usually involves changing it through some IDE that can statically prove that the change it’s making won’t break the code. Note that it’s not very easy to do this for dinamically typed languages.

    Typical refactors include:
    - Extract method
    - Rename variable/method/class/whatever
    - Introduce variable
    - Inline method
    - Push member up (in a class hierarchy)

    …and many others. IDEs that support refactoring code, sometimes add other transformations that are not as safe

RSS feed for comments on this post · TrackBack URI

Leave a Comment

You must be logged in to post a comment.