向后兼容性与标准合规性?

发布于 2024-07-14 15:47:47 字数 82 浏览 7 评论 0原文

假设您有一个需要维护的旧代码库,并且它显然不符合当前标准。 您将如何分配您的努力来保持代码库向后兼容,同时获得标准合规性? 对你来说什么是重要的?

Say you got an old codebase that you need to maintain and it's clearly not compliant with current standards. How would you distribute your efforts to keep the codebase backwards compatible while gaining standards compliance? What is important to you?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浊酒尽余欢 2024-07-21 15:47:47

在我的工作场所,我们没有时间仅仅因为代码变得更好而进行重构。 必须存在错误或客户提出功能请求。

根据该规则,我会执行以下操作:

重构时:

如果我必须对旧项目进行更改,我会清理、重构或重写我正在更改的部分。

因为我始终必须理解首先更改代码,这是进行其他更改的最佳时机。

此外,这也是为您的更改和现有代码添加缺少的单元测试的好时机。

我总是先进行重构,然后进行更改,这样我就更有信心我的更改不会破坏任何内容。

优先级:

最需要重构的代码部分通常包含最多的错误。 此外,我们不会收到任何客户不感兴趣的零件的错误报告或功能请求。 因此,通过这种方法,优先级会自动出现。

规避糟糕的设计:

我想有很多关于这方面的书籍,但以下是对我帮助最大的:

我构建了 外观

  1. 采用新的良好设计的外观,“隔离”现有的不良代码。 如果我必须编写新代码并且必须重用结构不良的现有代码(由于时间限制我无法更改这些代码),我就会使用它。
  2. 原来的糟糕设计的外观,隐藏了新的好的代码。 如果我必须编写现有代码使用的新代码,我会使用它。

这些外观的主要目的是将好的代码与坏的代码分开,从而限制依赖性和级联效应。

At my workplace we don't get any time to refactor things just because it makes the code better. There has to be a bug or a feature request from the customer.

Given that rule I do the following:

When I refactor:

If I have to make changes to an old project, I cleanup, refactor or rewrite the part that I'm changing.

Because I always have to understand the code to make the change in the first place, that's the best time to make other changes.

Also this is a good time to add missing unit tests, for your change and the existing code.

I always do the refactoring first and then make my changes, so that way I'm much more confident my changes didn't break anything.

Priorities:

The code parts which need refactoring the most, often contain the most bugs. Also we don't get any bug reports or feature requests for parts which are of no interest to the customer. Hence with this method prioritization comes automatically.

Circumenventing bad designs:

I guess there are tons of books about this, but here's what helped me the most:

I build facades:

  1. Facades with a new good design which "quarantine" the existing bad code. I use this if I have to write new code and I have to reuse badly structured existing code, which I can't change due to time constraints.
  2. Facades with the original bad design, which hide the new good code. I use this if I have to write new code which is used by the existing code.

The main purpose of those facades is dividing good from bad code and thus limiting dependencies and cascading effects.

笛声青案梦长安 2024-07-21 15:47:47

当我需要使用模块时,我会花时间来修复它们。 在任何合理的公司中,预先重写/重构都不会成功,但维护一个庞大的代码库而不对其进行一些清理几乎肯定是一场噩梦。

I'd factor in time to fix up modules as I needed to work with them. An up-front rewrite/refactor isn't going to fly in any reasonable company, but it'll almost definitely be a nightmare to maintain a bodgy codebase without cleaning it up somewhat.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文