何时从头重写代码库 [英] When to rewrite a code base from scratch

查看:24
本文介绍了何时从头重写代码库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我回想起 Joel Spolsky 关于永远不要从头重写代码的文章.总结一下他的论点:代码不会生锈,虽然在多次维护版本后它可能看起来不太漂亮,但如果它有效,它就有效.最终用户并不关心代码有多漂亮.

I think back to Joel Spolsky's article about never rewriting code from scratch. To sum up his argument: The code doesn't get rusty, and while it may not look pretty after many maintenance releases, if it works, it works. The end user doesn't care how pretty the code is.

您可以在此处阅读文章:您不应该做的事情

You can read the article here: Things You Should Never Do

我最近接手了一个项目,在查看了他们的代码后,它非常糟糕.我立即想到了我之前构建的原型,并明确表示不应将其用于任何生产环境.但当然,人们不听.

I've recently taken over a project and after looking through their code, it's pretty awful. I immediately thought of prototypes I had built before, and explicitly stated that it should not be used for any production environment. But of course, people don't listen.

代码构建为网站,没有关注点分离,没有单元测试,到处都是代码重复.没有数据层,没有真正的业务逻辑,除非你数一数 App_Code 中的一堆类.

The code is built as a website, has no separation of concerns, no unit testing, and code duplication everywhere. No Data layer, no real business logic, unless you count a bunch of classes in App_Code.

我已经向利益相关者提出了建议,虽然我们应该保留现有代码,并发布错误修复版本和一些小功能版本,但我们应该立即开始重写它,并考虑到测试驱动开发并明确关注点分离.我正在考虑采用 ASP.NET MVC 路线.

I've made the recommendation to the stake holders that, while we should keep the existing code, and do bug fix releases, and some minor feature releases, we should start rewriting it immediately with Test Driven Development in mind and with clear separation of concerns. I'm thinking of going the ASP.NET MVC route.

当然,我唯一担心的是,从头开始重写可能需要多长时间.它并不完全复杂,具有会员资格等的工厂 Web 应用程序运行良好.

My only concern is of course, the length of time it might take to rewrite from scratch. It's not entirely complicated, pretty run of the mill web application with membership, etc..

你们有遇到过类似的问题吗?您采取了哪些具体步骤?

Have any of you come across a similar problem? Any particular steps you took?

更新:

那么..我最终决定做什么?我采用了 Matt 的方法,并决定重构许多领域.

So.. What did I end up deciding to do? I took Matt's approach and decided to refactor many areas.

  • 由于 App_Code 越来越大,从而减慢构建时间,我删除了许多课程并将它们转换为一个类图书馆.
  • 我创建了一个非常简单的数据访问层,其中包含所有 ADO调用,并创建了一个 SqlHelper 对象执行这些调用.

  • Since App_Code was getting rather large and thus slowing down the build time, I removed many of the classes and converted them into a Class Library.
  • I created a very simple Data Access Layer, which contained all of the ADO calls, and created a SqlHelper object to execute these calls.

我实现了更干净的日志记录
更简洁的解决方案.

I implemented a cleaner logging
solution, which is much more concise.

虽然我不再参与这个项目 [资金、政治、等等],但我认为它让我深入了解了一些项目可以写得有多糟糕,以及开发人员可以采取的步骤让事情变得更清晰,随着时间的推移,通过小的、渐进的步骤,可读性更强.

While I no longer work on this project [funding, politics, blah blah], I think it gave me some enormous insight into how bad some projects can be written, and steps one developer can take to make things a lot cleaner, readable and just flat out better with small, incremental steps over time.

推荐答案

仅仅因为它现在有所有这些问题并不意味着它必须继续有这些问题.如果您发现自己在系统中进行了特定的错误修复,例如可以受益于新数据层,那么请创建一个新数据层.仅仅因为整个站点都没有使用它并不意味着您不能开始使用它.在错误修复期间根据需要进行重构.并确保在更改代码之前准确了解代码的作用.

Just because it has all those problems now doesn't mean it has to continue to have them. If you find yourself making a specific bug fix in the system that could benefit from, say, a new data layer, then create a new data layer. Just because the whole site doesn't use it doesn't mean you can't start using one. Refactor as you need to during your bug fixes. And make sure you understand exactly what the code is doing before you change it.

代码重复问题?将其提取到类或实用程序库中,下次您必须修复重复代码中的错误时,将其放在中心位置.

Problem with code duplication? Pull it out into a class or utility library, in a central location next time you have to fix a bug in the duplicated code.

而且,正如其他响应者已经提到的 - 现在开始编写测试.如果代码听起来像是耦合的,那可能很难,但您可能可以从某个地方开始.

And, as already mentioned by other responders - start writing tests now. It may be hard if the code is a coupled as it sounds, but you can probably start somewhere.

没有充分的理由重写工作代码.但是,如果您已经在修复一个错误,那么您没有理由不能使用更好"的设计重新设计代码的特定部分.

There is no good reason to rewrite working code. However, if you are already fixing a bug, there is no reason you can't rework that specific part of the code with a "better" design.

这篇关于何时从头重写代码库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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