最后更新于2017年11月6日星期一21:36:51 GMT

我喜欢 结对编程. 我断断续续地做了大约10年. 每当我结对编程, 在会议结束时, 我离开的时候总是比刚开始的时候更优秀.

然而, the practice can be expensive when the pair doing the programming are not efficient. 当涉及的两个程序员之间存在很多摩擦时, costs can exceed double that of a single programmer trying to hash things out on his or her own. 然而,, 当事情进展顺利时, the time that it takes for two programmers to solve a problem together can be less than that of the single coder going it alone.

The trick is to get things to go smoothly, to not spin cycles unnecessarily. 对我来说,这是礼仪问题。 the customary code of polite behavior in society or among members of a particular profession or group. 良好的礼仪转化为高效的结对编程. So, always being one to contribute to making the world of software development a better place in which to make code that counts, allow me to share some rules of behavior that I think makes for more effective pair programming. 我把这些规则称为结对编程礼仪的5条规则. 这些规则是:

  1. 事先就物理环境达成一致
  2. 在讨论代码时,总是引用行号和文件名
  3. 不同意的时候,从利益的角度来谈
  4. 感到不自在时,就说出来
  5. 尽可能多地赞美别人

请允许我详细说明:

1. 事先就物理环境达成一致

当与他人一起编程时,物理环境很重要. 您可能习惯于在浅色背景上阅读深色文本. 你的伴侣可能更喜欢浅色的文字而不是黑色. 虽然听起来很奇怪,但这是一个重大的脱节. 很难谈论你看不见的代码. 你的眼睛变得习惯了.

键盘快捷键和鼠标行为也是如此. 有些人喜欢向下滚动的鼠标滚轮,以便在页面中移动, 有些人习惯吃面包卷. Asking a programmer to adjust the way he or she works hardware creates friction.

在鼠标和键盘方面, 如果有一个断开, 其中一个程序员可能必须指定一个驱动程序. 如果指定的驱动程序场景是不可能的,  you might allow each programmer to stay at his or her workstation 和 use screen sharing technology found in products such as TeamViewer, Skype, 去开会并加入.me.

页面配色方案格式有点难以适应, 特别是在集成开发环境中. 如果有足够的时间, one member of the pair programming team might agree to the other programmer’s screen preference. Or, both programmers might come up a color schema that is acceptable to each. 然而,, both developers need to be able to view the code in a variety of ways– variable inspection, 调用堆栈和变量监视, 例如.  需要确定一个公共环境. Not being able to glean code information quickly 和 accurately will cause friction 和 slow the pair down. Taking the time to agree on physical environment beforeh和 will save loads of time later on.

2.在讨论代码时,总是引用行号和文件名

看看下面的问题:

变量的值是多少?

将该问题的内容与以下问题进行比较:

“What is the value of the variable, obj at Line 232 of the file, MyFile.java?”

第一个问题需要更多的跟进才能弄清楚. 第二个问题,如果有的话,也不是那么多.

因此, 当谈到代码时, unless you are pointing directly at a monitor that you 和 your programming partner can see, 总是提到你关注的焦点, 至少按行号. Figuring out the place where you or your partner is giving attention takes time, 可以用来解决问题的时间.

如果您没有在IDE中打开行号,那么就打开行号. 知道该看什么可以节省大量的劳动时间.

3. 不同意的时候,从利益的角度来谈

我有想法. 你有想法. 所有程序员都有想法. 我们就是这样建立起来的. 有时候结对编程的想法是同步的. 有时不是这样. 有分歧是好事. 这就是更好的想法被合成的方式. 然而, disagreements that go on forever, with no resolution in sight, eat time.

One trick I’ve found that when I am in disagreement with a programming partner is to always talk in terms of benefit. For example, you can say, “I think that the benefit of using my idea is [STATE THE BENEFIT HERE]”. 一个没有好处的想法是不可能的. 这是一种观点. 意见就像鼻子. 几乎每个人都有一个.

Coming to resolution on an idea is a lot easier when comparing benefits. Jousting away in the Lists of Opinion goes on until the other guy falls off the horse. 结对编程不是通过战斗进行考验. 阐明福利工程!

4. 感到不自在时,就说出来

我总是意识到我的感觉对我的想法有多大的影响. 当我感到被侵犯时, 采取防御或沮丧的态度, 我最关心的是缓和这种感觉, 没有更好的主意. 试图让不好的感觉消失需要时间. 和, 在结对编程的情况下, making bad feeling go away without making the other party aware of my ill ease is counterproductive.

听着,我们都是人. 有时我们会被一句冷嘲热讽所迷惑, a piece of sarcasm or an unintended insult made by our programming partner. 它发生. 大多数时候,说这种话的人并没有恶意. 他或她不知道. 所以这是有好处的.

当你不自在的时候,就说出来. It’s better to let the information flow for a few minutes 和 make things right than to harbor a defensive grudge that goes on through the afternoon 和 into the night. 你可以这么简单地说, “Dude, I know you probably didn’t mean it, but calling my idea lame really hurt. Maybe moving forward you can just say that my idea has some shortcomings we need to address.”

大多数人本质上是善良的. 而那些不适合结对编程的则不适合. Better to make known your ill feelings as soon as you experience them. 如果这个人能适应,那就继续前进. 如果没有,请您的经理与其他人结对编程.

5. 尽可能多地赞美别人

Pair programming is a very special type of intimacy between two human beings. Two people are working together at a very detailed level to solve complex problems.Your pair partner is sharing a very special part of him or herself: his or her thinking. 无论好坏, 它是两个人之间的关系, 也许不是你和兄弟姐妹或朋友之间的那种, but it’s not exactly as transient as sharing a seat with another person on the subway. 通过和一个人一起工作,你可以真正了解他.

One of the great benefits that I’ve found when having a good pair programming experience is the sense of empowerment I feel when we’re moving ahead together efficiently. Either I feel as if I am helping out, or I feel as if I am being helped out. 这是双赢的.

One of the ways I’ve discovered to increase that sense of empowerment between myself 和 my programming partner is to always give a compliment when an opportunity to compliment presents itself. It is my firm belief that the human being has yet to be born that does not want to be appreciated for the work he or she does or the thinking he or she has. 人们希望对自己的工作感到满意. 结对编程也不例外. One of the fastest ways I have found to get a good feeling going is to offer a sincere compliment whenever I can. 没必要搞得很戏剧化. 有时候一个简单的“好主意”就足够了.

当我的搭档感觉良好时,我也会感觉良好. 和 for those of us that have been on the terrain for a while have come to underst和, 快乐的奶牛产更好的奶. The more compliments you make, the more efficiently the pair will move.

把它们放在一起

At first glance pair programming might seem like an expensive undertaking riddled with the risk of two programmers locked in a room, 为永恒而争论. 这是众所周知的事情. 然而, pair programming can work when the two developers involved are collaborating in an agreed upon work environment, 以纯净的清晰度彼此交谈, 和 in complete awareness of each other 和 complete respect for each other. 精通结对编程需要时间. Hopefully the 5 Rules presented above will help accelerate the pair programming process, reduce the costs associated with pair programming 和 increase the efficiency of the pair doing the work, 集体和个人.