向后兼容性与标准合规性?
假设您有一个需要维护的旧代码库,并且它显然不符合当前标准。 您将如何分配您的努力来保持代码库向后兼容,同时获得标准合规性? 对你来说什么是重要的?
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(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:
The main purpose of those facades is dividing good from bad code and thus limiting dependencies and cascading effects.
当我需要使用模块时,我会花时间来修复它们。 在任何合理的公司中,预先重写/重构都不会成功,但维护一个庞大的代码库而不对其进行一些清理几乎肯定是一场噩梦。
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.