`
touchmm
  • 浏览: 1037761 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

结对编程就不需要代码审查了吗?

阅读更多

原文:

Does Pair Programming Obviate the Need for Code Review?

http://www.softwarequalityconnection.com/2011/04/does-pair-programming-obviate-the-need-for-code-review/

by Jason Cohen | April 1, 2011

If you're working together with another person to write software, surely you don't need someone else to look over the code. That's part of the process. Or... is it?

Almost everyone I meet who practices pair programming says that they don’t need other forms of code review.

They have a point: Pair programming is in some sense the “ultimate code review.” It’s continuous, so you’re not just getting feedback at the end. It’s deep, so subtle important problems are identified that might be hard to find in a later pass. It’s personal, so people develop more rapport and a better working relationship with each other.

But is that the end of the story on code review? I’d argue no, in two ways: That certain important problems are missed in pair programming, and that we should all be open to applying different kinds of code review (including pairing) in different situations, rather than being absolute like “Pairing is always efficient.”

To address the first point, consider briefly why peer review is so useful (and is required) in other disciplines such as writing. Every book author has an editor, and not because the author is unable to write. Rather, no matter how adept we are at the subject matter and the art of writing, we can’t see the errors in our own work — both at a detailed level (incorrect wording) and macro level (whether this reads well to a new reader, or what passages are difficult to parse).

“每本书都会有一个编辑,并不是因为这个作者不能写,而是因为:不管我们在我们自己的写作领域多么地强,我们很多时候是发现不了自己的错误的 - 不管是在细节的地方(例如:用词不当),还是在宏观的把握上(例如:我们写的东西对于初学者是否易于理解)”

The editor isn’t there necessarily to instruct the author but rather to do what the author would herself do if the author weren’t so close to the material. It’s a matter of closeness, not ability. That’s why everyone needs an editor.

Code reviews are the same. Of course, if someone else wrote that code and you were the reviewer you would have picked up on a lot of that too! Or if you were the domain expert you’d have the same insights. That makes sense, and that’s why we all need code review.

Now back to pair programming. One of the (very few!) drawbacks about pair programming is that both people are involved in the creation. They’re both “authors” in the sense that neither can assume the perspective of a developer who wasn’t privy to this intense, deep process of creation and still needs to understand the code. That’s something only an outsider can bring, by very definition.

“结对编程不好的地方在于:结对的两个人都是创作者,他们都是‘作者’!”

You can argue how valuable that perspective is, or how much time it’s worth to get that perspective after already incurring the cost of pair programming. I think the answer is: In some cases it’s quite valuable, and in many it’s not. You as the developer should use your judgment and be honest about when a particular change might be hard for a third developer to understand, and therefore it would be valuable to have someone else evaluate.

Also, it’s different when you do a separate code review looking only for maintainability. Normally it takes lots of time because you’re looking at correctness and scalability and compatibility and formatting and all sorts of things, but not in this case. If you’re scanning only for comprehension, it can go really fast, like just 5 minutes for 100 lines of code. In that case, I’d argue the time trade-off is often valuable.

Speaking of the time all this takes, let’s address the second point: the time-commitment for pair programming. Clearly the practice causes the immediate development to take twice as many staff-hours. The theory is that the quality of the code — both in direct bugs and in architecture and documentation — is improved so much that in the long view we actually spend less time to deliver solid, working, maintainable code.

I won’t argue that other forms of code review are as intense or as deep, but it’s obvious that other forms take less time up-front. (In our studies at SmartBear, users of our software Code Collaborator spend about 1/8th of the time in code review than in writing the code.) And it’s clear that these other forms will certainly confer some of the benefits of pair programming, such as finding bugs, making code more maintainable, spreading knowledge, and working together. Just not as much as pair programming.

Suppose the benefit is 36% as good as pairing but 12% of the time commitment. That’s a 3x more efficient use of your time.

Clearly sometimes the code warrants pairing. For example, when the problem at hand is really difficult, or when one of the pair is a domain expert at the problem, or when you’re training someone. But often the change is simple and a quick look-see is sufficient. Or most of the change is in your area of expertise and you need a domain expert to peek at just one file.

Clearly in those areas it’s probably more efficient to use another form of code review.

Maybe now we can all stop being so dogmatic about pair programming as the be-all-end-all, or that pair programming always takes too much time, and just agree to be sensible about how and when it’s useful, and what advantages and disadvantages it presents.

<!--<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/"> <rdf:Description rdf:about="http://www.softwarequalityconnection.com/2011/04/does-pair-programming-obviate-the-need-for-code-review/" dc:identifier="http://www.softwarequalityconnection.com/2011/04/does-pair-programming-obviate-the-need-for-code-review/" dc:title="Does Pair Programming Obviate the Need for Code Review?" trackback:ping="http://www.softwarequalityconnection.com/2011/04/does-pair-programming-obviate-the-need-for-code-review/trackback/" /> </rdf:RDF>-->
分享到:
评论

相关推荐

    结对编程技术与策略pdf

    2. **重构旧代码**:对于需要重构的现有代码,结对编程有助于理解原有代码的逻辑结构,并进行优化改进。 3. **调试与修复**:在遇到难以定位的bug时,结对编程可以帮助更快地发现并解决问题。 #### 七、结对轮转...

    结对编程启示录

    2. **优势分析**:详述结对编程的优势,如即时代码审查、减少缺陷、增强团队凝聚力、促进知识转移等。这些优势有助于提高生产力,降低维护成本,尤其是在小型团队中尤为显著。 3. **实施步骤**:提供如何开始结对...

    在复杂的项目开发中使用结对编程

    1. **提高代码质量**:结对编程通过实时的代码审查,能够及时发现并修正错误,从而显著提升代码质量和可维护性。 2. **增强团队协作**:结对编程促进了团队成员之间的交流和协作,有助于建立更加紧密的合作关系,...

    结对编程在数据结构教学中的应用.pdf

    另一方面,要重视结对编程过程中代码的审查和讨论,这是确保代码质量的关键。最后,教师需要为学生提供一个合适的环境,让结对编程能够顺利进行,并在必要时给予指导和帮助。 综上所述,结对编程作为一种在数据结构...

    结对编程在Java Web开发课程实践教学中的应用.pdf

    此外,结对编程还可以减少代码检查的时间和代码的学习成本,提高软件质量和开发效率。 在Java Web开发课程实践教学中,结对编程可以应用于项目驱动教学法。学生可以以“团队合作”的方式完成项目任务,并通过结对...

    Addison Wesley - 结对编程启示录(手册)

    《结对编程启示录》是Addison Wesley出版的一本关于结对编程的实用手册,旨在帮助读者快速理解和掌握这种编程方法,以提升代码质量和开发效率。结对编程(Pair Programming)是极限编程(XP,Extreme Programming)...

    结对编程-魔方1

    结对编程是一种有效的软件开发方法,它鼓励两人一组共同编写代码,通过互相协作、讨论和监督来提高代码质量和团队效率。在这个场景中,学生们通过结对编程的方式解决了一项关于魔方状态表示和处理的编程任务。 首先...

    结对编程软件方法的研究与应用(1).pdf

    结对编程是一种软件开发实践,源自敏捷开发方法论,它提倡两个程序员在同一台电脑上共同工作,一人编写代码,另一人则审查、建议并提供反馈。这种方法的核心理念是通过即时的同行评审和协作来提高代码质量,减少错误...

    创新结对编程在高职《C语言程序设计》课程实践教学中的实现.pdf

    在结对编程过程中,两人需要不断交流沟通,协作完成算法设计、代码编写和软件测试等工作,这不仅能够提高程序设计能力和沟通协调能力,还能通过相互审查代码、互换角色等方法,取长补短,提高代码质量,降低错误率,...

    结对编程-快排1

    【结对编程】是一种软件开发方法,它提倡两个开发者共享同一台计算机,共同编写和调试代码。在这种模式下,一位开发者负责输入代码,另一位则专注于审查和提供反馈,确保代码的质量和符合设计要求。这种协作方式可以...

    Lab 1:结对编程实验报告.pdf

    在结对编程中,这可能涉及到两人一组,共同完成代码编写,互相审查对方的代码,以及定期交换角色以促进技能共享和理解。 2. 待求解问题描述与数学模型: 实验通常围绕一个特定的问题或挑战展开,例如设计一个算法...

    Python_aider是在您的终端中的AI结对编程.zip

    Python_aider是一个创新的工具,它将人工智能技术与编程环境相结合,为用户提供了一种全新的结对编程体验。在您的终端中运行Python_aider,您可以享受到AI的智能辅助,提升编程效率,解决编码过程中遇到的问题。 ...

    PairProgramming:CS 125 结对编程

    6. **代码审查**:结对编程本身就是一种形式的代码审查,因为每一行代码都在被实时地审查和讨论。这有助于提高代码质量,减少后期的调试工作。 7. **团队协作**:结对编程可以加强团队精神,增进团队成员之间的信任...

    PairProgramming:19秋地科结对编程

    在“PairProgramming-master”这个文件名中,我们可以猜测这可能是一个项目源代码库,包含了关于结对编程的示例代码、练习或教学资源。通过研究这些内容,参与者可以更深入地理解结对编程的实际操作和益处。 总之,...

    极限编程编程新理念,先测试后写代码

    - **结对编程**:两个程序员共享一个工作台,共同编写代码,有助于即时代码审查,提高代码质量。 - **用户故事**:以用户的角度描述需求,帮助团队理解功能的重要性。 - **计划游戏**:团队与客户共同确定下一个迭代...

    (PDF)Java 极限编程

    9. **集体所有权**:所有团队成员对代码都有修改权,鼓励代码审查,减少代码质量的个人差异。 10. **结账技术**:在XP中,技术债务(为了短期速度牺牲长期质量的做法)被视为一种债务,需要定期“结账”,即进行...

    Java 极限编程-英文版-高清无书签

    3. **结对编程**:在结对编程中,两个开发人员共享一个工作区,一起编写和审查代码。这种方式可以提高代码质量,减少错误,并促进团队间的知识共享。 4. **持续集成**:通过频繁地将代码合并到主分支,持续集成可以...

Global site tag (gtag.js) - Google Analytics