In software engineering, there is a legendary technique called 'Rubber-Duck Debugging'. Whenever a programmer gets stuck on a nasty bug, they explain the problem out loud to a rubber bath duck sitting on their desk.
By forcing themselves to explain what the code is supposed to do step by step, the human brain uncovers the mistake. With an AI, that rubber duck talks back—and offers instant, working solutions.
The 4-Part Code Debugging Prompt
- 1. The Environment: Language & framework (e.g. "React 19 with Vite and TypeScript").
- 2. The Failing Code: The specific function wrapped in backticks (keep it under 50 lines).
- 3. The Exact Error Message: The terminal stack trace or browser console error.
- 4. The Expected vs Actual Behavior: "Expected the button to open a modal, but nothing happens and console shows 'TypeError: undefined'."
Always instruct the AI: "Explain the root cause of the error in 2 sentences before providing the code fix." Understanding why code broke prevents you from making the same mistake twice!