AI code generation tips #1: use comments
๐ When you need to make small changes to existing code, hereโs a pro tip ๐
โ Donโt do this: Try to describe all the changes in a long prompt - itโs error-prone and the AI may misunderstand the context. Youโll end up trying and failing multiple times. ๐ฉ
โ Do this instead: Go through your code and add clear TODO comments, like:
// TODO: Add request validation to this endpoint
// TODO: Make this method take an extra parameter
// TODO: Refactor this to use async APIs
Then use a prompt like:
Go through the code and collect all TODO items, then for each item implement the changes and update the tests.
๐ฏ Why it works:
- The AI has extra context right in the code
- You get more predictable and accurate changes
Try it out - itโs a simple shift that makes a huge difference in codegen workflows. ๐ช
๐ Let me know your experiences or tricks in the comments!
Originally posted on LinkedIn.