Skip to content

[译] [103] Copilot 如何改变我们学习编程的方式 #5

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

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

[译] [103] Copilot 如何改变我们学习编程的方式 #5

cssmagic opened this issue Feb 28, 2024 · 0 comments

Comments

@cssmagic
Copy link
Owner

cssmagic commented Feb 28, 2024

1.3 How Copilot changes how we learn to program

1.3 Copilot 如何改变我们学习编程的方式

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.

为了阐明 AI 将如何改变编程学习方式,我们将向你展示 Copilot 在解决编程任务方面的强大能力,而这些任务正是选自编程教材中分派给学生的题目。

When learning how to program in the past, learners often spent most of their time working with the syntax and basic structure of programs. Writing a program from scratch (line by line), like the one we’ll show you next, 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]:

在以往的编程学习过程中,学习者们往往将大部分时间投入到程序的语法和基础结构上。能做到从零开始逐行手写一段完整的程序(比如下面即将展示的这个例子),通常就是他们学习编程的最终目标了。然而,在深入探讨具体的编程题目之前,我们必须指出:尽管大多数编程教育者和书籍作者都认为新手程序员应该能解决此类题目,但实际上许多初学者根本做不到。下面列出的就是这类题目的一个代表 [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.”

编写一段程序来读取每天的降雨量。若降雨量为负值,则认为这是不合法且不可接受的,应予以排除。该程序应输出以下信息:有效记录的天数、下雨的天数、整个时间段内的总降雨量,以及任何单日的最大降雨量。程序以 9999 作为结束输入的警界值。

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. But now, if we give this exact 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!)

如果你以前尝试过学习编程,那么对于这种类型的题目应该并不陌生,而且你可能在解决此类问题时头疼不已。但现在,如果我们将这段明确的提示词交给 Copilot,我们得到以下 Python 代码作为结果。(我们在引言中曾提到,Copilot 的行为具有不确定性,所以如果我们再次提问,可能会得到不一样的代码!)

Listing 1.1 Copilot code that solves the classic rainfall problem
代码清单 1.1 Copilot 解决经典降雨问题的代码
rainfall = 0
total_rainfall = 0
num_rainy_days = 0
num_valid_days = 0
max_rainfall = 0
rainfall = int(input("Enter the amount of rainfall for the day: "))
while rainfall != 9999:
    if rainfall < 0:
        print("Invalid rainfall amount. Please try again.")
        rainfall = int(input("Enter the amount of rainfall for the day: "))
    else:
        num_valid_days += 1
        total_rainfall += rainfall
        if rainfall > 0:
            num_rainy_days += 1
        if rainfall > max_rainfall:
            max_rainfall = rainfall
        rainfall = int(input("Enter the amount of rainfall for the day: "))
print("Number of valid days:", num_valid_days)
print("Number of rainy days:", num_rainy_days)
print("Total rainfall over the period:", total_rainfall)
print("Maximum amount of rain that fell on any one day:", max_rainfall)

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 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 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.

以前学习编程的人们可能需要花费几周甚至几个月的时间才能写出这种水准的程序。而如今,Copilot 能够瞬间生成这样的代码。后续的章节会一直强调,我们仍然需要验证这些代码的正确性,因为 Copilot 有可能犯错。但我们再也不需要从零开始手写代码了。我们相信,与 Copilot 的这次成功互动,预示了我们过去教编程和学编程的方式已然终结。

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 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 because 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 programming.

作为一个有志于学习编程的人,你不必再像以往那样在语法、控制流程等众多 Python 概念上苦苦挣扎。诚然,我们会在本书中讲解这些概念,但目的不是让你通过从零开始手写代码来证明你已理解,因为 Copilot 已经能够轻松生成这些代码。我们学习这些概念,仅仅是因为它们有助于我们解决实际问题,并与 Copilot 进行更富有成效的互动。正是由于 AI 助手从根本上改变了学习编程所需的技能,你才能更快学会如何编写规模更庞大、意义更深远的软件。

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

No branches or pull requests

1 participant