How to compose code using ChatGPT

Can ChatGPT supplant software developers? What programming languages is ChatGPT proficient in? We provide answers to these and other generative AI programming queries.

ChatGPT's ability to produce decent code is one of its more intriguing characteristics. In February, I put this to the test by requesting that it create a WordPress plugin for my wife's website. It did a good job, but the assignment was extremely straightforward.

Using ChatGPT to compose: resumes | Excel formulas | essays | cover letters

How can you use ChatGPT to compose code as part of your daily coding routine? Here, we will investigate this topic.

 

Which categories of coding are ChatGPT proficient at?

There are two essential aspects concerning ChatGPT and coding. The first is that it can actually generate effective code. The second is that it can become completely lost, tumble down the rabbit hole, chase its own tail, and produce unusable trash.

 

ALSO READ:125+ Top-Rated ChatGPT Prompts for Every Type of Workflow

 

I learned this lesson the hard way. I decided to see how far ChatGPT could go after completing the WordPress plugin. I meticulously composed a prompt for a Mac application, detailing user interface elements, interactions, what would be provided in settings, how they would operate, etc. I then sent it to ChatGPT.

ChatGPT's response merely consisted of text and code. The code then abruptly ceased. When I prompted it to continue, it vomited out additional code and text. I repeatedly pressed the proceed button, but the output of code only increased. However, none of it could be used. It did not specify where the code should go or how to construct the project, and when I examined the generated code closely, it omitted the main operations I had requested, leaving only simple text descriptions stating "program logic goes here."

After a large number of repeated experiments, it became evident to me that ChatGPT will fail if asked to deliver a complete application. A corollary to this observation is that ChatGPT will fail if you have no knowledge of coding and request that it create something for you.Where ChatGPT succeeds and excels is in assisting those who already know how to code to create specific routines and accomplish specific duties. Avoid requesting a navigation bar application. But if you ask ChatGPT for a routine to add a menu to the menu bar and then copy and paste that code into your project, everything will go quite smoothly.

Keep in mind that although ChatGPT appears to possess a vast quantity of domain-specific knowledge (which it frequently does), it lacks wisdom. As a result, it may be able to write code, but it won't be able to write code containing the nuances for extremely specific or complex problems, which require extensive experience to comprehend.

ChatGPT can be used to demonstrate techniques, program small algorithms, and create subroutines. You can even use ChatGPT to help you break up a larger undertaking into smaller chunks, and then ask it to assist you in coding those chunks.

In light of this, let's examine some specific ChatGPT code-writing instructions.

 

How ChatGPT facilitates code writing

1. Limit and concentrate your request.

This initial phase consists of deciding what you will ask ChatGPT, but not yet asking it anything. Determine what you want your function or routine to do, or what you want to learn in order to implement into your code. Determine the input and output parameters for your code. Then, consider the manner in which you will describe it.

 

Suppose you are paying a human programmer to perform this task. Are you providing this individual with sufficient information to complete your assignment? Or are you too vague, causing the individual you're paying to be more likely to ask questions or produce something completely unrelated to what you want?

This is an example. Suppose I desire the ability to summarize any website. I'd like to feed it an article similar to this one and receive a concise, well-written summary in return. I will specify the URL of a website as my input. My output is a summary-containing text segment.

 

2. Utilize ChatGPT to investigate libraries and resources.

Continuing with the preceding example, an archaic technique for extracting data from web pages consisted of simply locating the text between HTML paragraph elements.

Nonetheless, with the rise of AI tools, it makes more sense to utilize an AI library to perform an intelligent extract and summary. The ability to locate libraries and resources is one of ChatGPT's strengths (and it's also an area you can readily verify to avoid its authoritative-but-incorrect behavior pattern).

 

OpenAI (the creator of ChatGPT) sells API access to the GPT-3 and GPT-4 engines that do exactly what we require. Let's presume, however, that we do not wish to pay transaction fees in the context of this example.

Therefore, let's examine how to interact with ChatGPT to determine how to use such a utility for free with a PHP-based project.

I began by posing a question designed to elicit information regarding which libraries could provide the desired functionality. A library (for those of you who are not programmers) is a collection of code that a programmer can access that performs the majority of the work for a specific purpose. Finding and selecting the appropriate libraries is a major aspect of modern programming. Therefore, this is an excellent starting point.

 

In this instance, I am examining text-summarizing code authored by others. Here is my initial prompt:

Describe ten distinct open-source AI libraries (along with the programming languages they support) that I can use to generate a summary of the primary content of any web page, excluding advertisements and embedded content.

This provided me with precisely what I desired, including a mention of OpenAI's services. I believe OpenAI would perform admirably in this scenario, but API fees are not budgeted for this hypothetical undertaking. Therefore, I will restrict the query.

Is any of this free?

In its response, ChatGPT hedged its wagers. It stated, "Yes, all ten of these AI libraries are open source and free to utilize. However, some of them may have utilization limits or require payment for access to additional features or resources." I clarified my question accordingly.

Which of these libraries have no utilization limits and do not require any additional fees or licensing?

Observe how this is essentially a dialogue. I am not required to repeat the initial inquiry. I'm simply delving deeper in the same manner that I would if I had an expert available and was seeking clarification. In this instance, ChatGPT provided me with eight library options, none of which mentioned the PHP programming language I intended to use. The next prompt is as follows:

Can I utilize any of the eight libraries with PHP??

It returned three libraries, but I did not know what each one did. Hence, a second question:

How are Sumy, Gensim, and NLTK distinct from one another?

I was still uncertain, so I clarified my use plan and then questioned:

Which library would perform best if I wished to generate summaries of news articles from web pages?

The response I received was straightforward and encouraging: "Sumy is specifically designed for text summarization, which is the task of creating a summary that captures the most important information from a piece of text." Consequently, it was time to determine what was necessary to use it with PHP. I posed my final inquiry pertaining to this portion of the endeavor.

Can you clarify how to integrate Sumy with PHP?

Please feel free to participate along on your computer by pasting these prompts into your instance of ChatGPT. Observe that in step 1 I chose the program module for which I would seek assistance. Then, in this stage, I spoke with ChatGPT to determine which library to use and how to incorporate it into my project.

 

ALSO READ:GPT 4: How to Use It? Chatgpt-4 Register, Login, GPT-4 Install App

 

It may not appear to be programming, but I assure you that it is. Programming is not as simple as slamming lines of code onto a page. Programming is the process of determining how to integrate all of your solution's resources and systems, as well as how to communicate with each component. ChatGPT assisted me with this integration analysis.

In addition, I was intrigued if Google's Bard could assist in a similar manner. Bard can't actually write code, but this provided additional insight into the planning aspect of programming than ChatGPT's answers. Therefore, do not be hesitant to utilize multiple tools to triangulate desired answers. Here's what happened: ChatGPT versus Bard Can Bard aid you in coding? Google has added coding capabilities to Bard since this article was published. However, they are not all remarkable. Here is more information: I examined the new coding abilities of GoogleBard. It didn't go well.

Next is coding.

3. Request example code from ChatGPT

Okay, let's pause here for a brief moment. This article's title is "How to Use ChatGPT to Write Code." And it will, but we are primarily requesting ChatGPT to generate example code. Wait. What?

Let us be precise. Unless you are writing a very tiny function (such as the line sorter/randomizer ChatGPT created for my wife), ChatGPT will not be able to write your final code. First, you will be responsible for its maintenance. ChatGPT is inept at modifying previously-written code. Negative, as in it does not work. You must therefore request ChatGPT to generate new code in order to obtain new code. As I've discovered in the past, even if your prompt is nearly identical, ChatGPT may alter its response in a very unanticipated manner.

In conclusion, ChatGPT is incapable of maintaining or modifying your code.


That means you must do it yourself. The initial prototype of a piece of code is rarely the final version, as is well-known. Even if you expected ChatGPT to generate complete code, it would only be a starting point that you would need to finish, integrate into your larger project, test, refine, debug, etc.

 

However, this does not imply that the example code has no value. Not at all. Let's take a look at a writing prompt I created based on the assignment I described earlier. Here is the beginning:

Create a summarize_article function in PHP.

As input, summarize_article will receive the URL of a news-related website article, such as ZDNET.com or Reuters.com.

I am instructing ChatGPT on the programming language it should employ. I'm also giving it the input, but I'm also providing two websites as examples to assist ChatGPT understand the article's style. Sincerely, I have my doubts that ChatGPT followed that instruction. I'll then instruct it on how to complete the majority of the work:

Retrieve the web page's content from the supplied URL within summarize_article. Using the PHP library Sumy and any other required libraries, extract the article's main body, excluding advertisements and embedded content, and condense it into approximately 50 words. Ensure that each sentence in the summary is comprehensive. If necessary, you may exceed the 50-word limit to complete the final sentence.

Identical to how I would train an employee. I would want that individual to be aware that they were not limited to Sumy alone. If they required a different instrument, I wanted them to use it.

In addition, I provided an approximation of the number of words necessary to establish limits for the summary I desired. This number could be a parameter in a subsequent version of the routine. I concluded by stating the outcome I desired:

Once processing is complete, code summarize_article to return the article summary in plain text.

The generated code is relatively straightforward. ChatGPT did use a different library (Goose) to retrieve the article's contents. This was then sent to Summy with a 50-word limit, and the result was returned. That's it. However, once the fundamentals are written, it is a simple matter of programming to go back and add adjustments, customize what is passed to the two libraries, and deliver the results.

 

An interesting topic to note. ChatGPT crafted an example call to the routine it developed, utilizing a URL from after 2021 (when ChatGPT's dataset concludes).

https://www.reuters.com/business/retail-consumer/teslas-musk-says-fremont-california-factory-may-be-sold-chip-shortage-bites-2022-03-18/

Both Reuters' website and the Wayback Machine's archive indicate that this URL does not exist. It was created by ChatGPT.

 

FAQ

Replaces programmers with ChatGPT?

Currently, or at least not yet. ChatGPT is programmed at the level of a talented first-year programming student, but it lacks initiative (much like that first-year student). At its present level, I believe it will merely make it simpler for entry-level programmers (and even more experienced programmers) to write code and access information. It is unquestionably a time-saver, but it can only handle a limited number of programming tasks by itself -- at least for now. In 2030? Who knows?!

 

How do I obtain coding answers on ChatGPT?

Just ask it. You saw in the preceding section how I utilized an interactive discussion dialogue to hone in on the specific answers I desired. Do not expect a single question to magically complete all of your tasks when using ChatGPT. However, if you utilize ChatGPT as a tool and resource, it will provide you with a great deal of very useful information. Obviously, that information should be verified, because, as OpenAI co-founder John Schulman explains, "our biggest concern was around factuality, because the model likes to fabricate things."

 

What programming languages is ChatGPT proficient in?

Many of them. This endeavor was extremely distracting. I tested prevalent contemporary languages, including PHP, Python, Java, Kotlin, Swift, and C#, among others. Then, I instructed it to generate code in obsolete languages such as COBOL, Fortran, Forth, LISP, ALGOL, RPG (the report program generator, not the role-playing game), and even IBM/360 assembly language.

 

ALSO READ:ChatGPT stores your data?

 

I added this prompt as the icing on the cake:

Create a sequence that displays "Hello, world" in ascii flickering lights on the PDP 8/e front panel.

The PDP 8/e was my first computer, and ChatGPT provided instructions on how to toggle a program using the front panel controls. I was astonished, ecstatic, and slightly terrified.

 

What is the conclusion, then? ChatGPT can be a very useful instrument, truth be told. Just don't assign it any capabilities. Yet.


Ojike Stella

1727 Blog posts

Comments
YA2206 48 w

This looks really hectic

 
 
Abubakar Akanfe 48 w

I'm trying this

 
 
Chisom Ajah 49 w

Okay

 
 
Franklin Ahazinkem 49 w

Gonna give it a trial

 
 
XENOMIKE 49 w

Ok I will try it

 
 
Timothy Tidjoro 49 w

Interesting 🤔

 
 
Abdulhakeem Tijjani 49 w

Good

 
 
Yazidu Abubakar Dogondaji 49 w

Chat Gpt is significant because does alot of manipulation, processing and given out sensible information.