Prompt
How can I use AI pair programming assistants to get help with debugging and writing functions from prompts?
Latest observation
You can use AI pair-programming assistants as a “coding partner” by giving them clear context, a specific task, and the relevant code/error output. They’re especially useful for:
- Debugging: finding likely causes, explaining errors, suggesting fixes
- Writing functions: generating boilerplate, edge-case handling, tests, and refactors
- Learning: asking “why” a piece of code fails or how an algorithm works
A good workflow
1) Give context first
Include:
- Language/framework
- What the code is supposed to do
- Relevant snippet
- Error message or failing behavior
- Any constraints (performance, style, version)
Example:
I’m using Python 3.11. This function should parse CSV rows into dicts, but it crashes on rows with missing columns. Here’s the function and the traceback: …
2) Ask for a diagnosis before a rewrite
For debugging, ask the assistant to:
- identify the root cause
- explain why it happens
- propose the smallest fix
- suggest tests to confirm
Good prompt:
Here’s the error and function. Can you identify the most likely bug, explain it briefly, and suggest the smallest code change to fix it?
3) Request code in a specific format
For writing functions, be explicit:
- inputs/outputs
- edge cases
- style preferences
- whether you want just the function or also tests
Example:
Write a TypeScript function
groupByStatus(items)that returns an object grouped bystatus. Handle empty arrays, preserve original items, and include 3 unit tests.
4) Iterate with the assistant
Use the assistant like a pair programmer:
- “That fix didn’t work; here’s the new error.”
- “Can you simplify this?”
- “Can you make it more efficient?”
- “Can you add tests?”
- “What assumptions are you making?”
5) Verify everything
AI can be wrong, so always:
- run the code
- inspect diffs
- add tests
- check edge cases
Prompt templates
Debugging template
I’m working in [language/framework].
Goal: [what the code should do].
Expected behavior: [details].
Actual behavior: [what happens].
Error/traceback: [paste it].
Code: [paste relevant snippet].
Please:
- identify the likely cause
- explain it concisely
- suggest a minimal fix
- recommend a test to verify it
Function-writing template
Write a function in [language] that:
- takes [inputs]
- returns [outputs]
- handles [edge cases]
- follows [constraints/style]
- is compatible with [version/framework] Also include:
- a short explanation
- 2–3 tests
Refactor template
Refactor this function to be:
- simpler/more readable
- faster for large inputs
- more testable
Keep behavior the same and explain any tradeoffs.
Tips for better results
- Paste only the relevant code, not the whole project unless needed
- Mention versions and libraries
- State exactly what “done” looks like
- If debugging, include the full error text
- Ask for tests, not just code
- Ask the assistant to show the diff if you want minimal changes
Example debugging prompt
I have this JavaScript function. It’s supposed to filter out invalid emails, but it throws
Cannot read properties of undefined. Here’s the function and sample input. Can you find the issue and fix it with the smallest change?
Example function prompt
Create a Python function
normalize_name(name)that:
- trims whitespace
- converts to title case
- preserves hyphenated names
- returns
Nonefor non-string inputs
Please include a few tests.
If you want, I can also give you:
- a ready-to-copy prompt library for debugging and function generation, or
- examples tailored to your language/framework.
Observation history
Unlock observation history
Create a free Obsurfable account to unlock historical responses, model comparisons, and deeper brand intelligence.
How did Obsurfable measure this prompt?
Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.
Which AI systems does Obsurfable collect answers from?
OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, and Meta AI.