《代码评审资料总结CodeReview》由会员分享,可在线阅读,更多相关《代码评审资料总结CodeReview(4页珍藏版)》请在金锄头文库上搜索。
1、Code Review (代码评审)评审项目组针对代码培训的资料总结。What is Code Review(什么是代码评审)Code review is systematic examination (often as peer review) of computer source code intended to find and fix mistakes overlooked in the initial development phase, improving both the overall quality of software and the developers skills.
2、代码评审是指在软件开发过程中,通过对源代码进行系统性检查的过程。通常的目的是查找系统缺陷,保证软件总体质量和提高开发者自身水平。Why we do Code Review(为什么进行代码评审)1. 提高质量2. 及早发现潜在缺陷与 BUG,降低事故成本。3. 促进团队内部知识共享,提高团队整体水平4. 评审过程对于评审人员来说,也是一种思路重构的过程。帮助更多的人理解系统。5. Types of Code Review(代码评审的几种类型)Code review practices fall into two main categories: formal code review and li
3、ghtweight code review.一般来说,代码评审分为正式代码评审与轻量级代码评审俩种.Formal Code Review(正式代码评审)Fagan inspection(著名的范根检查法):Fagan inspection refers to a structured process of trying to find defects in development documents such as programming code, specifications, designs and others during various phases of the software
4、 development process. It is named after Michael Fagan who is credited with being the inventor of formal software inspections.范根检查法是一种正式的,结构化的软件评审方式,它针对的对象包含了软件开发生命周期中的需求说明、系统设计、测试样例以及程序代码等大部分输出物。Roles Author/Designer/Coder: 作者 Reader: paraphrases the document(阅读者) Tester: reviews the document from a
5、 testing standpoint(评审员) Moderator: responsible for the inspection session, functions as a coach(协调人) Recorder:record detects.(记录员)FlowLightweight Code Review(轻量级代码评审)Lightweight code review typically requires less overhead than formal code inspections, though it can be equally effective when done p
6、roperly. Lightweight reviews are often conducted as part of the normal development process:相对于正式代码评审,轻量级代码评审所需要的各种成本要明显低的多,如果流程正确,它可以起到更加积极的效果。正因如此,轻量级代码评审经常性得被引入到软件开发过程中。延伸阅读: Michael Fagan? father of a legacy几种常见的轻量级代码评审方式: Over-the-shoulder One developer looks over the authors shoulder as the lat
7、ter walks through the code.(它由作者启动和主持评审,作者向评审者展示文档。优点是启动快,成本低,缺点是容易被作者误导过程) Email pass-around Source code management system emails code to reviewers automatically after checkin is made.(优点自动化,可以及时提供最新代码进行评审,缺点是无法达到人工筛选的功效) Pair Programming Two authors develop code together at the same workstation, s
8、uch is common in Extreme Programming.(源于XP,作者与评审者平级,可以帮助同伴间的学习和共享) Review Meeting (定期组织 review会议,轮流有团队成员选出自己的评审作品,需要系统化得预备、总结和追踪。优点可以提高团队整体技能和对产品的理解,缺点是评审范围有限,成本较高 ) Tool-assisted code review Authors and reviewers use specialized tools designed for peer code review. (大量的代码评审工具,比较流行的 checkstyle/findb
9、ugs/pmd)本文以下内容都是指针对轻量级代码评审进行进一步讨论。Options of Code Review(代码评审的选择) 最近一次迭代开发的代码 系统关键模块 业务较复杂的模块 缺陷率较高的模块 Practice of Code Review(代码评审实践)Something youd better to realize.(注意事项) 代码评审不是批斗会,不能以缺陷和错误来打击开发人员的积极性。“Oh Man!your code sucks!”是更加不允许的。评审的目标的提高质量和提高整体水平,作者应该带着学习和提高的态度来参加评审。 代码集体所有制:对发现的问题要本着整体承担责任 的原则,因此建议把代码质量与团队绩效(而不是个人绩效)挂钩。 评审程度,进行一次整体的地毯式的评审成本很高。 代码评审的可操作性,首先需要评审团队具备经验丰富的系统架构师和精通业务的行业专家。其次团队需建立其开发规范或指南,在项目初期建立少量的 Sample代码与 checklist为评审提供依据。 评审人员的职责是发现工作成果中的缺陷,并帮助开发人员给出消除缺陷的办法,而不是替开发人员消除缺陷 。 记录评审中出现的问题,跟踪改进。 评审前充分准备,评审后详细总结。 不要因为时间和成本问题取消评审。