Is it a good practise to remove a function instead of making it stay there with a deprecated annotation [closed]

落花浮王杯 提交于 2019-12-13 09:08:21

问题


So i had this long argument with some guys and they kept fighting over their self made code conventions. According to which , they said if there is a method that you while coding the stuff you thought it should be deprecated.You simply remove it,change everywhere it has been used,notify others and let them change their stuff too.

My counter question

What if java people simply removed the Date class instead of deprecating it and still they would not agree.

Expectation

Even if i am wrong, i would expect a nice explanation to the fact. Some additional facts or links would be great.


回答1:


This maybe might be something for Programmers.

If you were making a library used by others, a new version should not break existing code. Only after a major revision, say from 3.8.7 to 4.0 you might require the users to recode. Mind that other bug repairs might make a branching, a back porting to a new 3.8.8 becessary.

Mind those others might use still other libraries, that use your library too. So being backward compatible means people can upgrade without waiting that a library that uses your library is upgraded.

For a local company's internal library it might be more appealing, to remove the old API, ensuring that everyone in the firm switches to the new code.

There are still some uses for @Deprecated locally:

I had once a method with a long parameter that in the new version would be Object. I did this in a library:

/**
 * Please replace the long parameter with the Object ...
 */
@Deprecated
public boolean f(long x) { ... }

public boolean f(Object x) { ... }

Here simply deleting the old version would be fatal for all library usages, apart from an ugly if (x instanceof Long) { return fOld(((Long)x).longValue()); } in the new function.

So a deprecation might give a javadoc info on what to replace the call with. Generally shown in IDEs as popup window.




回答2:


From the time being I am with Java, I have just seen a clause about the deprecated things in java from good sources and found it completely valid,

Clause is


However from 'X' version of java this 'abc' feature is deprecated because of 'xyz' reason,but you may come across some old code in your career,so its a good thing to have knowledge about it

But its a very rare case that Java people will have to remove something by flagging anything as deprecated.The deprecated flag just says that it should not be used in future. And its valid too, if issues related to backward compatibility are considered.

In context with writing some api yourself,you may have your own circumstances.



来源:https://stackoverflow.com/questions/26235730/is-it-a-good-practise-to-remove-a-function-instead-of-making-it-stay-there-with

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!