AI CodingThrive Editorial

25 prompts de IA para refactorizar código

La refactorización debe conservar el comportamiento. Estos prompts exigen pruebas existentes, un cambio acotado y un diff que se pueda revisar antes de aceptar la limpieza.

14 min de lectura
Un programador reorganiza módulos de software enredados en una estructura clara.

La versión breve

  • La refactorización debe conservar el comportamiento. Estos prompts exigen pruebas existentes, un cambio acotado y un diff que se pueda revisar antes de aceptar la limpieza.
  • No pegues credenciales, datos privados de clientes ni repositorios propietarios completos en un asistente no autorizado. Ejecuta los comandos y las pruebas en tu propio entorno. Que un parche parezca correcto no demuestra que funcione.

La refactorización debe conservar el comportamiento. Estos prompts exigen pruebas existentes, un cambio acotado y un diff que se pueda revisar antes de aceptar la limpieza.

No pegues credenciales, datos privados de clientes ni repositorios propietarios completos en un asistente no autorizado. Ejecuta los comandos y las pruebas en tu propio entorno. Que un parche parezca correcto no demuestra que funcione.

Cómo usar esta colección

Elige la tarea más parecida a tu trabajo. Copia el prompt, sustituye la escena o el contexto de código genérico por tus datos y conserva las restricciones que te permitan evaluar el resultado. Cambia una variable cada vez para saber qué ha mejorado.

El método sigue la guía de ingeniería de prompts de GitHub Copilot: aporta contexto concreto y revisa el resultado, sin dar por correcta una primera respuesta bien presentada.

Prompts de diagnóstico

Este grupo se centra en el diagnóstico. Facilita tu código y el comando de pruebas antes de aceptar la respuesta.

1. Una larga cadena de condiciones

Help with a long conditional chain 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

2. Una regla de validación duplicada

Help with a duplicated validation rule 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

3. Una función auxiliar de base de datos con efectos secundarios

Help with a database helper with side effects 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

4. Un componente grande de React

Help with a large React component 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

5. Un controlador de API enredado

Help with a tangled API controller 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

6. Una configuración con cadenas fijas sin explicar

Help with a magic-string configuration 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

7. Una utilidad con nombres imprecisos

Help with a utility with vague names 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

8. Un bucle lento

Help with a slow loop 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

9. Una antigua cadena de callbacks

Help with a legacy callback chain 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

A tangled software function reorganized into three smaller modules.

10. Una comprobación de permisos dispersa

Help with a scattered permission check 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.

Revisión: Ejecuta la reproducción propuesta antes de aplicar un parche.

Prompts de implementación

Este grupo se centra en la implementación. Facilita tu código y el comando de pruebas antes de aceptar la respuesta.

11. Una larga cadena de condiciones

Help with a long conditional chain 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

12. Una regla de validación duplicada

Help with a duplicated validation rule 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

13. Una función auxiliar de base de datos con efectos secundarios

Help with a database helper with side effects 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

14. Un componente grande de React

Help with a large React component 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

15. Un controlador de API enredado

Help with a tangled API controller 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

16. Una configuración con cadenas fijas sin explicar

Help with a magic-string configuration 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

17. Una utilidad con nombres imprecisos

Help with a utility with vague names 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

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

18. Un bucle lento

Help with a slow loop 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

19. Una antigua cadena de callbacks

Help with a legacy callback chain 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

20. Una comprobación de permisos dispersa

Help with a scattered permission check 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.

Revisión: Revisa el diff para detectar cambios ajenos a la tarea y accesos a datos no previstos.

Prompts para probar casos límite

Este grupo se centra en probar los casos límite. Facilita tu código y el comando de pruebas antes de aceptar la respuesta.

21. Una larga cadena de condiciones

Help with a long conditional chain 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.

Revisión: Ejecuta las pruebas y, cuando sea posible, comprueba que fallen antes de aplicar la corrección.

22. Una regla de validación duplicada

Help with a duplicated validation rule 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.

Revisión: Ejecuta las pruebas y, cuando sea posible, comprueba que fallen antes de aplicar la corrección.

23. Una función auxiliar de base de datos con efectos secundarios

Help with a database helper with side effects 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.

Revisión: Ejecuta las pruebas y, cuando sea posible, comprueba que fallen antes de aplicar la corrección.

24. Un componente grande de React

Help with a large React component 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.

Revisión: Ejecuta las pruebas y, cuando sea posible, comprueba que fallen antes de aplicar la corrección.

25. Un controlador de API enredado

Help with a tangled API controller 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.

Revisión: Ejecuta las pruebas y, cuando sea posible, comprueba que fallen antes de aplicar la corrección.

Qué comprobar antes de usar el resultado

No pegues credenciales, datos privados de clientes ni repositorios propietarios completos en un asistente no autorizado. Ejecuta los comandos y las pruebas en tu propio entorno. Que un parche parezca correcto no demuestra que funcione.

Si el resultado no resuelve la tarea, acorta el prompt y especifica el dato o la restricción que falta. Guarda la versión utilizada para poder reproducir el recurso final o el cambio de código.

Para seguir leyendo

Continúa con una guía relacionada

Llévalo a la práctica

Tu siguiente paso

¿Tienes una pregunta o una corrección?

Contactar con Thrive

Seguir leyendo

Más artículos del diario

Todos los artículos