Published on

Using AI as a Pair Programmer

Authors

Overview

This post explains how to use AI tools (like code assistants) effectively as a pair programmer. It covers a workflow, practical tips, and common pitfalls to avoid so you get useful, reliable help while maintaining control of your codebase.

Why use an AI pair programmer?

  • Speeds up routine tasks (boilerplate, refactors).
  • Helps brainstorm solutions and alternatives.
  • Acts as an on-demand documentation search and example generator.

A practical workflow

  1. Define the small, well-scoped task you want help with.
  2. Share the minimal relevant code and explain the desired behavior.
  3. Ask for one or two suggestions, not an entire redesign.
  4. Review the suggestions carefully; run tests and linting.
  5. Iterate: give targeted feedback and request a narrower change.

Tips for better results

  • Prefer specific prompts (input, expected output, constraints).
  • Share code snippets rather than large files; point to the exact function or area.
  • Ask for explanations of returned code so you can learn and audit changes.
  • Use tests as a contract: request unit tests or property-based tests for critical logic.

Example: small refactor

Here's a simple example (JavaScript) showing how you might ask an assistant to extract a helper function:

// before
function getUserFullName(user) {
  if (!user) return ''
  return `${user.firstName} ${user.lastName}`
}

// after: extracted helper
function formatName(first, last) {
  return [first, last].filter(Boolean).join(' ')
}

function getUserFullName(user) {
  if (!user) return ''
  return formatName(user.firstName, user.lastName)
}