Skip to main content


Posted by daniel on November 13, 2003 at 8:18 AM PST

Last night we had high winds in the midwest. Our house lost a piece of gutter and my office window blew open scattering papers everywhere. I interpret entropy to mean that the wind could not possibly have left my room neater than it was. Entropy also argues in favor of refactoring.

Sure there are arguments against refactoring and we pointed to them this summer when the debate heated up after Bob Cringely wrote an article based on correspondence with Paul Tyma. Tyma wrote "'Cleaning up code' is a terrible thing. Redesigning WORKING code into different WORKING code (also known as refactoring) is terrible.
The reason is that once you touch WORKING code, it becomes NON-WORKING code, and the changes you make (once you get it working again) will never be known. "

And yet I look at the loose papers covering my floor. Everything I need is there. It is possible, if I take the time to organize these papers into piles and folders that I will spend time on pages that I will never need to look at again. Perhaps that time is wasted. But when it comes time for me to find something I need, I'd like to be able to put my hand right on it.

Perhaps I'm thinking about refactoring out of context. That seems to be a recent sport. In Projects and Communities , the Java Patterns community points to an article about Using RUP to write a Moroccan cookbook. Follow the link and you will see how much of the process was applied to a one person project to write a book. Christophe Tournier uses the software and a ton of artifacts to produce his book. Even if you do not have time to read the article in its entirety, you can capture the flavor by checking out the numerous figures and tables that outline his process. As often happens when I'm confronted with a large number of carefully constructed artifacts, I'm not sure whether to be impressed or frightened.

But back to refactoring. One of my favorite refactorings is to use more meaningful names. I once had a student who had an unusual naming convention for his GUIs. The first component he thought of would be named one , the second two, and so on. He would have a JFrame with variables that looked like this.

public JButton three, seven, twelve;
public JTextField one, eight, nine, ten;
public JLabel two;
public JMenuBar six;

His code was then unreadable to me and to his fellow students. He was bright enough to keep everything in his head for a week or two so he remembered that six was a reference to a JMenuBar. Of course there were other problems with his code, but it was hard to clean it up because you had to double check what everything meant before changing anything. Maybe Tyma would argue that we should not clean up the code because it was working. But, as inevitably happens, the day came when functionality had to be added and the code was broken and needed to be fixed. All of a sudden the naming convention wasn't so cute.

There is no real difference in this code snippet

public boolean a(){
  if (a.a()){
    return true;
  } else return false;

and this one:

public boolean moveRightIfCan() {
  if ( piece.isAbleToMoveRight() ) {
    return true;
  } else return false;

In the first listing we have no idea what is going on. In fact, the two methods named a() belong to different classes and have nothing to do with each other. Although the second listing is logically the same as the first, its meaning is more clear. If there is a time when we need to go back the code to fix it or to understand it so that we can reuse it, I would rather be faced with code that looks like the second snippet than the first.

While I'm at it, I want to point to a renaming that we implemented yesterday on We had no real name for projects that did not belong to a community. We grouped them under the banner "Projects" but this proved to be confusing. You could be looking at a project in the projects category of the Projects heading. We have renamed them to general. We are also now able to feature general projects and so are highlighting SiteMesh a web-page layout system that allows you to abstract out the site-wide design elements in decorators.

Speaking of refactoring, we are currently featuring the excerpt Measured Smells from Bill Wake's Refactoring Workbook. Bill presents the smells for each refactoring together with pointers on when to and when not to fix them. For instance, an extra long method is a code smell but that doesn't mean you should shorten every long method. Comments in code often indicate a place where you can pull out the commented code into a method with a name that implies what it does. There are, however, comments about why code was written a particular way that should remain with the code. Try his exercises - note that we aren't running the answers as part of the excerpt.

In the Weblogs , James Gosling reports that he's been put back to work in Yes, I've got a real job again. He confirms that he has moved from Sun labs to the Sun tools organization. In an unrelated story, his RSS feed is working again. As Gosling works to move the results of his Jackpot project into tools, Jim Cushing's debut blog entry Standards Killed the IDE star on Sun possibly joining the Eclipse community. Jim asks whether insisting on standards will help the Eclipse project move ahead.

Brian O'Neill is inviting you to join his efforts in creating A Communications Services Framework (CSF) to fuel IP telephony deployment. The first task that he'd "like to tackle with the CSF is that of identity. Currently, there is no way to automagically discover a persons contact addresses given one of the set; SIP address, phone numbers, email address, AOL screenname, etc."

In Also in Java Today Michael Yuan writes about how to Develop state-of-the-art mobile games. In this JavaWorld article, Michael first details the requirements of these games and then highlights what is available to developers looking to code this up. For a brief overview of How to diagnose a performance problem in a J2EE Sysem, check out this WebLogic Developer's Journal article. Because of where it is published, it does mention the WebLogic platform several times. For the most part, however, the information and advice is broad enough to be widely applied.

In today's News Headlines :

Registered users can submit news items for the href=""> News Page using our
news submission form.
All submissions go through an editorial review by news director Steve
Mallet before being posted to the site. You can also subscribe to the href=""> News RSS

Current and upcoming Java Events:

Registered users can submit event listings for the href=""> Events Page using our href=""> events submission form.
All submissions go through an editorial review before being posted to the

This blog is delivered weekdays as the href="">Java Today RSS
feed. Once this page is no longer featured as the front page of href=""> Java Today it will be archived at href=""> You can
access other past issues in the href=""> Archive.