wp-secure-it by WPBeveiligen

Coding with ChatGPT – 5 tips and pitfalls!

Coding with ChatGPT – 5 tips and pitfalls!
datum-geschreven 4 Jul 2023

Can you use ChatGPT to write code for you? Absolutely! But with these 5 tips, you’ll have more success.

Tip 1: Use ChatGPT in Your native language (mine is Dutch as you can see in the images below)


It may seem obvious, but talk to ChatGPT in your own language!
Anyone who uses Google knows that code and solutions are usually found on English-language blogs and forums.

You can safely chat in almost any language with ChatGPT! It’s much easier! Let ChatGPT do the translation for you 🙂

Tip 2: Request your native language comments with the code


Ask for your own language comments to be included with the code generated by ChatGPT. This makes it much easier for you to read, and also easier to indicate new requirements or modifications to ChatGPT.

Example: Can you modify the function to check for server errors so that the $url is extracted from the current page? etc…

Tip 3: Be clear


Call things by their names. Refer to code by mentioning it explicitly.

Be precise about what you have in mind, what adjustments or code you want ChatGPT to write.
Example: It’s NOT “that” code, BUT the $headers variable, or $url, or the checkForServerError function. (taking the code from the above image as an example)

Tip 4: What, Where, Why?

ChatGPT works best when it knows WHAT you want. You want code, but WHERE will that code run?
WHY is that code being written, what is your objective?

ChatGPT is highly intelligent and sometimes knows better than yourself what you need to do to achieve a specific result

Below, you can see HOW you can put ChatGPT to work with targeted information using the WHAT, WHERE, and WHY method.

Tip 5: Break code into pieces


ChatGPT currently has a limit. The code it can write for you at once is limited to 2048 characters. After that, it simply stops writing the code.

You can sometimes ask to complete the code, but that often doesn’t work well. It becomes too long to write and the code is left incomplete, resulting in code that doesn’t work properly.

So how do you break code into pieces?

For example, say: We are now going to write a PLUGIN. For WordPress. (tip 4, be clear)
With 3 FUNCTIONS, each in a separate FILE.
FUNCTION 1 with filename: function-activation
FUNCTION 2 with filename: function-display
FUNCTION 3 with filename: function-deactivation

Assuming your code needs to fulfill multiple functions (or goals).

If you have styling as well, indicate

that you will put all STYLING in a separate CSS file. Otherwise, ChatGPT will include the styling inline, making the answer or code much too long and breaking off.

Continuously refer to those files/functions clearly when asking ChatGPT to write or modify code for you. Otherwise, ChatGPT may write code in new blocks, mix them up, or forget the interplay between them.

Bonus Tip: Do you code a lot?


Consider using ChatGPT Plus. At the time of writing, it costs 20 euros per month, but the code is written much faster (up to 4x faster), reducing your waiting time. This advantage becomes significant, especially when making many corrections.

Pssst: Do you have any tips for us? Share them in the comments below!

De meeste artikelen worden geschreven door Mathieu Scholtes, de eigenaar van WPBeveiligen. Op de hoogte blijven van het laatste WordPress nieuws? WordPress tips? WordPress aanbiedingen?
Connect dan op Linked-in!

Heb je een vraag? Tip of gedachte? Deel die!

Breng me op de hoogte
0 Reacties
Inline Feedbacks
Bekijk alle reacties