北京金同方计算机培训,考试认证
当前位置:中招首页 -> IT培训 -> 国外认证 -> 其他认证 -> 经验交流 -> 
RUP/XP指南:双人编程

2005-11-14 14:53:11 来源:未知

  作者 Robert C. Martin
Rational 白皮书

Overview
概述
------------------------------------------------------------------------------
Pairing, a brief description
双人编程简述

Pair Programming is a technique whereby software on a project is written by pairs of programmers. Each pair works together at a single workstation. One member of the pair drives the workstation while the other looks on, carefully watching the code being produced. The driver is thinking tactically, concerned for the line of code he is currently writing. The observer is validating syntax and is thinking strategically about the whole program. They trade these roles frequently and the resulting code is written faster than if by a single person and has fewer defects. Moreover, the code is intimately known by at least two developers.
双人编程指在一个项目中由两个程序员编写一个软件的技术.每两人在同一台机器上工作,其中一人操作机器的同时另一个在旁边仔细看着代码被编写出来.操作者从战术上关心当前自已在编写的每一行代码,观察者确认语法规范,并从战略上考虑整个程序.他们频繁地交换彼此的角色,并且更快地编写出比单人编写更少错误的代码.并且,这些代码至少被两个以上的开发者所熟悉。
  百事特软件编程课程 JAVA软件开发专业
  java2语言核心技术 平面设计师就业班


The case for pairing
双人编写的案例

Consider a typical code review session. A module that required eight hours for one person to develop is reviewed for one hour by eight people. The net result is that 16 person-hours are spent on the module. However, the reviewers cannot spend the needed time to become familiar with the code and their review is fairly shallow. A single developer is intimately familiar, but perhaps too familiar to find the bulk of the defects.
让我们观察一下一个典型的代码评审过程,一个模块要求一个人花八个小时开发,评审需要八个人花一个小时,最终结果是这个模块花了16个人小时.然而,评审者并不能花费所需的时间对该代码达到熟悉的程度,因此他们的评审是相当浅薄的,一个单独的程序员对此倒是相当熟悉,但是反而会因为太熟悉而对里面的大多错误视而不见。

Contrast this with the practice of pair programming. If the module requires eight hours for the pair to develop, a total of 16 person-hours will be expended. However, in this case, two developers will have intimate knowledge of the code. The defects hidden from one developer will be visible to the other.
对比如果对于双人编程,如果一个模块要求八个小时,同样花费了16个人小时,然而,两个程序员对该代码是同样熟悉的,一个错误对于某人而言是视而不见,而对于另一个却显而易见。


The case for pair programming is simple, but the repercussions are subtle and far reaching. Pair programming is simply a much more effective way to write and review code. With two people intimately familiar with a module, far fewer defects will be written into the code. The code will have a better structure and intimate knowledge of it will be in twice as many brains. If these were the only benefits they would be sufficient, but the act of pairing provides still more benefits.
双人编程看来简单,但是影响却是微妙而深远,双人编程是一个简单而更有效的编码和评审的方法。由于由两个人用紧密合作的方式编码,更少的错误被写入代码中,代码会更有更好的结构并且被两人所熟悉。双人编程仅此优点就已足够使用,但实际上可得到的好处远不止于此。

Pairs are more courageous: What a single programmer might be afraid to try, a pair will have the courage to attempt and the skill to evaluate.
双人编程更有勇气:单个程序员可能会怯于尝试,而两个人会有勇气去尝试和技巧评估(theskill to aluate.)。

Pairing fosters teamwork: Since modules are not written by a single person the code becomes the property of the team, rather than of a particular developer.
双人编程可以促进团队合作:因为模块不是一个人写的,代码是整个团队的财产,而不是某个开发者的。

Pairing fosters the spread of knowledge: The more developers who pair with each other, the more the knowledge of the system diffuses through the whole team. The result is a team whose members are familiar with all of the system rather than each member knowing only their one particular part.
双人编程促进了知识的传输:越多的开发者互相配对编码,系统的知识越能传输到整个团队,结果是每个团队成员都熟悉整个系统,而不是每个成员只了解他们所写的那部分。


Pairing promotes productivity: A person programming alone goes through bursts of energy followed by periods of relative inactivity. Pairs pace each other. When one gets tired, they swap roles. They manage to keep the intensity turned on for much longer than a single person can usually tolerate.
双人编程提高了生产力:一个单独的程序员会突然精力爆发,然后却是周期性的呆滞(inactivity)。双人可以协调步调,当其中一个劳累时,他们可以调换角色,他们会设法保持一个持续的强度,而这种强度不是单个人可以吃得消的。

Pairing is fun: Working with another developer is educational, stimulating, and just plain fun. Pairing increases job satisfaction and overall morale.
双人编程充满乐趣:和另一个开发者工作富有教育性,充满刺激和乐趣。提高了工作满意度和全面的士气。

The Practice
实践
------------------------------------------------------------------------------
Pairing
配对

Pairing begins when the developer responsible for a task asks someone else for help. The rule is: when asked, you must say yes. This does not mean you have to immediately stop what you are doing. Rather it means that you must negotiate a time when you can offer that help and another time when you can get help in return.
双人编程开始于负责某个任务的程序员寻求他人的帮助。原则是:有人来问,你必须说是,不过这不意味着你要马上停下你在做的工作,而是说,可以商定某个时间帮忙,而在另一个时间让对方帮你的忙。

The pair partner does not assume responsibility for the task. That responsibility remains with the task owner. Nor does the pair partner commit to staying with the owner until the task is complete. The pair partner only commits to help.
双人编程的拍档者不对所做的任务承担责任,责任由负责任务的那个程序员承担,,拍档者直到任务完成也不会承诺与任务负责人共同负担任务的责任,只是承诺会帮忙。


One member of the pair becomes the driver, while the other looks on. The driver types in the code, runs the compiler, runs the unit tests, and so forth. The watcher examines each keystroke, each command, each test result, and offers help and suggestions. Both parties are engaged at all times.
双人编程中的某个成员成为操作者,同时另一个作为观察者。操作者敲代码,编译,做单元测试,观察者检查每一次敲击,每一个命令,每次测试的结果,并提供帮助和建议,整个时间里两边都同样的忙碌。

Sometimes the driver will know best what to do, and the watcher will simply be following along. At other times, the watcher will dictate what to do to the driver. Sometimes the driver will get frustrated and will hand the keyboard to the watcher,thereby switching roles. Other times, the watcher will ask for the keyboard and switch roles. this will happen many times in a pairing session.
有时,操作者知道该如何做到最好,这时观察者就只是随着思路走就行了。反之,观察者可以指示操作者该如何做。有时操作者会思路阻碍做不下去,键盘交给观察者,两者便换了角色。在整个编码过程中,观察者会主动要求键盘输入,从而交换角色,这种情况是经常发生的。

Changing pairs
交换配对

Pair partners are not long term. A typical pairing session will last about half a day. Either partner can opt out of the pair for any reason. When this happens, the owner of the task must find another pair partner. This may mean that it is time for the task owner to pay back a favor to someone who paired with him or her last week. On the other hand, perhaps he or she should ask
someone with the right experience to help with a particularly sticky problem.
双人编程的两个拍档不是长期合作的。一个典型的双人编程会持续大约半天,其中每个拍挡可以以任何理由要求重新选择,这种情况下,任务负责人要找另一位拍档,这就意味着是时候让任务负责人给一个回报了,对象或者是上个星期给他或她做拍档的某人,或者是给他或她解决了某个难题的某人。

This changing of pairs causes knowledge of the system to diffuse throughout the entire development team. Within a short time, every member of the team will have spent time working on almost every part of the system. This drastically reduces the sensitivity of the project to turnover, and makes every programmer more confident in dealing with the whole system.
这种交换拍档的方式会让整个系统的知识传播整个开发团队,只用一个短的时间,团队里的每个成员花了时间在系统的每个部分。这大大减少了项目大变动时的敏感度,每个成员会更有信心去对付整个系统的问题。

Collective ownership
集体拥有代码

Since everybody works on all the different modules in the system, nobody owns any particular module. This means that responsibility for the system is not divided up on a module-by-module basis. Rather, the entire team is collectively responsible for the entire system. Any member of the team may check out and change any module in the system for any reason. When a pair makes a change to module X and that change causes module Y’s unit tests to fail, the pair repairs module Y.
由于在系统的每个模块上都工作过,没有某个人拥有某段特定的模块,这意味着整个系统的责任不能按模块分割,整个团队全体对整个系统负责。团队的任何一个成员都可以以任何理由将系统中的某个模块check out出来做修改,如果某一对编程员修改了模块X,造成模块Y单元测试失败,他们就修改模块Y。

Pacing and collaboration
协调和协作

Pair programming is a very intense form of communication. Verbal dialog is often spars, and an outside observer might have trouble making sense of it. As an observer, you may hear the pair uttering singular words like: “semicolon”, or “close brace”.Or you may simply hear less articulate grunts as the programmers agree or disagree with what is appearing on the screen. The two are so intimately engaged in the code that is appearing that much communication is on-verbal. Body language plays an important part. One pair-partner can tell when his counterpart is uncomfortable with the code, even though no words are spoken. A grimace, a sigh, a nervous fidget—all conspire to increase the bandwidth of communication between the partners.
双人编程是一种极其密切的交流方式,口头对话常变成争论,这对于一个观察者而言并无意义,观察者可能会听到的单词是:“分号”或者“括号(close brace)”,或者只听到只是程序员对屏幕上的东西同意或反对时发出的咕哝声。两个人在代码上的交流是如此忙碌以至交流并非用口头形式,肢体语言是一个重要方式,某个拍挡对某个代码很不顺眼时,并不一定要说,可能会是痛苦的表情,叹气,烦躁的动作--这些拓宽了两人之间交流的幅度。


Sometimes one partner will grab the mouse, while the other operates the keyboard. The mouse-holder controls the location within the module where work will take place. The keyboarder controls the content that is altered or added at that location. At other times, one partner will be typing, and the other partner will foresee a function call coming and will open the API documents to the right page just as the coder needs the spec.
某些时候,其中一个成员会控制鼠标,而同时另一个则操作键盘。拿鼠标的人控制下面将在模块的哪个位置进行工作。拿键盘的人则掌管在这个位置将要进行的添加于修改工作。在另一些时候,其中一个正在编码输入,另一个则会预见到可能将会调用某一个函数并且以编码者需要的要求在API文档中打开合适的那页。

When one partner gets tired, the other can take the lead, allowing his or her partner to rest by playing the observer role. Other times, both partners will be high energy and will swap the keyboard and mouse frequently.
当其中一个成员感到疲劳时,另一个能承担起主导的职责,让他或她的伙伴扮演旁观者的角色而得到休息。在其余时候,两个成员都会精神饱满并频繁的交换鼠标和键盘。

In summary, there are few rules and fewer procedures. The only real constraint is that both parties have to remain engaged and communication between them must be intense. A pair in which one partner is typing and the other is looking out the window is not truly pairing.
总的来说,这里没有太多的规则更没有多少规章。唯一存在的规则时:两个成员都必须保持处于工作状态并且他们之间的交流必须是密切的。当另一个伙伴在输入而自己却看着窗外的伙伴不是一个真正的伙伴。

What can the lone developer do?
单独的开发者该做什么?

You can’t be pairing all the time. Some projects—that is, those that adopt the eXtreme Programming (XP) (see reference [1]) process—follow the rule that pairs must produce all production code. In that case, when you aren’t pairing you can check your email, read up on a new technique or API, read through code that you are unfamiliar with, or talk with the stakeholders about the current iteration or future plans. Indeed, there is always something profitable that a developer can find to do in those few hours when a pair partner cannot be found.
你不可能随时随地都能找到搭挡。某些项目—比如那些采用《极限编程方法》(见参考[1])--遵循诸如所有产品代码必须双人开发等规则。在那种情况下,当你无法找到伙伴时,你可以检查你的电子邮件,通过阅读一个新的技术或API来增长知识,阅读你不熟悉的代码,或者和经纪人谈论当前的股价变化未来的计划。事实上,这些事情通常也就是当开发者不能找到一个合作伙伴的那几个小时中所能想到去做的那点事情。

Some projects are less strict about pairing. Some will allow single developers to write tests. Others allow single developers to write abstract classes or interfaces. Still others simply allow the developers to decide when it’s best to pair. One thing is clear,however—studies have shown that defect rates drop dramatically when pairing is practiced.
有些项目对双人编程不是那么严格,有的让单独的开发者去写测试,有的让单独的开发者去写抽象类或接口,有的甚至完全让开发者去决定什么时候找搭挡才是最好的。只有一件事是确定的,就是--研究表明,当开始实施双人编程时,错误率戏剧性地降低了。

Some people don’t like pairing
有些人不喜欢结对子

Some people feel uncomfortable with the concept of pairing. In our experience, those that actually try it for a week or so find that their discomfort evaporates, and that they enjoy pairing and find it useful. Very few continue to dislike the practice. So, for most people, it’s simply a matter of trying it and getting used to it. For those who make an honest attempt and still find they dislike the practice, the team will have to find something appropriate for them to do.
有些人不喜欢结对子这种概念,以我们的经验来看,那些确确实实尝试了的人,在一个星期左右以后,这种不适感蒸发了,不但乐在其中而且发现确实有用。只有很少的人仍然不喜欢。所以,对于大多数人而言,去尝试并习惯只是个小问题,对于确实做了努力却仍然觉得不适的人,要给他们另找一些合适的工作。


Furniture, Facilities, and Logistics
设备,工具和后勤
------------------------------------------------------------------------------
Monitor and keyboard placement
显示器和键盘的摆放

Furniture placement is critically important to successful pairing. One cannot pair well if the partners cannot sit next to each other and rapidly swap the keyboard. The rule is: you have to be able to hand the keyboard and mouse back and forth without changing seats.
设备的摆放与双人编程是否成功息息相关,如果你的搭档不能坐近你而能快速地和你交换键盘,双人编程是没法做好的。摆放的原则是:你可以不用换位置就能把你的键盘和鼠标交给对方。

The best arrangement is usually a nice long flat table. Place the monitor in the middle and place two chairs facing the monitor. Sit with the monitor between you. Make sure it’s easy to slide the keyboard and mouse back and forth between you. Also make sure that while you have the keyboard, you are comfortable and sitting erect. Make sure the monitor is visible to both partners without having to swivel it.
最好的排列是一张又长又平的桌子,显示器放在中间,面对着显示器放两张桌子,确认键盘和鼠标可以灵活地前后移动,并且确定当你操作键盘时,你可以舒服地坐直,显示器可以不用转动两个人就可以都看见。

Bullpen
大房间

To facilitate the changing of pair partners, it’s often wise to work in a bullpen arrangement. Place several pair stations in a single room. Use wheeled chairs and linoleum or tile floors. Arrange the workstations so that the pairs face each other. The goal here is to increase communications. Sometimes the most important communications are those that are serendipitous. We want to increase the chances that such communications will take place.
为了使得换搭档更容易,在大房间里工作是个聪明的办法。几对搭档在一个的房间里,坐有滚轮的椅子,铺油毡或铺瓷砖的地板。电脑的排列让两人可以面对面。目的是为了提高交流。有时重要的交流是很偶然的。我们要提高这种交流出现机会的可能性。

Inside corners
小房间

Many cubicles nowadays have workstations placed in the inside corners. The developer sits facing a corner of the cubicle with a monitor in front of him or her. While this is convenient for individual work, it’s nearly impossible to pair well in this environment. If you have cubicles with workstations in inside corners, then set up some pair stations elsewhere—perhaps in a conference room. Pairing at a conference room table using a laptop is often very effective.
现在有很多人在小房间角落里用电脑,开发人员面对着角落坐着,前面是显示器,这种情况对于单独工作是很方便的,对于双人编程几乎不可能。如果你是在小房间里用电脑,那么就在其他地方放另一台做双人编程用--比如在会议室,在会议桌上用笔记本电脑做双人编程倒是个有效的方法。

Problems and Concerns
关心的问题
------------------------------------------------------------------------------
Pairing halves productivity
双人编程降低了一半的生产力

It stands to reason that two people working together on one task will consume twice as many person-hours as one person working on the same task. As reasonable as this is, it doesn’t seem to be the case. Independent studies (see reference [2]) have shown that little, if any, productivity is lost by working in pairs. Those same studies show that pairing substantially decreases the defect rate, and the code size, while greatly increasing job enjoyment.
有种观点认为两个人做一件任务会浪费掉两倍和一个人在同一件任务上工作一样多的人小时,由于这种原因,看来不能用这种方法。独立的研究(见参考[2])表明,双人编程只损失了一点儿生产力。也有相同的研究表明双人编程充分地降低了错误率,代码长度,同时大大地提高了工作的趣味性。

Disputes between pair partners
两人之间会争论

The owner of the task has final say in all design disputes, but the best way to settle a dispute is to try both ideas and choose the one that works best.
在整个设计过程争论的最后,还是任务的所有者说了算,但是最好的解决办法还是两种主意都试,然后挑个工作得最好的。

Specialists
专家

Conventional wisdom suggests that developers who specialize in a particular area, such as databases or GUIs, should apply their efforts solely to those areas. In a pair-programming environment, however, these specialists become mentors to others who don’t share their specialty. Developers can sign up for tasks outside of their specialty and then recruit help from the specialists. This way, knowledge of specialties tends to diffuse through the project team, greatly reducing the sensitivity of the project to turnover.
按惯例权威们建议开发者的专长用于特定的领域,比如数据库或者界面,会更加专心致志。在双人编程环境中,这些专家会成为对方的良师益友。开发者可以以他们不具有某种技能的新人身份参加任务,而从有另种专长的对方得到帮助。通过这种方法,专长者的知识会传到整个项目组,很大程度上降低了项目大改动时的敏感度。

Noise
噪声

A pair will make noise as they program. A bullpen full of pairs will maintain a continual, low-level buzz. Some feel that this noise will be bothersome and distracting. This has not proven to be a significant problem. If you find the noise distracting, you can move to a conference room for a while.
双人在编程时会发出噪声,满是对子的大房间里总存在着低低的嗡嗡声。有些人会觉得这种噪声会令人厌烦和分心。其实这不是什么大问题,你要是觉得分心了,就到会议室去呆一会。

Cowboys
西部牛仔

Many teams find that they are the proud owners of one or two cowboy coders. These are the programmers who get the job done faster than anybody else, cannot work with others, and nobody else is allowed (or would be able, if allowed) to read their code. The best thing to do with these developers is to move them off the project or into a role where they are not writing production code. Perhaps they can write short-lived tools or do some maniacal torture testing.
有些团队会以有几个牛仔程序员(核心编码人员)为荣。他们比比其他人更快地完成工作,但是没法和别人一起工作,不让别人读他们的代码,或者让读也读不懂。最好的办法是让他们在项目内或外担任一个不写生产代码的角色,说不定他们会开发出一些临时的工具,或者是一些折磨得令人发狂的测试来。

Physical impediments and impediments of style
物理上和风格上的障碍

Some folks use QWERTY keyboards. Others prefer DVORAK. Some need special keyboards, mice, displays, foot switches,and on, and on. Some cannot program without headphones and loud music. Others must surround themselves with empty Twinkie packages. Some folks like emacs. Others like VI. Still others want to work in WordPad. Indeed, the impediments that can be named are innumerable. But each and every one of them can be resolved with a little thought and the ability to compromise. A team that lets such things impede them is a team that will simply not succeed in any endeavor they try.
有些人爱敲QWERTY,另一些喜欢DVORAK。有些人需要特殊的键盘,鼠标,显示器,脚踏开关等等。有些人得戴着耳机听着震耳欲聋的音乐才能写得出东西,另一些得埋头在一堆空箱子里面。有些人爱用emacs,另一些喜欢vi,要么要记事本。事实上,这些差异多得数不清,但是每一个都可以动一些小主意或者做一些妥协就能解决。老是被这些差异束缚住手脚的团队是那些根本不想下决心去尝试解决的团队。

How can the team plan for pairing?
一个团队如何去实施双人编程的计划?

We don’t believe that tasks should be assigned to pairs. Rather each developer should be responsible for a set of tasks. We like the pairs to form informally. Each developer, pursuing his or her own responsibilities, asks other developers to briefly help. The owner of the task keeps that ownership and accountability. The pair partners are just helpers. Each developer must take into account the amount of time he or she will be pairing when offering estimates for tasks.
我们不相信指派一件任务给两个人能做好,宁愿每个人负责一件任务。双人编程最好形式上是非正式的,每个人都在为自己的任务快马加鞭,只要求别人短暂的帮助,每个人都保持自已对任务的所有权和责任,搭档只是帮忙的。每个程序员在评估他们的任务时要重视双人编程会花掉的时间。

Conclusion
结论
------------------------------------------------------------------------------
Pair programming is a well-tested, well-accepted alternative to code reviews. More than that, it’s a fundamentally different way to write software. The benefits go far beyond productivity and quality, and affect such things as the robustness and morale of the team.
双人编程是测试得更好,方式更易接受的代码评审方法,根本上,这是一种完全不同的编程方式,提供了更高的生产力,更好的品质,提高了团队的效率和士气。

References
参考资料
------------------------------------------------------------------------------
[1] eXtreme Programming eXplained, Kent Beck, Addison Wesley, 2000.
[2] Strengthening the Case for Pair Programming, Laurie Williams, University of Utah, July/Aug 2000 IEEE Software.

   关键词  >>ACCP
 
新世纪电脑培训学校
北京新华电脑学校
百事特教育学院
金同方计算机学校
北大燕工教育研究院
中科院计算所培训中心

  ■ 最新推荐课程

 ·长城平面设计师就业专修课程  ·育人电脑组装维修培训课程  ·新科海三维设计师就业班课程
 ·中科院JAVA软件工程师培训课程  ·中科院计计算机网络系统集成  ·千禧艺海高级三维室内装潢设计
 ·金同方高级文秘助理实战课程  ·科华时代 3ds max设计师课程  ·北京交通大学日语软件工程师
相关文章
 ·等级考试,水平考试,ACCP的比较
 ·ACCP软件工程师认证培训课程浅析
 ·学ACCP课程 做实用型软件人才
 ·一个教师眼中的ACCP
 ·学习ACCP的心得体会
论坛热贴
 【发表评论】
 昵称:
 内容:
 
 【最新评论】 更多...
中招在线版权与免责声明:
① 凡本站注明“稿件来源:中招在线”的所有文字、图片和音视频稿件,版权均属本网所有,任何媒体、网站或个人未经本网协议授权不得转载、链接、转贴或以其他方式复制发表。已经本站协议授权的媒体、网站,在下载使用时必须注明"稿件来源:中招在线",违者本站将依法追究责任。
② 本站注明稿件来源为其他媒体的文/图等稿件均为转载稿,本站转载出于非商业性的教育和科研之目的,并不意味着赞同其观点或证实其内容的真实性。如转载稿涉及版权等问题,请作者在两周内速来电或来函联系。
热 点 聚 焦
Google
   
精 彩 推 荐
免费下载Firefox,改进网页浏览
免费下载相片软件整理你的照片
·新科海平面设计师就业课程
·新科海软件测试工程师课程
·理工百事特软件编程课程
·百事特装饰装潢设计师课程
·J2EE Struts及XML编程技术
·千禧艺海影视后期特效课程
·JAVA软件开发专业课程
·清华万博1+6网络技术总监
·中科院企业VI平面广告课程
·中科院VC++ 6.0/VC++.Net
 
本周院校排行榜
最新资源排行榜
 
 
关于中招 - 广告服务 - 网站建设 - 版权声明 - 联系我们 - 英才加盟 - 网站地图 - 友情链接 - 免责声明 - 设为首页
Copyright @ 2005-2008 zhongzhao.com All Rights Reserved.
中招在线 版权所有