你可以对遗留代码库做些什么,这将对提高质量产生最大的影响? [英] What can you do to a legacy codebase that will have the greatest impact on improving the quality?

查看:41
本文介绍了你可以对遗留代码库做些什么,这将对提高质量产生最大的影响?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您在遗留代码库中工作时,随着时间的推移,什么会对提高代码库的质量产生最大的影响?

As you work in a legacy codebase what will have the greatest impact over time that will improve the quality of the codebase?

  • 删除未使用的代码
  • 删除重复代码
  • 添加单元测试以提高覆盖率低的测试覆盖率
  • 跨文件创建一致的格式
  • 更新第 3 方软件
  • 减少静态分析工具(即Findbugs)生成的警告

多年来,代码库由许多具有不同专业知识水平的开发人员编写,其中许多领域未经测试,有些领域无需花费大量时间编写测试就无法测试.

The codebase has been written by many developers with varying levels of expertise over many years, with a lot of areas untested and some untestable without spending a significant time on writing tests.

推荐答案

  • 阅读 Michael Feather 的书有效使用旧代码"
  • 这是一本很棒的书.

    如果你不喜欢那个答案,那么我能给的最好的建议是:

    If you don't like that answer, then the best advice I can give would be:

    • 首先,停止编写新的遗留代码[1]

    [1]:遗留代码 = 没有单元测试的代码,因此是未知的

    [1]: Legacy code = code without unit tests and therefore an unknown

    在没有适当的自动化测试套件的情况下更改遗留代码是危险且不负责任的.如果没有良好的单元测试覆盖率,您就不可能知道这些更改会产生什么影响.Feathers 推荐了一种束缚"方法,您可以隔离需要更改的代码区域,编写一些基本测试来验证基本假设,在单元测试的支持下进行小的更改,然后从那里开始工作.

    Changing legacy code without an automated test suite in place is dangerous and irresponsible. Without good unit test coverage, you can't possibly know what affect those changes will have. Feathers recommends a "stranglehold" approach where you isolate areas of code you need to change, write some basic tests to verify basic assumptions, make small changes backed by unit tests, and work out from there.

    注意:我并不是说您需要停止一切并花数周时间为一切编写测试.恰恰相反,只需围绕您需要测试的区域进行测试,然后从那里开始.

    NOTE: I'm not saying you need to stop everything and spend weeks writing tests for everything. Quite the contrary, just test around the areas you need to test and work out from there.

    Jimmy Bogard 和 Ray Houston 在一个与此非常相似的主题上做了一个有趣的屏幕转换:http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/05/06/pablotv-elimating-static-dependencies-screencast.aspx

    Jimmy Bogard and Ray Houston did an interesting screen cast on a subject very similar to this: http://www.lostechies.com/blogs/jimmy_bogard/archive/2008/05/06/pablotv-eliminating-static-dependencies-screencast.aspx

    这篇关于你可以对遗留代码库做些什么,这将对提高质量产生最大的影响?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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