Skip to content

Commit e8ccf29

Browse files
committed
feat: add raw chapter(s)
1 parent db9b857 commit e8ccf29

File tree

6 files changed

+196
-0
lines changed

6 files changed

+196
-0
lines changed

chapter-1/102.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
---
2+
idxx: xx
3+
title: "[译] [102] About the technology"
4+
---
5+
6+
7+
## 1.2 About the technology
8+
9+
We’ll be using two main technologies in this book: Python and GitHub Copilot.
10+
11+
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.
12+
13+
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!
14+
15+
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+
17+
**Figure 1.1 Your Python program goes through several steps before you see the output on your screen**
18+
19+
![](chapter-1.files/chapter-16764.png)
20+
21+
#### Copilot, your AI Assistant
22+
23+
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+
25+
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+
27+
#### How Copilot works behind the scenes-—in 30 seconds
28+
29+
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.
30+
31+
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.
32+
33+
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.
34+
35+
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.
36+
37+
38+
39+
Figure 1.2 will give you an idea of how Copilot goes from prompt to program.
40+
41+
**Figure 1.2 Going from prompt to program with Copilot**
42+
43+
![](chapter-1.files/chapter-19302.png)
44+
45+
46+
47+
48+
49+
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.
50+
51+
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.

chapter-1/103.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
---
2+
idxx: xx
3+
title: "[译] [103] How Copilot changes how we learn to program"
4+
---
5+
6+
7+
## 1.3 How Copilot changes how we learn to program
8+
9+
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+
11+
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\].
12+
13+
“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.”
14+
15+
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+
17+
18+
19+
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!)
20+
21+
22+
23+
**Listing 1.1 Copilot code that solves the classic rainfall problem.**
24+
25+
```python
26+
rainfall = 0
27+
total_rainfall = 0
28+
num_rainy_days = 0
29+
num_valid_days = 0
30+
max_rainfall = 0
31+
rainfall = int(input("Enter the amount of rainfall for the day: "))
32+
while rainfall != 9999:
33+
if rainfall < 0:
34+
print("Invalid rainfall amount. Please try again.")
35+
rainfall = int(input("Enter the amount of rainfall for the day: ")
36+
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: ")
44+
print("Number of valid days:", num_valid_days)
45+
print("Number of rainy days:", num_rainy_days)
46+
print("Total rainfall over the period:", total_rainfall)
47+
print("Maximum amount of rain that fell on any one day:", max_rainfall)
48+
```
49+
50+
51+
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.
52+
53+
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.
54+
55+
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.**

chapter-1/104.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
---
2+
idxx: xx
3+
title: "[译] [104] What else can Copilot do for us?"
4+
---
5+
6+
7+
## 1.4 What else can Copilot do for us?
8+
9+
As we’ve seen, we can use Copilot to write Python code for us starting from an English description of what we want. Programmers use the word _syntax_ to refer to the symbols and words that are valid in a given language. So, we can say that Copilot takes a description in English syntax and gives us back code in Python syntax. That's a big win, because learning programming syntax has historically been a major stumbling block for new programmers. What kind of bracket— \[, (, or { —am I supposed to use here? Do I need indentation here or not? What's the order that we're supposed to write these things: x and then y, or y and then x?
10+
11+
Such questions abound and let's be honest: it's uninteresting stuff. Who cares about this when all we want to do is write a program to make something happen? Copilot can help free us from the tedium of syntax. We see this as an important step to help more people successfully write programs, and we look forward to the day when this artificial barrier is completely removed. For now, we still need Python syntax, but at least Copilot helps us with it.
12+
13+
But that's not all Copilot can do. Here are some associated—and no less important—tasks where Copilot can help us:
14+
15+
* **Explaining code**. When Copilot generates Python code for us, we’ll need to determine whether that code does what we want. Again, as we said above, Copilot is going to make mistakes. We’re not interested in teaching you every nuance of how Python works (that’s the old model of programming). We _are_ going to teach you how to read Python code to gain an overall understanding of what it does. But we’re also going to use the feature of Copilot that explains code to you in English. When you finish with this book and our explanations, you’ll still have Copilot available to help you understand that next bit of gnarly code that it gives you.
16+
17+
* **Making code easier to understand**. There are many different ways to write code to accomplish the same task. Some of them may be easier to understand than others. Copilot has a tool that can reorganize your code to make it easier for you to work with. For example, code that’s easier to read is often easier to enhance or fix when needed.
18+
19+
* **Fixing bugs**. A _bug_ is a mistake made when writing a program that can result in the program doing the wrong thing. Sometimes, you’ll have some Python code, and it almost works, or works almost always but not in one specific circumstance. If you’ve listened to programmers talk, you may have heard the common story where a programmer would spend hours only to finally remove one = symbol that was making their program fail. Not a fun few hours! In these cases, you can try the Copilot feature that helps to automatically find and fix the bug in the program.

chapter-1/105.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
idxx: xx
3+
title: "[译] [105] Risks and challenges of using Copilot"
4+
---
5+
6+
7+
## 1.5 Risks and challenges of using Copilot
8+
9+
Now that we're all pumped up about getting Copilot to write code for us, we need to talk about the dangers inherent in using AI Assistants. See references
10+
11+
\[2\] and \[3\] for elaboration on some of these points.
12+
13+
**Copyright**. As we discussed above, Copilot is trained on human-written code. More specifically, it was trained using millions of GitHub repositories containing open-source code. One worry is that Copilot will “steal” that code and give it to us. In our experience, Copilot doesn't often suggest a large chunk of someone else’s code, but that possibility is there. Even if the code that Copilot gives us is a melding and transformation of various bits of other people's code, there may still be licensing issues. For example, who owns the code produced by Copilot? There is currently no consensus on the answer.
14+
15+
The Copilot team is adding features to help; for example, Copilot will be able to tell you whether the code that it produced is similar to already-existing code and what the license is on that code \[4\]. Learning and experimenting on your own is great, and we encourage that—but take the necessary care if you do intend to use this code for purposes beyond your home. We’re a bit vague here, and that’s intentional: it may take some time for laws to catch up to this new technology. It’s best to play it safe while these debates are had within society.
16+
17+
**Education**. As instructors of introductory programming courses ourselves, we have seen first-hand how well Copilot does on the types of assignments we have historically given our students. In one study \[5\], Copilot was asked to solve 166 common introductory programming tasks. And how well did it do? On its first attempt, it solved almost 50% of these problems. Give Copilot a little more information, and that number goes up to 80%. You have already seen for yourself how Copilot solves a standard introductory programming problem. Education needs to change in light of tools like Copilot, and instructors are currently discussing how these changes may look. Will students be allowed to use Copilot, and in what ways? How can Copilot help students learn? And what will programming assignments look like now?
18+
19+
**Code quality**. We need to be careful not to trust Copilot, especially with sensitive code or code that needs to be secure. Code written for medical devices, for example, or code that handles sensitive user data must always be thoroughly understood. It's tempting to ask Copilot for code, marvel at the code that it produces, and accept that code without scrutiny. But that code might be plain wrong. In this book, we will be working on code that will not be deployed at large, so while we will focus on getting correct code, we will not worry about the implications of using this code for broader purposes. In this book, we start building the foundations that you will need to independently determine whether code is correct.
20+
21+
**Code security.** As with code quality, code security is absolutely not assured when we get code from Copilot. For example, if we were working with user data, getting code from Copilot is not enough. We would need to perform security audits and have expertise to determine that the code is secure. Again, though, we will not be using code from Copilot in real-world scenarios.
22+
23+
Therefore, we will not be focusing on security concerns.
24+
25+
**Not an expert**. One of the markers of being an expert is awareness of what one knows and, equally importantly, what one doesn't. Experts are also often able to state how confident they are in their response; and, if they are not confident enough, they will learn further until they know that they know. Copilot, and LLMs more generally, do not do this. You ask them a question, and they answer, plain as that. They will confabulate if necessary. They will mix bits of truth with bits of garbage into a plausible sounding but overall nonsensical response. For example, we have seen LLMs fabricate obituaries for people who are alive, which doesn’t make any sense, yet the “obituaries” do contain elements of truth about people’s lives. When asked why an abacus can perform math faster than a computer, we have seen LLMs come up with responses—something about abacuses being mechanical and therefore necessarily the fastest. There is ongoing work in this area for LLMs to be able to say, "sorry, no, I don't know this," but we are not there yet. They don't know what they don't know and that means they need supervision.
26+
27+
**Bias**. LLMs will reproduce the same biases present in the data on which they were trained. If you ask Copilot to generate a list of names, it will generate primarily English names. If you ask for a graph, it may produce a graph that doesn’t consider perceptual differences among humans. And if you ask for code, it may produce code in a style reminiscent of how dominant groups write code. (After all, the dominant groups wrote most of the code in the world, and Copilot is trained on that code.) Computer science and software engineering have long suffered with a lack of diversity. We cannot afford to stifle diversity further, and indeed we need to reverse the trend. We need to let more people in and allow them to express themselves in their own ways. How this will be handled with tools like Copilot is currently being worked out and is of crucial importance for the future of programming. However, we believe Copilot has the potential to improve diversity by lowering barriers for entry into the field.

chapter-1/106.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
idxx: xx
3+
title: "[译] [106] The skills we need"
4+
---
5+
6+
7+
## 1.6 The skills we need
8+
9+
If Copilot can write our code, explain it, and fix bugs in it, are we just done? Do we just tell Copilot what to do and celebrate our pure awesomeness?
10+
11+
No. It's true that some of the skills that programmers rely upon (writing correct syntax, for example) will decrease in importance. But other skills remain critical. For example, you cannot throw a huge task at Copilot like,
12+
13+
14+
15+
"Make a video game. Oh, and make it fun." Copilot will fail. Instead, we need to break down such a large problem into smaller tasks that Copilot can help us with. And how do we break a problem down like that? Not easily, it turns out. This is a key skill that humans need to hone in their conversations with tools like Copilot, and a skill that we will teach throughout the book.
16+
17+
Other skills, believe it or not, may take on even more importance with Copilot than without. Testing code has always been a critical task in writing code that works. We know a lot about testing code written by humans, because we know where to look for typical problems. We know that humans often make programming errors at the boundaries of values. For example, if we wrote a program to multiply two numbers, it’s likely that we’d get it right with most values but maybe not for when one value is 0. What about code written by AI, where twenty lines of flawless code could hide one line so absurd that we likely wouldn't expect it there? We don’t have experience with that. We need to test even more carefully than before.
18+
19+
Finally, some required skills are entirely new. The main one here is called _prompt engineering_, which involves how to tell Copilot what to do. When we're asking Copilot to write some code, we're using a _prompt_ to make the request. It's true that we can use English to write that prompt and ask for what we want, but that alone isn't enough. We need to be very precise if we want Copilot to have any chance of doing the right thing. And even when we are precise, Copilot may still do the wrong thing. In that case, we need to first identify that Copilot has indeed made a mistake, and then tweak our description to hopefully nudge it in the right direction. In our experience, seemingly minor changes to the prompt can have outsized effects on what Copilot produces.
20+
21+
In this book, we will teach you all of these skills.

0 commit comments

Comments
 (0)