Developing code with ChatGPT: and my favorite approach to debug what it generates
One of the most interesting discoveries of ChatGPT is that it can generate really good code. I first tested this in 2023 when I asked my wife to use PHP to build a PayPal plugin for her website. This was a rudimentary experiment, even if ChatGPT functioned admisitely.
How then might you utilize ChatGPT to produce code for your daily coding needs? Here is a synopsis:
ChatGPT may produce both great and bad code. For best results, provide exact, complete directions.
ChatGPT excels at supporting certain coding tasks or routines instead of from scratch app development.
Using ChatGPT, search and choose the suitable code libraries for certain requirements; then, have an interactive discussion to narrow your options.
Always be cautious of who oversees artificial intelligence generated codes and always examine their trustworthiness. Never depending only on the created good.
Imagine interactions with ChatGPT as a conversation. The responses of the AI help you to refine your questions and approach the desired outcome.
Let us now probe ChatGPT in much more depth.
For what kind of code may ChatGPT shine?
About ChatGPT and coding, there are two striking observations. First, the artificial intelligence can generate useful programs.
The second is that the AI may chase its tail, enter a rabbit hole, vanish completely, and create meaningless garbage.
Moreover: what not to utilize and the best artificial intelligence for programming by 2025?
I learn this the hard way. After finishing the PowerShell plugin for my wife, I wanted to see how far ChatGPT could go.
I developed a really complete prompt for a Mac program with detailed descriptions of user interface components, interactions, what would be provided in settings, how they would behave, and more. I then fed ChatGPT the prompt.
Emails, ZDNet Tech Today
ZDNET’s Tech Today newsletter provides daily summaries of the newest, most talked about products five days a week.
Note
Consider all.
ChatGPT responded with a burst of text and code. It then stopped half through the code. When I told the AI to carry on, it fumbled even more in words and codes. I requested for constant after-continue, and it spit more and more codes. Still, none of the output was practically usable. The artificial intelligence lacked awareness of where the code should go, how to structure the project, and — when I thoroughly studied the produced code — it excluded major activities I requested for, leaving in plain English descriptions suggesting “program logic goes here”.
Also: by scanning 170k lines of code in seconds, ChatGPT saved me hours of work.
Multiple tests clearly showed that ChatGPT would not be able to provide a complete application if one expects it. This realization follows that ChatGPT will fail should you want anything but know nothing about programming.
ChatGPT shines—and does so very brilliantly—where it helps someone who already knows how to code construct specific routines and execute tasks. Steer clear of asking for a running menu bar application. ChatGPT will perform really well, however if you ask it for a routine displaying a menu on the menu bar and copy that into your project.
Remember also that ChatGPT lacks wisdom even if it looks to have a high degree of domain-specific knowledge (and usually does). The tool might therefore be able to generate code, but it will not be able to create code with the intricacies for special or challenging circumstances necessitating sophisticated understanding.
Furthermore: How may ChatGPT be used to create a project?
Using ChatGPT, create subroutines, build tiny algorithms, and show ideas. ChatGPT could even be requested to help you divide a more ambitious project into smaller pieces and then code those bits.
Given this, let’s now look at some specific activities ChatGPT might provide for your code development process.
Creating code using ChatGPT: 1. Narrow down and refine your ask.
Though not yet specific, this first step is selecting what you will ask ChatGPT of. Choose what your function or routine is supposed to do or what you want to learn to implement into your code. Select the values you want to include into your code and the intended result. Then think about your language of choice for explaining it.
How might one enhance ChatGPT questions?
Think of yourself paying a human developer to handle this. That person is getting enough knowledge to be working on your project? Alternatively are you too elusive and the person you are paying is more likely to ask questions or turn in something very different from what you are looking for?
Here is one example. For the time, suppose I could compress any web page. I want to give the artificial intelligence this material and get back a considered and appropriate summary. About my recommendation, I will provide a web page URL. My output is a synopsis-style chunk of text.
2. Using ChatGPT, search libraries and resources
With the previous example, an old school method of locating the content within HTML paragraph elements was to compile web page data.
However, with artificial intelligence methods at hand, you may create an intelligent extract and summary utilizing an AI library. One of the areas ChatGPT excels in is locating libraries and resources; you may quickly examine these to stop its authoritative but erroneous behavior pattern.
Top free artificial intelligence courses also
OpenAI, the creator of ChatGPT, offers API access to their LLMs in order to exactly meet our needs. In this case, let’s assume, we want not to pay transaction fees.
Thus, let’s look at how to use such a tool, for free, with a PHP-running project by means of connecting with ChatGPT.
I started by wondering what libraries might provide for the specified usage. For those reading along who are not programmers, a library is a collection of code a programmer may use that accomplishes a lot of the heavy work for a specific purpose. Modern programming mostly consists on finding and choosing suitable libraries, hence this is a great starting point.
In this case, I’m looking at code blocks produced by others aiming to condense information. My initial clue is this:
Ignoring any ads or embedded content, list ten different open source AI libraries (and the languages they operate with) I may use to provide a synopsis of the main core aspects of any web page.
Including reference to OpenAI’s products, this prompt generated exactly what I was searching for. OpenAI would be great here, however for my hypothetical startup I wouldn’t want to invest for API fees. So, I will concentrate the research using:
Among these, any are absolutely free?
With their answer, ChatGPT hedged its bets: “Yes, all 10 of these AI libraries are open source and free to use. Some of them, meanwhile, could have access to additional tools or services requiring purchase or usage limitations.” That statement then enabled me to precisely ask my question:
Which of these libraries have no usage limitations and do not demand any further license or payment?
See how this really is very much a conversation. I need not ask the original question once again. I am just excavating as I would have if a professional were right next by me. This time ChatGPT gave me eight library choices, but none mentioned the PHP language I want to create. Therefore, the next stimulus is:
Among those eight libraries, may I utilize any with PHP?_
It brought three libraries back, but I had no idea what each held. Thus, another question is:
Different from NLTK, Gensim, and Sumy what is?
Still not convinced, I said my intended use then followed with:
If I wanted to build summaries of web page news items, which library would be best?
The answer was clear and motivating: “Summary is specifically designed for text summarizing, which is the task of creating a summary that captures the most important information from a piece of text.” It was therefore time to look at what using Sumy with PHP demanded. With this stage of the project, I asked my last question:
How would one use Sumy from PHP?
Play along on your PC and replicate these instructions exactly into ChatGPT. Note that in the first step I decide the software module I need help with. In this step, then, I discussed with ChatGPT the library to use and how to add it into my project.
Also: The best artificial intelligence chatbots
Though it may not seem like programming, I can assure you that is precisely what this is. Programming is more than just placing on a page lines of code. Programming is deciding how to mix all the many resources and systems and interact with every element of your solution. ChatGPT helped me here to complete the integration analysis.
By the way, I was thinking if similarly might Google’s Gemini artificial intelligence be useful. Gemini did provide some further research on the planning element of programming above ChatGPT’s responses.
Thus, make sure not to hesitate to triangulate your answers utilizing many methods. The story is this: Gemini vs ChatGPT: Can Gemini help with coding? After I turned in the essay, Google added some coding tools to Gemini, but they’re not very useful. We address this ability here: I tested the upgraded coding skills of Google Gemini. It turned not nearly. More recently yet, I dug into Gemini Advanced. Artificial intelligence is failing several tests yet.
Furthermore: In what way would you evaluate an artificial intelligence chatbot’s coding capacity?
Then comes coding.
Ask ChatGPT for an example of code.
Alright; let us stop here. Also would be useful the article “How to use ChatGPT to write code”. Instead, we are basically asking ChatGPT to provide example code.
Moreover: The changes in the popularity of programming languages since 2016 – and what they expose about
Allow me to be clear. Unless you are developing a basic function—like the line sorter/randomizer ChatGPT produced for my wife—ChatGPT cannot generate your final code. You have to save it first. ChatGPT does terrible on modifying already-written code. horrible, as in, it does not do it. If you appreciate original code, you must therefore ask ChatGPT to produce something new. ChatGPT might surprise you, as I found earlier even if your request is practically accurate.
ChatGPT essentially cannot maintain your code, much less develop it.
That limitation asks for your own effort. First drafts of codes are, as we know, seldom the final version for a certain project. Even if you expect ChatGPT to provide completed code, it would be a starting point and one from which you must take it to completion, include into your more general project, test it, refine it, debug it, and so on.
That does not mean, however, the example code is worthless — far from it. Let’s go over a prompt I developed using the above referenced project. The first part is:
Utilize the PHP method summary_article.
Summarize_article will be provided a URL to an article on a news-related website like ZDNET.com or Reuters.com.
I am guiding ChatGPT on the programming language it should apply. To help ChatGPT understand the content style, I also provide the AI two sites as samples and input. To be honest, I’m not sure ChatGPT missed that little bit of instruction. I will then go over how to handle most of the work:
Get the contents of the web page at the URL provided inside summarize_article. Ignoring any advertising or embedded objects, use the library Sumy from within PHP to extract the main points of the article then summarize it to around 50 words. Any other libraries needed may be obtained here. See if the summary runs in entire sentences. You might go above the 50 words to finish the sentence if necessary.
This approach resembles me rather similarly how I would mentor a staff member. I would want that person to realize they were not confined to Sumy. If they needed another tool, I wanted them to apply another one.
IBM will also provide you a competence certificate in 10 hours and teach you artificial intelligence concepts free.
I also provided an approximately word count to define boundaries for what I wanted as a summary. That figure might be used as a reference in future iterations of the dance. I then finished by saying what I meant to have said:
After processing is finished, codes summarize articles in plain text.
The last code is extremely simple. ChatGPT approached another library—Goose—to get the article contents. It then produced the summary and transmitted it to Sumy within a 50-word limit. Once the basics are established, however, it’s just a matter of programming to go back in and make changes, tailor what’s given to the two libraries, and obtain the results.