Tips for using ChatGPT to create code
/I’ve written a few lines of code with ChatGPT now. Here are my tips.
Start with the most detail about the problem that you can. I’ve actually found that this is a great way to solve a problem whether you use ChatGPT or not - because it forces you to think hard about what you want it to make.
Don’t let ChatGPT add complication. It frequently suggests writing more code (for example processing the output of a method rather than changing what the method does).
Show ChatGPT the exact error that you got by pasting it into the conversation.
Ask ChatGPT to write your documentation too. If you ask it specifically, it will generate markdown files that you can download straight into your project. This works really well. Explain what kind of documentation you want, and the audience it is for.
Make a ChatGPT project and upload the source code into the project once you’ve got it mostly working. Then you can refer back to it directly later. Add documents too, especially ones that ChatGPT has written for you that need to be updated as you add functionality.
Try very hard not to let ChatGPT rewrite you entire program. When it does this the names of variables may change (filename will become file or name) and changes that you specifically requested earlier may well be omitted. Instead, ask for a set of step-by-step changes and additions that you can work through with it. This helps you build understanding of what ChatGPT is making for you.
Tell ChatGPT which bits you want to make first, and just make those. Then put the partially completed files in the project (see above) for it to work on.
If it does something that feels wrong, call it out. Best case you’ll get a good explanation of why it is working that way. Worst case you’ll find it has missed something. Which leads to….
Don’t assume that the emphatic way that it explains things means it knows what it’s doing. I’ve caught it making the most amazing howlers and heading off in really strange directions.
Don’t get upset when you are debugging code that it has written and it starts referring to the code as yours…..