ChatGPT for Coding: Tips, How-to & Examples

Chatbot Chat with AI, Artificial Intelligence. man using technology smart robot AI, artificial intelligence by enter command prompt for generates something, Futuristic technology transformation.

From process automation to content creation, artificial intelligence is helping today’s organizations make significant advancements along their path toward growth and efficiency.

One such advancement stems from utilizing ChatGPT to support programming efforts, helping developers save time, drive efficiency and write more functional code.

However, in order to reap the benefits, it’s essential to understand what ChatGPT really does, how to use it and what its limitations are.

As experts in helping businesses drive successful transformations by implementing new technology, we’ve outlined everything you need to know about coding with ChatGPT and some simple yet effective tips for getting started.

Things to know about how to use ChatGPT for Coding:

  1. What is ChatGPT?
  2. When should you use ChatGPT to write code?
  3. Common use cases for using ChatGPT to write code
  4. Quick tips & steps for using ChatGPT to write code
  5. What is a real-world example of using ChatGPT to write code?
  6. What is a real-world example of using ChatGPT to write code for NetSuite?

What is ChatGPT?

ChatGPT is a language model and form of generative AI that essentially functions as a chatbot to process and respond to inputs. It uses machine-learning (ML) algorithms and other techniques to provide human-like responses to prompts, helping its users quickly solve problems and gain a better understanding of the topic at hand.

From answering questions and providing real-world examples to creating marketing materials and debugging code, ChatGPT can be a helpful tool for businesses looking to save time and foster more efficiency.

When should you use ChatGPT to write code?

While ChatGPT wasn’t specifically created as a coding platform, it can significantly bolster developers’ productivity and coding accuracy.

ChatGPT is a fantastic tool if you already have a solid understanding of how to code and are skilled enough to catch any errors – but you shouldn’t fully rely on it. Instead, view it more as a coding assistant like GitHub Copilot or a supplemental tool like Stack Overflow.

The reason for this is because ChatGPT can come off incredibly confident even when it’s providing inaccurate information, and it takes a keen and knowledgeable eye to parse through the outputs to ensure they’re free of errors.

And what’s more is that according to a recent study conducted by ChatGPT researchers from Stanford and Berkley, ChatGPT seems to be showing a decrease in the percentage of usable code it offers. It’s not so much that the code was wrong per se, but rather the outputs contained an excess of unusable text and required more corrections before they were ready to be entered into the desired platform.

This further highlights the importance of having a solid understanding of how to code before turning to a tool like ChatGPT.

Common use cases for using ChatGPT to write code:

  • You’re a novice programmer who is looking to learn more about how to code.
  • You need a code snippet for a specific task or algorithm.
  • You aren’t sure how an algorithm functions and require some examples or additional guidance to move forward.
  • You have a bug or error within your code but aren’t sure where it originates from.
  • You need your code to adhere to programming standards and best practices.
  • You have already created some basic code but feel that it could run more efficiently.
  • You need to make sure your code has the proper syntax and uses the programming language correctly.
  • You want to get a second pair of eyes on your code to provide additional recommendations for improvement before entering it into a platform.

Quick tips & steps for using ChatGPT to write code:

  1. Be careful with the information you enter into ChatGPT. The platform processes everything it receives, and it’s vital to avoid inputting sensitive information, such as passwords, financial data, personal information, company data, and more.
  2. Decide where the code will be used: a website, a cloud-based system like NetSuite or Oracle, or another platform of your choosing.
  3. Compile some basic information about the code you want to create, including coding language, context and/or the problem you’re looking to solve.
  4. Begin interfacing with ChatGPT using guiding questions and prompts, such as “What is an example of recursion within JavaScript?” or “Create a simple website landing page using CSS and HTML.”
  5. Analyze ChatGPT outputs to see whether or not the platform adequately answered your question or prompt. If it failed to do so, try asking a follow-up question or providing more detail. The platform will learn more from each entry, so don’t be discouraged if it doesn’t provide a perfect answer the very first time around.
  6. Remember: It’s in programming best practices to only use code you understand. Make sure you understand the coding outputs offered by ChatGPT before progressing.
  7. Test the code within your desired platform to ensure it functions properly.

What is a real-world example of using ChatGPT to write code?

We asked ChatGPT to write code for a basic landing page using HTML and CSS.

Here’s what it said:

“Sure! Below is a basic example of a landing page using HTML and CSS. You can use this as a starting point and customize it further to fit your specific needs.

This code creates a simple landing page with a header, main section, call-to-action button, and footer. The header contains the site’s title, the main section has a welcome message and some content, and the footer displays copyright information. You can adjust the styles and content as per your preferences.”

What is a real-world example of using ChatGPT to write code for NetSuite?

We also asked ChatGPT to write a NetSuite script that sets a custom date field when the customer status changes. Pay close attention to what it says here – you’ll notice that it didn’t fully provide the right answer this time around.

“To create a NetSuite script that sets a custom date field when the customer status changes, you can use a User Event Script. This script will be triggered whenever a customer record is edited, and it will check if the status has been changed. If so, it will update the custom date field accordingly. Here’s a sample script to achieve this:

Instructions for creating the User Event Script:

  1. Log in to your NetSuite account as an administrator.
  2. Go to Customization > Scripting > Scripts > New.
  3. Enter a name for the script (e.g., “Set Custom Date Field on Customer Status Change”).
  4. Select the “User Event” option for the script type.
  5. In the Script Deployment section, choose “All” for the Applies To field, so the script will run on all customer record edits.
  6. Copy and paste the provided script into the Script field.
  7. Replace ‘custentity_custom_date_field’ with the actual internal ID of your custom date field. You can find the internal ID of the field in the NetSuite Customization area.
  8. Click Save.

Now, whenever a customer status is changed, the script will be triggered, and it will update the custom date field with the current date.”

While this solution looks acceptable upon first glance, it’s not actually 100% accurate. After receiving this initial response, we asked ChatGPT, “Will it work with inline editing?”

“No, the script provided in the previous response will not work with inline editing. Inline editing in NetSuite does not trigger User Event Scripts like regular form-based edits do. User Event Scripts are only triggered when a record is saved using the “Edit” button on the record’s standard form.

If you want to handle inline editing as well, you’ll need to use a different approach. Instead of a User Event Script, you can use a Client Script that listens for field changes and then performs the necessary actions. Here’s an example of how you can achieve this:

Instructions for creating the Client Script:

  1. Log in to your NetSuite account as an administrator.
  2. Go to Customization > Scripting > Scripts > New.
  3. Enter a name for the script (e.g., “Set Custom Date Field on Customer Status Change – Client Script”).
  4. Select the “Client” option for the script type.
  5. In the Script Deployment section, choose “All” for the Applies To field, so the script will run on all customer record pages.
  6. Copy and paste the provided script into the Script field.
  7. Replace ‘entitystatus’ with the actual field ID of your customer status field and ‘custentity_custom_date_field’ with the actual internal ID of your custom date field.
  8. Click Save.

Now, whenever a user changes the customer status, either through inline editing or regular form editing, the script will be triggered, and it will update the custom date field with the current date.”

Those unfamiliar with NetSuite might not necessarily have immediately identified a need for inline editing, but down the road, they may find that the data is not valid because the initial script offered by ChatGPT was an incomplete solution.

In addition, part of the problem with the first answer is that the AI tool made assumptions on what we were looking for and failed to communicate them.

So while this instance won’t necessarily lead to bad data, it still has a decent potential to do so – that’s why it’s essential to conduct a detailed review of any outputs and ask follow-up questions to ensure the answers you’re receiving are as accurate and usable as possible.

Final Thoughts on Using ChatGPT for Programming

While ChatGPT can be incredibly helpful for identifying programming bottlenecks and cleaning up code, a human touch is still required to ensure its outputs are free of errors and will function correctly within a platform.

For best results, remember to be incredibly careful with the information you enter into ChatGPT, and always be sure to thoroughly review its answers before progressing.

Need Support to Leverage Technology for Growth?

Our Cloud Solutions technical team is well schooled in using platform development tools to extend the capabilities of NetSuite, Oracle and Smartsheet. We bring a human touch and apply modern techniques for coding efficiency. If you have development needs or questions, contact us at the link below.