How do you review code when coding with ChatGPT?
I've been using ChatGPT quite a lot for personal projects lately, but I feel uneasy about using the generated code as-is, so I'm trying to review it.
I'm curious how everyone verifies it.
6 answers
Do you have a source? I’m curious about the basis for saying library version mismatches are common. I’ve rarely had that happen with GPT-4.
I took the opposite approach. Instead of reviewing the code myself, I ask the AI, "Find 10 problems and edge cases in this code," and then I verify them. It's more efficient than reading everything from scratch. That said, since the AI can be wrong, you have to make the final judgment yourself, and it's a good idea to split your git commits into small chunks so you can easily revert if problems arise.
Agreed, this is surprisingly important. I usually just run it first and start from wherever errors pop up, but I guess that’s not really a review lol
Can't I just use it as is? If it's a personal project, I don't see why I'd need to go that far.
At first, I just copied and pasted too, but later when debugging I lost my mind, so now I've set some rules.
1. Extract and verify only one function at a time
2. Check that library versions match (this is really often wrong)
3. Check for places missing exception handling
4. Have it write test code separately and run it
Doing it this way made me feel at least a bit less anxious. Number 2 especially is absolutely essential. Sometimes it even makes up functions that don't exist...
Well, that's a bit... A lot of people call it a "review" when they're really just running it to see if it works, and that's not a review. At a minimum, I think you should be able to explain, at the diff level, why it was written this way. Especially for security-related code, using AI-generated code as-is is dangerous.