views:

202

answers:

4

Once a method is marked as deprecated, are there any tools which replace these methods with non-deprecated workarounds ?

+12  A: 

If you would like to do this automatically - no.

The tool is called a programmer.


The reason is that the tools would need to profoundly understand both the deprecation, the 'un-deprecation' , your program and the target programming language.

For instance, java.util.Date.setMonth is deprecated in favour of Calendar.set(Calendar.MONTH, int month).

That is a non-trivial change to apply, since it requires replacing object instantiations, method calls, taking into account synchronisation. Actually nightmarish to do automatically.

Robert Munteanu
Although a funny response, it's not really taking the question seriously -1
krosenvold
@krosenvold: I'm almost always half tongue-in-cheek, it's my way of presenting arguments. I did _not_ poke fun at the question, and I stand by my opinion. And thanks for the +1 Funny/-2 Not serious mod :-), but especially for leaving a comment.
Robert Munteanu
Your recent edit is nice.
krosenvold
I agree with this response =) If the original implementation of a class/method is considered so poor that it can't be fixed without breaking legacy code, then the change must be nontrivial. In other words, if you can't search/replace your way out of the problem, you probably have to do it by hand anyway.
mikek
+1  A: 

I can't see how this would work at the moment. Typically at least some thought needs to go into changing the client code. Ideally the deprecated method will include a comment saying, "Use method X instead, passing in null as the final parameter" or something similar, but only in the simplest cases could this be fully automated. Often there'll be something like "If you need to deal with null entries, use X. Otherwise, use Y."

(In addition, even in the simplest cases, there's no current way of representing the transformation in a machine-readable format - basically the appropriate protocol hasn't been defined as far as I'm aware.)

It's a nice idea, but I suspect that to implement it in a useful way would introduce more complexity than it would remove. Additionally, I'd be very wary of a tool doing this for me completely automatically - I'd probably want to preview every change anyway. At that point, it usually wouldn't save much time over doing it manually to start with.

Jon Skeet
+4  A: 

Automated tools could only reasonably handle cases where there's a new preferred method or class to use to accomplish exactly the same task. Any case where a method is deprecated because of defective design (think anything dealing with date's in Java) or because a "better" way is now supported (think AWT to Swing or SWT) requires far to much thought to be automated.

In short, no there are no such tools. I doubt there ever will be any in the future as well.

Kevin Montrose
+2  A: 

Usually, you should use something like regexps, ANTLR or JavaCC for implementing your own tool.

Besides, some IDEs offers relatively higher-level tools for facilitating this. In IntelliJ IDEA these are "Structural Search and Replace" and "Migrate" refactoring.

Rorick