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

在本文中,我们将探索一些专为软件开发人员量身定制的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].

0
点赞
赏礼
赏钱
0
收藏
免责声明:本文仅代表作者个人观点,与本站无关。其原创性以及文中陈述文字和内容未经本网证实,对本文以及其中全部或者 部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。 凡本网注明 “来源:XXX(非本站)”的作品,均转载自其它媒体,转载目的在于传递更多信息,并不代表本网赞同其观点和对 其真实性负责。 如因作品内容、版权和其它问题需要同本网联系的,请在一周内进行,以便我们及时处理。 QQ:617470285 邮箱:617470285@qq.com
相关文章
买车一定要慎重!质量可靠的十大品牌:本田第四,奥迪领先丰田!..
导读:随着国民经济不断发展,买得起私家车的消费者也是越来越多,不过对..
十大开起来最舒服的车,准备买车的来看看
2、日产天籁天籁,是B级车里最舒服的车型之一,因为天籁主打中高级豪华轿..
2022年最佳汽车品牌排行榜前十名:日系德系全包揽
根据近日《消费者报告》公布的《2022年度汽车品牌综合排行榜》统计的32个..
美媒公布2022年度质量最可靠的十大品牌:本田第五,丰田宝马前三..
导读:近日从美媒ConsumerReports方面了解到,2022年度汽车可靠性报告出..
美媒公布质量表现最好的十大汽车品牌:榜首易主,起亚别克很意外..
本文导读:近几年,消费者在选购车型也是愈加理性了,大家不再一味地“以..
买合资车需谨慎!公认质量最好的十大品牌出炉,日产本田进前五!..
导读:近两年,以品质著称的合资车受到了消费者们的青睐,而像本田、大众..
二线豪华品牌性价比低、价格高?买车认准这2个品牌,能避坑..
二线豪华品牌的特点就是,他能用一个偏低的价格让我们买到一个有个性的品..
车与表不愧为天作之合 盘点与汽车品牌及赛事合作的表款..
[爱卡汽车 导购原创]汽车与手表,既是男人的浪漫,也是机械的绝配。从20..
七大国产品牌10月销量:比亚迪狂卖50万辆,奇瑞年内销量破200万..
据乘联会初步统计,10月份,乘用车市场零售236.1万辆,同比增长16%,较上..
关于作者
帝王之星(普通会员)
文章
1172
关注
0
粉丝
0
点击领取今天的签到奖励!
签到排行

成员 网址收录40405 企业收录2984 印章生成241794 电子证书1085 电子名片61 自媒体65700

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

个人中心

每日签到

我的消息

内容搜索