A Funny Java Flavoured Look at the World

Tuesday, April 25, 2006

You know you have started to write better code when changing things isn't too painful

When you go back to some code and it's actually quite easy to add some more code to it.

The code I was looking at was adding a new block of code, without going into to much detail the code was dealing with connections and I was adding in an Access connection. I had tried to do this in hibernate but it doesn't support Access databases.

So I had to add in another connection block. All I had to do was extend my baseConnection class and create my new AccessConnection object and then add one if in my baseConnectionFactory and I was away. The code that uses the connections is in a Struts action (general database search) and it uses the baseConnection superclass so it didn't have to change at all. The code also picks up the connections details from an xml file.

I have to admit that this was one of the few occasions that going back and adding to some code didn't involve *Wedging* it in and re writing it. Some of it was legacy code but this particular code I had refactored before and this time. I also did some refactoring (pulling up a method into the super class) but I think you always do that.

Anyway it has certainly has shown the benefits of firstly spending some time designing a piece of code properly and separating out the dependencies of the code. It also has shown me the benefits of refactoring the code when you are in there fixing a bug or adding some new code in. I think I have heard this mentioned as code debt, if you wedge in a quick fix into the code then you are in debt to that code. So even though you have benefited by adding the fix in quickly, next time when you have to change it again you may have your debt called in and will have to fix it properly. Last time I did fix the code to a better standard and this time I have felt the benefit

Of course the downside is that there is already much better connection code out there and why am I wasting my time writing connection is a completely different story.

0 Comments:

Post a Comment

<< Home