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

[译] [307] 本章小结 #28

Open
cssmagic opened this issue Feb 29, 2024 · 0 comments
Open

[译] [307] 本章小结 #28

cssmagic opened this issue Feb 29, 2024 · 0 comments

Comments

@cssmagic
Copy link
Owner

cssmagic commented Feb 29, 2024

Summary

本章小结

  • Problem decomposition involves breaking a large problem into smaller tasks.
  • We use functions to perform problem decomposition in our programs.
  • Each function must solve one small, well-defined task.
  • Functions reduce duplication, make it easier to test our code, and reduce the likelihood of bugs.
  • Unit testing involves checking that the function does what we expect on a variety of different inputs.
  • A function header or signature is the first line of code of the function.
  • Parameters are used to provide information to functions.
  • The function header indicates the name of the function and names of its parameters.
  • We use return to output a value from a function.
  • A docstring uses the names of each function parameter to describe the purpose of the function.
  • To ask Copilot to write a function, we provide it the function header and docstring.
  • We get a function to do its work by calling it with values (also called arguments) for its parameters.
  • A variable is a name that refers to a value.
  • A helper function is a small function written to make it easier to write a bigger function.
  • A leaf function doesn’t call any other function to do its job.
  • To test whether a function is correct, we call it with different types of inputs.
  • Every Python value has a type, such as a number, text (string), true/false value (bool), or collection of values (list or dictionary).
  • Prompt engineering involves modifying our prompt for Copilot to influence the code that we get back.
  • We need to ensure that we import any module (such as string) our code is using.
  • 问题分解是指将大问题拆解为更小的任务。
  • 我们利用函数在我们的程序中执行问题分解。
  • 每个函数都应解决一个小而具体定义的任务。
  • 函数帮助减少代码重复,使得测试我们的代码变得更容易,并且减少了出现错误的可能性。
  • 单元测试涉及到检查函数在各种不同输入上的表现是否符合我们的预期。
  • 函数的头部或签名是该函数的首行代码。
  • 参数被用于向函数传递信息。
  • 函数头部显示了函数的名称和它的参数名称。
  • 我们使用 return 来从函数返回一个值。
  • 文档字符串利用函数参数的名称来说明函数的用途。
  • 向 Copilot 请求编写函数时,我们需要提供函数的头部和文档字符串。
  • 通过为其参数提供值(亦称为实参)来调用函数,从而使函数执行其功能。
  • 变量是引用值的名字。
  • 辅助函数是一个小型函数,旨在简化编写更大函数的过程。
  • 叶子函数不会调用其他任何函数来完成其任务。
  • 测试函数是否正确的一个方法是,用不同类型的输入去调用它。
  • 每个 Python 的值都有类型,比如数字、文本(字符串)、真/假(布尔值)、或值的集合(列表或字典)。
  • 提示工程指的是调整我们对 Copilot 的提示词,从而影响我们收到的代码。
  • 我们需要确保我们的代码使用的任何模块(例如 string)都被导入。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant