9 Proven Programming Productivity Prompt Tips for ChatGPT

April 12th, 2023
Learn to harness the potential of ChatGPT4, your virtual programming partner, with nine prompting tips. Improve your programming skills by communicating clearly, engaging in conversation, using the proper syntax, and iterating on complexity. Keep context fresh, and ChatGPT4 will be invaluable in your coding journey.
Cyborg red eyes

Introduction

As a developer, you always look for ways to improve your programming skills and streamline your workflow. Currently, ChatGPT4 is the state-of-the-art language model by OpenAI and can be your go-to virtual programming partner. To get the most out of this powerful AI, you must know how to interact effectively. I share nine prompting tips based on my experience that'll help you harness the potential of ChatGPT.

#1 Cut the Ambiguity: Be Specific

The first step to effective prompting with ChatGPT is being clear and concise. Lay out your requirements in plain English, but make sure there's no room for misinterpretation. This ensures that the AI comprehends your goals and provides accurate responses.

Example

Bad:

I need a function to get the sum.

Better:

Create a Python 3 function that takes two integer arguments and returns their sum.

#2 Baby Steps: Start Simple, Then Iterate

Do not confuse ChatGPT with complex prompts from the get-go. Start with the most straightforward problem, the "happy path," and then gradually add complexity and edge cases.

Importantly, as code and complexity grow, refactor and modularise so your interactions and relevant code stay as small and focused as possible. Keep breaking down the code and problems into smaller chunks.

Example

Start with:

"Create a Python function to add two numbers."

Then iterate:

"Now, modify the function to cast strings to numbers."

#3 Engage in Conversation: Ask for Clarity

ChatGPT wants to please you and will guess missing or unclear requirements from your prompt. That can often work with minor oversights but waste time and frustrate otherwise. There is a simple solution, close your statements with a question to ask for clarifications or additional information if needed.

Example

Question:

Create a Python function to calculate a pseudo-random number. Are there any questions or clarifications needed?

ChatGPT response:

Before proceeding, I would like to confirm if you have any specific requirements or constraints for the pseudo-random number generation, such as a specific range, distribution, or seed value. Additionally, I would like to know whether you have a preference for a particular algorithm or library to be used for the generation.

Now, you can add the missing details to the original prompt and retry until ChatGPT runs out of questions. This can be powerful and rewarding, i.e. you might be surprised by what ChatGPT reveals about edge cases and issues you have yet to think of.

#4 Triple Backticks: Your New Best Friend

When sharing code snippets in your prompt, use triple backticks to help ChatGPT differentiate between code and text for more accurate responses.

Example

Add error handling and logging to my code:
``` def add_numbers(a, b):
 return a + b
```

#5 Errors and Strack Traces: Explanation Please

If ChatGPT's code generates an error, immediately share the error message as a prompt with the previous ChatGPT code as existing context. You'll often get a helpful fix or explanation without even adding any thought or comment yourself. Note you will occasionally have to do the heavy debugging yourself. But it is sweet when a complex-looking stack trace is traced back to a typo or missing variable by ChatGPT in seconds with no effort.

Example

"'TypeError: unsupported operand type(s) for +: 'int' and 'str''

This also works for your code. Of course, you would have to share the relevant snippet with the error to give it context.

#6 It's All About Continuity: Use the Magic Word

The AI's output stops long answers in the middle of a sentence or code because it has a length limit. You can use 'continue' to prompt a continuation. However, things get messy when it breaks in the mid-line of code output. You want to continue from the last complete line and hint that it was code to give a better chance of it continuing the output formatted as a code block. To do so, backtick-quote the last complete line and ask to include it.

Example

"Continue from and including `return a + b`"

#7 Crave Excellence: Ask for Best Practices

Increase the quality of ChatGPT's output by adding 'Use best practices.' to your prompt. This nudges the AI towards implementing error handling, documentation, type annotations (in Python), logging, and other good practices. Of course, being explicit about anything you want to do or adding examples works even better.

Example

Give it a hint.

Create a Python function to parse a CSV file. Use best practices.

Be explicit and get even more.

Create a Python function to parse a CSV file.
Use documentation, type annotation, error handling, and logging.
Use best practices.

#8 Refactor, but with Control: List Improvements First

ChatGPT can refactor your code or suggest improvements. However, it might apply suggestions immediately, which can combine good and bad suggestions. Prompt the AI to list and explain recommendations before applying them to maintain control.

Example

Can you list and explain suggestions for improving this Python code without applying them?

After reviewing the suggestions:

Please apply suggestions 2 and 4 to the code.

#9 Keep It Relevant: Refresh the Context

ChatGPT has a limited context window, so it's essential to refresh relevant information, especially if you've made changes or mentioned it many questions ago. Include important aspects in your prompt within triple backticks to help the AI maintain context.

Example

How can I refactor the code to be more modular?
```
<relevant code>
```

Conclusion

By incorporating these prompt tips into your interactions with ChatGPT, you'll find that it can become an invaluable asset in your programming journey. The key is to communicate clearly, engage the AI in a conversational manner, and use the appropriate syntax for code snippets. Start simple and build complexity iteratively, and remember to keep the context fresh for the AI. With these strategies in place, you'll unlock the full potential of ChatGPT and elevate your programming productivity to new heights.

Happy coding!


Christian Prokopp, BoldData.org Founder

    Let's talk

    You have a business problem in need for data and analysis? Send us an email.

    Subscribe to updates

    Join Bold Data's email list to receive free data and updates.

Related Posts

Llamar.ai: A deep dive into the (in)feasibility of RAG with LLMs

Llama looking through wooden fence
Over four months, I created a working retrieval-augmented generation (RAG) product prototype for a sizeable potential customer using a Large-Language Model (LLM). It became a ChatGPT-like expert agent with deep, up-to-date domain knowledge and conversational skills. But I am shutting it down instead of rolling it out. Here is why, how I got there and what it means for the future.

Javascript TDD with ChatGPT

Screen with Javascript code
Test-driven development in Javascript with ChatGPT-4 works. An example demonstrates it using a precise description and refined prompt engineering.

Deep Dive into Code with ChatGPT

Deep diver
Open Source libraries offer user documentation. But expert users and contributors have a deeper understanding of the inner workings stemming from a mental model and architecture derived from deep dives into the code. That understanding and model are helpful to employ the library more effectively, debug issues when using it, and teach interesting concepts on how to structure complex reusable code.

Understanding the Power of ChatGPT

A robot and a teacher in school
ChatGPT is a state-of-the-art language model developed by OpenAI, utilising the Transformer model and fine-tuned through reinforcement learning to produce accurate and ethical text responses.

Python TDD with ChatGPT

Being tested
Programming with ChatGPT using an iterative approach is difficult, as I have demonstrated previously. Maybe ChatGPT can benefit from Test-driven development (TDD). Could it aid LLMs as it does humans?

How to code Python with ChatGPT

Meditating robot
Can ChatGPT help you develop software in Python? Let us ask ChatGPT to write code to query AWS Athena to test if and how we can do it step-by-step.

One simple thing companies miss about their data

When you can't see the wood for the trees
There is one simple thing most companies miss about their data. It has been instrumental in my work as a data professional ever since.

Why I became a Solo Founder

Single lego figure walking in sand
I never wanted to be a solo founder. Yet, in 2021, I quit my job and started Bold Data to mine the Internet single-handedly. Trust me, it sounds as insane to write as to read. What on earth possessed me, and more importantly, would I do it again?

All Blog Posts

See the full list of blog posts to read more.
Subscribe for updates, free datasets and analysis.