阿川私房教材:學程式,拿 offer!

63 個專案實戰,直接上手!
無需補習,按步驟打造你的面試作品。

立即解鎖你的轉職秘笈

下列 ChatGPT-4 咒語,對開發者很有幫助。附上原文與中文指令,供您參考。

原文出處:https://dev.to/hackertab_org/50-chat-gpt-prompts-every-software-developer-should-know-tested-9al

程式碼生成

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

  • 為名為 [name] 的 [class/module/component] 生成樣板 [language] 程式碼,具有以下功能:`[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].

  • 基於[設計模式],用[語言]建立一個程式碼片段,演示其對[用例]的實現。

例子:

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.

程式碼完成

  • 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].

  • 完成“[語言]”程式碼以使用[參數]對“[API 端點]”進行 API 呼叫並處理響應:“[程式碼片段]”。

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

示例:完成計算給定以下輸入參數的數字列表的平均值的 Python 函數:

def calculate_average(num_list)

錯誤檢測

  • 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:

示例:辨識以下 Python 程式碼片段中的任何潛在錯誤:

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

程式碼審查

  • 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:

示例:查看以下 Python 程式碼以獲得最佳實踐並提出改進建議:

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

API 文件生成

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

  • 為以下“[語言]”程式碼生成 API 文件:“[程式碼片段]”。

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

  • 為給定的“[語言]”類建立簡明的 API 參考:“[程式碼片段]”。

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

  • 為以下“[語言]”API 生成用法示例:“[程式碼片段]”。

Example : Generate API documentation for the following JavaScript code:

示例:為以下 JavaScript 程式碼生成 API 文件:

/**
 * 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;
}

查詢優化

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

  • 優化以下 SQL 查詢以獲得更好的性能:[SQL 查詢]

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

  • 分析給定的 SQL 查詢是否存在任何潛在瓶頸:[SQL 查詢]

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

  • 為以下 SQL 查詢建議索引策略:[SQL 查詢]

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

  • 優化以下 NoSQL 查詢以獲得更好的性能和資源使用:[NoSQL 查詢]

Example : Optimize the following SQL query for better performance:

示例:優化以下 SQL 查詢以獲得更好的性能:

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

用戶界面設計

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

  • 為專注於 [用戶目標或任務][web/mobile] 應用程式生成 UI 模型。

  • 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.

  • 為適應不同螢幕尺寸和方向的“[web/mobile]”應用程式設計響應式用戶界面。

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

示例:為專注於管理個人財務的移動應用程式生成 UI 模型。

自動化測試

  • 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:

示例: 根據輸入參數和預期輸出為以下 Python 函數生成測試用例:

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

程式碼重構

  • 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:

示例:優化以下 Python 程式碼以獲得更好的性能:

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

設計模式建議

  • 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].

  • 確定在以下 [語言] 程式碼庫中應用 [設計模式] 的機會:[存儲庫 URL 或程式碼庫描述]

  • 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:

例子: 根據給定的Python程式碼,推薦合適的設計模式來改進其結構:

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

算法開發

  • 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].

  • 提出以下算法的並行或分佈式版本以提高性能:[算法或偽程式碼]

程式碼翻譯

  • 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:

示例:將以下 Python 程式碼轉換為 JavaScript:

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

個性化學習

  • 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].

  • 建議專案想法或編碼練習,以練習和提高我在“[編程語言或技術]”方面的技能。

程式碼可視化

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

  • 為以下“[語言]”程式碼生成一個 UML 圖:“[程式碼片段]”。

  • 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:

示例:為以下 Java 程式碼生成 UML 圖:

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");
    }
}

資料可視化

  • 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].

  • 設計一個表示以下變數之間相關性的熱圖:[變數列表]


以上,簡單分享,希望對您有幫助!


共有 0 則留言


精選技術文章翻譯,幫助開發者持續吸收新知。

阿川私房教材:學程式,拿 offer!

63 個專案實戰,直接上手!
無需補習,按步驟打造你的面試作品。

立即解鎖你的轉職秘笈