Skip to content

Commit 2d100b0

Browse files
committed
feat: update chapter(s) by CAT
1 parent 0c2bf67 commit 2d100b0

File tree

4 files changed

+45
-8
lines changed

4 files changed

+45
-8
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232
* [1.7 大众对于 AI 编程助手的担忧](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/9)
3333
* [本章小结](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/10)
3434
2. 快速上手 Copilot
35-
3. 设计函数
35+
3. [设计函数](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/27)
36+
* (TBD)
37+
* [本章小结](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/28)
3638
4. [理解 Python 代码(上)](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/25)
3739
* (本章正文略)
3840
* [本章小结](https://github.com/cssmagic/Learn-AI-Assisted-Python-Programming/issues/26)

content/chapter-1/108.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ id: 10
33
title: "[译] [108] 本章小结"
44
---
55

6-
## 1.8 Summary
7-
## 1.8 本章小结
6+
## Summary
7+
## 本章小结
88

99
* Copilot is an AI Assistant, which is an Artificial Intelligence (AI) agent that helps you get work done.
1010
* Copilot changes how humans interact with computers, and the way that we write programs.

content/chapter-3/300.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
id:
2+
id: 27
33
title: "[译] [300] 第三章 设计函数"
44
---
55

@@ -14,10 +14,25 @@ title: "[译] [300] 第三章 设计函数"
1414
* The standard workflow when interacting with Copilot
1515
* Examples of writing good functions using Copilot
1616

17+
<!-- -->
18+
19+
* Python 函数以及它们在软件设计中的作用
20+
* 适合由 Copilot 来解决的合理任务
21+
* 与 Copilot 交互的标准工作流程
22+
* 利用 Copilot 编写优良函数的实例
23+
1724
One of the hardest challenges for programming novices is to know what a reasonable task is to give to Copilot so that it finds a good solution. If you give it too big a task, it will often fail in spectacular ways that can be extremely difficult to fix. What, then, is a reasonable task?
1825

26+
对编程初学者而言,识别出哪些任务适合交给 Copilot,以期待其提出有效解决方案,是一个巨大的挑战。如果赋予的任务过于庞大,Copilot 往往会以引人注目的方式失败,且这类失败的修正通常非常困难。那么,什么样的任务才算是合理的呢?
27+
1928
This question is important for our use of Copilot but goes far beyond it. Human programmers struggle with complexity, too. If experienced software engineers try to write code to solve a problem that’s too complex without breaking it down into smaller, more solvable sub-parts, they often have trouble as well. The solution for humans has been to use something called a function, whose job is to perform one task. There are various rules of thumb for how to write a reasonable function in terms of number of lines of code, but fundamentally these rules try to capture writing something that (1) performs a single task and (2) is not so complex that it’s hard to get right.
2029

30+
这个问题不仅对我们使用 Copilot 至关重要,而且意义深远。人类程序员也面临着处理复杂性的挑战。经验丰富的软件工程师如果试图直接编写代码来解决一个复杂问题,而不是将其分解为更小、更易于解决的子问题,往往也会陷入困境。人们的解决方法是采用所谓的函数,它的职责是完成一个任务。虽然有许多关于如何编写合理函数的经验规则,例如代码的行数,但这些规则的根本目的是要确保所写的内容(1)执行一个单一任务,并且(2)其复杂度不至于难以正确执行。
31+
2132
For students who learned to program the old-fashioned way, without Copilot, they’ll have been struggling with syntax in code that’s 5-10 lines long for about a month before we typically introduce functions and, at that point, it’s a natural segue to tell them not to write more code in a single function than they can handle testing and debugging. As you all are learning to work with Copilot rather than syntax directly, our job in this chapter is to teach you about functions and what are reasonable, and unreasonable, tasks to ask Copilot to solve in a single function.
2233

34+
对于通过传统方法学习编程且未使用 Copilot 的学生,他们在我们通常开始介绍函数的大约一个月前,可能已经与 5-10 行长的代码语法作斗争。在此时,向他们自然地指出不要在单一函数中写入超过他们测试和调试能力范围的代码是很合适的。鉴于你们正学习如何利用 Copilot 而不是直接处理语法,本章的使命是向你们介绍有关函数的知识,并说明在单个函数中要求 Copilot 解决的哪些任务是合理的,哪些是不合理的。
35+
2336
To help you gain perspective on functions, we’ll provide you with a number of examples in this chapter. For those examples, you’ll see us employ the central workflow of interacting with Copilot; specifically, the cycle of writing prompts, receiving code from Copilot, and testing to see if that code is correct. In the functions produced by Copilot, you’ll begin to see the core programming tools, like loops, conditionals, and lists, that we’ll expand on in the next chapter.
37+
38+
为了加深你对函数的理解,我们将在本章提供若干示例。在这些示例中,你将体验到与 Copilot 互动的核心流程;即编写提示词、从 Copilot 接收代码、测试代码是否正确的循环过程。通过 Copilot 创建的函数,你将初步了解像循环、条件语句和列表这样的核心编程工具,这些是我们下一章将要详细探讨的内容。

content/chapter-3/307.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
2-
id:
3-
title: "[译] [XXX] XXXXXXXXXXXXXXXX"
2+
id: 28
3+
title: "[译] [307] 本章小结"
44
---
55

66

7-
## 3.7 Summary
8-
## 2.6 本章小结
7+
## Summary
8+
## 本章小结
99

1010
* Problem decomposition involves breaking a large problem into smaller tasks.
1111
* We use functions to perform problem decomposition in our programs.
@@ -28,3 +28,23 @@ title: "[译] [XXX] XXXXXXXXXXXXXXXX"
2828
* We need to ensure that we import any module (such as string) our code is using.
2929

3030
<!-- -->
31+
32+
* 问题分解是指将大问题拆解为更小的任务。
33+
* 我们利用函数在我们的程序中执行问题分解。
34+
* 每个函数都应解决一个小而具体定义的任务。
35+
* 函数帮助减少代码重复,使得测试我们的代码变得更容易,并且减少了出现错误的可能性。
36+
* 单元测试涉及到检查函数在各种不同输入上的表现是否符合我们的预期。
37+
* 函数的头部或签名是该函数的首行代码。
38+
* 参数被用于向函数传递信息。
39+
* 函数头部显示了函数的名称和它的参数名称。
40+
* 我们使用 `return` 来从函数返回一个值。
41+
* 文档字符串利用函数参数的名称来说明函数的用途。
42+
* 向 Copilot 请求编写函数时,我们需要提供函数的头部和文档字符串。
43+
* 通过为其参数提供值(亦称为实参)来调用函数,从而使函数执行其功能。
44+
* 变量是引用值的名字。
45+
* 辅助函数是一个小型函数,旨在简化编写更大函数的过程。
46+
* 叶子函数不会调用其他任何函数来完成其任务。
47+
* 测试函数是否正确的一个方法是,用不同类型的输入去调用它。
48+
* 每个 Python 的值都有类型,比如数字、文本(字符串)、真/假值(布尔)、或值的集合(列表或字典)。
49+
* 提示词工程指的是调整我们对 Copilot 的提示词,以影响我们获得的代码。
50+
* 我们需要确保我们的代码使用的任何模块(例如 string)都被导入。

0 commit comments

Comments
 (0)