当前位置: 技术文章>> ChatGPT精选:为软件开发者提供的20个绝佳贴士和技巧,助你轻松驾驭开发流程

文章标题:ChatGPT精选:为软件开发者提供的20个绝佳贴士和技巧,助你轻松驾驭开发流程
  • 文章分类: 后端
  • 16347 阅读


OpenAI的ChatGPT是一种使用自然语言处理(NLP)与人类用户进行对话的聊天机器人。它接受称为“提示”的文本输入,并且只以文本形式回复。使其脱颖而出的品质是,它可以根据给定的规范生成代码,并且对于任何类型的查询(无论是职业,教育,娱乐还是某个领域的太多技术或利基),都会给出非常描述性的答案。它还可以调试输入的代码,也可以充当解释器或编译器。


![](/uploads/images/20230812/e72e7e1b11c7b7488dde74069de40b6b.png)


由于ChatGPT接受自然语言的提示,如果我们提供更描述性的提示,我们往往会获得更准确和精确的答案。这类似于提供更多详细信息,在地址中更准确地到达所需的位置。


现在问题来了,如何制定“提示”以获得更准确和精确的答案?因此,我们列出了面向软件开发人员的20个ChatGPT提示。


### Explain

软件开发就是一边学习一边实现的过程。ChatGPT可以通过解释所需的概念来帮助我们。Explain提示可以用来理解概念、一段代码,或者让我们说算法的时间或空间复杂性。ChatGPT通过给出详细的答案来回答。


> Explain how the {concept or function} works in {programming language}.



![](/uploads/images/20230812/75a6d88a618d36e0ae9a1849ce03c789.png)


示例:

> Explain how the below {programming language} code works {code snippet}


示例:

> Explain the time and space complexity of the below code written in {programming language} {code snippet}


### 语法


软件开发人员使用各种各样的技术堆栈。因此,在选择新的堆栈时,很难记住每种语言和技术的语法。这就是ChatGPT的用武之地,它通过提供具有适当示例的编程语言元素的正确语法来提供帮助。


示例:

> What is the correct syntax for a {statement or function} in {programming language}?


![](/uploads/images/20230812/53e43f6573477254f0ac89ff461d8a76.png)


### 修复bug

在软件开发中,大量的时间都花在查找代码中的漏洞上。它不仅阻碍了个人的生产力,还延迟了代码的发货。使用这个提示,人们可以很容易地了解代码中的漏洞并获得调试方面的帮助。


示例:

> How do I fix the following {programming language} code which {explain the functioning}? {code snippet}


![](/uploads/images/20230812/c4d859bb8bc7f5d4e8aa5538b69509ee.png)


### 最佳实践

了解行业最佳实践在编码时非常重要。这使得代码易于阅读,并在组织成长时有助于维护代码库。我们可以要求ChatGPT在为特定编程语言编写代码时遵循一组规则和建议。


示例:

> Show me best practices for writing {concept or function} in {programming language}.


![](/uploads/images/20230812/814cf434924364fec5aaeb77402faa7d.png)


### 优化

建议始终编写最优化代码,因为这可以提高程序性能并帮助节省资源。优化可以是行数方面,也可以是空间和时间复杂度方面。我们可以使用ChatGPT来获取一段优化后的代码。


示例:

> Optimize the following {programming language} code which {explain the functioning}: {code snippet}


示例:

> Example – Optimisation in terms of number of lines of code


![](/uploads/images/20230812/423f117e03498a18fba19187423da3fa.png)


### 生成代码


我们还可以使用ChatGPT根据输入中提供的要求为我们编写一段代码。在这里,描述需求对于获得所需结果是至关重要的。


示例:

> Write a program/function to {explain functionality} in {programming language}


![](/uploads/images/20230812/32116dc7fa0dfa1fc63333d7b98eb438.png)


### 代码转换


我们经常需要将给定的代码从一种编程语言转换为另一种编程语言。这可能是因为组织改变了其技术堆栈。在学习新编程语言时,了解如何使用另一种语言实现相同任务也是很有帮助的。


示例:

> Convert the following {programming language 1} code to {programming language 2}: {code snippet}


![](/uploads/images/20230812/f994579e81d5e50c83656df41df9585c.png)



### 让ChatGPT扮演口译员

ChatGPT还可以扮演口译员或编译器的角色。为了实现这一目标,我们不需要下载任何东西。这使我们能够在浏览器中编写代码。它可以在测试/实验命令或学习时使用。


示例:

> I want you to act like a {programming language} interpreter/compiler. I will give you {programming language} code, and you will execute it. Do not provide any explanations. Do not respond with anything except the output of the code. The first code is: {code}


![](/uploads/images/20230812/787d2a6d6f14e29a1c39ca6815d52163.png)


### 关于网页设计的咨询

我们可以向ChatGPT咨询关于我们网站的UI/UX设计的任何问题,以便在没有设计团队的实际帮助下,首先为它提供一个更好的外观。


示例:

> I want you to act as a web design consultant. I will provide you with details related to an organization needing assistance in designing or redeveloping its website, and your role is to suggest the most suitable interface and features that can enhance user experience while also meeting the company’s business goals. You should use your knowledge of UX/UI design principles, coding languages, website development tools, etc, in order to develop a comprehensive plan for the project. My first request is “I need help creating a {website type} for {purpose}.”


![](/uploads/images/20230812/51275cb80699c329f2c492792213515d.png)


### 建议一个框架


在开始一个项目之前,选择正确的框架或库非常重要。它会对项目的性能、可扩展性和复杂性产生巨大影响。而且,通常很难决定使用哪个框架。但是,我们可以利用ChatGPT来获得想法。


示例:

> Can you recommend a suitable front-end framework/library for my website?? I’m making {type of website}.


![](/uploads/images/20230812/7d8a21534d8e4238e9f700d2787dfd9b.png)


### 编写代码注释

在编写程序时,编写注释非常重要。这些注释有助于在以后理解特定函数或代码块的功能,并可以帮助新加入者理解代码库。ChatGPT可以帮助我们为给定的代码片段生成适当的注释。


示例:

> Regenerate the code snippet below, but please include comments on each line of code {enter code}


![](/uploads/images/20230812/4b8a2977f7777455c347b63204556e97.png)


### 生成Readme文件

Readme是存储库的重要组成部分,其中包含存储库的用途以及下载和/或使用项目(如果有)的指南。编写良好的readme有助于吸引更多人访问您的存储库。


示例:

> Generate documentation for the code below. You should include detailed instructions to allow a developer to run it on a local machine, explain what the code does, and list vulnerabilities that exist in this code. {enter code}


### 生成Dataset


在处理机器学习项目时,数据集非常重要。如果我们无法找到合适的数数据集或需要更多数据来训练我们的模型,我们可以使用ChatGPT来获取生成的数据,而且还可以获得所需格式和数量的数据。


示例:

> Generate {type of dataset} dataset containing {n} data points regarding {service or product} with fields including {fields}


![](/uploads/images/20230812/4fadc7b7b17593bbcc61a7e4a7fb961b.png)


### 网络抓取

网络抓取是用于从网站上收集数据。使用ChatGPT,也可以通过这种方式实现:


示例:

> Web scrape data from {url} using Python and Beautifulsoup


![](/uploads/images/20230812/6ea50aad9b4243a7cc4301db73fdb109.png)


### 规划阶段

在开始项目之前,我们必须计划好我们可能面临的任何潜在挑战、估计的成本和时间表,以便我们可以采取相应的行动。ChatGPT可以通过回答这些问题来帮助确定项目的范围和要求。


示例:

> I’m in the planning phase of my software development project and need guidance on [specific task/challenge]. Here are some project details: [Provide a brief overview, requirements, timeline, team, and risks].


### 分析阶段:准备SRS文档

我们可以使用ChatGPT根据项目描述准备SRS文档。这可以节省大量时间,因为它可以作为软件开发者可以改进和创建最终文档的框架。


示例:

> Generate a comprehensive Software Requirements Specification (SRS) document for my software development project. The details are as follows: [Provide project overview, stakeholders, functional requirements, non-functional requirements, assumptions, and constraints.]


### 设计阶段

我们可以要求ChatGPT根据项目的规范建议适当的数据模型和要遵循的设计模式。数据模型和设计模式是项目的重要部分,需要在开始之前明智地选择,否则可能会导致金钱和精力的损失,也可能延迟项目交付。


示例:

> I need suggestions for designing an effective data model for my software project. Here are some details: [Briefly describe the project, key functionalities, user requirements, data sources, and relationships].


### 开发阶段

我们可以就如何从可能卡住的地方继续前进或就如何扩展项目等方面征求建议。


示例:

> I’m working on a software project and need advice on ensuring scalability. Details: [Briefly describe the project, current usage and future growth, and technology stack].


### 测试阶段

在代码发布到生产环境之前进行测试非常重要。这有助于发现可能被忽略的任何漏洞或极端情况,从而提高用户体验,并防止对组织声誉造成损害。我们可以借助ChatGPT来生成测试用例


示例:

> Can you help me write test cases for this feature {explain the feature}?


### 布署阶段

在此阶段,一个重要的问题是选择哪种部署策略。部署策略定义了如何向用户显示软件新版本的更改,这样理想情况下就没有停机时间,用户几乎不会注意到所做的更改,即用户不会因软件的更新而受到任何干扰。我们可以要求ChatGPT建议最适合我们的项目的部署策略并自行评估。


示例:

> What are the best deployment strategies for this software project? {explaint the project}


### 小结:

毫无疑问,ChatGPT可以完成广泛的使命,使软件开发人员的生活更加轻松,包括解释概念以生成完整的代码。但是,一切都有代价。我们不能盲目信任它,毕竟,它正在运行的机器学习算法可能导致错误的结果。它也可能有一些偏见。此外,在使用ChatGPT时,始终存在安全问题。人们不应该将组织的内部代码提供给ChatGPT,也不应该透露与组织的政策或即将推出的项目有关的任何机密信息。它只应作为助理使用,而不是自由职业者。





推荐文章