删除函数,而不是使用弃用的注解使其保留在那里是一种好习惯吗? [英] Is it a good practise to remove a function instead of making it stay there with a deprecated annotation

查看:100
本文介绍了删除函数,而不是使用弃用的注解使其保留在那里是一种好习惯吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我和一些人争论了很久,他们一直在为自己制定的代码约定而斗争. 他们说,据他们说,如果有一种方法,您在编码您认为不应该使用的内容时就进行了编码.您只需删除它,在已使用过的地方进行更改,通知其他人并让他们也更改他们的内容.

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.

如果Java员工只是删除了Date类而不是弃用了Date类,但他们仍然不同意该怎么办?

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

即使我错了,我也希望对这一事实有一个很好的解释. 一些其他事实或链接会很棒.

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

推荐答案

对于程序员.

如果您要创建供他人使用的库,则新版本不应破坏现有代码.仅在进行重大修订后,例如从3.8.7更改为4.0,您才可能要求用户重新编码.请注意,其他错误修复程序可能会引起分支,并向后移植到新的3.8.8.

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.

对于本地公司的内部库,删除旧的API,以确保公司中的每个人都切换到新代码,可能会更具吸引力.

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.

@Deprecated在本地仍然有一些用途:

There are still some uses for @Deprecated locally:

我曾经有一个带有long参数的方法,在新版本中将是Object.我是在图书馆做的:

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) { ... }

简单地删除旧版本对所有库使用都是致命的,除了新功能中难看的if (x instanceof Long) { return fOld(((Long)x).longValue()); }.

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.

因此,弃用可能会提供有关替换该调用内容的javadoc信息.通常在IDE中显示为弹出窗口.

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

这篇关于删除函数,而不是使用弃用的注解使其保留在那里是一种好习惯吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆