What Makes a Good Debugging Question? Give Humans and AI Reproducible Evidence



☰

Start NorthStar

AI Learning & Future Skills

What Makes a Good Debugging Question? Give Humans and AI Reproducible Evidence

Turn 'it does not work' into a minimal, reproducible, privacy-safe question with clear expected and actual behavior.

AI 学习与未来技能

什么才是一个好的 Debugging Question?给人和 AI 可复现的证据

把“不能运行”改写成最小、可复现、保护隐私,并明确预期与实际结果的调试问题。

Share this article

Copy the link, open your phone share sheet, scan the QR code for WeChat, or send by email.




Email

“My code does not work” provides almost no evidence. A useful debugging question lets another person or an AI reproduce the failure, compare expected and actual behavior, and focus on the first incorrect state.

The Core Idea

Include the goal, minimal runnable code, input, expected result, actual result or complete error, relevant environment, what you tried, and one focused question.

The Stack Overflow guide to a Minimal, Reproducible Example uses three practical criteria: minimal, complete, and reproducible. Remove irrelevant code, include everything needed to run the example, and test that the reduced example still fails.

A Seven-Part Template

  1. Goal: Describe the intended behavior.
  2. Minimal code: Include the smallest readable program that still fails, as text.
  3. Input: Give exact input or reproduction steps.
  4. Expected: State the value or state you expected.
  5. Actual: Copy the complete error, traceback, or observed output.
  6. Environment and attempts: Include relevant versions and what you already tested.
  7. Focused question: Ask about the specific transition or concept you do not understand.

Weak vs. Strong

A weak question says, “My Shell Game code does not work.” A strong question shows a start at 1, swap 1 and 2, expected position 2, actual position 1, and the two if statements that reproduce the failure. It then asks why the second condition becomes true and how to make the branches exclusive.

That small example can be run immediately. A two-row dry run reveals that the first assignment changes the truth of the second condition. The minimal fix is if / elif.

When Asking AI

Ask for an explanation before a patch: identify the first incorrect state, explain the cause, and make the smallest change. Also ask for a test that fails before the fix and passes afterward. Then run and independently verify the suggestion.

Privacy and Security

Never paste passwords, API keys, tokens, private keys, student records, client data, internal connection strings, or proprietary code you are not authorized to share. Replace real data with a structurally similar fictional sample. If a secret has already been exposed, revoke or rotate it; deleting a message is not sufficient.

After You Receive an Answer

Explain which state or assumption changed, rerun the minimal failing case, add boundary and neighboring-branch tests, keep the test as a regression check, and summarize the cause in your own words.

Copyable Template

Goal:
Minimal runnable code:
Input or reproduction steps:
Expected result:
Actual error or output:
Environment:
What I tried:
Focused question:

“我的代码不工作,怎么办?”几乎没有提供可判断的信息。一个好的调试问题,不是写得更长,而是让别人能够重现问题、看见预期与实际的差异,并把注意力放在第一个错误状态上。

一句话结论

高质量 Debugging Question 应包含:目标、最小可运行代码、输入、预期结果、实际结果或完整错误信息、运行环境、已经尝试过什么,以及一个具体问题。

为什么“它不工作”无法帮助调试?

调试需要比较两件事:

expected behavior vs. actual behavior

如果没有预期结果,我们不知道“正确”是什么;如果没有实际输出、错误信息和输入,我们无法重现;如果没有最小代码,我们会被无关细节淹没。

Stack Overflow 的 Minimal, Reproducible Example 指南把关键标准概括为 minimal、complete、reproducible:代码尽量小,但必须包含重现问题所需的全部部分,而且提问者自己应先确认它确实能复现问题。

一个七部分模板

1. Goal:你想实现什么?

用一两句话描述行为,不要只说作业名称。

2. Minimal code:最小可运行代码

删除与错误无关的界面、文件、类和数据,但保留能让错误出现的部分。代码要作为文本提供,不要只发截图。

3. Input:怎样触发?

给出最小输入、调用方式或重现步骤。

4. Expected:你预期什么?

写出具体值或状态,例如“交换 1 和 2 后,position 应为 2”。

5. Actual:实际发生了什么?

复制完整错误类型、信息和 traceback,或写出实际输出。不要只写“报错了”。

6. Environment and attempts:环境与已尝试步骤

必要时写语言版本、依赖和平台。说明你已经做过哪些检查,以及结果是什么。

7. Focused question:你具体想问什么?

例如:“为什么第二个条件会在第一次更新后再次成立?”比“帮我修代码”更容易得到解释性的答案。

差的问题与好的问题

差的问题

> Shell Game 代码不工作,AI 能帮我修吗?

缺少输入、代码、预期、实际和问题焦点。

改进后的问题

> 我在模拟交换。输入是起点 1,交换 1 2。我预期 position 变成 2,但实际仍是 1。最小代码如下:

position = 1
a, b = 1, 2

if position == a:
    position = b
if position == b:
    position = a

print(position)  # actual: 1, expected: 2

> 为什么第二个 if 会执行?怎样表达“只选择一个交换分支”?

这个问题很短,却能直接运行、直接观察,也明确了学生真正不理解的地方。

先做一次 Dry Run

提问前先列一个最小状态表:

Step Condition Before After Expected
1 position == a 1 2 2
2 position == b 2 1 2

现在问题已经缩小:第一次更新改变了第二个条件的真假,两个独立 if 不是互斥分支。应该使用 if / elif。

向 AI 提问时再加两条要求

要求解释,不只要补丁

可以问:

请先指出第一个错误状态,解释原因,再给最小修改。
不要重写整段程序。

要求给验证方法

请给一个能在修正前失败、修正后通过的最小测试,
并说明为什么这个测试能覆盖错误。

AI 的建议仍需要运行、手算或用官方资料独立验证。流畅的解释不等于正确答案。

隐私与安全:提问前必须删除什么?

永远不要粘贴:

  • 密码、API key、access token、private key;
  • 学生姓名、成绩、联系方式或其他个人信息;
  • 客户数据、内部 URL、数据库连接串;
  • 未获授权的专有代码或完整作业答案。

把真实数据替换成结构相同的虚构小样本。如果秘密已经发出,应立即撤销或轮换,而不只是删除消息。

怎样缩小一个大程序?

  1. 复制到临时文件;
  2. 固定一个能复现的输入;
  3. 删除看起来无关的一半代码;
  4. 重新运行;
  5. 错误仍在就继续删除,错误消失就恢复最后一部分;
  6. 重命名敏感数据并再次确认可复现。

这个过程本身常常会找到错误。即使没有,最终问题也更容易获得准确帮助。

回答到手后怎样处理?

  1. 先解释答案修改了哪个状态或假设;
  2. 运行原来的最小失败案例;
  3. 加一个边界案例和一个相邻分支案例;
  4. 把测试保留下来防止回归;
  5. 用自己的话总结原因。

不要直接把整段答案粘回项目。一个修复只有在你能验证并解释时,才真正属于你的学习。

可复制提问模板

Goal / 目标:
Minimal code / 最小可运行代码:
Input or steps / 输入或重现步骤:
Expected / 预期:
Actual error or output / 实际错误或输出:
Environment / 环境:
What I tried / 已尝试:
Focused question / 具体问题:

家长和老师可以怎样检查?

  • 学生是否能说出预期结果?
  • 代码是否足够小而且仍能运行?
  • 是否提供完整错误信息,而不是截图的一角?
  • 是否删除了个人信息和密钥?
  • 学生能否解释采纳的修复?

Questions or feedback?

Have a question about this article or want to suggest an improvement? Send us a private message.

Send Feedback

有问题或建议?

如果你对本文有疑问,或希望提出改进建议,请给我们发送私密留言。

发送反馈

Back to AI Learning & Future Skills
返回AI 学习与未来技能

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top