《代码大全》第20章,讨论软件质量。
平时工作经常被组里服务的软件质量困扰,觉得离 App 稍远的部分,被过度轻视,离 App 近的又一味依赖测试,总的质量管理其实很脆弱,开发的成本也危楼高百尺。读这部分,在主观感觉之外,找到了很多研究印证,有些数据和结论也比较有意思。遂记录。
External and internal quality characteristics
External
- Correctness
- Usability
- Efficiency
- Reliability
- Integrity??
- Adaptability
- Accuracy
- Robustness
Internal
- Maintainability
- Flexibility
- Portability
- Reusability
- Readability
- Testability
- Understandability
Techniques for detecting defects
结论:
缺陷检测方法组合使用的效果优于单独使用。
Defect-detection methods work better in combination than they do singly.
研究发现:
- 典型的组织使用重度测试的缺陷检测方法,只能达到大约85%的缺陷移除效率。领先的组织使用更广泛的技术,可以达到95%或更高的缺陷移除效率。
The typical organization uses a test-heavy defect-removal approach and achieves only about 85 percent defect-removal efficiency. Leading organizations uses a wider variety of techniques and achieve defect-removal efficiencies of 95 percent or higher.
- 人工过程(如检查和走查)比计算机测试更擅长发现某些类型的错误,而另一些类型的错误则相反。
Human processes (inspections and walk-throughs, for instance) tend to be better than computer-based testing at finding certain kinds of errors and the opposite is true for other kinds of errors.
- 单独使用测试的效果不佳。单独使用单元测试、功能测试和系统测试,通常缺陷检测效率不到60%,这通常对于生产软件来说是不够的。
The outlook for the effective of testing used by itself is bleak." … “A combination of unit testing, functional testing, and system testing often results in a cumulative defect detection of less than 60 percent, which is usually inadequate for production software.
Cost of Finding Defects
结论:
大多数研究发现,审查比测试更便宜。
Most studies have found that inspections are cheaper than testing.
研究数据:
- 与测试相比,读代码每小时发现的错误数量多 80%.
code reading detected about 80 percent more faults per hour than testing.
- 要发现软件设计中的缺陷,测试花费的时间是代码审查的6倍。
It costs six times as much to detect design defects by using testing as by using inspections.
- 3.5个工时的代码审查,可以发现一个错误,而测试需要15-25个工时才能发现一个错误。
Only 3.5 staff hours were needed to find each error when using code inspections, whereas 15-25 hours were needed to find each error through testing.
Cost of Fixing Defects
结论:
更早发现错误的检测技术能带来更低的修复成本。
A detection technique that finds the error earlier therefore results in a lower cost of fixing it.
研究数据:
- 代码审查是一种一步式的技术,而测试是一种两步式的技术。使用代码审查发现和修复一个缺陷需要3个小时,而使用测试发现和修复一个缺陷需要12个小时。
It takes three hours to find and fix a defect by using code inspection, a one-step technique, and 12 hours to find and fix a defect by using testing, a two-step technique.
- 一份关于超过400名开发者构建的70万行程序的报告表明,代码审查的成本效益是测试的数倍——前者投资回报率为1.38,而后者仅为0.17。
According to a report on “a 700,000-line program built by over 400 developers”, “Code reviews were several times as cost-effective as testing - a 1.38 return on investment vs. 0.17.
The General Principle of Software Quality
即:提高代码质量会降低开发成本。
- The General Principle of Software Quality is that improving quality reduces development costs.
- The single biggest activity on most projects is debugging and correcting code that doesn’t work properly.
研究数据:
- 166个程序员写代码解决同一个问题,最终平均代码量为220行,平均用时约5h。花费时间在中位数上下的程序员,代码中的 bug 最多。花费时间低于或高于中位数时间的程序员,代码 bug 明显较少。
结论:好的未必慢,差的未必快。