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
Clean code, clean mind.
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.