Graphite Reviewer is now Diamond

Best practices for pair programming with AI assistants

Greg Foster
Greg Foster
Graphite software engineer
Try Graphite

Pair programming—where two developers work together on the same code—has been a valued practice in software development for decades. With the rise of AI coding agents, this practice has evolved into a human-AI collaboration that brings unique benefits and challenges. This technical guide explores best practices for effective pair programming with AI assistants, helping developers maximize productivity while maintaining code quality.

Pair programming with AI assistants represents a fundamental shift in how developers interact with their tools. Unlike traditional pair programming between two human developers, AI-assisted pair programming pairs a human developer with an AI coding agent that can generate, explain, and refine code.

  • Always available: AI assistants don't need breaks, schedule synchronization, or rest periods
  • Knowledge scope: AI assistants have broader language and framework knowledge but lack domain-specific understanding
  • Interaction patterns: Communication happens through text/voice rather than natural human interaction
  • Learning dynamics: The AI doesn't learn from your codebase over time (without specific integration)

Effective pair programming with AI assistants requires clear role definition:

  • Navigator Role (Human): Direct the overall development strategy, make architectural decisions, and review AI-generated code
  • Driver Role (AI): Generate code implementations, suggest refactoring opportunities, and explain complex algorithms

Example workflow:

Terminal
Developer: "I need to implement a user authentication system using JWT in Node.js"
AI: *generates implementation code*
Developer: *reviews code, identifies security concerns, requests modifications*
AI: *refines implementation based on feedback*

AI coding agents sometimes lack the full context of your project. To maximize effectiveness:

  • Share relevant parts of your codebase when requesting assistance
  • Explain project architecture and design decisions
  • Specify coding standards and patterns to follow
  • Define any constraints or requirements clearly

Example:

Terminal
Developer: "I'm working on a React component that needs to fetch data from our API.
Here's our API client implementation and our standard pattern for handling loading states.
The component should follow our established error handling pattern."
AI: *generates code that follows established patterns and integrates with existing code*

Rather than expecting perfect code immediately:

  • Start with a rough implementation and iterate
  • Use the AI to generate alternative approaches
  • Ask for explanations of complex sections
  • Request refinements based on specific criteria

Example iterative process:

  1. Request initial implementation
  2. Review and identify areas for improvement
  3. Ask AI to explain complex algorithms or patterns
  4. Request specific refinements
  5. Validate against requirements

You should always review AI-generated code before implementation. While AI tools can produce functional code, they may:

  • Generate security vulnerabilities
  • Miss edge cases
  • Introduce inefficient algorithms
  • Make incorrect assumptions about your requirements

Tools like Diamond can significantly reduce the burden of reviewing AI-generated code. Diamond automates the identification of common errors, style inconsistencies, and inefficiencies in code produced by AI assistants. By leveraging Diamond, developers can focus on deeper logical checks and application-specific validation, thereby improving overall code quality.

Sample code review checklist:

  • Verify security practices (input validation, proper authentication)
  • Check edge case handling
  • Evaluate performance characteristics
  • Ensure readability and maintainability
  • Validate against requirements

Your prompts significantly impact code quality. Use these prompting strategies:

  • Be specific and detailed about requirements
  • Include examples of desired functionality
  • Specify edge cases that need handling
  • Reference existing patterns in your codebase
  • Request explanations alongside code generation

Example of effective prompting: "Generate a React component that displays a paginated list of user transactions. It should:

  • Fetch data from '/api/transactions' with pagination parameters
  • Display loading states during data fetching
  • Handle and display error states
  • Implement client-side filtering by transaction type
  • Follow our component pattern where we separate data fetching from presentation
  • Include test cases for the component"

Developers can use AI pair programming as a learning opportunity:

  • Ask the AI to explain complex algorithms or patterns
  • Request alternative implementations to understand trade-offs
  • Use the AI to learn new frameworks or languages
  • Document insights gained from AI-assisted development

When choosing AI tools for pair programming, consider:

  • Code completion and generation: Ability to write entire functions or modules
  • Context awareness: Understanding of surrounding code and project structure
  • Explanation capabilities: Ability to explain complex code patterns
  • Multiple programming language support: Support for your tech stack
  • Integration with development environment: Seamless workflow in your IDE
  1. GitHub Copilot: Integrates with various IDEs, strong code generation.
  2. Amazon Q Developer: Good security awareness, AWS integration.
  3. Tabnine: Privacy-focused, lightweight suggestions.
  4. Claude Code: Strong natural language understanding and explanation abilities
  5. Diamond: Specialized in code review and validation of AI-generated code.
  • Challenge: Over-reliance on AI-generated code

  • Solution: Establish review protocols, understand generated code thoroughly before implementation

  • Challenge: Integration with existing systems

  • Solution: Provide context about existing architecture, request code that follows established patterns

  • Challenge: Privacy and security concerns

  • Solution: Use tools with strong privacy policies, avoid sharing sensitive code, deploy on-premise solutions when necessary

  • Challenge: Inconsistent code quality

  • Solution: Implement thorough review processes, use Diamond or similar tools to validate code quality

Pair programming with AI assistants represents a powerful evolution in software development. By following these best practices, developers can leverage AI coding agents to enhance productivity while maintaining code quality and security. The key lies in establishing clear roles, providing adequate context, critically reviewing AI-generated code, and using AI as both a productivity tool and a learning resource.

As AI tools continue to evolve, the human-AI pair programming relationship will become increasingly sophisticated, potentially transforming software development workflows. Developers who master effective collaboration with AI coding agents will have a significant advantage in productivity and innovation.

Built for the world's fastest engineering teams, now available for everyone