删除紧密耦合的代码
如果这是一个骗局,请原谅我,但我找不到任何能解决这个问题的东西。
我正在使用一个紧密耦合的遗留应用程序。我们正在删除一些主要功能,因为我们将从外部服务获取该功能。
开始删除现在未使用的代码的最佳方法是什么?我应该从最底层开始,删除并重构堆栈吗?午餐期间,我将去看看有效地使用旧代码。
Forgive me if this is a dupe but I couldn't find anything that hit this exact question.
I'm working with a legacy application that is very tightly coupled. We are pulling out some of the major functionality because we will be getting that functionality from an external service.
What is the best way to begin removing the now unused code? Should I just start at the extreme base, remove, and refactor my way up the stack? During lunch I'm going to go take a look at Working Effectively with Legacy Code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果可以的话,并且这在您的问题领域有意义,我会尝试在开发过程中保持旧代码与新 API 并行运行。并使用旧 API 的结果来交叉检查新 API 是否按预期工作。
If you can, and it makes sense in your problem domain, I would try to, during development, try and keep the legacy code functioning in parallel with the new API. And use the results from the legacy API to cross check that the new API is working as expected.
我认为你能做的最重要的事情是以非常小的块进行重构/删除/测试。这是乏味且耗时的,但它将有助于限制以后的风险和错误。
我也会从“低风险”更改的代码开始。
I think the most important thing you can do is to refactor/remove/test in very small chunks. It's tedious and time consuming but it will help limit risks and errors later on.
I would also start with code that is "low risk" to change.
我的建议是使用 findbugs 和 PMD/CPD(复制粘贴检测器)来删除死代码(不能或不会被调用的代码)未使用的变量和重复的代码。摆脱这些垃圾将使重构变得更容易。
然后了解 IDE 中常见重构的按键映射。提取方法和引入变量应在一小时后致力于肌肉记忆。
My advice is to use findbugs and PMD/CPD (copy-paste-detector) to remove dead code (code that can not or will not be called) unused variables and duplicated code. Getting rid of this junk will make re-factoring easier.
Then learn the key mappings for the common re-factoring in your IDE. Extract method and introduce variable should be committed to muscle memory after an hour.
利用紧密耦合代码的主要缺点来...您的优势!
步骤 1:确定提供您想要替换的冗余功能的区域。打破它......对应用程序的一些关键部分进行快速冒烟测试。感受一下。
步骤 2:根据语言找到相关的静态代码分析工具并获取所需的重构信息。
步骤 3:重复步骤 1,逐渐缩小范围至精确模式。
当然,这一切都是在沙箱环境中进行的。这可能看起来有点随意,但如果您将自己限制在关键功能测试上……您可能会在此过程中获得许多线索。如果没有别的,您肯定会识别遗留代码的模式。
Use the primary disadvantage of tightly coupled code to... your advantage!
Step 1: Identify the area which provides the redundant functionality which you want to replace. Break it...do a quick smoke test of some of the critical parts of the application. Get the feel.
Step 2: Depending on what language it is find the relevant static-code analysis tools and get the needed refactoring info.
Step 3: Repeat Step 1 in incremental levels of narrowing down to the exact pattern.
All this of course, in a sandbox environment. This may seem a bit haphazard but if you limit yourself to critical functionality testing ... you may get many leads in the process. You will definitely identify the pattern of the legacy code, if nothing else.
您绝对不能使用实时开发版本[正在添加新功能]。您必须从功能冻结开始。
我倾向于概览系统的所有组件,并了解最大的重用位置。从那里我将实施适当的设计模式来解决它,并使新组件可重用。编写测试用例以确保新代码按预期工作,然后围绕新更改重构代码。然后重复【概述等】直到您满意为止。
我建议这样做的原因有很多:
You absolutely cannot do with with a live development version [new features being added]. You must start with a feature freeze.
I tend to look at all of the components of the system in an overview and see the biggest places of reuse. From there I would implement the appropriate design pattern to solve it, and make the new component reusable. Write test cases to ensure the new code works as expected, then refactor your code around the new change. Then repeat [overview, etc] till you are satisfied.
I would suggest this for many reasons: