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)
Clean code, clean mind.
Posted by Michael | April 16, 2005 12:09 PM
Posted on April 16, 2005 12:09
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...
Posted by Michael | April 17, 2005 7:29 PM
Posted on April 17, 2005 19:29
I read Michael Feathers "Working Effectively With Legacy Code" for ideas. :)
Oh, and good code inspection tools.
Posted by Robert Watkins | April 18, 2005 12:55 PM
Posted on April 18, 2005 12:55