You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: chapter-1/102.md
+43-7Lines changed: 43 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -6,46 +6,82 @@ title: "[译] [102] About the technology"
6
6
7
7
## 1.2 About the technology
8
8
9
+
## 1.2 技术简介
10
+
9
11
We’ll be using two main technologies in this book: Python and GitHub Copilot.
10
12
13
+
在这本书中,我们将重点介绍两项主要技术:Python 和 GitHub Copilot。
14
+
11
15
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.
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!
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.
16
24
17
-
**Figure 1.1 Your Python program goes through several steps before you see the output on your screen**
> Figure 1.1 Your Python program goes through several steps before you see the output on your screen
28
+
>
29
+
> 
30
+
31
+
> 图 1.1 在你的屏幕上看到输出之前,你的 Python 程序需要经历几个步骤
18
32
19
-

20
33
21
34
#### Copilot, your AI Assistant
22
35
36
+
#### GitHub Copilot,你的 AI 助手
37
+
23
38
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.
24
39
40
+
什么是**AI 助手**?AI 助手是一种人工智能(AI)代理,它帮助你完成任务。你可能在家中使用亚马逊的 Alexa 设备,或拥有一部集成了 Siri 的 iPhone——这些都属于 AI 助手。这类助手能帮你订购生鲜、查询天气,或是确认那位在《哈利·波特》电影中饰演贝拉特里克斯的女演员确实也参演了《搏击俱乐部》。AI 助手只不过是一个响应人类语音和文本输入的计算机程序,并以类人的方式给出答案。
41
+
25
42
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.
26
43
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
+
27
48
#### How Copilot works behind the scenes-—in 30 seconds
28
49
50
+
#### GitHub Copilot 幕后工作原理——仅用 30 秒
51
+
29
52
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.
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.
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.
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.
Figure 1.2 will give you an idea of how Copilot goes from prompt to program.
40
70
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
+
>
42
76
43
-

77
+
> 图 1.2 使用 GitHub Copilot 从提示词生成程序
44
78
45
-
46
79
47
-
48
80
49
81
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.
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.
title: "[译] [103] How Copilot changes how we learn to program"
3
+
title: "[译] [103] Copilot 如何改变我们学习编程的方式"
4
4
---
5
5
6
6
7
7
## 1.3 How Copilot changes how we learn to program
8
8
9
+
## 1.3 Copilot 如何改变我们学习编程的方式
10
+
9
11
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.
10
12
13
+
为了阐明 AI 辅助下学习编程方式的变化,我们将展示 GitHub Copilot 解决典型编程任务的强大功能,这类任务通常会在编程课程中期或编程入门书籍中给出。
14
+
15
+
11
16
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\].
“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.”
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.
16
25
17
-
26
+
如果你以前尝试过学习编程,这种类型的问题描述可能对你并不陌生,你可能在解决此类问题时遭遇过挑战。
18
27
19
28
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!)
rainfall =int(input("Enter the amount of rainfall for the day: ")
36
48
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: ")
44
56
print("Number of valid days:", num_valid_days)
45
57
print("Number of rainy days:", num_rainy_days)
46
58
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)
50
62
51
63
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.
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.
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