ChatGPT and other large language models like it could generate human-like text, but they are not capable of replacing programmers. While these models can generate code, they lack the understanding and reasoning abilities of a human programmer.
In this article, we will learn how to leverage ChatGPT to generate code snippets for our everyday coding tasks.
How ChatGPT Can Generate Different Kinds of Code Effectively
Two things are essential to know about ChatGPT and coding. One is that it can actually generate helpful code. The other is that it can also go completely astray, wander off the track, spin in circles, and create utterly worthless nonsense.
Oopsie! I learned a valuable lesson the hard way. I had just wrapped up , and I thought to myself, “Hey, why not test the limits of ChatGPT’s brainpower?” So, I composed an incredibly meticulous prompt that included intricate descriptions of all the user interface elements, interactions, and settings features. I covered everything down to the smallest detail, and then I tossed it over to ChatGPT to see what would happen.
Well, well, well…looks like I got myself into a bit of a pickle with ChatGPT! After feeling all high and mighty from creating a Story app, I thought it would be a breeze to put ChatGPT to the test. But boy, was I wrong!
I gave it a detailed prompt with specific instructions on how to construct the project, but ChatGPT responded with a flood of text and code that made my head spin. And just when I thought it couldn’t get any worse, the code stopped mid-operation, leaving me scratching my head and asking for it to continue.
But instead of producing usable code, ChatGPT oozed out even more nonsense, leaving me frustrated and confused.
It’s crystal clear after numerous tests that asking ChatGPT to whip up an entire app is a big fat FAIL. And let’s face it, if you’re clueless about coding and expect ChatGPT to work miracles, well, you’re in for a big disappointment.
But hey, don’t fret! ChatGPT is still an amazing tool that can help you in so many ways. Just don’t put all your eggs in one basket and expect it to do everything for you.
Remember, programming is a skill that requires practice and effort. So, unless you want your app to crash and burn, it’s best to leave the coding to the experts. And let ChatGPT handle the other stuff, like answering your burning questions or providing you with some entertainment.
But don’t ask ChatGPT to make an app for you. That’s too much. Ask ChatGPT to write a routine for you. Like how to put a menu on the menu bar. Then copy and paste that into your project. Easy peasy.
ChatGPT can also show you how to do cool stuff with your code. Like debugging, optimizing, refactoring, and more. ChatGPT can even help you plan your big project. It can break it down into smaller chunks for you. And then it can help you code those chunks. How awesome is that?
So, are you ready to use ChatGPT to write code? Here are some steps to follow.
How to Use ChatGPT for Faster and Better Coding
1.How to Make Your ChatGPT Request More Specific and Effective
Before you ask ChatGPT anything, think about what you want. What do you want your code to do? What inputs and outputs do you need? How will you describe it to ChatGPT? Pretend you’re hiring a human coder to do this for you. Would you give them enough details to get the job done? Or would you be so vague that they would either bug you with questions or give you something totally wrong? Don’t be that person. Be clear and specific about what you want from ChatGPT.
Imagine you can summarize any web page or book in a snap. You just give it a web page URL or link to an e-book and it gives you back a summary that’s smart and relevant. Like this article for example. Wouldn’t that be awesome? That’s what I want from ChatGPT. A web page URL as my input and a summary text as my output.
2.How ChatGPT Can Help You Discover and Use Coding Libraries and Resources
Hey there! If you want to extract data from a web page and summarize it like a boss, forget about the old-school HTML paragraph tag method! AI libraries are the way to go, my friend.
And guess what? ChatGPT is a master at finding the best libraries and resources for the job. No need to worry about its authoritative-but-wrong behavior pattern – you can easily verify its recommendations.
Sure, OpenAI sells API access to the GPT-3 and GPT-4 engines for this purpose, but why pay transaction fees when you can get the same functionality for free? Let’s explore how to use ChatGPT to get the job done in PHP.
As a programmer, you know that libraries are the holy grail of coding. They do the heavy lifting for you, so you don’t have to reinvent the wheel every time. And finding the right library is key. So, let’s start with a prompt that’ll help us discover the perfect library for text summarization.
Ready? Let’s go!
How to use 5 open source AI libraries (with languages) to create summaries of the main content of any web page, without ads or embedded stuff.
This was exactly what I needed, and it even included OpenAI’s options. OpenAI would be awesome for this, but I don’t want to pay API fees for this imaginary project. So I’ll make the question more specific.
Are these all free of charge?
Do any of these cost nothing?
ChatGPT played it safe with its answer. It said: “Yes, all five of these AI libraries are open source and free to use. But some of them may have limits or need money for more features or resources.” So I asked it again with more details.
Which of these libraries are unlimited and free of any extra fees or licenses?
This is like talking to a real expert. I don’t need to repeat the original question. I just ask more questions like I would if I had an expert nearby. ChatGPT gave me all five libraries, but none of them works with PHP, the language I want to code in. So here’s what I asked next:
Do any of those 5 libraries work with PHP?
I got three libraries back, but their functions were unclear to me.so, I asked again:
How do Sumy, Gensim, and testrank differ from each other?
To clear my doubts, I explained how I intended to use them and then posed a question:
Which library is more suitable for creating summaries of news articles on web pages?
Bingo! I hit the jackpot with this answer: “Text summarization is Testrank’s speciality. It can squeeze the juice out of any text and give you a tasty summary.” Now I had to figure out how to make it work with PHP. Time for the final question of this phase:
What is the procedure to integrate testrank and PHP?
Join the fun and copy these prompts into your ChatGPT. In step 1, I picked the program module I needed help with. Then, in this step, I chatted with ChatGPT to choose the best library and make it work with my project.
Trust me, this is programming. You don’t just spit out code like a machine gun. You need to figure out how to make all the different resources and systems work together, and how to communicate with all the parts of your solution.
I also wondered if Google’s Bard could be helpful. Bard can’t write code for real, but it gave me some extra tips on how to plan my programming better than ChatGPT. So use more than one tool to get the answers you need.
Time for coding.
3. How to Get ChatGPT to Write Sample Code for You
Are you ready to dive into the world of coding with ChatGPT? Well, hold on to your hats, because we’re about to explore how ChatGPT can help you write code (with a little bit of humor thrown in, of course!).
Now, let’s get one thing straight: ChatGPT won’t be able to write your final code. It’s not the greatest at maintaining or tweaking existing code. But fear not, dear reader! ChatGPT can still generate example code to get you started.
To prove it, let’s take a look at a prompt I wrote based on a project I had in mind. We’ll be focusing on how to summarize web pages using AI libraries. Sound interesting? Then keep reading, my friend.
Create a summarize_article function in PHP.
The function summarize_article will require a URL to be passed as input, which will refer to an article on an AI Blogging-oriented website, such as fuddyduddyme.com.
I’m giving ChatGPT the name of the programming language. I’m also giving it the input and showing it two sites as examples to help it get the style of the article. But I have a feeling ChatGPT didn’t care about that part. Now I’ll show it how to do most of the work.
In the summarize_article function, extract the main body of the article from the provided URL, excluding any ads or embedded materials, using Sumy and other relevant PHP libraries. Create a summary of about 50 words that comprises complete sentences, and if required, go beyond the word limit to complete the final sentence.
This set of instructions is comparable to how I would guide a team member. I would emphasize that they have the freedom to use other tools if necessary and give a rough estimate of the desired summary length as a boundary. A future iteration of the process could take that length as an input parameter. Finally, I would clearly state the expected outcome of the routine.
After finishing the processing, make summarize_article return the summary as plain text.
After generating the initial code, it becomes a straightforward process to refine and modify it as needed. ChatGPT utilized the Goose library to retrieve the contents of the article and then applied Sumy to generate a summary of approximately 50 words.
However, the code can be further customized by adjusting the parameters passed to the libraries or incorporating additional tools to enhance its functionality.