18

Flow is a concept introduced by Mihaly Csikszentmihalyi; in short, it means to get into the "zone". You feel immersed in your task, focused; the task can be difficult but challenging at the same time. When people achieve flow their productivity shoots up. Programming requires a great deal of mental focus because we often need to juggle several things in our minds at once. Many like to work in a quiet environment where they can direct their full attention to the task. If they are interrupted, it may take several minutes or even hours to get back into flow.

I understand there's a practice in agile development and extreme programming called pair programming. It means you put the whole software development team in one room so that communication is seamless. You do write code with your pair because this way you get instant code reviews and fewer bugs get through.

I've always had problems achieving flow while doing pair programming because of constant interruptions. I'm thinking deep about an issue then all of sudden someone asks me a question from another pair. My train of thought is lost.

How can you achieve and maintain flow while pair programming?

Eric Wilson
  • 12,111
siamii
  • 1,320
  • 12
  • 23

5 Answers5

16

Edit: Disclaimer - This is how I define "the zone": A state of extreme focus, in which one is able to understand how many intricate details connect together, regardless of whether these do so elegantly (or simply) or not.

I try to avoid this state because, while I may produce correct code in the zone, I and other developers will have a hard time understanding it later on. To put it short: reading code that was written in the zone may often require the reader being in the zone. That constraint is my problem.

There's a lovely chapter on The Clean Coder where Uncle Bob persuasively explains why "getting into the zone" is a delusively bad idea.

Here's a possibly better alternative than "getting in the zone": think straight and consider calmly and professionally what you're doing. Communicate. Share thoughts with your partner(s). Identify the real problems. Discuss possible solutions. You might not feel supernaturely focused, but you're likely to make good decisions, and approachable designs.

If you and your pair-partner can discuss the problem without both of you being extremely focused, then chances are you've boiled the problem down to its simpler nature. That suggests you'll be able to understand it again whenever you need to.

On the flip side... If you just need some time alone to get your head straight (we all do sometimes), just take it. Get your thoughts together. Work the problem out in your head first.

But the thing is that if you do - don't use that time to write production code. Instead, play around with sample code and prototypes. Try to understand the problem, without thinking about solutions just yet. Once you get everything straight and written down, discuss it with your team and pair partner, or even the rubber duck on your desk. If you still can't articulate it, or they can't understand it, then refine your ideas. Once you've nailed all of that down - integrate all that thought and sample code into a real, working solution.

Yam Marcovic
  • 9,390
5

Pair programming sometimes requires periods of isolation from your partner.

Example

You are working together on a particular class, and you realize that you need to write a method that requires deep thought on some complex logic, but otherwise returns a mundane result. You work together on creating unit tests for that method, and defer the writing of that method to a period of time when you're working in isolation. When the method is completed, you get back together as a pair and evaluate the results.

Robert Harvey
  • 200,592
5

I've found there is a small class of problems for which pair programming works. For example, if you are working on a cross platform product and the Winders guy has implemented a feature that requires OS specific code, he can help the Mac guy implement the same feature on the Mac code while the Mac guy drives.

However in my experience pair programming unusually results in a net loss of productivity. It so often feels like we're paying two developers to do the job of one.

Yes, it reduces the horrifying possibility that a dev might take a stackexchange break during the workday.

IMHO it would be cheaper for those companies who want to police their devs to just pair every dev with a private security guard to stand behind the developer and hit the dev with a truncheon if he ever slows down or tries to peak at a non-essential web page.

Jim In Texas
  • 1,453
3

As a developer attempting to get into the zone, you'll attempt to isolate yourself as best as you can to get comfortable and clear your mind. Why should pair programming be any different?

You and your partner should find a zone-inducing environment that works for you both. This will possibly require compromise on some things, but my main point is that the pair environment should be similar to the solo. Turn off the external world. The pair is programming together; other pairs (other co-workers in general) should not be interrupting (excepting critical, drop-what-you-are-doing problems).

sarumont
  • 463
0

Flow is a great state to be in when you know the exact steps to solve a problem. i.e. few unknown unknowns. You sit in a quiet corner and hammer away the solution. However, most problems/stories/features are not very clear when you start programming them. There will always be a "gap" between the end state expected and how your brain has "planned" it. You learn a lot of things when you actually "do it". Your brain juggles

  • Code Design

  • Typing

  • Learning new things about the domain and code

When I program alone, I struggle to balance these things. I tend to get into "rabbit holes" where my sunk cost fallacy prevents me from taking a step back and looking at the big picture and changing my design. It is also hard for me to talk to an imaginary rubber duck or a real one for that matter. I am after all in "flow".

When I am productively pair programming though, I get alternating periods of typing followed by periods of thinking and reflection. This is where a lot of hidden things reveal themselves and a different design may emerge. If I am going into a rabbit hole, my pairing partner can pull me out of it. Talking/explaining something to a real human being has this wonderful effect of making your thoughts clearer somehow. Sometimes, I do miss being in the "flow", but I think I contribute much more to my team when I pair program than when I program solo. After all programming != typing. Programming happens in the brain and better programming happens when two brains collaborate and criticise each other.

uttamkini
  • 121