« Contextual Sessions in Hibernate | Main | How the new Hibernate bulk queries work »

Deleting code gives me a warm fuzzy feeling...

I love it when I get to delete code. Deleting code, particularly dead code, is such a wonderfully therapeutic exercise. You should try it some time.

That's why I love it when I find code like the method I just stumbled across. It cast the result of a Hibernate Session.find()1 call directly to a domain object. But that would never work: instant class cast exception!

Quick scan of the code base: yep, this method never gets used anywhere. And 5 seconds later, this method no longer exists. And only the CVS system has any evidence it ever did...

----

1 sf.net.hibernate.Session.find(String) returns a java.util.List

Comments (3)

Michael:

Clean code, clean mind.

Michael:

Robert - obviously in the example you had you where 100% confident you could delete it (as it would never work anyway).

What about in cases <100%... to get the confident sleep-well-at-night feeling after deleting - how do you go about being sure it isn't used?

I guess test coverage would be a large part...

I read Michael Feathers "Working Effectively With Legacy Code" for ideas. :)

Oh, and good code inspection tools.

Post a comment


About

This page contains a single entry from the blog posted on April 15, 2005 12:02 PM.

The previous post in this blog was Contextual Sessions in Hibernate.

The next post in this blog is How the new Hibernate bulk queries work.

Many more can be found on the main index page or by looking through the archives.

Creative Commons License
This weblog is licensed under a Creative Commons License.
Powered by
Movable Type 3.35