3 AI Pair Programming Rules for Better Code and Fewer Rewrites
The author shares three rules they follow after 100 sessions of using AI assistants for pair programming: 1) Never accept the first draft, 2) Give the scope before the task, and 3) Make the AI write tests first, then the code.
Why it matters
These rules help developers leverage the power of AI assistants more effectively, leading to higher-quality code and fewer debugging hours.
Key Points
- 1The first draft from AI assistants often has subtle bugs that need to be caught
- 2Providing clear scope and constraints upfront leads to better code than open-ended prompts
- 3Writing tests before the implementation ensures the code meets the required specifications
Details
The author has been using AI assistants for pair programming regularly and has converged on three rules that consistently improve the quality of the code and reduce the need for rewrites. The first rule is to never accept the first draft from the AI, as it tends to optimize for plausible-looking code that may still have edge cases and missing error handling. Instead, the author asks the AI to review the implementation for issues and rewrite it. The second rule is to provide the scope and constraints before giving the task, as this narrows the solution space and leads to better code than open-ended prompts. The third rule is to make the AI write the tests first, before the implementation, as this ensures the code meets the required specifications. The author found this last rule to be the most impactful, as it acts as a specification for the AI to work towards.
No comments yet
Be the first to comment