Skip to content

Commit 4444430

Browse files
committed
feat: update chapter(s) by CAT
1 parent e8ccf29 commit 4444430

File tree

2 files changed

+74
-19
lines changed

2 files changed

+74
-19
lines changed

chapter-1/102.md

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,46 +6,82 @@ title: "[译] [102] About the technology"
66

77
## 1.2 About the technology
88

9+
## 1.2 技术简介
10+
911
We’ll be using two main technologies in this book: Python and GitHub Copilot.
1012

13+
在这本书中,我们将重点介绍两项主要技术:Python 和 GitHub Copilot。
14+
1115
Python is a programming language. It’s a way to communicate with a computer. People use it to write all kinds of programs that do useful things, like games, interactive websites, visualizations, apps for file organization, automating routine tasks, and so on.
1216

17+
Python 是一门编程语言,是与计算机进行交流的途径。人们使用它编写各种程序来完成有用的事情,如游戏、交互式网站、数据可视化、文件管理应用以及自动化常规任务等。
18+
1319
There are other programming languages, too, like Java, C++, Rust, and many others. Copilot works with those, too, but at the time of writing, it works really well with Python. Python code is a lot easier to write compared to many other languages (especially assembly code). Even more importantly, Python is easy to _read_. After all, we’re not going to be the one writing the Python code. Our AI assistant is!
1420

21+
还有其他的编程语言,如 Java、C++、Rust 等。GitHub Copilot 也支持这些语言,但截至目前,它对 Python 的支持尤其出色。与许多其他语言(尤其是汇编语言)相比,编写 Python 代码要简单得多。更为重要的是,Python 更易于**阅读**。毕竟,编写 Python 代码的将不是我们,而是我们的 AI 助手!
22+
1523
Computers don’t actually know how to read and run Python code. The only thing computers can understand is something called _machine code_, which looks even more ridiculous than assembly code as it is the binary representation of the assembly code (yep, just a bunch of 0s and 1s!). Behind the scenes, your computer takes any Python code that you provide and converts it into machine code before it runs, as shown in Figure 1.1.
1624

17-
**Figure 1.1 Your Python program goes through several steps before you see the output on your screen**
25+
实际上,计算机并不懂得如何读取和执行 Python 代码。计算机唯一能够理解的是称为**机器码**的内容,这种码相比汇编代码来说更加难以理解,因为它是汇编代码的二进制表现形式(没错,仅仅是一连串的 0 和 1!)。在幕后,你的计算机将接收你所提供的任何 Python 代码,并在执行之前把它转换成机器码,正如图 1.1 所展示的那样。
26+
27+
> Figure 1.1 Your Python program goes through several steps before you see the output on your screen
28+
>
29+
> ![](chapter-1.files/chapter-16764.png)
30+
31+
> 图 1.1 在你的屏幕上看到输出之前,你的 Python 程序需要经历几个步骤
1832
19-
![](chapter-1.files/chapter-16764.png)
2033

2134
#### Copilot, your AI Assistant
2235

36+
#### GitHub Copilot,你的 AI 助手
37+
2338
What is an _AI Assistant_? An AI Assistant is an Artificial Intelligence (AI) agent that helps you get work done. Maybe you have an Amazon Alexa device at home, or an iPhone with Siri-—these are AI assistants. Those ones help you order groceries, learn the weather, or determine that, yes, the woman who played Bellatrix in the Harry Potter movies really was in Fight Club. An AI assistant is just a computer program that responds to normal human inputs like speech and text with human-like answers.
2439

40+
什么是**AI 助手**?AI 助手是一种人工智能(AI)代理,它帮助你完成任务。你可能在家中使用亚马逊的 Alexa 设备,或拥有一部集成了 Siri 的 iPhone——这些都属于 AI 助手。这类助手能帮你订购生鲜、查询天气,或是确认那位在《哈利·波特》电影中饰演贝拉特里克斯的女演员确实也参演了《搏击俱乐部》。AI 助手只不过是一个响应人类语音和文本输入的计算机程序,并以类人的方式给出答案。
41+
2542
Copilot is an AI Assistant with a specific job: it converts English into computer programs. (It can also do a whole lot more as we will soon see.) There are other AI assistants like Copilot, including CodeWhisperer, Tabnine, and Ghostwriter. We chose Copilot for this book by a combination of the quality of code that we have been able to produce, stability (it has never crashed for us!), and our own personal preferences. We encourage you to check out other tools as well when you feel comfortable doing so.
2643

44+
GitHub Copilot 是一款具有特定任务的 AI 助手:它能将英语转换成计算机程序(我们很快就会看到,它还能做更多的事情)。除了 GitHub Copilot,还有其他一些类似的 AI 助手,如 CodeWhisperer、Tabnine 和 Ghostwriter。我们选择了 GitHub Copilot 作为本书的主要工具,是因为我们能够生成的代码质量、稳定性(它从未在我们的使用中崩溃过!)以及我们个人的偏好。当你感到舒适时,我们鼓励你也去尝试其他工具。
45+
46+
GitHub Copilot 是一个专门任务的 AI 助手:它能把英文转化为计算机程序。(当然,我们很快会发现,它还能完成更多任务。)除了 GitHub Copilot,还有其他的 AI 助手,如 CodeWhisperer、Tabnine 和 Ghostwriter。我们选择 GitHub Copilot 作为本书介绍的工具,这是基于我们所生成的代码质量、其稳定性(它从未发生过崩溃!)以及我们个人的偏好。我们也鼓励你在感觉合适时,探索其他的工具。
47+
2748
#### How Copilot works behind the scenes-—in 30 seconds
2849

50+
#### GitHub Copilot 幕后工作原理——仅用 30 秒
51+
2952
You can think of Copilot as a layer between you and the computer program you’re writing. Instead of writing the Python directly, you simply describe the program you want in words—this is called a _prompt_—and Copilot generates the program for you.
3053

54+
你可以把 GitHub Copilot 想象成你和你正在编写的计算机程序之间的一个中介层。不必直接编写 Python,你只需用语言描述你想要实现的程序——这称为**提示词**——之后 GitHub Copilot 就会为你生成相应的程序。
55+
3156
The brains behind Copilot is a fancy computer program called a **large language model**, or LLM. An LLM stores information about relationships between words, including which words make sense in certain contexts, and uses this to predict the best sequence of words to respond to a prompt.
3257

58+
GitHub Copilot 的智能核心是一个称为**大型语言模型**(LLM)的复杂计算机程序。大型语言模型存储了关于单词之间关系的信息,包括在特定上下文中哪些单词是有意义的,并利用这些信息来预测对一个提示词最佳的单词序列。
59+
3360
Imagine that we asked you what the next word should be in this sentence: "The person opened the ________". There are many words that you could fill in here, like “door” or “box” or “conversation,” but there are also many words that would not fit here, like “the” or “it” or “open.” An LLM takes into account the current context of words to produce the next word, and it keeps doing this until it has completed the task.
3461

62+
设想我们询问你在这个句子中:“这个人打开了______。” 下一个词应当是什么。这里有很多可能的填词,如“门”、“盒子”或“谈话”,但同时也存在许多不适合此处的词,如“这”、“它”或“打开”。大型语言模型会根据当前词汇的上下文来预测下一个合适的词,并持续这个过程直到任务完成。
63+
64+
3565
Notice that we didn't say anything about Copilot having an understanding of what it is doing. It just uses the current context to keep writing code. Keep this in mind throughout your journey: only we know whether the code that's generated actually does what we intended it to do. Very often it does, but you should always exercise healthy skepticism regardless.
3666

37-
67+
请注意,我们并未提及 GitHub Copilot 是否真的理解其正在进行的操作。它仅根据当前上下文继续编写代码。在你的编程旅程中,请始终牢记这一点:只有我们自己知道生成的代码是否确实按照我们的意图行事。虽然很多时候它确实能够实现这一点,但无论如何,你都应当始终保持一种健康的怀疑心态。
3868

3969
Figure 1.2 will give you an idea of how Copilot goes from prompt to program.
4070

41-
**Figure 1.2 Going from prompt to program with Copilot**
71+
图 1.2 将为你揭示 GitHub Copilot 是如何从提示词生成程序的过程。
72+
73+
> Figure 1.2 Going from prompt to program with Copilot
74+
>
75+
>![](chapter-1.files/chapter-19302.png)
4276
43-
![](chapter-1.files/chapter-19302.png)
77+
> 图 1.2 使用 GitHub Copilot 从提示词生成程序
4478
45-
4679

47-
4880

4981
You might wonder why Copilot writes Python code for us and not machine code directly. Isn’t Python an expendable intermediate step now? Well, no, and the reason is that Copilot is going to make mistakes. And if it’s going to make mistakes, and we need to get them fixed, then it’s a lot easier to do that with Python than with machine code.
5082

83+
你可能好奇,为什么 GitHub Copilot 会为我们编写 Python 代码,而不是直接生成机器码。Python 难道现在不只是一个可有可无的中间步骤吗?实际上,并非如此,这是因为 GitHub Copilot 可能会出错。既然它可能犯错,我们需要对这些错误进行修正,那么相比于机器码,使用 Python 进行修正无疑要简单得多。
84+
5185
In fact, virtually no one checks if the machine code produced from Python is correct. This is partially because of the determinism of the Python language specification. One could imagine a future where Copilot conversations are so accurate that inspecting the Python is unnecessary, but we’re a long way from that.
86+
87+
实际上,几乎无人检查由 Python 转换而成的机器码是否准确。这在一定程度上是因为 Python 语言规范的决定性。可以设想,将来 GitHub Copilot 的对话准确率如此之高,以致于审查 Python 代码将变得非必需,但距离那一天我们还有很长的路要走。

chapter-1/103.md

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,38 @@
11
---
22
idxx: xx
3-
title: "[译] [103] How Copilot changes how we learn to program"
3+
title: "[译] [103] Copilot 如何改变我们学习编程的方式"
44
---
55

66

77
## 1.3 How Copilot changes how we learn to program
88

9+
## 1.3 Copilot 如何改变我们学习编程的方式
10+
911
To illustrate how learning to program changes in the presence of an AI Assistant, we want to show you how powerful Copilot is at solving a programming task typically given to students in the middle of a programming course or in a book on how to program.
1012

13+
为了阐明 AI 辅助下学习编程方式的变化,我们将展示 GitHub Copilot 解决典型编程任务的强大功能,这类任务通常会在编程课程中期或编程入门书籍中给出。
14+
15+
1116
When learning how to program in the past, learners often spent most of their time learning how to work with the syntax and basic structure of programs. Being able to write a program from scratch (line-by-line), like the one we’ll show you below, is seen as the culmination of all of their learning. Before we dive into the problem, we need to be clear: many new programmers cannot write the code to solve this problem despite the fact most programming instructors (and book authors) think that new programmers should be able to do so. Here are the instructions for one version of this problem \[6\].
1217

18+
在过去,学习编程的过程中,学习者往往需要花费大量时间掌握程序的语法和基础结构。能够从零开始(逐行)编写程序,如下面即将向你展示的示例,被认为是学习过程的顶峰。然而,在我们深入探讨这个问题之前,有一点需要明确:虽然多数编程导师和书籍作者认为新手程序员应该有能力做到这一点,但实际上许多新手程序员却无法编写代码解决此类问题。以下是该问题一个版本的指示 \[6\]
19+
1320
“Write a program that will read the amount of rainfall for each day. A negative value of rainfall should be rejected since this is invalid and inadmissible. The program should print out the number of valid recorded days, the number of rainy days, the rainfall over the period, and the maximum amount of rain that fell on any one day. Use a sentinel value of 9999 to terminate the program.”
1421

22+
“编写一个程序,读取每天的降雨量。降雨量的负值应该被拒绝,因为这是无效且不可接受的。程序应该打印出有效记录天数、下雨天数、该时期的降雨总量以及任意一天降下的最大雨量。使用 9999 作为哨兵值来终止程序。”
23+
1524
If you have tried to learn to program before, this kind of problem statement may be familiar to you, and you may have struggled to solve such a problem.
1625

17-
26+
如果你以前尝试过学习编程,这种类型的问题描述可能对你并不陌生,你可能在解决此类问题时遭遇过挑战。
1827

1928
But now, if we give exactly this prompt to Copilot, we get the following Python code as a result. (Remember from the Introduction that Copilot is nondeterministic, so if we ask it again, we might get different code!)
2029

30+
但现在,如果我们将这个确切的提示词交给 Copilot,我们得到了以下的 Python 代码作为结果。(请记得引言中提到的,Copilot 是非确定性的,所以如果我们再次提问,可能会得到不同的代码!)
2131

2232

23-
**Listing 1.1 Copilot code that solves the classic rainfall problem.**
33+
> Listing 1.1 Copilot code that solves the classic rainfall problem.
34+
35+
> 清单 1.1 Copilot 解决经典降雨问题的代码。
2436
2537
```python
2638
rainfall = 0
@@ -31,16 +43,16 @@ max_rainfall = 0
3143
rainfall = int(input("Enter the amount of rainfall for the day: "))
3244
while rainfall != 9999:
3345
if rainfall < 0:
34-
print("Invalid rainfall amount. Please try again.")
35-
rainfall = int(input("Enter the amount of rainfall for the day: ")
46+
print("Invalid rainfall amount. Please try again.")
47+
rainfall = int(input("Enter the amount of rainfall for the day: ")
3648
else:
37-
num_valid_days += 1
38-
total_rainfall += rainfall
39-
if rainfall > 0:
40-
num_rainy_days += 1
41-
if rainfall > max_rainfall:
42-
max_rainfall = rainfall
43-
rainfall = int(input("Enter the amount of rainfall for the day: ")
49+
num_valid_days += 1
50+
total_rainfall += rainfall
51+
if rainfall > 0:
52+
num_rainy_days += 1
53+
if rainfall > max_rainfall:
54+
max_rainfall = rainfall
55+
rainfall = int(input("Enter the amount of rainfall for the day: ")
4456
print("Number of valid days:", num_valid_days)
4557
print("Number of rainy days:", num_rainy_days)
4658
print("Total rainfall over the period:", total_rainfall)
@@ -50,6 +62,13 @@ print("Maximum amount of rain that fell on any one day:", max_rainfall)
5062

5163
We’re not expecting you to have any intuition right now that this code is good. But it is. As Computer Science Professors, we’d grade this code very highly.
5264

65+
我们目前并不指望你能直觉上判断这段代码的优劣。但事实上,它是非常好的。作为计算机科学的教授,我们会给这段代码打上很高的分数。
66+
67+
5368
People learning to program used to spend weeks or months to get to a point where they could write programs like this. Now Copilot can offer code immediately. As we’ll see in the rest of the book, we still need to work to verify that this code is correct because Copilot can make mistakes. However, we don’t need to write it from scratch anymore. We believe this successful interaction with Copilot signals the end of the way that we have historically taught and learned programming.
5469

70+
以往,学习编程的人们可能需要花费几周甚至几个月的时间才能编写出类似这样的程序。如今,Copilot 能够立即提供代码。正如我们将在本书其余部分看到的,我们仍需努力以验证这段代码的正确性,因为 Copilot 有可能犯错。但我们不再需要从零开始编写代码。我们相信,这次与 Copilot 的成功互动预示着我们过去教学和学习编程方式的终结。
71+
5572
You, as someone interested in learning how to program, simply don’t need to struggle with syntax, control flow, and the host of other Python concepts needed to write code like this as you had to in the past. Sure, we are going to learn about those concepts in this book, but not so that you can demonstrate your understanding by writing code from scratch that Copilot can produce easily. No, we’ll learn those concepts only inasmuch as they help us solve meaningful problems and interact productively with Copilot. **Instead, you get to learn how to write larger, more meaningful software faster, because of how an AI-Assistant fundamentally changes the skills needed to learn to program.**
73+
74+
作为一个有志于学习编程的人,你不必再像以往那样,为了掌握语法、控制流程以及编写类似代码所需的诸多 Python 概念而苦苦挣扎。诚然,我们会在本书中讲解这些概念,但目的不是让你通过从零开始编写 Copilot 能轻而易举输出的代码来展示你的理解。不,我们学习这些概念,仅仅是为了它们能帮助我们解决实际问题,并与 Copilot 产生有成效的互动。**反过来,你将因为 AI 助手从根本上改变了学习编程所需的技能,而学会如何更快地编写规模更大、意义更深远的软件。**

0 commit comments

Comments
 (0)