My Profession

| Home | Outline | Stylesheet insipired by CSS Colouring Book | Referrers |

day-level permalink  Saturday, February 08, 2003

permalink A RE-Reading Assigment: Refactoring.

I was getting really frustrated debugging a jsp yesterday. The screen revealed an ugly spew of System.out.println() debug statements had rendered my code unreadable. Realizing I was mired in reckless hacker mode, I turned off the monitor, took a breath, and decided to come up with three different ways to uncover the bug before returning to the keyboard. I grabbed my neglected copy of Refactoring for help. I had forgotten what fun this book can be.

I love the concept of code smells, "deciding when to start refactoring, and when to stop, is just as important to refactoring as knowing how to operate the mechanics of refactoring". I realized that I often resist working on this jsp-servlet project because I am not seasoned enough with J2EE to recognize the code smells. In other words, I know I am unhappy with the project's code, but I don't know why.

I also reviewed the catalog's "Composing Methods" and "Simplifying Conditional Expressions" sections. Below the name is a short summary of the situation in which you need the refactoring and a summary of what the refactoring does. Under Extract Method: "You have a code fragment that can be grouped together. Turn the fragment into a method whose name explains the purpose of the method." Under Decompose Conditional: "You have a complicated conditional (if-then-else) statement. Extract methods from the condition, then part, and else parts."

As for my jsp problem, the refactoring I used was not from the book or even Martin Fowler. It did conform to the structure of a good refactoring: it had nice, terse sections on Motivation and Mechanics, and the example was thorough (though it did meander off course at times). It was such a relief to locate this little gem, and the "Mechanics" to guide me off of the endless out.println() hamster wheel.

--------------------------------------------------------------------------------

See Also:

 

2:32:17 PM  comment [] | Topics: extremeProgramming programming_books 

About:

A weblog to stash links & notes for programming, books, stuff.

Posts by Topic:

wedgeXML (27)

ChannelRoll: