When @deprecated becomes in dead code

In java @deprecated word means (directly from the Java API):

A program element annotated @Deprecated is one that programmers are discouraged from using, typically because it is dangerous, or because a better alternative exists. Compilers warn when a deprecated program element is used or overridden in non-deprecated code.

a way to say that something is from the past and we’re not going to update/use anymore. No more fix, no changes, no maintenance.

It’s easy to use, because you only need to write:

/**
  * @deprecated any-reason-if-you-want
  */

or use @Deprecated annotation.

Easy to use, but not always well used. Sometimes I find uses of this keyword that it’s bad, at least in my opinion. I’m talking about refactoring. As bis as your project is, it’s very difficult to refactor, I know. But IDEs like Eclipse give you a very good tools to refactoring, in particular, change the name of your method or class.

If you use deprecation like a way to “change” the name of a method, because you found one more descriptive, you’re doing something wrong. The first, you are giving two different ways to do the same thing. The next developer could think why you don’t change this name and the most probably is that he don’t delete it. Other problem is that you have to update your Javadoc when you decide to change the new method name. Why don’t you decide to change the name only and fix the issues if they exist?

Don’t left that for the next iteration, don’t allow others to think “Why is this here?”. And don’t think that you are going to have more time in the future to delete that.

It’s different if you are using your class in serialization, the problem is more complex, not impossible, but yes more complex. If you have a public API with some version open to customers, you must to use deprecation.

This entry was posted in Java, Tips & Tricks and tagged . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>