On refactoring...

Matts on 2002-12-04T18:40:36

In conversation with a co-worker:

> [Refactoring] is like decorating a house. You sort out one place > and give it a nice new coat of paint, and it shows up the next bit. And > so on, until you decide to stop.

Yes, then you end up with our house. Nicely decorated, a few cracks, but DO NOT GO INTO THE BATHROOM


what is refactoring

pault12 on 2002-12-04T21:05:24

In my universe, refactoring simply means eliminate as much copy&paste as possible.

Usually that would result in actually rewriting a lot of 'broken' things. Of course, one may always put an API layer around some crappy component, but to me that is orthogonal to refactoring.

Or, more accurately - placing a nice API around some crappy componenet - that is not an essence of refactoring.

Eleminating copy & paste - that is an essence of refactoring.

http://www.xmlsuck.com/X/1037127117/index_html

Cut 'n' paste is only part ofit

autarch on 2002-12-04T21:31:37

Eliminating redundant code is certainly one major goal of refactoring. But it's also just about improving the readability and _design_ of the code on an ongoing basis. For example, in the Refactoring book, Fowler talks about a refactoring called "rename method". This is exactly what it sounds like.

This won't eliminate any cut and paste, but if you have a misnamed method (or variable, or whatever) then renaming it can certainly improve code readability.

Unfinished Business

jonasbn on 2002-12-07T10:59:48

DO NOT GO INTO THE BATHROOM would imply an unfinished refactoring, but only in the eyes of the last refactorer.

The problems are in my opinion really:
  - when to stop refactoring
  - when is code finished

Postulating that code never is finished would imply refactoring can never be called complete and therefore refactoring is a tool to 'make the best of it for now'.

My kitchen table is not fastened to the element beneath it, I can still cook and do the dishes, but I would not recommend having several people running around my kitchen at the same time cooking for many people.

If code can obtained a state of being finished, then a refatoring can take place to make the code readable, fast, reliable and compliant with whatever standards it has to follow. Only a an addition rewriting etc. would legalise yet another refactoring.

So if a refactoring is simply a 'curly-braces' removing then don't.