> 自媒体 > (AI)人工智能 > 每个软件开发人员都应该知道的50个ChatGPT提示(已测试验证)
每个软件开发人员都应该知道的50个ChatGPT提示(已测试验证)
来源:xTech
2023-05-30 12:33:23
542
管理

在本文中,我们将探索一些专为软件开发人员量身定制的ChatGPT-4提示词。这些提示可以帮助完成代码生成、代码完成、bug检测、代码审查、API文档生成等任务。

代码生成 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].

例子:

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.

Bug检查检查潜在bug 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].

例子: 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 sumCode审查是否符合最佳实践 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].模块化、可维护性方面的检查Evaluate the modularity and maintainability of the given [language] code: [code snippet].

例子: 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文档生成

例子: 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;}查询优化

例子: Optimize the following SQL query for better performance:

SELECT *FROM ordersWHERE order_date BETWEEN '2022-01-01' AND '2022-12-31'ORDER BY order_date DESCLIMIT 100;UI设计

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

自动化测试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.

例子: 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代码重构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].

例子: 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_numDesign pattern suggestionsBased 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:

代码转换从一种编程语言转化为另一种编程语言 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].

例子: Translate the following Python code to JavaScript:

def factorial(n): if n == 0: return 1 else: return n * factorial(n-1)代码可视化生成UML图 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].

例子: 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"); }}数据可视化数据集可视化 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].

1
点赞
赏礼
赏钱
0
收藏
免责声明:本文仅代表作者个人观点,与本站无关。其原创性以及文中陈述文字和内容未经本网证实,对本文以及其中全部或者 部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。 凡本网注明 “来源:XXX(非本站)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对 其真实性负责。 如因作品内容、版权和其它问题需要同本网联系的,请在一周内进行,以便我们及时处理。 QQ:617470285 邮箱:617470285@qq.com
相关文章
ChatGPT 发布一周年: OpenAI 的人工智能聊天机器人是如何彻底改变科技界的..
站长之家(ChinaZ.com) 12 月 1 日消息:OpenAI 于一年前的今天(2022 年 1..
00后的网聊“黑话”火了,网友:我才没有暗中找科普........
“你能不能好好说话!”小时候,你是否也被妈妈这样数落过呢?每一代年轻..
为什么ChatGPT不是摇钱树?|《MPW零度对话》
《MPW零度对话》是我们最新推出的女性领导力专栏。我们将邀请中国最具知..
ChatGPT有了中文名,少了随帮没了唱影
米国人最近推出了一个可迭代自学习的智能云工具软件,上了热搜,于是人..
17名医生都没能诊断出的病竟被ChatGPT破解,AI医疗的潜力有多大..
近日,一则令人瞩目的医疗故事在美国掀起了轩然大波。一个年仅4岁的男孩..
开发不会消灭人类的AI!马斯克官宣TruthGPT,暗示将起诉OpenAI..
对于AI,马斯克曾发表过“AI比核弹更危险”、“AI可能会操纵舆论、破坏文..
高情商聊天技巧
从陌生人到恋人只要一个小时,看到这个标题你可能就会开始吐槽了,一个小..
2.ChatGPT并不完美 你是否对人工智能和自然语言处理充满好奇..
ChatGPT并非完美。虽然ChatGPT看起来无所不能,但它仍存在一些问题。有些..
OpenAI 将推出新订阅选项 满足企业客户需求
品玩4月26日讯,据 TechCrunch 报道,OpenAI 表示正在计划为 ChatGPT 推..
关于作者
有点醉(普通会员)
文章
572
关注
0
粉丝
0
点击领取今天的签到奖励!
签到排行

成员 网址收录40350 企业收录2981 印章生成210575 电子证书903 电子名片56 自媒体30867

@2022 All Rights Reserved 浙ICP备19035174号-7
1
0
分享
请选择要切换的马甲:

个人中心

每日签到

我的消息

内容搜索