{"id":154,"date":"2008-04-07T23:00:30","date_gmt":"2008-04-07T22:00:30","guid":{"rendered":"http:\/\/t-machine.org\/index.php\/2008\/04\/07\/why-did-people-start-calling-rewriting-things-better-refactoring\/"},"modified":"2008-04-07T23:00:30","modified_gmt":"2008-04-07T22:00:30","slug":"why-did-people-start-calling-rewriting-things-better-refactoring","status":"publish","type":"post","link":"http:\/\/new.t-machine.org\/index.php\/2008\/04\/07\/why-did-people-start-calling-rewriting-things-better-refactoring\/","title":{"rendered":"Why did people start calling &#8216;rewriting things better&#8217; refactoring?"},"content":{"rendered":"<p>(re-posting from private forum thread)<\/p>\n<p>My response to this question was a bit of a gross generalization, and made several assumptions about the questioner; I hope I didn&#8217;t misinterpret what they were getting at. I *think* I got it right:<\/p>\n<blockquote><p>Because it&#8217;s not &#8220;rewriting things better&#8221;.<\/p>\n<p>It&#8217;s &#8220;changing the implementation of things without changing the observable effects of the overall system, even if the system is BROKEN at the moment&#8221;.<\/p>\n<p>By cutting out a much smaller problem than &#8220;rewriting things better&#8221;, you get a more powerful suite of techniques: there are complete processes which just don&#8217;t work if you allow yourself to spend time improving the code at the points where, instead, you are meant to merely &#8220;refactor&#8221;.<\/p>\n<p>Damn useful technique &#8211; although I found it hard at first to get over the idea of leaving broken features broken: I felt guilty doing it. But it works, and eventually the guilt goes away, as you see that it really is the right thing to do (&#8230;in the appropriate situations, of course, and as part of the right process(es)&#8230;)<\/p>\n<\/blockquote>\n<p>In the forum thread, I didn&#8217;t go into the details &#8211; you can google a lot of uses for refactoring.<\/p>\n<p>There&#8217;s one great example I ALMOST wrote about last year, but didn&#8217;t get around to (I didn&#8217;t realise until now that I&#8217;d never posted it&#8230;Doh!): using refactoring with unit testing to convert an old code base to a new code base, but doing it with many many passes.<\/p>\n<p>Brief summary of the parts that would be relevant here:<\/p>\n<ul>\n<li>Traditionally, with a horrendous mess of a codebase that needs converting, you&#8217;d either suck it down and spend many months (maybe many man-years) &#8220;converting&#8221; it &#8211; or else give up and rewrite it from scratch, one part at a time<\/li>\n<li>With Refactoring, you can rewrite it from scratch INSIDE the existing codebase, LESS than one part at a time, so that you get to use all the new code you&#8217;re creating immediately (instead of waiting for the complete system to be rebuilt-from-scratch)<\/li>\n<li>This works because Refactoring does NOT &#8220;fix&#8221; the code, it merely moves it around a bit, perhaps changes some minor subparts of it, often parts that have no effect on the overall system<\/li>\n<li>&#8220;no effect&#8221; means NO effect: no performance improvement, no change to the end-users<\/li>\n<li>&#8230;which allows you to use a particular Refactoring task in your schedule to merely &#8220;make the code slightly more amenable to be improved in the future; make it a bit less messy&#8221;<\/li>\n<\/ul>\n<p>Yes, this shows no overall improvement in the system after each Refactoring pass &#8211; but you make those passes so EASY and so QUICK to do that one individual programmer can do literally HUNDREDS of them in a few weeks.<\/p>\n<p>Traditionally, even doing just one &#8220;rewrite this small part of the system better&#8221; task would take months to even get started, because each time you think you&#8217;ve &#8220;fixed&#8221; it, you uncover another broken part, somewhere else in the system, somewhere that SHOULD be unrelated but sadly isn&#8217;t, that prevents your fix from working.<\/p>\n<p>With refactoring you just shrug, smile, ignore it, and get on with making small incremental improvements every day, and go home happy in the knowledge you&#8217;ve at least achieved SOMETHING today, even if no-one else will see the result of it until you&#8217;ve achieved many more days of little somethings. But then they&#8217;ll be amazed, because in the limit &#8211; as the complexity of the codebase \/ number of refactorings tends towards large numbers &#8211; the sum total of small steps of refactoring quickly becomes net improvements to the code base that were literally IMPOSSIBLE with traditional software engineering: they would have taken so many man years, you&#8217;d never have finished them in the liftetime of the product you&#8217;re working on.<\/p>\n<p>So. Just one example there, of how refactoring is a useful &#8211; and unique &#8211; tool, quite separate from &#8220;rewriting things better&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>(re-posting from private forum thread) My response to this question was a bit of a gross generalization, and made several assumptions about the questioner; I hope I didn&#8217;t misinterpret what they were getting at. I *think* I got it right: Because it&#8217;s not &#8220;rewriting things better&#8221;. It&#8217;s &#8220;changing the implementation of things without changing the [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[],"_links":{"self":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/154"}],"collection":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/comments?post=154"}],"version-history":[{"count":0,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/posts\/154\/revisions"}],"wp:attachment":[{"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/media?parent=154"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/categories?post=154"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/new.t-machine.org\/index.php\/wp-json\/wp\/v2\/tags?post=154"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}