Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

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

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

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

在过去,学习编程的过程中,学习者往往需要花费大量时间掌握程序的语法和基础结构。能够从零开始(逐行)编写程序,如下面即将向你展示的示例,被认为是学习过程的顶峰。然而,在我们深入探讨这个问题之前,有一点需要明确:虽然多数编程导师和书籍作者认为新手程序员应该有能力做到这一点,但实际上许多新手程序员却无法编写代码解决此类问题。以下是该问题一个版本的指示 [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 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!)

但现在,如果我们将这个确切的提示词交给 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 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.

以往,学习编程的人们可能需要花费几周甚至几个月的时间才能编写出类似这样的程序。如今,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 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.

作为一个有志于学习编程的人,你不必再像以往那样,为了掌握语法、控制流程以及编写类似代码所需的诸多 Python 概念而苦苦挣扎。诚然,我们会在本书中讲解这些概念,但目的不是让你通过从零开始编写 Copilot 能轻而易举输出的代码来展示你的理解。不,我们学习这些概念,仅仅是为了它们能帮助我们解决实际问题,并与 Copilot 产生有成效的互动。反过来,你将因为 AI 助手从根本上改变了学习编程所需的技能,而学会如何更快地编写规模更大、意义更深远的软件。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant