你如何对待遗留代码(和数据)?

时间:2022-09-02 08:55:00

I am currently in the process of restructuring my local Subversion repository by adding some new projects and merging legacy code and data from a couple of older repositories into it.

我目前正在重建我的本地Subversion存储库,通过添加一些新项目并将来自几个旧存储库的遗留代码和数据合并到其中。

When I have done this in the past I have usually put the legacy code in a dedicated "legacy" folder, as not to "disturb" the new and "well-structured" code tree. However, in the spirit of refactoring I feel this is somewhat wrong. In theory, the legacy code will be refactored over time and moved to its new location, but in practice this rarely happens.

当我在过去这样做时,我通常将遗留代码放在专用的“遗留”文件夹中,以免“干扰”新的和“结构良好”的代码树。但是,根据重构的精神,我觉得这有点不对。理论上,遗留代码将随着时间的推移而重构并移动到新位置,但实际上这很少发生。

How do you treat your legacy code? As much as I feel tempted to tuck away old sins in the "legacy" folder, never to look at it again, on some level I hope that by forcing it to live among the more "healthy" inhabitants in the repository, maybe the legacy code will have a better chance of getting well some day?

你如何对待遗留代码?尽管我觉得想要把旧版的遗骸收藏在“遗产”文件夹中,但再也不要再看它了,在某种程度上我希望通过强迫它生活在储存库中更“健康”的居民中,也许是遗产代码有一天会有更好的成功机会吗?

(Yeah, we all know we shouldn't rewrite stuff, but this is my "fun" repository, not my business projects...)

(是的,我们都知道我们不应该重写内容,但这是我的“有趣”存储库,而不是我的业务项目...)

Update

I am not worried about the technical aspects of keeping track of various versions. I know how to use tags and branches for that. This is more of a psychological aspect, as I prefer to have a "neat" structure in the repository, which makes navigating it much easier—for humans.

我并不担心跟踪各种版本的技术方面。我知道如何使用标签和分支。这更像是一种心理方面,因为我更喜欢在存储库中有一个“整洁”的结构,这使得人类更容易导航。

5 个解决方案

#1


4  

All code becomes 'legacy' one day, why seperate it at all? Source control is by project/branch or project/platform/branch and that type of hierarchy. Who cares how long in the tooth it is?

有一天所有代码都变成了“遗产”,为什么要分开呢?源控件是由项目/分支或项目/平台/分支以及该类型的层次结构。谁在乎牙齿有多长?

#2


2  

Tagging is a very cheap operation in subversion. Tag your code when you start refactoring and at regular stages while you go along. That way it's easy to still access the old (but functional code) as a reference for your shiny new (but broken code). :-)

标记是颠覆中非常便宜的操作。在开始重构时以及在常规阶段标记代码。这样很容易仍然可以访问旧的(但功能代码)作为您闪亮的新(但破坏的代码)的参考。 :-)

#3


1  

Here's your free psychological analysis:

这是你的免费心理分析:

What you have here is a deep-rooted desire to fix your legacy code so that it's not legacy anymore. When you hide it away, you're just repressing that desire, trying to avoid it because it's an uncomfortable feeling. If you leave it out in the open, one of two things will happen: it'll eventually drive you and insane and you'll have to kill yourself, or (more optimistically), you'll be reminded of each messy bit over and over until you finally break down and clean it up.

你在这里有一个根深蒂固的愿望,修复你的遗留代码,使它不再是遗产。当你把它隐藏起来时,你只是压抑那种欲望,试图避免它,因为这是一种不舒服的感觉。如果你把它公之于众,就会发生以下两种情况之一:它最终将驱使你疯狂,你将不得不自杀,或者(更乐观地),你会被提醒每一个凌乱的东西直到你最终崩溃并清理它。

Don't hide the mess; clean it. Otherwise it'll come back to bite you sooner or later.

不要掩盖一团糟;打扫。否则它迟早会回来咬你。

#4


1  

It depends on what you call legacy. If by saying legacy you really mean 'code from some retired application which is so bad we'll never use it any more' it should be separated from you current code. If it is something from your current project but is written by other people or is not up to your current standards just treat it normally but flag it for re-factoring in the future in your issue tracker.

这取决于你所说的遗产。如果通过说遗留你真的意味着'来自某个退役应用程序的代码非常糟糕,我们将永远不再使用它'它应该与您当前的代码分开。如果它来自您当前的项目,但是由其他人编写或者不符合您当前的标准,那么只需正常处理它,但标记它以便将来在您的问题跟踪器中进行重新分解。

#5


1  

Use Externals Definitions (svn:externals property) to reference your legacy code as you would a third-party repository.

使用外部定义(svn:externals属性)来引用您的遗留代码,就像使用第三方存储库一样。

Then you can separate your refactoring work from your dependent projects and (using fixed revision references i.e. -r1234) be very explicit about which revision of the legacy code the dependent project depends on.

然后,您可以将重构工作与依赖项目分开,并且(使用固定修订引用,即-r1234)非常明确依赖项目所依赖的遗留代码的哪个版本。

#1


4  

All code becomes 'legacy' one day, why seperate it at all? Source control is by project/branch or project/platform/branch and that type of hierarchy. Who cares how long in the tooth it is?

有一天所有代码都变成了“遗产”,为什么要分开呢?源控件是由项目/分支或项目/平台/分支以及该类型的层次结构。谁在乎牙齿有多长?

#2


2  

Tagging is a very cheap operation in subversion. Tag your code when you start refactoring and at regular stages while you go along. That way it's easy to still access the old (but functional code) as a reference for your shiny new (but broken code). :-)

标记是颠覆中非常便宜的操作。在开始重构时以及在常规阶段标记代码。这样很容易仍然可以访问旧的(但功能代码)作为您闪亮的新(但破坏的代码)的参考。 :-)

#3


1  

Here's your free psychological analysis:

这是你的免费心理分析:

What you have here is a deep-rooted desire to fix your legacy code so that it's not legacy anymore. When you hide it away, you're just repressing that desire, trying to avoid it because it's an uncomfortable feeling. If you leave it out in the open, one of two things will happen: it'll eventually drive you and insane and you'll have to kill yourself, or (more optimistically), you'll be reminded of each messy bit over and over until you finally break down and clean it up.

你在这里有一个根深蒂固的愿望,修复你的遗留代码,使它不再是遗产。当你把它隐藏起来时,你只是压抑那种欲望,试图避免它,因为这是一种不舒服的感觉。如果你把它公之于众,就会发生以下两种情况之一:它最终将驱使你疯狂,你将不得不自杀,或者(更乐观地),你会被提醒每一个凌乱的东西直到你最终崩溃并清理它。

Don't hide the mess; clean it. Otherwise it'll come back to bite you sooner or later.

不要掩盖一团糟;打扫。否则它迟早会回来咬你。

#4


1  

It depends on what you call legacy. If by saying legacy you really mean 'code from some retired application which is so bad we'll never use it any more' it should be separated from you current code. If it is something from your current project but is written by other people or is not up to your current standards just treat it normally but flag it for re-factoring in the future in your issue tracker.

这取决于你所说的遗产。如果通过说遗留你真的意味着'来自某个退役应用程序的代码非常糟糕,我们将永远不再使用它'它应该与您当前的代码分开。如果它来自您当前的项目,但是由其他人编写或者不符合您当前的标准,那么只需正常处理它,但标记它以便将来在您的问题跟踪器中进行重新分解。

#5


1  

Use Externals Definitions (svn:externals property) to reference your legacy code as you would a third-party repository.

使用外部定义(svn:externals属性)来引用您的遗留代码,就像使用第三方存储库一样。

Then you can separate your refactoring work from your dependent projects and (using fixed revision references i.e. -r1234) be very explicit about which revision of the legacy code the dependent project depends on.

然后,您可以将重构工作与依赖项目分开,并且(使用固定修订引用,即-r1234)非常明确依赖项目所依赖的遗留代码的哪个版本。