Skip to content
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

[译] [305] 使用 Copilot 设计函数的流程 #40

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

[译] [305] 使用 Copilot 设计函数的流程 #40

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

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 协作的常规编辑流程。前提是你定义的函数是合理的。

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant