How to Use ChatGPT for Coding to Maximise Your Coding Potential

How to use ChatGPT for coding
Reading Time: 8 minutes

The release of ChatGPT, an advanced predictive chatbot based on GPT-3.5, by OpenAI has got many people wondering, indeed worrying, what it portends for them. Among them are programmers and developers. Entering “Will ChatGPT replace” in the search bar gives “programmers” and “developers” as two of the top suggestions. This indicates the type of people building ChatGPT are asking if their tools will supplant them, whether generative AIs such as ChatGPT can write code on their own.

The curiosity (and concern) is justified, if only slightly. AI has already shown promise in creating codes for various applications, from website development to game design. It doesn’t stop at those; AI is now being used to create more advanced AI systems. This technique, called automated machine learning (AutoML), allows machines to create complex models and optimise algorithms without or with little human intervention.

While it’s unlikely for an AI to build a more intelligent and powerful version of itself, and the enhanced version to build an even more enhanced version and so on ad infinitum until it becomes infinitely intelligent and powerful. It is plausible, however, that they’ll get as good as humans at coding, if not better, in the near future.

But that is then. In the meantime, we can use AI such as ChatGPT for coding to write code more efficiently and increase productivity.

Uses of ChatGPT for coding

Programmers and developers can use ChatGPT for coding in a number of ways, especially for brainstorming and generating codes in skeletal forms that can be modified and polished. ChatGPT’s ability to generate codes from natural language is a game-changer. It is yet a step towards bridging the language gap between machines and humans.

Here are a few ways that we can use ChatGPT for programming and development purposes:

  1. Generate code
  2. Complete and modify code
  3. Debug code
  4. Translate code from one language to another
  5. Explain codes in natural language
  6. Act as a Linux terminal
  7. Act as an SQL command line

Let us learn how we can use ChatGPT for coding by considering the above use cases in more detail.

Tips to use ChatGPT for coding

Before we can start using ChatGPT for programming, it’ll be useful to learn some important ChatGPT coding tips and tricks that will help you get the most from ChatGPT coding capability.

Here are some other tips on how to use ChatGPT for coding to generate codes that are more usable, functional, and better optimised.

  • As far as possible, break the code or programming ideas into the smallest functional units possible to reduce errors. You can then piece them together to create a functional whole. If you ask ChatGPT for a lengthy code, you’re more likely to get a code that is either patently wrong or does not work as you want it to, as it has a short context window.
  • To overcome text limitations in the response, ask it to use helper functions and avoid comments and explanations. This way you can copy the code and use it directly. If it gives an incomplete code, you can ask it to continue or keep going.
  • Instead of “Write a code in C#…”, you can use short forms without reducing details: “C#: A program that…”
  • Quite often it generates generic or unrelated responses. So you can append to your prompt: “Ask more questions to help you build context”. And it’ll ask you relevant questions that you can fill in to get a more accurate answer.
  • Ask it to cross-check the code it generated.

Generate code

ChatGPT can be used for writing simple codes in any language. But that doesn’t mean you can just throw any words and it’ll give you complete, polished, optimised codes that you can push live. However, there are certain things that we can do to generate more desirable answers.

Context is crucial for ChatGPT. Asking “What is Javascript?”, then “Give me an example of an application created in Javascript”, and then following up with “Show me an application in Javascript that makes the phone vibrate” is better than directly asking the last question, as sometimes it’ll say that it’s a language model and cannot do this or that.

Write a regular expression that extracts all dates from a text file.

Use ChatGPT to generate regular expressions

Write a Javascript code for a compound interest calculator.

Use ChatGPT for coding in Javascript

Complete code

We can not only use ChatGPT for coding afresh but also use it to complete codes. If you have an incomplete code or want to insert additional information into the code, ChatGPT can help you to complete the code or add additional details. You can use it to modify and rewrite codes to achieve certain ends, or add comments to original codes.

Provide as much context as possible so that it can understand what you want to accomplish.

I ask ChatGPT to complete an HTML code by adding a footer with links to the support page, privacy page, and social media links. It gave the original code with the additional elements added.

Code completion with ChatGPT

Related: Use ChatGPT as a Writing Assistant to Write Faster and Better

Debug code

Debugging codes is another useful application of ChatGPT. A study found that ChatGPT’s bug-fixing performance is on par with deep learning approaches CoCoNut and Codex. But it does have an edge over those in some aspects.

What differentiates ChatGPT is that it provides an explanation and fixes the codes and offers a dialogue system through which further information can be provided. By providing further hints and details, its success rate can be increased.

Debugging codes with ChaGPT

And if you want to check the code, you can ask it to show you the output.

Generating code output with ChatGPT

Code translation

ChatGPT can also be used to translate codes from one language to another. You may be more comfortable with one language but needs to get things done in another language, or just want to test the code in another language. Or you may want to use the code in another project. Then you can use ChatGPT to translate the code into the desired language.

Below is the Javascript code generated above translated into Python.

Using ChatGPT for code translation

Related: How to Use ChatGPT for Design Inspiration: A Beginner’s Guide

Explain code in natural language

ChatGPT can explain codes in plain English (or in any language for that matter). This is especially helpful for beginners learning a programming language or for those who are not well-versed in that language. Another scenario where this can be handy is if you have a random line of code that you have no idea what it does, you can input the code into ChatGPT to find out what it’s about.

Using ChatGPT for code explanation

You can also use ChatGPT to decode regular expressions and explain to you what they do.

Using ChatGPT to decode a regular expression

Related: How to Write Effective Emails with ChatGPT: Tips and Tricks

Linux terminal

ChatGPT can be used to simulate a Linux terminal. To transform ChatGPT into a terminal by asking it to act as a terminal.

You can also instruct it to behave in certain ways and not do certain things by explicitly mentioning the rules in the prompt.

I want you to act as a Linux terminal. I will type commands and you will reply with what the terminal should show. I want you to only reply with the terminal output inside one unique code block, and nothing else. do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English, I will do so by putting text inside curly brackets {like this}.

Using ChatGPT as a Linux terminal

To quit the terminal, simply close it as you would normally.

Exit

Act as an SQL Command Line

You can also use ChatGPT as an SQL terminal and run SQL commands from that virtual SQL terminal.

Act as an SQL terminal in front of an example database. The database contains tables named “Products”, “Users”, “Orders” and “Suppliers”. I will type queries and you will reply with what the terminal would show. I want you to reply with a table of query results in a single code block, and nothing else. Do not write explanations. Do not type commands unless I instruct you to do so. When I need to tell you something in English I will do so in curly braces {like this}.

Using ChatGPT as an SQL terminal

There are more ways that you can use ChatGPT for coding and other developmental purposes which we are not getting into. As you use it more often, you’ll discover more capabilities and niche and novel uses.

Programmers and developers can use ChatGPT as a coding companion to increase productivity and streamline their workflows. ChatGPT will not replace programmers (not now, at least) but raises expectations and more will be demanded of them as a result. It is therefore important that coders and developers utilise all the tools at their disposal to not just stay relevant but ahead.

Coding with ChatGPT can make a more productive programmer and it can help with roadblocks and automating mundane tasks. But it will not turn you into an expert programmer; which is a good thing because if it could, then it would replace you.

Some AI tools for coding

Using ChatGPT for coding is only one of the many ways to use AI ace coding. Below are some ChatGPT alternatives for coding that you can use to achieve more with less input.

OpenAI Codex

OpenAI Codex

An AI system that translates natural language into codes. Proficient in more than a dozen programming languages, Codex can interpret simple commands in natural language and execute them on the user’s behalf—making it possible to build a natural language interface to existing applications.

Copilot

GitHub Copilot

A programming companion developed by GitHub and used OpenAI Codex. Suggest code and entire functions in real-time, right from the editor.

AlphaCode

AlphaCode

An AI code generation tool developed by DeepMind. It uses transformer-based language models to generate code in response to natural language descriptions of a problem.

DeepGenX

DeepGenX logo

A free and open-source code generator available as an extension in Visual Studio Code.

SourceAI 

SourceAI logo

An AI-powered tool that can generate code in any programming language from human language description. It can also simplify, find errors and fix and debug the code.

Tabnine

Tabnine

Tabnine’s AI code completion IDE plugin completes code based on millions of programs in all languages and in your own context, empowering developers to code better and faster.

Codeium

Codeium logo

An AI coding assistant that provides AI-generated autocomplete code in over 20 programming languages and integrates directly with various IDEs such as VSCode, Colab, Vim, etc.

Some recommended articles

Export Google Ads Data To Google Sheets

Export Facebook Ads Data to Google Sheets

Import Jira Data to Google Sheets

Leave a Reply

Discover more from Amigo: No-code Data Integrations to Google Sheets

Subscribe now to keep reading and get access to the full archive.

Continue reading