Last updated at Mon, 06 Nov 2017 21:36:51 GMT

我喜欢 结对编程. I’ve been doing it episodically for about 10 years. 每当我结对编程, 在会议结束时, I’ve always walked away a better developer than when I started.

然而,当编程的效率不高时,这种做法可能会代价高昂. When a lot of friction exists between the two coders involved, 成本可能会超过一个程序员独自解决问题的两倍. 然而,, 当事情进展顺利时, 两个程序员一起解决一个问题所花费的时间可能比一个编码员单独解决问题的时间要少.

诀窍是让事情顺利进行,而不是不必要地旋转循环. For me it’s a matter of etiquette: 礼仪:社会上或某一特定职业或群体成员之间礼貌行为的习惯准则. Good etiquette translates into efficient pair programming. So, 永远是一个为软件开发世界做出贡献的人,在这个世界里编写有价值的代码, 请允许我分享一些行为规则,我认为这些规则可以使结对编程更有效. I call these rules the 5 Rules of 结对编程 Etiquette. 这些规则是:

  1. Agree on the physical environment beforehand
  2. When talking about code, always refer to line number and file name
  3. When disagreeing, talk in terms of benefit
  4. When feeling ill at ease, say so
  5. Bestow as many compliments as possible

请允许我详细说明:

1. Agree on the physical environment beforehand

When coding with another person physical environment counts. You might be accustomed to reading dark text on a light background. Your partner might prefer light text against black. As strange as it sounds, this is a significant disconnect. It’s hard to talk about code you cannot see. 你的眼睛变得习惯了.

The same is true with keyboard shortcuts and mouse behavior. Some people like mouse wheels that roll down to move through a page, some people are used to down rolls. 要求程序员调整他或她使用硬件的方式会产生摩擦.

在鼠标和键盘方面, 如果有一个断开, one of the programmers might have to designate a driver. If a designated driver scenario is not possible,  您可以允许每个程序员留在他或她的工作站上,并使用TeamViewer等产品中的屏幕共享技术, Skype, 去开会并加入.me.

Page color scheme format is a bit harder to accommodate, particularly when Integrated Development Environments are in play. 如果有足够的时间, 结对编程团队中的一个成员可能会同意另一个程序员的屏幕偏好. 或者,两个程序员可能会提出一个各自都能接受的颜色模式. 然而,, 两个开发人员都需要能够以多种方式查看代码——变量检查, call stack and variable watches, 例如.  A common environment needs to be identified. 不能快速准确地收集代码信息将导致摩擦并减慢配对速度. 事先花时间商定物理环境将为以后节省大量时间.

2.When talking about code, always refer to line number and file name

Take a look at the following question:

What’s the value of the variable?

Compare the content of that question to the following question:

在文件MyFile的第232行,变量obj的值是多少.java?”

第一个问题需要更多的跟进才能弄清楚. The second question, not so much, if any at all.

因此, 当谈到代码时, 除非您直接指向您和您的编程伙伴可以看到的显示器, always reference your focus of attention, 至少按行号. 找出你或你的伴侣关注的地方需要时间, time that could be spent solving a problem.

If you don’t have line numbers turned on in your IDE, do so. Knowing what to look at will save oodles of time in your labors.

3. When disagreeing, talk in terms of benefit

我有想法. 你有想法. 所有程序员都有想法. 我们就是这样建立起来的. Sometimes pair programming ideas are in sync. 有时不是这样. 有分歧是好事. That’s how better ideas are synthesized. 然而,永远持续下去的分歧,看不到解决办法,会浪费时间.

当我与编程伙伴意见不一致时,我发现的一个技巧就是总是从利益的角度来谈论. 例如,你可以说,“我认为使用我的想法的好处是[在这里说明好处]”. An idea without a benefit ain’t. 这是一种观点. 意见就像鼻子. 几乎每个人都有一个.

在比较利益时,对一个想法做出决定要容易得多. 在意见清单上的比武一直持续到另一个人从马上摔下来. Pair programming is not about trial by combat. 阐明福利工程!

4. When feeling ill at ease, say so

I am always aware about how much my feelings influence my thinking. 当我感到被侵犯时, put on the defensive or frustrated, my immediate concern is to assuage the feeling, 没有更好的主意. Trying to make bad feelings go away eats time. 和, when in a pair programming situation, 让不好的感觉消失而不让对方意识到我的不安是适得其反的.

听着,我们都是人. Sometimes we get thrown by a snide remark, 我们的节目合作伙伴说的一句讽刺或无意的侮辱. 它发生. Most time the person casting the remark has no intention of harm. 他或她不知道. 所以这是有好处的.

When you are ill at ease, say so. 最好让信息在几分钟内流动,把事情做好,而不是从下午一直到晚上怀恨在心. You can say something as simple as, “伙计,我知道你可能不是故意的,但是说我的想法很差劲真的很伤人. 也许接下来你可以说我的想法有一些缺点需要解决.”

Most people are intrinsically kind. Those that aren’t are not good candidates for pair programming. Better to make known your ill feelings as soon as you experience them. If the person can adjust, then move forward. If not, ask your manager to pair program with someone else.

5. Bestow as many compliments as possible

结对编程是两个人之间一种非常特殊的亲密关系. 两个人在非常详细的层面上一起工作来解决复杂的问题.你的搭档正在分享他或她自己的一个非常特别的部分:他或她的想法. 无论好坏, it’s a relationship between two people, maybe not the type you have with a sibling or friend, 但这并不像在地铁上与他人合坐那么短暂. You really do get to know a person by working with them.

我发现,拥有良好的结对编程经验的一大好处是,当我们一起高效地前进时,我能感受到一种赋权感. 要么我觉得自己在帮助别人,要么我觉得自己在被别人帮助. 这是双赢的.

我发现的增加我和我的编程伙伴之间的授权感的方法之一是,当有机会赞美时,总是给予赞美. 我坚信,还没有出生的人,并不希望自己所做的工作或思想得到赞赏. People want to feel good about they work they do. Pair programming is no exception. 我发现让人感觉良好的最快方法之一就是随时真诚地赞美别人. 没必要搞得很戏剧化. Sometimes a simple, “good idea” will suffice.

When my pair partner feels good, I tend to feel good. 对于我们这些在这片土地上待了一段时间的人来说已经开始明白了, 快乐的奶牛产更好的奶. 你赞美得越多,两人的交往就越有效率.

把它们放在一起

乍一看,结对编程似乎是一项昂贵的事业,充满了两个程序员被锁在一个房间里的风险, 为永恒而争论. 这是众所周知的事情. 然而, 当涉及的两个开发人员在商定的工作环境中协作时,结对编程可以起作用, talking to each other with pristine clarity, 完全了解彼此,完全尊重彼此. It takes time to get good at pair programming. 希望上面列出的5条规则能够帮助加速结对编程的过程, 减少与结对编程相关的成本,并提高结对工作的效率, 集体和个人.