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

[译] [101] 我们如何与计算机对话 #3

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

[译] [101] 我们如何与计算机对话 #3

cssmagic opened this issue Feb 27, 2024 · 0 comments
Labels

Comments

@cssmagic
Copy link
Owner

cssmagic commented Feb 27, 2024

1.1 How we talk to computers

1.1 我们如何与计算机对话

Would you be happy if we started by asking you to read and understand this?

如果我们在开头要求你阅读并理解的是以下内容,你的感受会怎么样?

section .text
global _start
_start:
    mov ecx, 10
    mov eax, '0'
    l1:
    mov [num], eax
    mov eax, 4
    mov ebx, 1
    push ecx
    mov ecx, num
    mov edx, 1
    int 0x80
    mov eax, [num]
    inc eax
    pop ecx
    loop l1
    mov eax, 1
    int 0x80
section .bss
    num resb 1

That monstrosity prints out the numbers from 0 to 9. It's written using code in assembly language, a low-level programming language. Low-level programming languages, as you can see, are very far from languages that humans can easily read and write. They’re designed for computers, not humans.

这段 “天书” 能够打印出 0~9 的数字。它是使用汇编语言编写的,是一种低级编程语言。正如你所见,低级编程语言与我们能够轻松读写的语言相去甚远。它们主要是为计算机而设计的,并非面向人类。

No one wants to write programs like that. But, especially in the past, it was sometimes necessary. Programmers could use it to do exactly what they wanted the computer to do, down to individual instructions. This level of control was needed in order to squeeze every bit of performance out of underpowered computers. For example, the most speed-critical pieces of 1990s computer games such as Doom and Quake were written in assembly language like the code above. It simply wouldn't have been possible to make those games otherwise.

没人愿意写这种程序。但在早期,这是不得已而为之。程序员能借此控制每一条指令,让计算机精确实现他们的意图。这种控制层次是必须的,为的是从计算能力不足的电脑中挤出每一点性能。90 年代电子游戏中对速度要求极高的部分,比如《毁灭战士(Doom)》和《雷神之锤(Quake)》,都是采用上面那种汇编语言编写的。否则,根本无法制作出这些游戏。

Making it a little easier

让难度降低一点儿

Okay, no more of that. Let's move on. Would you be happier with this?

好的,汇编到此为止。我们继续。以下这段代码感觉如何?

for num in range(0, 9):
    print(num)

This, by contrast, is code in the Python language and is what many programmers use these days. Unlike assembly language, which is a low-level language, Python is considered a high-level language because it's much closer to natural language. Even though you don't know about Python code yet, you might be able to guess what this program is trying to do. The first line looks like it's doing something with the range of numbers from 0 to 9. The second line is printing something. It may not be too hard for you to believe that this program, just like the assembly language monstrosity, is supposed to print the numbers from 0 to 9. Unfortunately, something is wrong with it.

对上面不同,这段代码是用 Python 语言编写的,目前许多程序员都在使用它。不同于汇编语言这样的低级语言,Python 被视为高级语言,因为它与自然语言的距离更近。即便你对 Python 代码尚无了解,你或许也能猜出这段程序的目的。第一行似乎在处理 0~9 的数字范围。第二行在进行打印操作。不难理解,这段程序的目的与上面那段汇编语言天书一样,是要打印出 0~9 的数字。不过很可惜,程序中存在错误。

While this code is closer to English, it isn’t English. It's a programming language that, like assembly language, has specific rules. As in the code above, misunderstanding the details of those rules can result in a broken program.

尽管这种代码更接近英语,但它并非英语。它还是一种编程语言,就像汇编语言一样,有着特定的规则。正如上面的代码所示,误解这些规则的细节可能会导致程序错误。

The holy grail of communicating with a computer is to do so in a natural language such as English. We've been talking to computers using various programming languages over the past 70 years not because we want to, but because we have to. Computers were simply not powerful enough for the vagaries and idiosyncrasies of a language like English. Our programming languages improved—-from symbol soup assembly language to Python, for example—-but they are still computer languages, not natural languages.

与计算机沟通的终极目标是能够使用诸如英语这样的自然语言。在过去的 70 年中,我们之所以使用各种编程语言与计算机对话,并非出于喜好,而是迫于无奈。计算机的计算能力不足以应对英语等自然语言的复杂性和特异性。我们的编程语言虽然一直在演进——比如从天书一般的汇编语言发展到了 Python——但它们依旧是计算机语言,并非自然语言。

This is changing.

然而,这种情况正在发生变化。

Making it a lot easier

让难度降低一大截

Using an AI assistant, we can now ask for what we want in English and have the computer code written for us in response. To get a correct Python program that does actually print the numbers from 0 to 9, we can ask our AI assistant (Copilot) in normal English language like this:

有了 AI 助手,我们现在可以用英文明确提出我们的需求,并让计算机相应地编写代码。如果我们希望得到一段正确 Python 程序,打印出 0~9 数字,我们可以用日常英语向我们的 AI 助手(Copilot)发出指令:

# Output the numbers from 0 to 9
# 打印出 0~9 的数字

Copilot might respond to this prompt by generating something like this:

对此,Copilot 可能会根据这一指令生成如下代码:

for i in range(10):
    print(i)

Unlike the example we showed you before, this piece of Python code actually works!

不同于我们在上面看到的那个示例,这段 Python 代码确实能够正常运行!

AI coding assistants can be used to help people write code. In this book, we will learn how to use Copilot to write code for us. We will ask for what we want in English, and we will get the code back in Python.

AI 编程助手能够帮助人们编写代码。在本书中,我们会探索如何利用 Copilot 来编写代码。我们只需用英语描述我们的需求,便能收到用 Python 编写的代码作为回应。

More than that, we'll be able to use Copilot as a seamless part of our workflow. Without tools like Copilot, programmers routinely have two windows open: the one where they write code and the other where they ask on Google how to write code. This second window would have Google search results, Python documentation, or forums of programmers talking about how to write code to solve that particular problem. They're often pasting code from these results into their code, then tweaking it slightly for their context, trying alternatives, and so on. This has become a way of life for programmers—but you can imagine the inefficiency here. By some estimates, up to 35% of programmer’s time may be spent searching for code [1], and much of the code that is found is not readily usable. This will be much improved with Copilot helping us write our code.

更重要的是,我们将能够把 Copilot 无缝集成到我们的工作流程中。在没有 Copilot 这类工具的情况下,程序员通常需要同时打开两个窗口:一个用于编写代码,另一个用于在 Google 上查询编码方法。这第二个窗口可能充斥着 Google 搜索结果、Python 文档或是程序员论坛上讨论如何解决特定编码问题的帖子。他们经常需要从这些结果中复制代码到自己的项目中,随后进行适当的调整以符合自己的应用场景,尝试不同的解决方案等等。这已经成为了程序员生活的一部分——但你可以想象这种工作方式的效率有多低。据估计,程序员可能有多达 35% 的时间花在搜索代码上[1],而且找到的代码并不是立即可用的。有了 Copilot 协助我们编写代码,这种情况将得到显著改善。

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

No branches or pull requests

1 participant