Friday, August 1, 2008

Gain a better understanding of code

What motivates us to refactor? Joshua Kerievski asks (and answers) himself this very same question. One of the reasons he gives is to "gain a better understanding of code". To quote:

Sometimes we look at code and have no idea what it does or how it works. Even if someone could stand next to us and explain the code, the next person to look at it could also be totally confused. Is it best to write a comment for such code? No. If the code isn't clear, it's an odor that needs to be removed by refactoring, not by deodorizing the code with a comment.

I'd like to stress the second part of the quote. Is this the way we behave? I'd like to say yes, but too often I don't. The most recurring reason for which this happens is that the typical codebase on which you experience this problem has no test harness. I know, I know, I did not only buy the Feathers', I also read and studied it: everything looks neat and beautiful, but sometimes the processes described can be really exhausting, and you obviously come to fear changes (which is against XP values, for example).

Now, to everyone who thinks Star Wars to be just a useless bunch of movies, I'll show you how it can help you experiences professionals through. Powerful master Yoda said:

Fear is the path to the dark side.

The dark side is represented by hacks'n'comments. When you find them, you should follow Darth Sidious' advice:

Wipe them out. All of them.

Extreme as it might look, this is by far the best solution in the long run. And... May the force be with you.

No comments: