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

在本文中,我们将探索一些专为软件开发人员量身定制的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
相关文章
这或是美国最后一次向中国出售AI芯片!黄仁勋知道时间不多了..
以deepseek为代表的中国AI企业进化太快了。其次,美国不甘心放弃中国市场..
千问模型新增多款技术产品 涵盖语音、视觉、代码等多领域..
封面新闻记者 孟梅 欧阳宏宇9月24日,2025云栖大会现场,阿里云CTO周靖人..
2025年:互联网还是舒适区?
在AI与社交媒体深度捆绑的时代,我们的注意力被算法不断重塑。从GPT5到Ge..
大打免费牌争夺用户 马斯克Grok4与ChatGPT5“短兵相接”..
《科创板日报》8月12日讯(记者 李佳怡)继ChatGPT后,Grok4宣布免费开放..
18款AI模型幻觉率大公开|你的AI靠谱吗?
根据Artificial Analysis最新发布的Omniscience Index测评数据,18款主流..
解放军总医院联合南大、吉大等机构,共同提出SpineGPT..
本研究由解放军总医院牵头,联合浙江大学医学院附属第二医院、复旦大学附..
千问首家接入东航,AI助手竞赛开始抢“机票”
4月23日,千问宣布对外开放“AI办事”能力,首家接入中国东方航空,上线..
千问上线AI讲教材能力,首批覆盖小学阶段语文、数学..
齐鲁晚报·齐鲁壹点记者 季明智进入新学期后,不少学生陷入“开学综合症..
千问免费开放财经分析模块,AI能否替代人工投研判断..
4月7日,阿里巴巴旗下AI助手千问宣布升级“深度研究”能力,新增财经分析..
关于作者
帝王之星(普通会员)
文章
1895
关注
0
粉丝
0
点击领取今天的签到奖励!
签到排行

成员 网址收录40418 企业收录2986 印章生成263660 电子证书1157 电子名片68 自媒体105939

0
0
分享
请选择要切换的马甲:

个人中心

每日签到

我的消息

内容搜索