0% found this document useful (0 votes)
69 views56 pages

Chatgpt Developer Cheatsheet

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
69 views56 pages

Chatgpt Developer Cheatsheet

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 56

ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.

io/blog/chatgpt-cheat-sheet-for-developer

Login

1 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Home / Articles / Cheat Sheets

Vijay Singh Khatri | 08 Jun, 2023

ChatGPT Cheat Sheet for


Developers | 40 Best
Prompts

ChatGPT has created a huge amount of hype since its


release. If you don’t already know, this AI-powered
large language model �LLM� can simulate human
conversations with impressive ease and accuracy.

While it remains to be seen whether Google Bard will


topple ChatGPT from its throne, developers are now
turning to ChatGPT on a daily basis.

Developed by OpenAI, ChatGPT runs on top of the


GPT�3.5 and GPT�4 families of language models. And
with 100 million users and 1 billion visitors per month,
ChatGPT currently receives 10 million requests per
day!

Simply provide a descriptive text prompt or


description of what you want ChatGPT to do, and
you'll get the desired result. It also remembers your
previous queries and declines inappropriate requests.

As a developer, learning how to master ChatGPT can


help you to generate code snippets in various
languages, learn programming concepts by example,
quickly debug code, write test cases, write
2 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

quickly debug code, write test cases, write


documents, and gather information.

All of this adds up to huge time savings when writing


or debugging code.

The key to using ChatGPT is the humble text prompt.


If these are accurate, precise, and clearly indicate
what you want to do, you’ll get the desired results
quickly. That’s why we created this ChatGPT cheat
sheet for developers.

Whether you’re a coding beginner or a seasoned


developer, we’ve added 40 descriptive text prompts
to save you time during development. We’ve also
taken the time to break down how to create an
effective text prompt for ChatGPT. Let’s dive in!

How Does ChatGPT Work?

Developed by OpenAI, ChatGPT leverages a deep


neural network to respond to user queries. This model
uses massive volumes of data to generate responses
for a wide range of queries, spanning from science
and technology to literature.

Let’s take a closer look at a high-level overview of


how ChatGPT works:

• A user inputs a text prompt with the ChatGPT


interface, whether that’s a question, a request for
information, or a general statement
• The AI language model analyzes and interprets the
input using machine learning algorithms and
responds to user requests by using its trained data
• The user receives a response in the form of text
• The user can input additional text prompts, and the
AI language model will analyze these to generate a
relevant response
• This process continues until the user ends the

3 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

This process continues until the user ends the


conversation

How to Write Effective ChatGPT


Text Prompts

If you want to generate useful information from


ChatGPT, your text prompt has to be effective and
descriptive.

Text prompts are what make this chatbot run. Without


them, it would not be possible for ChatGPT to
respond to your queries.

More importantly, poorly-written text prompts will


often result in irrelevant and incorrect responses from
ChatGPT.

Let’s take a look at some guidelines to help you write


effective text prompts.

• Use Keywords: Add keywords for your topic to help


ChatGPT understand the context and what you
expect from the response. You could even use
keyword research tools to generate keywords for
your text prompts.
• Be Specific and Concise: Simple, clear, and
concise text prompts are essential to getting
relevant and correct results. Vague or broad text
prompts may result in confusing responses. Also,
avoid technical jargon.
• Provide Context: Adding context to your query will
help ChatGPT generate an accurate response and
relevant response.
• Use Proper Grammar and Spelling: Changes in
spelling or grammar can change the context of a
question, so use proper grammar and spelling for
text prompts.
• Keep it Simple and Engaging: Keep your text
prompt simple to allow the AI model to understand
4 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

prompt simple to allow the AI model to understand


it easily. Avoid overly complex words or phrases.
• Ask Open-Ended Questions: Ask the AI model
open-ended questions to enable a variety of
responses. Yes or no questions do not produce
detailed answers.
• Have Fun and Be Creative: Try different text
prompts, analyze the responses, and find which
text prompts work best to get the most relevant
results.

Let's look at some examples of effective and,


importantly, ineffective ChatGPT prompts.

Examples of Effective Text Prompts:

Can you provide me with the salient features of


Angular, a front-end development framework?
This is clear, concise, and simple for ChatGPT to
understand and respond quickly.

Can you generate a code snippet in Python for


displaying the Fibonacci series of up to 10 natural
numbers?
This is specific, relevant, and simple, helping the AI
language model to provide the desired response.

Examples of Ineffective Text Prompts:

Can you generate a code snippet for finding the


average from the given numbers?
This prompt does not tell ChatGPT which
programming language to use to generate the code
snippet.

Can you help me with the following code snippet?


This prompt does not specify the type of help that
ChatGPT should provide for the code.

5 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Code


Generation

1. Can you generate code for [add specific


programming task or problem] in [specify
programming language or framework]?
Example Prompt: Can you generate code for a
function that takes a list of n integers and returns a
new list of only even numbers from the input list? I
want you to create this function in the Python
language.

6 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

2. What is the most efficient or elegant way


to generate code for [insert specific
programming task or solution] in [insert
programming language or framework]?
Example Prompt: What is the most efficient way to
write code in JavaScript to find the sum of the list of
integers?

7 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

3. Is there a library or tool that can assist


with generating code for [insert specific
programming task or goal] in [insert
programming language or framework]?
Example Prompt: Is there any library or tool that can
help me generate code for working with dates in
Java?

4. Write a [language] function to filter [data


structure] based on [condition] with the
8 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

structure] based on [condition] with the


following inputs: [input variables] and
expected output: [output description].
Example Prompt: Write a Python function to filter a
list of integers based on whether they are greater
than 5, with the following input variables:

Input: list of integers

Expected output: a new list containing only the


integers greater than 5.

5. Design a [language] algorithm to solve


[problem] using [strategy or technique].
Example Prompt: Design a C�� algorithm to find the
9 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Example Prompt: Design a C�� algorithm to find the


maximum element in an array using the divide and
conquer strategy.

ChatGPT Prompts for Code


Completion

6. Complete the [language] code that


[function]: code snippet
Example Prompt: Complete the Python code that
takes the list of integers and returns the sum of all
elements:

10 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

def sum_list(nums):

7. Complete the [language] code to convert


[data structure] into [output format]: [code
snippet].
Example Prompt: Complete the Java code to convert
an integer into a string:

import java.util.*;

public class Example{

11 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

8. Finish the [language] implementation of


a multithreading solution for [problem]
Example Prompt: Finish the Java implementation of a
multithreading solution for a program that calculates
the sum of even and odd numbers in a given range.

import java.util.*;

public class evenodd {

ChatGPT generates the following code:

import java.util.*;
public class evenodd {
public static void main(String[] ar
gs) throws InterruptedException {
Scanner sc = new Scanner(Syste
m.in);
System.out.print("Enter the low
er range: ");
int lower = sc.nextInt();
System.out.print("Enter the upp
er range: ");
int upper = sc.nextInt();

SumThread evenThread = new SumT


hread(lower, upper, true);
SumThread oddThread = new SumTh
read(lower, upper, false);

evenThread.start();
oddThread.start();

evenThread.join();

12 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

evenThread.join();
oddThread.join();

int evenSum = evenThread.getSum


();
int oddSum = oddThread.getSum
();

System.out.println("Sum of even
numbers: " + evenSum);
System.out.println("Sum of odd
numbers: " + oddSum);
}
}

class SumThread extends Thread {


private int lower;
private int upper;
private boolean isEven;
private int sum;

public SumThread(int lower, int upp


er, boolean isEven) {
this.lower = lower;
this.upper = upper;
this.isEven = isEven;
this.sum = 0;
}

public void run() {


for (int i = lower; i <= upper;
i++) {
if (i % 2 == 0 && isEven) {
sum += i;
} else if (i % 2 != 0 && !i
sEven) {
sum += i;
}
}
}

13 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

public int getSum() {


return sum;
}
}

ChatGPT Prompts for Bug


Detection

9. Locate any logical errors in the following


[language] code snippet: [code snippet]
Example Prompt: Locate any logical errors in the
following JavaScript code:

function calculateSum(nums) {
let sum = 0;
for (let i = 1; i < nums.length; i++)
{
if (nums[i] % 2 == 0) {
sum += nums[i];
}
else {
sum -= nums[i];
}
}
return sum;
}

let nums = [1, 2, 3, 4, 5];


console.log(calculateSum(nums));

14 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

10. Find the performance issues in the


[language] code: code snippet.
Example Prompt: Find the performance issues in the
Python code:

def find_max(lst):
max_value = lst[0]
for i in range(1, len(lst)):
if lst[i] > max_value:
max_value = lst[i]
return max_value

lst = [5, 10, 3, 8, 12]


print(find_max(lst))

15 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

11. Check for potential deadlock issues in


the [language] code: code snippet.
Example Prompt: Check the potential deadlock
issues in Java code:

public class BankAccount {


private double balance;
private int accountNumber;

public BankAccount(int accountNumbe


r, double balance) {
this.accountNumber = accountNum
ber;
16 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ber;
this.balance = balance;
}

public synchronized void deposit(do


uble amount) {
balance += amount;
}

public synchronized void withdraw(d


ouble amount) {
balance -= amount;
}
}

public class BankTransaction implements


Runnable {
private BankAccount account1;
private BankAccount account2;

public BankTransaction(BankAccount
account1, BankAccount account2) {
this.account1 = account1;
this.account2 = account2;
}

public void run() {


synchronized(account1) {
synchronized(account2) {
account1.withdraw(100);
account2.deposit(100);
}
}
}
}

public class Main {


public static void main(String[] ar
gs) {
BankAccount account1 = new Bank
Account(123 1000.0);
17 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Account(123, 1000.0);
BankAccount account2 = new Bank
Account(456, 2000.0);

BankTransaction transaction1 =
new BankTransaction(account1, account
2);
BankTransaction transaction2 =
new BankTransaction(account2, account
1);

Thread t1 = new Thread(transact


ion1);
Thread t2 = new Thread(transact
ion2);

t1.start();
t2.start();
}
}

18 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

12. Analyze the following [language] code


and determine potential SQL injection
vulnerabilities: [code snippet]
Example Prompt: Analyze the following PHP code
and determine potential SQL injection vulnerabilities:

$username = $_POST['username'];
$password = $_POST['password'];
$query = "SELECT * FROM users WHERE use
rname = '$username' AND password = '$pa
ssword'";
$result = mysqli_query($conn, $query);

ChatGPT provides the following answer:

19 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Algorithm


Development

13. Write a heuristic algorithm to solve a


specific problem: [problem description]
Example Prompt: Write a heuristic algorithm to solve
a travel salesman problem.

20 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

14. Analyze the following machine learning


algorithm to improve its accuracy:
[algorithm/pseudocode].
Example Prompt: Consider that we have a current
algorithm that predicts customers’ sentiments. The
text prompt would be:

Analyze the following machine learning algorithm to

21 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Analyze the following machine learning algorithm to


improve its accuracy:

• Compile a database of client reviews together with


the associated emotions (good or negative).
• Clean up the text and transform it to a numerical
representation (such as bag-of-words) to prepare
the data.
• Create training and test sets from the dataset.
• Utilize the training set to train a Naive Bayes
classifier.
• Use measures like accuracy, precision, recall, and
F1 score to assess the classifier's performance on
the test set.

22 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

15. Create a streaming algorithm to process


data in real-time for [a specific purpose].
Example Prompt: Create a streaming algorithm to
process data in real-time for the stock market.

23 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

16. Assess the trade-offs of the given


algorithm in terms of performance and
resource usage: [algorithm or
pseudocode].
Example Prompt: Asses the trade-offs of the
following algorithm in terms of performance and
resource usage:

• Compile a database of client reviews together with


the associated emotions (good or negative).
• Clean up the text and transform it to a numerical
representation (such as bag-of-words) to prepare
the data.
• Create training and test sets from the dataset.
• Utilize the training set to train a Naive Bayes
classifier.
• Use measures like accuracy, precision, recall, and
F1 score to assess the classifier's performance on
the test set.

24 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Code


Review

17. Review the following [language] code


for code smells and suggest improvements:
[code snippet].
Example Prompt: Review the following Python code
for code smells and suggest improvements:

def calculate_mean(numbers):
total = sum(numbers)
mean = total / len(numbers)
return mean

def calculate_median(numbers):
numbers.sort()

25 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

numbers.sort()
if len(numbers) % 2 == 0:
mid = len(numbers) / 2
median = (numbers[mid - 1] + nu
mbers[mid]) / 2
else:
mid = len(numbers) // 2
median = numbers[mid]
return median

numbers = [1, 2, 3, 4, 5]
mean = calculate_mean(numbers)
median = calculate_median(numbers)

print(f"Mean: {mean}")
print(f"Median: {median}")

26 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

18. Review the following [language] code


for scalability issues: [code snippet].
Example Prompt: Review the following Java code for
scalability issues:

public class MyDatabase {


private List<String> data;

public MyDatabase() {
data = new ArrayList<String>();
}

public void insert(String value) {


data.add(value);
}

public String find(String key) {

27 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

for (String value : data) {


if (value.startsWith(key))
{
return value;
}
}
return null;
}
}

19. Evaluate the following [language] code

28 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

19. Evaluate the following [language] code


for compatibility with [technology]: [code
snippet].
Example Prompt: Evaluate the given Java code for
compatibility with NetBeans IDE�

public class MyDatabase {


private List<String> data;

public MyDatabase() {
data = new ArrayList<String>();
}

public void insert(String value) {


data.add(value);
}

public String find(String key) {


for (String value : data) {
if (value.startsWith(key))
{
return value;
}
}
return null;
}
}

29 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

20. Evaluate the test coverage of the


[language] code: [code snippet].
Example Prompt: Evaluate the test coverage of the
Python code:

def calculate_mean(numbers):
total = sum(numbers)
mean = total / len(numbers)
return mean

def calculate_median(numbers):
numbers.sort()
if len(numbers) % 2 == 0:
mid = len(numbers) / 2
median = (numbers[mid - 1] + nu
mbers[mid]) / 2
else:
mid = len(numbers) // 2
median = numbers[mid]
return median

numbers = [1, 2, 3, 4, 5]
mean = calculate_mean(numbers)
median = calculate_median(numbers)

assert mean == 3
assert median == 3

30 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Natural


Language Processing

21. Perform text classification of the


following text: [text sample].
Example Prompt: Perform text classification of the
following text:

"Apple is expected to release a new version of the


iPhone next month with improved features and a
better camera. The company has been facing tough
competition from Samsung and other rivals in the
smartphone market, but hopes that the new release
will help boost sales."

31 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

22. Analyze the sentiment of the following


product review: [product review].
Example Prompt: Analyze the sentiment of the
following product review:

"I recently purchased the new iPhone, and I'm


extremely happy with my purchase! The camera is
amazing, and the new features make it so much
easier to use. The only downside is the price, but it's
worth it for the quality. Overall, I highly recommend
this phone to anyone in the market for a new one."

32 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

23. List out the key phrases in the social


media posts: [social media post].
Example Prompt: List out the key phrases in the
following social media post:

“Exciting news everyone! We are thrilled to announce


the launch of our brand-new digital marketing
platform!

This platform is the perfect solution for anyone


looking to take their online presence to the next level.
With powerful tools to help you create and manage
your campaigns, you can reach your target audience
like never before.

Say goodbye to the hassle of managing multiple


platforms and hello to a seamless and intuitive
experience. Our platform is designed to help you save
time, increase efficiency, and drive results.

Don't wait any longer to take your online marketing to


the next level. Try our new platform today and
experience the difference for yourself.
#digitalmarketing #newproductlaunch
#onlinemarketing”

33 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Code


Refactoring

24. Suggest the refactoring improvements


for the following [language] code: [code
snippet].
Example Prompt: Suggest the refactoring
improvements for the following Python code:

def calculate_grade(score):
if score >= 90:
grade = "A"
elif score >= 80:
grade = "B"
elif score >= 70:
grade = "C"
elif score >= 60:
grade = "D"
else:
grade = "F"

34 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

return grade

25. Optimize the following [language] code


for lower memory usage: [code snippet].
Example Prompt: Optimize the following JavaScript
code for lower memory usage:

function sum(n) {
let result = 0;
for (let i = 1; i <= n; i++) {
result += i;
}
return result;
}

console.log(sum(1000000));

35 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

26. Refactor the following [language] code


to improve its error handling: [code
snippet].
Example Prompt: Refactor the following C�� code to
improve its error handling:

#include <iostream>
#include <fstream>

int main() {
std::string filename = "example.txt";

36 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

std::string filename = "example.txt";


std::ifstream file(filename);

if (file) {
std::cout << "File opened successfu
lly." << std::endl;
} else {
std::cout << "Failed to open file."
<< std::endl;
}

file.close();

return 0;
}

37 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for Code


Translation

27. Translate the following [language] code


for calculating the average of user input
numbers into [desired language]: [code
snippet].
Example Prompt: Translate the following Python code
for calculating the average of user input numbers into
Java:

numbers = input("Enter numbers separate


d by spaces: ")
num_list = numbers.split()

try:
num_list = [float(num) for num in n
um_list]
except ValueError:
print("Error: Invalid input")
exit()

if not num_list:
print("Error: No numbers provided")
exit()

average = sum(num_list) / len(num_list)


print("The average is:", average)

38 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for


Requirement Analysis

28. Analyze the following project


requirements and suggest the technology
stack: [project requirements].
Example Prompt: Analyze the following project
requirements and suggest the technology stack:

We need to build a web application that allows users


to create and share online surveys. The application
should allow users to create survey questions, define
answer options, and track responses. The application
should also allow users to analyze survey results
using charts and graphs.

39 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

using charts and graphs.

29. Interpret the following project


requirements and provide a detailed project
plan with milestones and deliverables:
[project requirements].
Example Prompt: Interpret the following project
requirements and provide a detailed project plan with
milestones and deliverables:

We need to build a web application that allows users


to create and share online surveys. The application
should allow users to create survey questions, define

40 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

answer options, and track responses. The application


should also allow users to analyze survey results
using charts and graphs.

30. Convert the following project


requirements into user stories: [project
requirements].

41 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Example Prompt: Convert the following project


requirements into user stories:

We need to build a web application that allows users


to create and share online surveys. The application
should allow users to create survey questions, define
answer options, and track responses. The application
should also allow users to analyze survey results
using charts and graphs.

ChatGPT Prompts for


Networking and Security

31. Create a secure [language] function


that performs [specific task] while
preventing [security threat or
vulnerability].
Example Prompt: Write a secure Python function or
module that performs password hashing while
preventing SQL injection attacks.

42 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

32. Design a secure protocol for [specific


use case] for my [app/website].
Example Prompt: Design a secure and efficient
protocol for secure communication between a client
and a server over the Internet.

43 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

33. Evaluate the security of the given


[language] code when interacting with
[external service/API�.
Example Prompt: Evaluate the security of the given
Python code when interacting with a database:

import psycopg2
conn = psycopg2.connect(
host="localhost",
database="mydatabase",
user="myusername",
password="mypassword"
)

cur = conn.cursor()
cur.execute("SELECT * FROM mytable")
rows = cur.fetchall()
conn.close()

44 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for


Automated Testing

34. Write a test script for the given


[language] code that covers [functional/
non-functional] testing.
Example Prompt: Write a test script for the given
Python code that covers functional testing:

numbers = input("Enter numbers separate


d by spaces: ")
num_list = numbers.split()

try:
num_list = [float(num) for num in n
um_list]
except ValueError:
print("Error: Invalid input")
exit()

if not num_list:

45 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

print("Error: No numbers provided")


exit()

average = sum(num_list) / len(num_list)


print("The average is:", average)

35. Design a performance testing strategy


for a [web/mobile] app for [resource usage,
latency, and throughput].
Example Prompt: Design a performance testing
46 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Example Prompt: Design a performance testing


strategy for a web app that focuses on latency.

36. Create a test suite for a [language]


library or framework that validates its
functionality and stability.
Example Prompt: Create a test suite for a Javascript
library or framework that validates its functionality
and stability.

47 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

37. Create an end-to-end testing strategy


for a [mobile/web] app that covers critical
user workflows.
Example Prompt: Create an end-to-end testing
strategy for a mobile app that covers critical user
workflows.

48 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

ChatGPT Prompts for


Personalized Development
Learning

38. What are the available free resources to


learn [programming language/
technology]?
Example Prompt: What are the available free
resources to learn Python with their official links?

49 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

39. What learning path should I follow to


become a proficient �IT job role]?
Example Prompt: What learning path should I follow
to become a proficient DevOps Engineer?

50 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

40. Suggest coding challenges or


competitions improve my [programming
language/technology] skills.
Example Prompt: Suggest coding challenges or
competitions to improve my front-end development
skills.

Unleash the Power of ChatGPT


for Development!

And there you have it, 40 of the most helpful


ChatGPT text prompts for developers. We hope you
found this ChatGPT Cheat Sheet for developers
helpful and interesting!

Whether you’re a beginner to development that’s


trying to learn new skills or a seasoned professional

51 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

that wants to ramp up productivity, these ChatGPT


text prompts can help you to save significant amounts
of time when writing and debugging code.

While this list is not exhaustive, you should now have


a stronger idea of how to use ChatGPT to facilitate
the development process while also ensuring
response accuracy.

You should also remember that any code suggestions


from ChatGPT may themselves have room for
improvement, and they may even contain errors! We
hope you feel encouraged to explore this brave new
world of AI-assisted development, as with the right
prompts and a willingness to learn, ChatGPT can be
an amazing tool.

Want to take your AI chatbot skills to the next level?


Check out:

The Ultimate Guide to AI Prompt Engineering

People are also reading:

• Top Artificial Intelligence Technologies


• Different Types of AI �Artificial Intelligence]
• Best Artificial Intelligence Books for Beginners
• Benefits of Artificial Intelligence
• Future of Artificial Intelligence
• Artificial Intelligence �AI� Skills In Demand
• Best Programming Language for AI Development
• Best AI Projects With Source Code
• How to learn Artificial Intelligence
• Best Artificial Intelligence Courses

Explore More
search...

52 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

By Vijay Singh Khatri

With 5� years of experience across various tech


stacks such as C, C��, PHP, Python, SQL, Angular,
and AWS, Vijay has a bachelor's degree in computer
science and a specialty in SEO and helps a lot of ed-
tech giants with their organic marketing. Also, he
persists in gaining knowledge of content marketing
and SEO tools. He has worked with various analytics
tools for over eight years.
View all post by the author

Subscribe to our Newsletter for Articles, News, & Jobs.

First name

Email address

I accept the Terms and Conditions.

Subscribe

Disclosure: Hackr.io is supported by its audience. When you


purchase through links on our site, we may earn an affiliate
commission.

In this article

How Does ChatGPT Work?

53 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

How Does ChatGPT Work?


Learn More
How to Write Effective ChatGPT Text Prompts

GitHub
ChatGPTCopilot
Promptsvs
forAmazon CodeWhisperer | Who's
Code Generation
Best in 2024?
ChatGPT Prompts for Code Completion

ChatGPT Prompts for Bug Detection


Artificial Intelligence �AI� Code Editors IDEs
ChatGPT Prompts for Algorithm Development

ChatGPT Prompts for Code Review


7 ChatGPT
Best AI Prompts
Codingfor
Assistants In 2024
Natural Language �Free � Paid]
Processing

ChatGPT Prompts for Code Refactoring


Artificial Intelligence �AI� Code Editors IDEs
ChatGPT Prompts for Code Translation

ChatGPT Prompts for Requirement Analysis


Learn To Prompts
ChatGPT Build A for
Python Chatbot
Networking In 24 Hours
and Security

ChatGPT Prompts for Automated Testing


Python Courses
ChatGPT Prompts for Personalized Development Learning

Unleash the Power of ChatGPT for Development!

Please login to leave comments

Always be in the loop.


Get news once a week, and don't worry — no spam.

Your email Subscribe

I accept the Terms and Conditions.

54 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

Programming

DevOps

Data Science

Design

Articles About us

Roadmaps We Feedback

Jobs Advertise / Partner

Help center Write for us

Privacy Policy

Cookie Policy

Change Privacy Settings

Disclosure Policy

Terms and Conditions

Disclaimer

Refund Policy

Follow us

Disclosure: This page may contain affliate links, meaning when you

55 of 56 11/24/24, 19:53
ChatGPT Cheat Sheet for Developers | 40 Best Prompts https://hackr.io/blog/chatgpt-cheat-sheet-for-developer

click the links and make a purchase, we receive a commission.

56 of 56 11/24/24, 19:53

You might also like