Skip to content

[译] [104] Copilot 还可以做什么 #6

Open
@cssmagic

Description

@cssmagic

1.4 What else can Copilot do for us?

1.4 Copilot 还可以做什么

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? What’s the order in which we’re supposed to write these things: x and then y, or y and then x?

正如我们所见,Copilot 能够根据我们用英语描述的需求来编写 Python 代码。编程领域里的 “语法” 是指在当前编程语言中合法的符号和词汇。因此,我们可以这样说:Copilot 接收符合英语语法的描述,生成符合 Python 语法的代码。这无疑是一大福音,因为学习编程语法历来是新手程序员的头号难关。这里应该使用哪种括号——是使用方括号 [、圆括号 ( 还是花括号 {?这里需要缩进吗?这些东西的顺序应该怎么排:是先 x 后 y,还是先 y 后 x?

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.

这样的问题层出不穷,坦白说:这些事情确实有些枯燥无味。如果我们的目标完全是通编写程序来实现某些功能,那这些细节又有谁会去在意呢?Copilot 能够让我们从语法的繁琐枯燥中解放出来。我们把这视为帮助更多人掌握编程的关键一步,并期待有一天,这种人为设定的障碍能够彻底消除。目前,我们依然需要学习 Python 语法,但至少有了 Copilot 的协助,我们不再是一个人战斗了。

But that’s not all Copilot can do. Here are some associated—and no less important—tasks Copilot can help us with:

但 Copilot 能做的远不止这些。以下是一些与编程紧密相关且同样至关重要的任务,Copilot 也能够帮到我们:

  • 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 previously, Copilot is going to make mistakes. Although 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. 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.

  • 解释代码。当 Copilot 为我们生成 Python 代码时,我们需要判断这些代码是否符合我们的预期。正如之前所述,Copilot 可能会犯错。我们不打算深入讲述 Python 的每一个细节(那属于过时的编程方式)。我们必须教会你如何阅读 Python 代码,以便全面理解其功能。同时,我们还将利用 Copilot 的代码解释功能,用自然语言为你讲解代码。读完本书之后,你仍然可以依靠 Copilot 来帮你理解它为你生成的那些复杂代码。

  • Making code easier to understand—There are different ways to write code to accomplish the same task. Some may be easier to understand than others. Copilot has a tool that can reorganize your code to make it easier to work with. For example, code that’s easier to read is often easier to enhance or fix when needed.

  • 让代码更易理解。完成一项任务的编程方法往往不止一种,其中某些方法可能比其他方法更容易理解。Copilot 提供了一种工具,可以重组你的代码,让它更加易于使用。举例来说,易于阅读的代码通常在需要扩展或修正时也更加易于处理。

  • Fixing bugs—A bug is a mistake made when writing a program that can result in the program doing the wrong thing. Sometimes, your Python code 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.

  • 修复 bug。所谓 “bug”,是指在编写程序时引入的错误,这些错误会导致程序执行不符合预期的操作。它可能导致你的 Python 代码不能完全正常运行,也可能导致代码在大多数情况下正常,但在特定场景下出问题。如果你曾听过程序员聊天,或许会听到这样一种普遍的遭遇:某位程序员花费数小时进行排查,结果发现导致程序挂掉的只是一个多余的等号。这种经历苦不堪言!以后再遇到这类问题,你就可以用上 Copilot 的这项功能,它能够自动帮助你定位并修复程序中的 bug。

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions