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

[译] [033] 引言 #45

Open
cssmagic opened this issue Aug 7, 2024 · 0 comments
Open

[译] [033] 引言 #45

cssmagic opened this issue Aug 7, 2024 · 0 comments

Comments

@cssmagic
Copy link
Owner

cssmagic commented Aug 7, 2024

Introduction

引言

Software is essential today. It’s hard to think of any industry where software isn’t changing practically everything about how work is done. Manufacturing needs software to monitor production and shipping, let alone the robots that increasingly perform the actual task. Advertising, politics, and fitness, among others, are awash in big data and they routinely use software to make sense of it. Video games and movies are created using software. We could go on and on, but you get the point.

软件在当今社会扮演着至关重要的角色。很难找到一个不受软件影响、不因软件而改变的行业。制造业依靠软件来监控生产线和物流系统,更别提那些日益增多、执行具体操作的机器人了。在广告、政治、健身等多个领域,大数据无处不在,而这些行业正是通过软件来分析和理解这些数据的。视频游戏和电影的制作同样离不开软件的应用。这些例子数不胜数,足以说明软件的重要。

The result has been that more people than ever want to learn how to program. We’re not just talking about the computer science, computer engineering, and data science majors at universities who have been in a perpetual “enrollment crisis” for the past decade. We’re also talking about the scientist who needs to write software to evaluate their data, the office worker who wants to automate some of their tedious data processing tasks, and the hobbyist who wants to create a fun video game for their friends.

这一结果催生了一个显著的趋势:越来越多的人渴望学习编程。这不仅包括那些在大学中主修计算机科学、计算机工程和数据科学的学生,这些专业在过去十年一直“爆满”;同样也涵盖了那些需要编写软件来评估自己数据的科学家,希望将日常繁琐的数据任务自动化的办公室工作者,以及那些出于爱好,想要为朋友制作有趣电子游戏的业余爱好者。

Despite the desire to learn programming, there are decades of research in our field (computing education) that have identified many reasons for why learning to write software is hard. Even after you figure out how to solve the problem, you have to tell a machine how to accomplish it in a programming language whose rules are unforgiving. Granted, writing programs in a language like Python is substantially easier than in machine code using punch cards, but it’s still hard. We know it’s hard because we’ve seen the failure rates of introductory computer science courses. We’ve seen first-hand as we’ve watched motivated and intelligent students fail our courses, sometimes multiple times, before they succeed or, worse, give up.

尽管人们有着强烈的学习编程的愿望,但我们在算机教育领域的长期研究揭示,学习编写软件所面临众多难题。即便你已经掌握了解决问题的方法,你仍需向机器传达如何使用一种规则严格且不容有误的编程语言来实现目标。虽然使用 Python 这样的语言编写程序,相较于使用打孔卡的机器代码,其难度已大大降低,但学习之路依然充满挑战。我们之所以深知这一点,是因为我们亲眼见证了许多充满动力和智慧的学生在初级计算机科学课程中屡遭挫折,他们往往需要经历多次尝试,才能获得成功;更糟糕的是,不少人选择放弃。

But what if we could talk to computers in a better way? A way that doesn’t require us to know all the detailed syntax rules that trip up most novices. That era has just begun thanks to AI assistants like Copilot that offer intelligent code suggestions in the same way ChatGPT can write reasonable text when prompted. This book is for everyone who wants to learn how to write software in the AI assistant era. We’re excited to be on your learning journey with you.

想象一下,如果我们能够与计算机进行更自然的对话,而不必了解那些常常让初学者感到困惑的繁琐语法规则,那该多好。这一愿景已经随着像 Copilot 这样的 AI 助手的出现而逐步实现,它们能够提供智能的代码建议;同样,ChatGPT 也能够在接收到提示时撰写出合理的文本。这本书专为那些希望在 AI 助手时代掌握软件编写技能的人士设计,我们很激动能与你一同开启这段学习之旅。

AI assistants change how programming is done

AI 助手正在改变编程方式

We’ll introduce you to your AI assistant, Copilot, in chapter 1, but we want to give you a brief overview now. If you read the news headlines or even opinion pieces by lauded software engineering professionals talking about Copilot or ChatGPT, you’ve seen that opinions run the gamut. Some people say that AI assistants mean the end of all programming jobs. Others say that AI assistants are so hopelessly flawed you are better without them. These views of the world are at such extremes that it’s easy to poke holes in either argument. AI assistants learn from existing code, so if some new tool/technology is developed, humans will need to write the bulk of the initial code. As a recent article well expressed, there isn’t a lot (or any) code out there for quantum computers since they are still in their infancy [1]. So human programmers aren’t going away, at least not any time soon. At the same time, in our time working with Copilot, we’ve seen how powerful it is. Both of us have written software for decades and Copilot can often give us correct code much faster than we could write it on our own. To ignore such a powerful tool seems analogous to a carpenter refusing to use power tools.

我们会在第一章向你详细展示你的人工智能助手Copilot,但本文会先给你一个简要的介绍。如果你关注过新闻或软件工程专家对Copilot和ChatGPT的评论,你会发现意见分歧很大。一些人认为AI助手将导致编程工作消失,还有一些人则认为AI助手存在缺陷,没有它们反而更好。这些极端观点都容易受到质疑。AI助手通过学习现有代码来提供帮助,因此在新技术或工具出现时,人类程序员仍需编写大部分初始代码。正如一篇近期文章所指出的,由于量子计算机仍处于初期阶段,目前还没有大量的相关代码[1]。这意味着人类程序员在可预见的未来仍将扮演重要角色。然而,根据我们多年使用Copilot的经验,我们发现它非常强大。我们两人都有长达数十年的软件开发经验,Copilot常常能迅速输出比我们自己写的还要准确的代码。忽视这样一个强大的工具,就像一个木匠拒绝使用高效的电动工具一样不明智。

As educators, the opportunity to help people learn to write software is instantly apparent. Why should students spend so much time fighting with syntax when writing code from scratch when the code suggested by an AI assistant is almost always syntactically correct? Why should students have to reach out to professors, instructional staff, friends, or internet forums for help explaining what a section of code is doing when AI assistants are really good at explaining code (particularly for questions asked by novices)? And if AI assistants often write correct code when solving common programming problems (by learning from huge volumes of code written in the past), why shouldn’t students be using it to help them program?

作为教育者,我们深知帮助人们学习编写软件的重要性。学生为何要在从头编写代码时,花费大量时间与语法规则较劲,尤其是当 AI 助手几乎总能语法正确的代码建议时?当 AI 助手在解释代码方面表现出色,特别是对于初学者的问题,学生为何还需要求助于教授、教学人员、朋友或互联网论坛?而且,鉴于 AI 助手在解决常见编程问题时,能够通过学习过往的大量代码来编写出正确的代码,学生为什么不利用这一工具来辅助他们的编程学习呢?

Be warned that this doesn’t mean that writing software is now just easy and that we can entirely offload the skill of programming onto the AI. Instead, the skills to write good software are evolving. Skills like problem decomposition, code specification, code reading, and code testing have become even more important than they were in the past; skills like knowing library semantics and syntax become less important. We’ll say more about this in the next chapters, but this book will teach you the skills that matter going forward. These skills will be valuable whether you dabble in writing software from time to time or you are starting a career in software engineering.

请注意,这并不意味着编写软件现在就变得容易了,或者说我们可以完全将编程技能抛卸给人工智能。相反,编写优秀软件的技能正在发生变化。像问题分解、代码规范、代码阅读和代码测试这样的技能,比过去变得更加重要;而了解库的语义和语法等技能就相对没那么重要了。我们将在接下来的章节中更详细地讨论这一点,但这本书将传授给你面向未来的重要技能。无论你是偶尔涉足编写软件,还是开始软件工程领域的职业生涯,这些技能都将非常有价值。

Audience

本书受众

We have two primary audiences for the book. The first is everyone who has thought about writing software (and even tried and failed before) to make their lives better in some way. This includes the accountant who gets frustrated that their software can’t do what they want so they are left solving problems by hand. Or scientists who want to analyze their data quickly, but existing tools aren’t capable of doing what they want. We also imagine the office manager who feels limited by what their spreadsheet software can do and wants a better way to gain insight from their data. Additionally, we imagine the exec at a small company who wants to be notified when something is said publicly on social media about their company but can’t afford to pay a software engineering team to write the tool for them. And we imagine the hobbyist of any age who just wants to write software for fun—whether it be for making their own small video games, storytelling with pictures, or creating fun family photo collages. These are just some of the people who want to write software to improve some element of their professional or personal lives.

本书的目标读者主要分为两类。第一类是那些曾经考虑过通过编写软件来改善自己生活的人,尤其包括那些尝试过但未获成功的人士。例如,会计师可能因现有软件无法满足特定需求而不得不手工解决问题;科学家可能需要快速分析数据,却发现现有工具力不从心。我们还能想像到那些觉得电子表格软件功能有限,渴望更深入地洞察数据的办公室经理。同时,也有小公司的高管希望在社交媒体上获得关于公司讨论的通知,但又无力承担软件工程团队的人力成本。此外,还有那些出于兴趣而编写软件的业余爱好者,无论是为自己制作小型电子游戏,为孩子创作故事绘本,还是为家庭设计趣味照片墙,他们都希望通过编写软件来提升自己的工作或生活的方方面面。

The second is the student who is considering a career in software engineering or programming and wants to learn how to write software. They want to learn the basics and start creating interesting software, without the trappings of a classic computer science class. Certainly, there will be more courses or books that will follow this first book on the road to becoming a professional software developer, but this will hopefully be a fun and rewarding first step.

第二类目标读者是那些有意投身于软件工程或编程领域的学生,他们渴望学习编写软件的技能。他们希望能够掌握编程的基础知识,并着手创造富有吸引力的软件产品,但又不愿受限于传统计算机课程的条条框框。诚然,在通往专业软件开发者的职业道路上,他们可能还需要阅读更多的书籍和学习更多的课程,但本书无疑将成为他们旅程中既愉快又有益的第一步。

What we expect from you

我们对你的期望

This book requires no background whatsoever in programming. If you learned some programming and forgotten or it didn’t go well the first time, we think this is a great place to resume your learning.

本书无需任何编程基础。如果你曾学习过编程却日渐生疏,或者初次尝试并未如愿以偿,我们相信这里就是你重新启程的理想之地。

This book does require basic computer literacy. This means you should be comfortable installing software, copying files between folders, and opening files on your computer. If you don’t have those skills, you could still start this book, but realize there may be moments when you need to look to outside resources (e.g., YouTube videos on how to copy a file from one folder to another).

本书确实要求你具备基本的计算机操作能力。这指的是你应该能够轻松地在电脑上安装软件、在文件夹之间复制文件以及打开文件。如果你尚未掌握这些技能,同样可以阅读本书,不过在某些情况下,你可能需要借助外部资源(例如,通过视频网站来学习文件复制等操作)。

You’ll also need a computer where you have permission to install software so you can follow along and apply the ideas we’re learning. Any Windows, Mac, or Linux personal computer or laptop will work.

你还需要有一台有权限安装软件的电脑,以便跟随我们的教程并实践所学的知识。无论是 Windows、Mac 还是 Linux 系统的台式机或笔记本电脑,都是可以的。

What you will be able to do after reading this book

读完本书后你能做到的事情

In this book, we’re going to teach you how to use Copilot to write Python code. We’ll teach you how to identify whether that code does what you want, and what to do when it doesn’t. We’ll teach you enough about Python to be able to read it for a general understanding of what it does and whether it is doing something potentially meaningful.

本书将向你传授如何借助 Copilot 来编写 Python 代码。我们不仅会教你辨别代码是否满足了你的需求,还会告诉你当代码未能如愿时如何应对。你还将学到足够深的 Python 知识,从而理解代码的基本功能,并能判断代码是否在以合理的方式运行。

We won’t, however, teach you how to program in Python entirely from scratch. You’ll be in a good position to learn to do that with other resources following this book if you like—but for many tasks, as we will show you, it may not be necessary.

尽管本书不包括完全零基础的 Python 编程教学,但阅读完本书后,你将具备利用其他资源继续学习的坚实基础,如果你也有此意向的话——不过,正如本书所展示的那样,对于许多实际任务而言,从头学起可能并非必需。

We don’t know exactly what it will look like to be a professional programmer or software engineer in light of AI coding assistants. That role is already changing and will change further as the AI technology improves. For now, we will say that you need more than this book to be a professional programmer or software engineer. You’ll need to know a great deal more about Python and other computer science topics to get there.

我们目前尚不确定,在人工智能编程助手的影响下,专业程序员或软件工程师的角色将会如何变化。随着人工智能技术的持续进步,这一角色的定义也会不断演变。目前,我们可以肯定的是,要成为一名专业的程序员或软件工程师,本书所提供的知识将是很好的基础,但还远远不够。你需要对 Python 语言以及计算机科学的其他关键领域有更深入的了解和掌握。

The good news is that learning how to program using Copilot will make you capable of writing basic software to address common needs. The software will be more complex than what we typically teach in an introductory course, and you’ll be able to write these useful programs without banging your head on syntax or spending months learning just Python. If you wish to continue learning about writing professional software, this will be your first step toward mastery.

不过令人欣慰是,能过 Copilot 学习编程,你将能写满足常见需求的基础软件,而这些软件比我们在大学的编程入门课程里所教授的内容更为复杂。你将能够轻松写出这些实用程序,无需在语法问题上苦苦纠缠,也不必单在 Python 身上就花费数月之久。如果你有意继续探索更专业的软件开发知识,这将是你迈向精通之路的坚实第一步。

By the end of this book, you will be able to write basic software capable of data analysis, automating repetitive tasks, and creating simple games, among many others.

通过本书的学习,你将能够编写自己所需的基本软件,涵盖数据分析、自动化执行重复性任务,甚至开发小游戏等众多场景。

The challenge in working with AI assistants

与 AI 助手协作的挑战

We expect you’re ready to jump into a technology that is maturing and changing quickly. What you see from Copilot may not match what you see in the book. Copilot is advancing and changing daily, and we cannot possibly keep up to the minute with such a moving target. More than that, Copilot is nondeterministic, which means that if you ask it to solve the same task multiple times, it may not give you the same code each time. And sometimes you’ll get correct code for a task, but then if you ask again, you get code that is not correct. So even if you use the exact same prompts we do, you will likely see different code responses than we do. Much of this book is devoted to ensuring you learn how to determine whether the answer from Copilot is right or not and, if it isn’t, how to fix it. In short, we hope you’re ready for what it means to learn on the leading edge of technology.

我们期待你已经准备好投身于这项快速发展且不断成熟的技术领域。**你在 Copilot 中实际获得的结果可能与本书的描述存在差异。**Copilot 每天都在升级和变化,我们无法实时跟进这样一个不断移动的目标。更为关键的是,Copilot 的行为具有不确定性,也就是说,当你多次要求它解决同一个任务时,它每次提供的代码可能都是不同的。有时,你可能会获得正确的代码,但再次询问时,得到的代码可能就是错误的。即便你使用了与我们完全相同的提示词,你所得到的代码响应也可能与我们不同。本书许多章节的讲解要点都是如何判断 Copilot 提供的答案是否正确,以及在答案不正确时如何进行修正。简而言之,我们希望你已经准备好在技术发展的最前沿进行学习。

Why we wrote this book

我们撰写本书的初衷

Both of us have been professors for over a decade and programmers for a decade longer than that. Our care for our students’ success led us to become researchers studying how students learn computing and how to improve their outcomes. Between the two of us, we’ve written nearly a hundred articles in our field exploring pedagogies, student beliefs, and assessments—all with the goal of improving the student experience.

我们两人都担任教授超过十年,并且作为程序员的时间比这还要再长十年。我们深切关心学生的成功,并因此投身于教育研究,专注于探索学生如何学习计算机科学以及如何提升他们的学习成果。我们合作发表了近百篇学术论文,深入探讨了教学方法、学习动机和评估策略,目标是不断丰富和提升学生的学习体验。

We’ve also had students in our office hours who struggled to learn how to program, even when we are employing best practices in teaching computing. These are intelligent students who want to learn, but who are tripped up on some part of the programming process. The programming process has many steps, from understanding a problem, to coming up with a solution, to imparting the process of solving the problem to a computer. So, when we began working with AI assistants, specifically Copilot, we instantly saw how it could be a game changer for students, particularly in improving that last step “imparting the process of solving the problem to a computer”. We want our students to succeed. We want you to succeed. And we believe AI assistants can help.

在工作期间,我们遇到大量在学习编程上遇到困难的学生,尽管我们已经采取了目前所知的计算机教育最佳实践。这些学生聪明且富有学习热情,但却在学习编程的某个阶段遇到障碍。编程是一个包含多个步骤的复杂过程,它的第一步是理解问题,接着是构思解决方案,最后则要将这一解决方案传达给计算机。因此,当我们开始使用 AI 助手,尤其是 Copilot 时,我们立刻意识到它可能成为学生学习过程中的转折点,特别是在将问题的解决方案传达给计算机这一关键环节上。我们希望我们的学生能够成功,同样也希望你能够成功。我们相信 AI 助手能够在这一过程中提供极大的帮助。

Warning: beware of elitism

警告:谨防精英主义陷阱

One of the saddest things we see in our classes at our universities is students intimidating other students. We’ve heard students in our introductory Python programming courses try to show off how they already learned to program in such-and-such programming language and the affect that has on the other students in the course. Although we try to gently point these students to other, more appropriate courses, we’ve also seen that the students bragging in this way are often the students struggling to pass at the end of the term, having vastly over-estimated their proficiency at the start. And it doesn’t take a licensed psychologist to see that this kind of posturing comes from a place of low self-esteem.

在我们大学的课堂上,我们看到的最令人悲哀的事情之一是:学生们相互施加心理压力。在 Python 入门课程中,我们听到部分学生夸耀自己曾经学过某种编程语言,这种行为对其他同学产生了不小的影响。我们也尝试温和地引导这些学生去改选其他更合适的课程,但我们也发现,那些夸耀自己的学生往往在期末考试阶段并不轻松,他们在学期开头大大高估了自己的能力。这种装腔作势的行为,显然是自卑感的一种体现。

Beyond students in our introductory courses, we see how different kinds of programmers treat each other and their respective fields. For example, Human-Computer Interaction (HCI) professionals study how to improve the design of software to make it better for its human users. Sounds important, right? Unfortunately, that field was put down by computer scientists as merely “applied psychology” for years, and then major companies showed that maybe, just maybe, if you care about the users of your technology, those people might just appreciate it more and be inclined to buy it. It’s not surprising that HCI quickly became mainstream in computer science. This snobbery isn’t limited to specific fields. We even see it occurring between programmers of different languages. For example, we’ve seen C++ (one programming language) programmers say silly things like JavaScript (another programming language) programming isn’t real programming. (It definitely is real programming, whatever that might mean!)

除了这些入门课程的学生,我们还注意到不同程序员群体以及他们各自领域之间的相互态度。举例来说,人机交互(Human-Computer Interaction,HCI)专业人士专注于研究如何提升软件设计,使其更贴合人类用户的行为和习惯。这听起来相当重要,对吧?但不幸的是,这个领域曾长期被一些计算机科学家贬低为“应用心理学”。随后,一些大型企业意识到,如果你真正关心自己软件产品的用户,这些用户不仅会更加欣赏你的产品,而且可能更愿意为之付费。因此,HCI 迅速在计算机科学领域占据了主流地位。这种自大和傲慢并不局限于特定领域,甚至在不同编程语言的程序员之间也存在。例如,我们听到 C++(一种编程语言)程序员说过一些像“JavaScript(另一种编程语言)编程不是真正的编程”这样的傻话。(JavaScript 编程绝对是真正的编程,不管“真正的编程”到底指的是什么!)

All of this, in our opinion, is unproductive and unfortunate posturing that pushes people away from the field. A comic we both enjoy called XKCD, captured the ludicrousness of this posturing well in “Real Programmers” [2]. In the comic, programmers argue about what the best text editor app is for programming. Programmers need to use a text editor to enter their code, which is exactly what you’ll start doing in chapter 2. There’s been a long-standing, and mostly unserious, debate over the best editors (“emacs” is one of many editors). The comic is making light of the meaninglessness of the debate in a truly clever way.

我们认为,这些行为不仅没有意义,而且令人遗憾,它们将人们排斥于这个领域之外。我们共同欣赏一部名为XKCD的漫画,它在“真正的程序员”这一集[2]巧妙地揭示了这种姿态的荒谬性。漫画中,程序员们就哪款文本编辑器最适合编程展开了辩论。正如你在第二章即将接触到的,程序员们需要使用文本编辑器来编写代码。关于最佳编辑器的辩论已经持续了很长时间,但大多数情况下这种争论并不严肃。漫画以一种极具智慧的方式,寥寥几笔就突显出这种争论的毫无意义。

The reason we’re talking about this unfortunate aspect of our field is we know what some people will say about learning to program with Copilot. They’ll say that to learn to write software, you have to learn how to write code entirely from scratch. And for future professional engineers, we actually agree that at some point in your career, you should learn to write code from scratch. But, for most people and even people starting their studies in software engineering, we wholeheartedly disagree that writing code entirely from scratch makes sense anymore as a starting place. So, if someone criticizes you for doing something to make yourself or your life or the world better, we encourage you to look to the immortal wisdom of Taylor Swift and just “Shake it off”.

我们之所以讨论这个令人遗憾的行业现象,是因为我们估计肯定有人会对“使用 Copilot 学习编程”指手画脚。他们可能会声称,要掌握软件开发,必须以完全手写代码的方式学习编程。对于有志成为专业软件工程师的人来说,我们确实认为在职业生涯的某个阶段,应该掌握从零开始编写代码的技能。但是,对于大多数普通人以及那些刚开始学习软件工程的学生来说,我们真心认为,将完全手写代码作为入门方法已经不再合理。因此,如果有人因为你做了一些使你自己、你的生活或这个世界变得更好的事情而批评你,那我们建议你采纳泰勒·斯威夫特的不朽箴言——“甩掉它”就好。

How this book is organized: a roadmap

本书结构导览:一份路线图

This book is divided into 11 chapters. We recommend that you read this book from beginning to end, rather than skipping around. That’s because most chapters introduce skills that will be assumed in later chapters:

本书共分为 11 章。我们建议你按顺序阅读全书,而不是随意跳读。这是因为每一章节所介绍的技能,都将作为后续章节的基础。

  • Chapter 1 describes what AI code assistants are, how they work, and why they are irrevocably changing how programming is done. It also explores the concerns we need to keep in mind when using AI coding assistants.
  • Chapter 2 helps you set up your computer to be able to program with GitHub Copilot (that’s your AI coding assistant) and Python (that’s the programming language we’ll use). Once your computer is set up, we’ll use Copilot in our first programming example: doing some analysis on freely available sports data.
  • Chapter 3 teaches you all about functions, which help you organize your code and make it easier for Copilot to write code for you. It also uses many examples to demonstrate the general workflow we’ll use in order to be productive with Copilot.
  • Chapter 4 is the first of two chapters that teaches you how to read Python code. It’s true that Copilot will be writing code for you, but you need to be able to read that code to help you determine whether that code is going to do what you want. And don’t worry: Copilot can help you read code, too!
  • Chapter 5 is the second of two chapters that teaches you how to read Python code.
  • Chapter 6 is a primer on two critical skills that you need to hone when working with AI coding assistants: testing and prompt engineering. Testing involves checking that your code operates correctly; prompt engineering involves changing the words you use in order to communicate more effectively with your AI assistant.
  • Chapter 7 is all about breaking large problems down into smaller problems that are easier for Copilot to handle. The technique is called top-down design, and in this chapter, you’ll use it to design a complete program to identify the author of mystery books.
  • Chapter 8 is a deep dive into bugs (errors in your code!), how to find them, and how to fix them. You’ll learn how to step line by line through your code to pinpoint exactly what’s going wrong and even how to ask Copilot to help you fix bugs.
  • Chapter 9 puts Copilot to work to help you automate tedious tasks. You’ll see three examples—cleaning up emails that have been forwarded many times, adding cover pages to hundreds of PDF files, and removing duplicate images—and you’ll be able to apply the principles to your own specific tasks as well.
  • Chapter 10 shows you how to use Copilot to write computer games. You’ll use the skills you developed throughout the book to write two games: a logic game similar to Wordle, and a two-player, press-your-luck board game.
  • Chapter 11 delves into the fledgling field of prompt patterns, which are tools to help you get even more out of your AI assistant. It also summarizes the current limitations of AI coding assistants and looks at what may be on the horizon.
  • 第一章介绍了 AI 编程助手是什么、它们如何工作,以及为什么它们正在不可逆转地改变编程的方式。这一章还探讨了我们在使用 AI 编程助手时需要考虑的问题。
  • 第二章帮助你设置你的电脑,以便使用 Copilot(这是你的 AI 编程助手)和 Python(这是我们将使用的编程语言)进行编程。一旦你的电脑设置完成,我们将通过 Copilot 进行首个编程实践:对公开可用的体育赛事数据进行分析。
  • 第三章深入讲解了函数的概念,函数不仅能帮助你更好地组织代码,还能让 Copilot 更有效地为你生成代码。本章通过多个实例展示了与 Copilot 高效协作的常规流程。
  • 第四章是讲解如何阅读 Python 代码的第一章。没错,Copilot 会帮你编写代码,但你还是需要具备读懂代码的能力,从而判断代码是否符合预期。请放心,Copilot 在此过程中也能提供帮助!
  • 第五章是讲解如何阅读 Python 代码的第二章。
  • 第六章初步介绍了在使用 AI 编程助手时必须掌握的两项关键技能:测试和提示工程。测试用于检查代码是否正确运行,而提示工程则可以优化我们与 AI 助手的沟通方式。
  • 第七章专注于探讨如何将复杂问题拆解为Copilot更易处理的小问题,这种方法称为自顶向下设计。在这一章里,你将使用这种方法来设计一个完整的程序,用来识别神秘书籍的作者。
  • 第八章将深入探讨 bug(也就是代码中的错误!),包括如何找到它们,以及如何修复它们。你将学习如何逐行检查代码,准确找出问题所在,并学会要求 Copilot 来帮助你修复错误。
  • 第九章展示了如何利用 Copilot 来自动化处理繁琐任务。你将看到三个示例——清理被多次转发的电子邮件、为数百个 PDF 文件添加封面以及删除重复的图像——而且你还可以将学到的方法应用到你自己的特定任务中。
  • 第十章向你展示如何使用 Copilot 开发电脑游戏。你将运用书中学到的技能来开发两款游戏:一款类似于 Wordle 的逻辑游戏和一款两人的冒险棋盘游戏。
  • 第十一章深入探讨了“提示词模式”这一新兴领域,这些工具旨在帮助你更充分地利用 AI 助手的潜力。同时,本章也对 AI 编程助手的现有局限进行了总结,并对未来的发展趋势进行了展望。

Source code downloads

下载本书的配套代码

For many books about programming, the reader types the code exactly as the author has written it in order to accomplish a task with code. Our book is different because, as described earlier, the code we get back from Copilot is nondeterministic; your code will not match our code. For that reason, we are not providing all of the code for download that you see in this book. We want you to focus on generating that code from Copilot, not typing it in yourself! That said, we do have some important files to share, and they are available from the publisher’s website at https://www.manning.com/books/learn-ai-assisted-python-programming.

对于许多编程书籍来说,读者通常需要按照作者所提供的代码逐字输入,才能走完特定的编程任务。但本书的做法有所不同,正如前文所述,我们从 Copilot 那里得到的代码是不确定的;你的代码很可能与我们的代码不一致。因此,我们不提供本书中所有示例代码的下载。我们希望你专注于使用 Copilot 来生成代码,而不是自己手动输入。尽管如此,我们依然提供了一些重要的文件供你下载,你可以访问本书英文版的官方网站 https://www.manning.com/books/learn-ai-assisted-python-programming 来获取这些文件。

This book contains many examples of source code both in numbered listings and in line with normal text. In both cases, source code is formatted in a fixed-width font like this to separate it from ordinary text. Comments or code we’ve written as prompts to be interpreted by Copilot or ChatGPT are in bold to highlight what we wrote rather than what was given to us by the large language model.

本书包含了大量的源代码示例,有些代码是有编号的代码清单,有些穿插于正文之中。无论哪种形式,源代码均采用等宽字体格式,以便于与普通文本进行区分。我们为 Copilot 或 ChatGPT 编写的注释或提示词会采用加粗字体,从而区分出哪些是我们亲自编写的内容,哪些是由大型语言模型所生成的内容。

In many cases, the original source code has been reformatted; we’ve added line breaks and reworked indentation to accommodate the available page space in the book. In rare cases, even this was not enough, and listings include line-continuation markers (➥). Additionally, comments in the source code have often been removed from the listings when the code is described in the text. Code annotations accompany many of the listings, highlighting important concepts.

在许多情况下,原始代码经过了重新排版处理;我们增加了空行并调整了缩进,以便适应书籍页面的空间限制。在极少数情况下,即便如此也无法满足需求,此时代码清单将不得不引入续行标记(➥)(译者注:非常遗憾,英文版原在最终排版阶段似乎遗忘了这个约定,书中采用的续行标记就是在行末添加一个 \ 字符。中文版很可能还是沿用英文原版的做法。)。此外,在正文中已经展示过的注释,在代码清单中可能就不再重复列出了。我们还在代码清单中附加了不少注解,用来突出关键概念。

Software/hardware requirements

软件与硬件需求

You’ll need access to any Windows, Mac, or Linux computer on which you have permission to install software. As we discuss in further detail in chapter 2, you’ll need to install the Python software, the Visual Studio Code (VS Code) software, as well as various extensions. You’ll also need to sign up for a GitHub Copilot account which, at the time of writing, has a free trial, is free for students and educators, but otherwise has a monthly charge.

你需要有一台 Windows、Mac 或 Linux 电脑,并且有权限在电脑上安装软件。我们会在第二章中更详细地讨论到,你需要安装 Python 环境、Visual Studio Code(VS Code)程序以及一些必要的插件。同时,你还需要注册 GitHub Copilot 账户,该服务目前提供一段免费试用期,并对在校学生及教育工作者免费,但对其他用户则会在试用期结束后收取一定的月费。

liveBook discussion forum

liveBook 在线论坛

Purchase of Learn AI-Assisted Python Programming with GitHub Copilot and ChatGPT includes free access to liveBook, Manning’s online reading platform. Using liveBook’s exclusive discussion features, you can attach comments to the book globally or to specific sections or paragraphs. It’s a snap to make notes for yourself, ask and answer technical questions, and receive help from the author and other users. To access the forum, go to https://livebook.manning.com/book/learn-ai-assisted-python-programming/discussion. You can also learn more about Manning’s forums and the rules of conduct at https://livebook.manning.com/discussion.

购买本书的英文原版纸质版,你还将获得免费访问 Manning 的在线阅读平台 “liveBook” 的权限。利用 liveBook 独特的讨论功能,你可以针对全书或特定章节段落发表评论。不论是为自己做笔记,或是发出或解答技术问题,还是从作者和其他用户那里获得帮助,讨论功能都是最简单快捷的选择。若要进入论坛,请前往此地址 https://livebook.manning.com/book/learn-ai-assisted-python-programming/discussion 。你还可以在 https://livebook.manning.com/discussion 了解更多关于 Manning 论坛及其行为准则的信息。

Manning’s commitment to our readers is to provide a venue where a meaningful dialogue between individual readers and between readers and the author can take place. It is not a commitment to any specific amount of participation on the part of the author, whose contribution to the forum remains voluntary (and unpaid). We suggest you try asking the author some challenging questions lest his interest stray! The forum and the archives of previous discussions will be accessible from the publisher’s website as long as the book is in print.

Manning 致力于为读者提供一个平台,让读者与读者之间,以及读者与作者之间能够开展富有意义的对话。不过这并不是对作者在论坛上参与程度的承诺,因为作者的参与是完全自愿且没有报酬的。我们建议你向作者提出一些有深度的问题,这会让他们更有参与讨论的兴趣。只要这本书还在印刷,你都可以通过出版社的官方网站访问论坛和之前讨论的存档。

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

No branches or pull requests

1 participant