Published on

ChatGPT Programming Prompts -- 5 Tips

Authors
  • avatar
    Name
    Tinker Assist
    Twitter

1. Copy/Paste Your Code

If you already have a baseline to start, add it to the prompt! Not only is ChatGPT great at writing code, it's effective at digesting it as well. This will provide it with some initial context on what you're doing and how to add to it.

2. Be Verbose with Programming Syntax

Which of the below prompts do you think is going to provide more robust and intentional code?

"I need to do arithmetic in python"

"create a class named arithmetic that has two variables, x and y, and has four methods: add, subtract, multiply, and divide"

Of course, this is an exaggerated response, but if you try this, you will see the latter prompt provides much more intentional code.

3. Reference Previous Responses & Prompts

ChatGPT can reference previous parts of a conversation, so use this to your advantage in your prompting. For instance, we already mentioned that it is important to copy/paste any existing code into a prompt as a baseline. If you had some function that followed a certain naming convention or utilized some libraries or functions, you can reference that and say, "create ___ function following the naming convention in my ___ function above", or "create five test cases for ___ function you wrote above".

As your exchange grows in length, the model builds more and more context regarding what you are trying to do - it's important to use this dialogue to your advantage.

4. Point Out What Worked

This is related to the last point, but it's so important that we believe it should stand alone. We have seen many cases in which code written by ChatGPT will be overwritten later in the dialogue as the model did not receive apt feedback on what worked.

It is rare to get what you want in one prompt, but it is crucial to not regress as the dialogue grows, and the only way to ensure that is to cement what is correct with proper feedback.

5. Provide Errors & Outputs Verbatim

ChatGPT is a piece of software, and sometimes it is important to treat it that way. If you were speaking with a human programmer, you likely wouldn't communicate an exact error message or program output, but in the case of an AI model, this is the most concise way to communicate results.

If the model provides you with a code snippet and it produces an error in your environment, don't simply say "that didn't work". Instead, say "the above code produced the following error: output from terminal/ide".