/    Sign up×
Articles /Pin to ProfileBookmark

AI Prompts to Improve Your Code

OpenAI’s artificial intelligence chatbot can be an incredible resource for developers who know the right prompts to ask. Since the AI version will continue to evolve (GPT-3, ChatGPT, GPT-4, and so on), we’ll simply refer to it as “ChatGPT” throughout this guide.

Setting the tone

The ability to structure the type of answer you want is an important step often overlooked. Let’s say you’re looking for inspiration on writing technical documentation. You can begin by telling ChatGPT:

Before I ask my question, let’s set the stage: you are an experienced developer writing documentation for others to learn from. Your answers are professional and will include: an intro summary, a code example, and
a bullet list of best practices.

You’ll see a reply similar to, “Great! I’m ready to assist.” At this point, you’re free to proceed with an additional prompt related to development and the generated output will follow the style as outlined above.

Defining the output format

You can also specify how you’d like the output of ChatGPT’s answer to be formatted. For example:

In a table with four columns, one for color names, another for hex values, one for RGBa values, and a final column for descriptions, list the most commonly used colors in websites.

Taking this one step further, you could then create an easy way to copy-paste that table elsewhere by following up with this prompt:

Repeat the last answer formatted as markdown in a copyable code block.

Longer replies

Have you ever asked ChatGPT for a lengthy answer that seemingly gets cut off? There’s an easy fix to that, simply follow-up with the word Continue in your next prompt and it will carry on with the previous reply.

Troubleshooting code

Did you know you can paste your own code snippets into ChatGPT? This is especially helpful when tracking down a stubborn bug. All you need to do is begin your prompt with something like:

In the following code, why is it generating [fill in the blank] error?

And then hit shift + enter on your keyboard to drop down to the next line in your prompt and paste your code snippet in. Of course, you should never share code that might contain sensitive info so be mindful of that.

Other powerful follow-up prompts

After your initial question to ChatGPT, there are useful ways to extract even more from the original answer. Here are some of our favorites:

  • Repeat the last code demo using tabs for indentation rather than spaces.
  • Give me the same code demo but written in [fill in the blank] web language.
  • Write that same code demo with lorem ipsum from Homer Simpson. 😂

Sign-up at Design.dev for more tips

This article was originally created for subscribers to the design.dev newsletter. Subscribe today to get additional content like this, as well as a set of 300 custom icons 🙌

Ai
×

Success!

Help @designdev spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...