AI CodingThrive Editorial

30 prompts de IA para depurar código

A depuração começa por um sintoma reproduzível.

16 min de leituraAtualizado em
Programador a analisar um problema de software num portátil num espaço de trabalho reservado.

Versão breve

  • A depuração começa por um sintoma reproduzível. Estes prompts pedem hipóteses, um teste delimitado e a menor alteração que explica a falha.
  • Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

A depuração começa por um sintoma reproduzível. Estes prompts pedem hipóteses, um teste delimitado e a menor alteração que explica a falha.

Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

Como utilizar esta coleção

Escolha a tarefa mais próxima do seu trabalho. Copie o prompt, substitua a cena genérica ou o contexto de código pelos seus dados e mantenha as restrições que ajudam a avaliar o resultado. Altere uma variável de cada vez para identificar o que melhorou.

A abordagem segue o guia de engenharia de prompts do GitHub Copilot: forneça contexto concreto e examine o resultado sem assumir que um primeiro rascunho bem apresentado está correto.

Prompts de diagnóstico

Este conjunto centra-se em o diagnóstico. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

1. Um valor null que faz uma página falhar

Help with a null value crashing a page in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

2. Uma conversão de fuso horário com um dia de diferença

Help with a timezone conversion off by one day in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

3. Uma resposta 401 intermitente

Help with an intermittent 401 response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

4. Uma condição de corrida entre duas gravações

Help with a race between two saves in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

5. Um item em falta numa lista após a filtragem

Help with a missing list item after filtering in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

6. Uma página lenta sob carga

Help with a slow page under load in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

7. Uma ligação direta que não funciona

Help with a broken deep link in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

8. Um analisador que rejeita uma entrada válida

Help with a parser rejecting valid input in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

9. Uma resposta desatualizada na cache

Help with a stale cached response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

10. Um envio de ficheiros que só funciona localmente

Help with an upload that works only locally in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then state competing hypotheses, request a minimal reproduction and identify evidence that separates them. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute a reprodução proposta antes de aplicar uma correção.

Developer investigating a timezone bug with two clocks and a date test.

Prompts de implementação

Este conjunto centra-se em a implementação. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

11. Um valor null que faz uma página falhar

Help with a null value crashing a page in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

12. Uma conversão de fuso horário com um dia de diferença

Help with a timezone conversion off by one day in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

13. Uma resposta 401 intermitente

Help with an intermittent 401 response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

14. Uma condição de corrida entre duas gravações

Help with a race between two saves in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

15. Um item em falta numa lista após a filtragem

Help with a missing list item after filtering in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

16. Uma página lenta sob carga

Help with a slow page under load in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

17. Uma ligação direta que não funciona

Help with a broken deep link in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

18. Um analisador que rejeita uma entrada válida

Help with a parser rejecting valid input in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

19. Uma resposta desatualizada na cache

Help with a stale cached response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

20. Um envio de ficheiros que só funciona localmente

Help with an upload that works only locally in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then make the smallest change that satisfies the stated behavior and show a focused diff. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Examine as diferenças para identificar alterações fora do âmbito e acesso não previsto a dados.

Three-step code workflow: brief the work, inspect the result, edit and verify.

Prompts para testar os limites

Este conjunto centra-se em os testes dos limites. Forneça o seu código real e o comando de teste antes de aceitar a resposta.

21. Um valor null que faz uma página falhar

Help with a null value crashing a page in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

22. Uma conversão de fuso horário com um dia de diferença

Help with a timezone conversion off by one day in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

23. Uma resposta 401 intermitente

Help with an intermittent 401 response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

24. Uma condição de corrida entre duas gravações

Help with a race between two saves in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

25. Um item em falta numa lista após a filtragem

Help with a missing list item after filtering in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

26. Uma página lenta sob carga

Help with a slow page under load in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

27. Uma ligação direta que não funciona

Help with a broken deep link in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

28. Um analisador que rejeita uma entrada válida

Help with a parser rejecting valid input in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

29. Uma resposta desatualizada na cache

Help with a stale cached response in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

30. Um envio de ficheiros que só funciona localmente

Help with an upload that works only locally in my existing codebase. Ask for the relevant file, expected behavior, actual behavior and test command if I have not supplied them. Then add unit or integration cases for empty, invalid and concurrent inputs as appropriate. Preserve public interfaces unless evidence requires a change. Show assumptions, a focused diff and the exact command I should run. Do not invent files, test results or security guarantees.

Verificação: Execute os testes e, quando possível, confirme que falham antes da correção.

O que verificar antes de utilizar o resultado

Nunca cole credenciais, dados privados de clientes ou repositórios proprietários completos num assistente não autorizado. Execute os comandos e os testes sugeridos no seu ambiente. Uma alteração plausível não comprova que funciona.

Se o resultado não cumprir a tarefa, encurte o prompt e indique o facto ou a restrição em falta. Guarde a versão utilizada para que o recurso final ou a alteração de código possam ser reproduzidos.

Leituras adicionais

Continue com um guia relacionado

Ponha em prática

O seu próximo passo

Tem uma pergunta ou uma correção?

Contactar a Thrive

Continuar a ler

Mais artigos do diário

Todos os artigos