DEV Community

Cover image for 50 Chat GPT Prompts Every Software Developer Should Know (Tested)
Hackertab.dev 🖥️ for Hackertab

Posted on • Originally published at blog.hackertab.dev on

50 Chat GPT Prompts Every Software Developer Should Know (Tested)

In this article, we'll explore some awesome ChatGPT-4 prompts specifically tailored for software developers. These prompts can assist with tasks such as code generation, code completion, bug detection, code review, API documentation generation, and more.

Code Generation

  • Generate a boilerplate [language] code for a [class/module/component] named [name] with the following functionality: [functionality description].

  • Create a [language] function to perform [operation] on [data structure] with the following inputs: [input variables] and expected output: [output description].

  • Generate a [language] class for a [domain] application that includes methods for [methods list] and properties [properties list].

  • Based on the [design pattern], create a code snippet in [language] that demonstrates its implementation for a [use case].

Example:

Generate a boilerplate Python code for a shopping cart module named "ShoppingCart" with the following functionality:

- A constructor that initializes an empty list to store cart items.

- A method called "add_item" that takes in an item object and adds it to the cart.

- A method called "remove_item" that takes in an item object and removes it from the cart if it exists.

- A method called "get_items" that returns the list of items in the cart.

- A method called "get_total" that calculates and returns the total price of all items in the cart.
Enter fullscreen mode Exit fullscreen mode

Code Completion

  • In [language], complete the following code snippet that initializes a [data structure] with [values]: [code snippet].

  • Finish the [language] function that calculates [desired output] given the following input parameters: [function signature].

  • Complete the [language] code to make an API call to [API endpoint] with [parameters] and process the response: [code snippet].

Example : Finish the Python function that calculates the average of a list of numbers given the following input parameters:

def calculate_average(num_list)

Enter fullscreen mode Exit fullscreen mode

Bug Detection

  • Identify any potential bugs in the following [language] code snippet: [code snippet].

  • Analyze the given [language] code and suggest improvements to prevent [error type]: [code snippet].

  • Find any memory leaks in the following [language] code and suggest fixes: [code snippet].

Example : Identify any potential bugs in the following Python code snippet:

def calculate_sum(num_list):
    sum = 0
    for i in range(len(num_list)):
        sum += num_list[i]
    return sum

Enter fullscreen mode Exit fullscreen mode

Code Review

  • Review the following [language] code for best practices and suggest improvements: [code snippet].

  • Analyze the given [language] code for adherence to [coding style guidelines]: [code snippet].

  • Check the following [language] code for proper error handling and suggest enhancements: [code snippet].

  • Evaluate the modularity and maintainability of the given [language] code: [code snippet].

Example : Review the following Python code for best practices and suggest improvements:

def multiply_list(lst):
    result = 1
    for num in lst:
        result *= num
    return result

Enter fullscreen mode Exit fullscreen mode

API Documentation Generation

  • Generate API documentation for the following [language] code: [code snippet].

  • Create a concise API reference for the given [language] class: [code snippet].

  • Generate usage examples for the following [language] API: [code snippet].

Example : Generate API documentation for the following JavaScript code:

/**
 * Returns the sum of two numbers.
 * @param {number} a - The first number to add.
 * @param {number} b - The second number to add.
 * @returns {number} The sum of a and b.
 */
function sum(a, b) {
  return a + b;
}

Enter fullscreen mode Exit fullscreen mode

Query Optimization

  • Optimize the following SQL query for better performance: [SQL query].

  • Analyze the given SQL query for any potential bottlenecks: [SQL query].

  • Suggest indexing strategies for the following SQL query: [SQL query].

  • Optimize the following NoSQL query for better performance and resource usage: [NoSQL query].

Example : Optimize the following SQL query for better performance:

SELECT *
FROM orders
WHERE order_date BETWEEN '2022-01-01' AND '2022-12-31'
ORDER BY order_date DESC
LIMIT 100;

Enter fullscreen mode Exit fullscreen mode

User Interface Design

  • Generate a UI mockup for a [web/mobile] application that focuses on [user goal or task].

  • Suggest improvements to the existing user interface of [app or website] to enhance [usability, accessibility, or aesthetics].

  • Design a responsive user interface for a [web/mobile] app that adapts to different screen sizes and orientations.

Example : Generate a UI mockup for a mobile application that focuses on managing personal finances.

Automated Testing

  • Generate test cases for the following [language] function based on the input parameters and expected output: [function signature].

  • Create a test script for the given [language] code that covers [unit/integration/system] testing: [code snippet].

  • Generate test data for the following [language] function that tests various edge cases: [function signature].

  • Design a testing strategy for a [web/mobile] app that includes [unit, integration, system, and/or performance] testing.

Example: Generate test cases for the following Python function based on the input parameters and expected output:

def divide(a: float, b: float) -> float:
    if b == 0:
        raise ZeroDivisionError('division by zero')
    return a / b
Enter fullscreen mode Exit fullscreen mode

Code refactoring

  • Suggest refactoring improvements for the following [language] code to enhance readability and maintainability: [code snippet].

  • Identify opportunities to apply [design pattern] in the given [language] code: [code snippet].

  • Optimize the following [language] code for better performance: [code snippet].

Example : Optimize the following Python code for better performance:

def find_max(numbers):
    max_num = numbers[0]
    for num in numbers:
        if num > max_num:
            max_num = num
    return max_num

Enter fullscreen mode Exit fullscreen mode

Design pattern suggestions

  • Based on the given [language] code, recommend a suitable design pattern to improve its structure: [code snippet].

  • Identify opportunities to apply the [design pattern] in the following [language] codebase: [repository URL or codebase description].

  • Suggest an alternative design pattern for the given [language] code that may provide additional benefits: [code snippet].

Example: Based on the given Python code, recommend a suitable design pattern to improve its structure:

class TotalPriceCalculator:
    def calculate_total(self, items):
        pass

class NormalTotalPriceCalculator(TotalPriceCalculator):
    def calculate_total(self, items):
        total = 0
        for item in items:
            total += item.price * item.quantity
        return total

class DiscountedTotalPriceCalculator(TotalPriceCalculator):
    def calculate_total(self, items):
        total = 0
        for item in items:
            total += item.price * item.quantity * 0.9 # apply 10% discount
        return total

class Order:
    def __init__ (self, items, total_price_calculator):
        self.items = items
        self.total_price_calculator = total_price_calculator

    def calculate_total(self):
        return self.total_price_calculator.calculate_total(self.items)

class Item:
    def __init__ (self, name, price, quantity):
        self.name = name
        self.price = price
        self.quantity = quantity

Enter fullscreen mode Exit fullscreen mode

Algorithm development

  • Suggest an optimal algorithm to solve the following problem: [problem description].

  • Improve the efficiency of the given algorithm for [specific use case]: [algorithm or pseudocode].

  • Design an algorithm that can handle [large-scale data or high-throughput] for [specific task or operation].

  • Propose a parallel or distributed version of the following algorithm to improve performance: [algorithm or pseudocode].

Code translation

  • Translate the following [source language] code to [target language]: [code snippet].

  • Convert the given [source language] class or module to [target language] while preserving its functionality and structure: [code snippet].

  • Migrate the following [source language] code that uses [library or framework] to [target language] with a similar library or framework: [code snippet].

Example: Translate the following Python code to JavaScript:

def factorial(n):
    if n == 0:
        return 1
    else:
        return n * factorial(n-1)

Enter fullscreen mode Exit fullscreen mode

Personalized learning

  • Curate a list of resources to learn [programming language or technology] based on my current skill level: [beginner/intermediate/advanced].

  • Recommend a learning path to become proficient in [specific programming domain or technology] considering my background in [existing skills or experience].

  • Suggest project ideas or coding exercises to practice and improve my skills in [programming language or technology].

Code visualization

  • Generate a UML diagram for the following [language] code: [code snippet].

  • Create a flowchart or visual representation of the given [language] algorithm: [algorithm or pseudocode].

  • Visualize the call graph or dependencies of the following [language] code: [code snippet].

Example : Generate a UML diagram for the following Java code:

public abstract class Vehicle {
    private String model;

    public Vehicle(String model) {
        this.model = model;
    }

    public String getModel() {
        return model;
    }

    public abstract void start();

    public abstract void stop();
}

public class Car extends Vehicle {
    public Car(String model) {
        super(model);
    }
    @Override
    public void start() {
        System.out.println("Starting car engine");
    }
    @Override
    public void stop() {
        System.out.println("Stopping car engine");
    }
}
public class Motorcycle extends Vehicle {
    public Motorcycle(String model) {
        super(model);
    }
    @Override
    public void start() {
        System.out.println("Starting motorcycle engine");
    }
    @Override
    public void stop() {
        System.out.println("Stopping motorcycle engine");
    }
}

Enter fullscreen mode Exit fullscreen mode

Data visualization

  • Generate a bar chart that represents the following data: [data or dataset description].

  • Create a line chart that visualizes the trend in the following time series data: [data or dataset description].

  • Design a heatmap that represents the correlation between the following variables: [variable list].

Thanks for reading

Hackertab

All Developer news in one tab!

As a developer, it can be difficult to stay on top of everything happening in the field. Hackertab makes it easy by allowing you to customise your default tab page to include news, tools and events from top sources such as GitHub Trending, Hacker News, DevTo, Medium, and Product Hunt.

Oldest comments (30)

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

Feel free to suggest any other cool chat GPT prompt not mentioned in the post!
Thanks

Collapse
 
hkiehc7 profile image
hkiehc7

Will try them for sure. Thanks

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
msa_128 profile image
Alex

Thanks for this. I'll try them in the future !

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
sehgalspandan profile image
Spandan Sehgal

Nice prompts... the are really gonna help me a lot.

Thanks for sharing 😊 🫂

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
urielbitton profile image
Uriel Bitton • Edited

I've been using github copilot for almost 2 years. It's way better for code generation than chatgpt, even though they're both based on open AI.

Chatgpt gets very frustrating sometimes. I've mastered chatgpt for code generation, I know exactly how to get it to generate the code I need, but it takes time and a lot of repeating and corrections. It's not smart enough right now. Even when I get a perfect result for X and Y I ask it to repeat the same exact task for Z and it will give me an incorrect and inconsistent result.

It's ok though gpt is in its infancy, it will get really good with time.

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

And also Copilot has a smooth integration and user experience with VSCode, it saves a lot of time and effort, I don't have to manually switch between ChatGPT and the editor to copy and paste relevant information or code snippets.

Collapse
 
ferbyshire profile image
Ferb

I've found using the two together can be helpful. In my django project I found if I don't know how exactly to implement something, I can explore solutions with Chatgpt and code it with Copilot. Has anyone else found this?

Collapse
 
jamesajayi profile image
James Ajayi

Absolutely. It's the more reason why developers have to see chatGPT as a tool and not just an end in itself.

Collapse
 
bwca profile image
Volodymyr Yepishev

Thanks for sharing :)

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
obere4u profile image
Nwosa Tochukwu

Interesting. Bookmarked

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
ignaciah profile image
Ignacia Heyer

Thanks, this information was very helpfull. Good information.

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌

Collapse
 
michaeltimbes profile image
Michael Timbes

I don’t know if any of these use cases are strong enough to justify using GPT. Even the best practices one seems like a stretch.

All of these cases can be configured and exist in popular IDE tools. The data cases are handled by existing tools like Excel.

It’s all neat and stuff but at this point I don’t personally see a good reason to jump on the wagon.

Collapse
 
nikkilopez2 profile image
Coding Journal by Nikki

Great tips!

Collapse
 
hackertab profile image
Hackertab.dev 🖥️ Hackertab

🙌