Skip to content

[译] [305] 与 Copilot 协作设计函数的流程 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cssmagic opened this issue Mar 15, 2024 · 0 comments
Open

[译] [305] 与 Copilot 协作设计函数的流程 #40

cssmagic opened this issue Mar 15, 2024 · 0 comments

Comments

@cssmagic
Copy link
Owner

cssmagic commented Mar 15, 2024

3.5 The cycle of design of functions with Copilot

3.5 与 Copilot 协作设计函数的流程

Designing functions with Copilot involves the following cycle of steps (see figure 3.3):

借助 Copilot 来设计函数时,我们需要遵循以下循环步(参见图 3.3):

  1. Determine the desired behavior of the function.
  2. Write a prompt that describes the function as clearly as possible.
  3. Allow Copilot to generate the code.
  4. Read through the code to see if it seems reasonable.
  5. Test the code to see if it is correct:
    1. If the code is correct after multiple tests, move on.
    2. If the code is incorrect, move to step 2 and edit the prompt.
  1. 确定函数想要实现的行为。
  2. 构造一段尽可能清晰的提示词来描述函数。
  3. 让 Copilot 生成相应的代码。
  4. 通读代码,判断其看起来是否比较合理。
  5. 对代码进行测试,验证其是否正确。
    1. 经过多次测试,若代码无误,便可以继续。
    2. 若发现代码有误,则回到第 2 步,对提示词进行调整。
Figure 3.3 General editing cycle with Copilot. This assumes you define a reasonable function.
图 3.3 与 Copilot 协作的常规编辑流程。前提是你定义的函数是合理的。

原文 译文 备注
Define the desired behavior of the function 确定函数需要实现何种行为
Write a prompt that describes the function 编写提示词来描述函数行为
Allow Copilot to generate the code 让 Copilot 生成代码
Examine the code to see if it is reasonable 粗略检查代码是否合理
Test the code to see if it is correct 测试代码是否正确
Incorrect 不正确
Correct 正确
Done 完成

We won’t learn how to do step 4 until the next chapter, but we bet you can already recognize when the code is blatantly wrong. For example, Copilot might give you only comments to fill the body of the function. Comments don’t do anything—they are not code!—so a bunch of comments with no other code is clearly not the right thing to do. Or it might just write a single line return -1. Or, our personal favorite, Your code here. Copilot learned that one from us professors when we provide students partial code and ask them to write the rest with “Your code here.” Those are all obviously incorrect, but in the next chapter, we’ll go over how to read code so you can more quickly spot when more complicated code is incorrect and, perhaps more importantly, see where and how to fix it. In later chapters, we’ll keep expanding on this cycle to include effective debugging practices, and we’ll keep practicing how to improve prompts.

我们直到下一章才会学习如何执行第 4 步,但我们相信你现在已经能够识别出明显的代码错误了。比如 Copilot 可能只用了注释来填充函数的主体。注释本身不执行任何操作——它们并非代码!——因此,只有一系列注释而无其他代码显然不是正确的结果。它也可能仅仅生成一行 “return -1”。或者,我们特别喜欢用的“Your code here”。Copilot 是从我们这些教授这里学到这种表达方式的,当我们向学生提供部分代码并要求他们完成剩余部分时,我们会说 “Your code here”。或许你现在只能辨别出这些比较明显的错误,但在下一章中,我们将会讲解如何阅读代码。这样当更复杂的代码包含错误时,你就能更快地发觉;而且更重要的是,你还能发现错在哪里以及如何修复。在后续章节中,我们将持续扩展这一循环,加入有效的调试技巧,并且持续练习如何改进提示词。

@cssmagic cssmagic changed the title [译] [305] 使用 Copilot 设计函数的循环 [译] [305] 使用 Copilot 设计函数的流程 Mar 15, 2024
@cssmagic cssmagic mentioned this issue Aug 7, 2024
@cssmagic cssmagic changed the title [译] [305] 使用 Copilot 设计函数的流程 [译] [305] 与 Copilot 协作设计函数的流程 Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant