By now, you've heard that ChatGPT can write code. But can the AI chatbot generate effective code? While ChatGPT isn't an experienced software engineer, the chatbot can help you write, debug, test, and improve code in languages like Python, JavaScript, Java, Go, Ruby, C++, C#, PHP, Swift, TypeScript, and SQL. This wikiHow guide will teach you the best ways to use ChatGPT to write code and boost your productivity as a software developer.
Things You Should Know
- ChatGPT can clean up existing code by correcting mistakes, simplifying complex ideas, and ironing out bugs.
- To save time as a developer, use ChatGPT to create scaffolding, templates, and boilerplate code for your applications.
- ChatGPT does make mistakes, so it's not a replacement for a software engineer. Always test ChatGPT code before implementing.
Steps
Getting Effective Code from ChatGPT
-
Provide ChatGPT with enough information to write the code you need. ChatGPT relies on a combination of the context you provide and its training data. If you don't specify exactly what you need, ChatGPT won't produce code you can use. Be very specific about what you want your program or website to do, what language you want to write it in, and what the program is for. For example, if you want ChatGPT to build you a website for your pet-sitting business that allows potential customers to view your services and inquire about bookings, try: [2] X Research source
- "Build a simple one-page website for my pet-sitting services, which include dog walks and overnight house-sitting stays. Create a table that contains my services and rates, which are $60 per night for overnight stays, and $20 for one-time 30-minute walks. Create a contact form that customers can fill out to request my services. On the form, allow the customers to select their desired dates from a calendar. Send customer responses to me via email at me@myemailaddress.com."
- With this example, ChatGPT will provide the HTML and CSS code for a simple website that you can upload to your web host. You'll just need to make a few minor tweaks to personalize the website, but the code is now yours to play with.
-
Add more details to get the code you want. Because ChatGPT is conversational, it can reference up to 3000 words from the current conversation, which gives you plenty of room to add to your code request. [3] X Research source
- Before, we asked ChatGPT to code us a website for a pet-sitting business. What if we also want to add our grooming rates to the table on the page? All you'll need to do is say, "Add grooming services for $100 to my rate list," and ChatGPT will regenerate the code to include your changes.
- You can also add other details, like "change the title tag to Affordable Pet Sitting Services in San Francisco," and "display a "thank you" page to the customer after they submit the form."
-
Ask questions to clear up errors or confusion. If the AI chatbot creates code that's confusing or flat out wrong, tell it so. Ask ChatGPT for clarification, and it will check its own work against its training data and adjust the code accordingly. You can also provide more context to get better answers. [4] X Research source
- Remember that ChatGPT is not a software engineer—it does not understand nuance, nor can it determine context that it can't find in its training data. It also relies primarily on data that was available on the internet prior to 2021, and cannot search the web for newer content on demand. [5] X Research source
-
Don't trust ChatGPT's code without testing it yourself. While ChatGPT can provide surprisingly good code for an AI chatbot, it often makes coding mistakes that it does not (or refuses to) correct. If ChatGPT's training data contains bad code examples, ChatGPT will interpret those bad examples as truths. Because of this, ChatGPT is not (yet) reliable enough to trust for writing programs on its own. Use ChatGPT as a resource while coding, but not as a replacement for a software engineer (or learning to code yourself).EXPERT TIPTechnologistTyrone Showers is a Technologist and the Co-owner of Taliferro Group, an IT consulting company based in Seattle, Washington. With over 35 years of professional experience, he specializes in API Design, e-Commerce, Operational Efficiency, and website development. He has a B.S. in Computer Science from DeVry Institute of Technology.
Test any code generated by ChatGPT, following best practices in software development. Experts warn against relying solely on ChatGPT responses when coding. Examine ChatGPT's codes to reveal its tendencies and recognize patterns in its output. Use this knowledge to guide GPT with effective prompts and avoid issues.
Expert Q&A
Video
Tips
- Your conversations with ChatGPT may be used to improve the quality of the service, so don't divulge anything private. [6] X Research sourceThanks
- ChatGPT's training data cuts off at 2021. If you're working on a program that requires libraries or coding conventions newer than that, ChatGPT will not provide accurate code.Thanks
-
Thanks
Expert Interview
Thanks for reading our article! If you’d like to learn more about computer programming, check out our in-depth interview with Kevin Burnett .
References
- ↑ https://www.zdnet.com/article/how-to-use-chatgpt-to-write-code/
- ↑ https://www.zdnet.com/article/how-to-use-chatgpt-to-write-code/
- ↑ https://www.zdnet.com/article/how-to-use-chatgpt-to-write-code/
- ↑ https://www.digitaltrends.com/computing/best-chatgpt-tips/#dt-heading-using-follow-up-prompts-to-improve-results
- ↑ https://help.openai.com/en/articles/6783457-chatgpt-general-faq
- ↑ https://openai.com/policies/privacy-policy