02 Jun 2013

Don't fear pair programming - A Guide to Starting

Pair Programming is becoming a big deal in the Ruby programming world: this guide will help you get started.

Pre-Reqs:

General familiarity with Ruby tools (Bundler, Gems, RVM/Rbenv) Basic commandline comfort

What is Pairing?

In its simplest form, pair programming is where a pair of programmers work on a problem using the same computer.

Since I live don’t live in a technology hub in America, programming in the same physical location is challenging. Instead, it’s possible to replicate that experience with both parties in separate locations.

How Does it Work?

Setup a video call using Skype, Google Plus, Twelephone. Both partners connect into a shared machine such as a Virtual Private Server (VPS). Each partner connects into a shared Tmux session. Both of the individuals can jointly edit the same files, as if they were present at the same keyboard.

Setting It Up From Scratch

Signup with a VPS provider (I’m currently very happy with DigitalOcean) Boot up a basic 512MB RAM instance in the Linux flavor of your choice. I’ll use Ubuntu 12.04 x32 for this example. Once the instance is booted up, let’s connect and setup basic sane defaults. Install tmux and vim-nox using the package manager. Install Ruby using RVM, Rbenv, or Chruby. Install Tweemux Gem - gem install tweemux Now that we’ve laid the groundwork for it, let’s work on making it available for a partner.

Inviting a Pair

When ready to invite a pairing partner, we start by adding a unique user for them. For convenience, it’s best to add their username from Github.

adduser --disabled-password $PAIRNAME

Next we’ll use the Tweemux Gem from RKing to pull down the partner’s public key from Github, and add it to their ~/.ssh/authorized_keys.

tweemux hubkey $PAIRNAME

At this point in the process, that user can login to your server using the IP address, their Github username, and their matching private key.

ie - ssh $PAIRNAME@IP_ADDRESS_OF_SERVER

At this point, the host should fire up a shared Tmux session:

tmux -S /tmp/pair

And enable that socket to be world readable:

chmod 777 /tmp/pair

NOTE: Doing this on anything other than a bare server, or with someone you don’t trust, isn’t a secure or a good idea. Don’t do this on a production server or with sketchy folks!

Next, it’s time for the guest to join the shared Tmux session:

tmux -S /tmp/pair attach

And you’re both in the same Tmux session! The view, keyboard and such is all shared =).