Category ‘Java‘

 
 

Code Duplication

A while ago I fixed some obscure bugs in one of the search results pages of an enterprise application that I work on. I spent about four hours of focused development time refactoring and cleaning up some of the logic that handles the rendering and paging of the results. The new code worked well.

A couple of weeks later I found myself bug squashing on another search results page. As I dove into the code, I found a nagging sense of deja vu. This page had the same logic errors and mistakes as the page I had worked on weeks earlier. I found myself fixing the same bugs and performing the exact same refactorings as I had before.

I became more frustrated as I realized that the original author had copied all of the logic from the original page. Rather than extracting the common functionality to a reusable location, he took the lazy approach with copy and paste.

This kind of mistake is expensive. By duplicating the code, the cost of maintenance has doubled. Bugs must now be fixed in both places. Merging the common logic after the fact is more difficult than it would have been initially.

We have these wonderful object oriented languages. There are many ways to reuse code. Some of the following come to mind:

  • Two subclasses can share common functionality in a parent class.
  • Duplicated code can be moved into it’s own class. This can be done in a concrete class or via a static utility class.

Guest Post: Eclipse 3.3.2 and DBEdit

On Tuesday, Eclipse told me it had updates (3.3.2) available. For the
next three days I got 404/503 errors from the mirror sites it tried to
use. I finally got it updated today and learned that they fixed
whatever was keeping DBEdit from working. So if Eclipse’s Database
Development views annoy you as much as me, upgrade when you get a
chance.

Article Continues…

Java 6 in Ubuntu, The Right Way

Ubuntu has made it extremely easy to install the Sun Java Development Environment. This is good, because the default java-gcj is very slow.

First install the package with:

sudo apt-get install sun-java6-jdk

That may take a while since the package is 125MB. Once it is installed, you still need to make it the default:

sudo update-java-alternatives -s java-6-sun