[java-gnome-hackers] An idiom for deprecating things
Brought to you by:
afcowie
From: Andrew C. <an...@op...> - 2008-07-29 02:16:04
|
Hello, A couple methods needed a signature changes yesterday (renames, as it happened). I implemented the correct signature, and then pondered what to do with the old one. People in the Java land are a lot more clued in about [not using] deprecated things that it seems most developers using GTK in C are. Tough for them. But part of the problem there is that they weren't strongly incented to get on with fixing their code. I came up with an idiom that I'm actually really happy with: /** * Original JavaDoc here. * * @since 4.0.8 */ public void betterMethodName() { GtkHotness.methodName(); } @Deprecated public void oldMethodName() { assert false : "Deprecated. Use betterMethodName()"; GtkHotness.methodName(); } This is lovely. It means that the old method is still present and people's programs will still build. But anyone with assertions enabled (which should be a default, but it depends on what VM you're using; certainly any developer who runs without -ea on the Java command line should be shot) will have the code fail. If a user is desperate to run the thing without fixing their code, then they can always use `java -da` to disable assertions and thus allow the code to run. So that's what I did. ++ As has been practise during the 4.0 series, deprecated methods will remain for one more release only (ie 4.0.8), and will be removed during the next one (ie before 4.0.9). The caveat on the website continues to apply until 4.2. ++ Thanks to Kenneth Prugh for his review. AfC Sydney -- Andrew Frederick Cowie Operational Dynamics is an operations and engineering consultancy focusing on IT strategy, organizational architecture, systems review, and effective procedures for change management. We actively carry out research and development in these areas on behalf of our clients, and enable successful use of open source in their mission critical enterprises, worldwide. http://www.operationaldynamics.com/ Sydney New York Toronto London |