这是用户在 2024-11-30 10:30 为 https://hackmd.io/stEeiI3mSkO5qlMINJNnGg 保存的双语快照页面,由 沉浸式翻译 提供双语支持。了解如何保存?
changed 10 hours ago
10 小时前改变

"Excellent! How you guys doing? Oh my word, give me a break people! This is my fourth talk today, so let's try this again - how you doing?"
太棒了!你们怎么样?哦天哪,让我歇歇吧,人们!这是我今天的第四次演讲,那让我们再试一次-你们怎么样?

"All right, all right. Sometimes I teach distance Ed courses. In fact, tomorrow morning I'm teaching one in Nicaragua, but I just checked - this is not a distance Ed course. We're in the same room, so we're going to do like interactive stuff, sound good?"
好的,好的。有时我教授远程教育课程。事实上,明天早上我将在尼加拉瓜教授一门课程,但我刚刚检查了一下,这不是一门远程教育课程。我们在同一个房间,所以我们将进行互动式的内容,这听起来不错吗?

"And normally we don't allow beer in my classroom, so I think this might go better. You never know, maybe we should change that policy. I'm I'm not sure. I agree the class would be more popular. Yeah, in class, mom! Seriously"
通常我们不允许在我的课堂上喝啤酒,所以我认为这样做会更好。你永远也无法确定,也许我们应该改变这一政策。我……我不太确定。我同意这门课会更受欢迎。是的,在课堂上,妈妈!说真的……

"So what I want to talk about tonight - what Calvin asked me to talk about (so if it's a bad idea, it's his fault) - was a little bit about how Python fits in the space for beginners. Now, I know a lot of you are not beginners, especially if you're looking for work. Maybe it's better not to be a beginner at that point. But even if you're not a beginner, is there anybody who is who's brave enough to say so you're just learning Python?"
那么我今晚想谈谈的 - 卡尔文让我谈的话题(如果是个糟糕的主意,那就是他的错) - 就是一些有关 Python 如何适合初学者的内容。现在,我知道你们中很多人都不是初学者,尤其是如果你们正在寻找工作。也许在那个时候最好不要是个初学者。但即使你们不是初学者,有谁有勇气说自己仍在学习 Python 吗?

"Yes? You and me, dude! Okay, excellent, great! This is for you - the rest of these people can hang out. But actually, this will be useful for all of us too, because I don't know about you, but as I've not gotten smarter but I've gotten grayer, and so people expect me to be able to help them learn how to do things. And as you become a senior Dev, you're always ending up having to teach people, am I right? Most of us are not good at that, I'm just saying. And you know, I love to go on the learning program forums and Reddit and so on, and oh, it's comedy gold!"
是的?你和我,伙计!好的,太棒了,太好了!这是给你的-其余的人可以休息。但实际上,这对我们所有人都有用,因为我不知道你是否也这样,但随着我变老,头发变灰,人们期望我能教他们学习如何做事情。当你成为一名高级开发人员时,你总是不得不教人,我说得对吗?我们大多数人并不擅长这样做,我只是说说而已。你知道,我喜欢去学习论坛和 Reddit 等地方,哦,那里简直是喜剧金矿!

"So what are we going to talk about? We'll see how you can think like a programmer even if you're not sure you can, and how to teach beginners with Python. You like that? Look at that! Woo, it's fun!"
我们将讨论什么呢?即使你不确定自己是否能做到,我们也将看看你如何像程序员一样思考,以及如何使用 Python 教育初学者。你喜欢吗?看看吧!哇,真有趣!

"All right, so you don't need to know much more about me except here's my favorite thing that Calvin didn't know - I used to be a special ed teacher. Yeah, I know! It was actually severe disabilities at North Central High School. That was the best, best preparation for being a computer science teacher I could have ever had. It really was, and I'm not being facetious here. I mean, some of my students are here, they're like 'Yeah, true.' Because I learned how to teach, I really learned a lot about teaching. And 20-some years in, I'm still learning about teaching."
没问题,你不需要知道我更多的信息,除了这一点 - 我曾经是一名特殊教育老师。是的,我知道!我在北中央高中教授严重障碍学生。这为我成为计算机科学教师提供了最佳、最佳的准备。这确实是如此,我并不是在开玩笑。我的一些学生在这里,他们会说"是的,确实如此。"因为我学会了如何教学,我真的学到了很多关于教学的知识。而且在 20 多年的教学生涯中,我仍在不断学习。

"I actually think programming is hard. Do you agree? See, this was the interactive part - yes? Okay, programming is every bit as hard as most people think it is. I think teaching is harder. I honestly do. I think that's the more valuable, more difficult, more rare skill. Which is funny because there's a lot of people with the title who don't have the skill."
我实际上认为编程很难。你同意吗?看,这就是互动部分 - 是的吗?好的,编程确实和大多数人认为的一样难。我认为教学更难。我真的这么认为。我认为那是更有价值、更难掌握、更稀缺的技能。这很有趣,因为有很多人拥有这个头衔,但却没有这种技能。

[Computer vs. Shoe Demonstration]
[计算机与鞋子演示]

"Okay, who's got a good gaming rig? Yeah, what you got? Tell us your specs!"
好的,谁有一台好的游戏电脑?是的,你有什么?告诉我们你的配置吧!

"Oh, it's been a couple years I guess, but it doesn't matter - 12 gigs of RAM, Core i7"
哦,我想已经几年了,但这并不重要 - 12 GB RAM,Core i7..

"Excellent, excellent! Good machine, good machine. Okay, normally I have a rock, but I'll just use a shoe. How smart are they? You thought I was talking about the students, didn't you? No, I was talking about how smart are the computers. There's that gaming computer and there's my shoe - which one's smarter? It's a tie! It's a tie, and if you don't get that, we're done. That's the most important thing about learning how to be a programmer, don't you agree? Now I'm going to have to take the other one off or I'll walk in circles!"
出色的,出色的!好机器,好机器。好的,通常我有一个石头,但我只会用一只鞋。他们有多聪明?你以为我在说学生,不是吗?不,我在说计算机有多聪明。那台游戏电脑和我的鞋子,哪个更聪明?平局!平局,如果你不明白,我们就此打住。这是学习如何成为程序员最重要的事情,你同意吗?现在我必须脱下另一只鞋,否则我会在原地打转!

"How smart are they? Not the people - that's never the problem. The people who I teach usually are super, super they're really, really clever and bright and wonderful. That's never the problem. I've not encountered anybody yet who couldn't learn to program if they wanted to. I've met several who don't want to. But how smart are they? I'm not talking about the people, I'm talking about the computer. See, the hard part about writing a computer program isn't trying to be as smart as the computer - it's trying to learn how to be as mind-numbingly stupid as a computer. That's the hard part, and until you can understand that, you'll never really be able to write programs. Do I get an amen?"
他们有多聪明?不是人们 - 那从来不是问题。我教的人通常非常,非常... 他们非常,非常聪明和明亮,很棒。那从来不是问题。我还没遇到过任何人,如果愿意的话,就学不会编程。我遇到过一些不想学的人。但是他们有多聪明?我不是在谈论人,我是在谈论电脑。你看,编写计算机程序最困难的部分不是试图像电脑一样聪明 - 而是试图学会像电脑一样麻木愚钝。这才是最难的部分,直到你能理解这一点,你永远无法真正编写程序。我说得对吗?

"Amen! Yeah, yeah!" 阿门!是的,是的!

"Learning to program is hard if you're just doing it now, do you agree with me? It's hard, and in fact, I'm still learning to program. I've been at this for 30 years, I'm still learning. I'll let you know when I figure it out. I still feel like an idiot all the time. Am I the only one? No! All the time! I like walk out of my office like, 'What? Do people pay to read my books? People are actually paying to see my class and I can't even get this stupid thing to work!' And my wife is like, 'Get back in there and get it working!' She is loving, she is awesome."
学习编程很难,如果你刚刚开始,你同意我的看法吗?这确实很难,事实上,我仍在学习编程。我已经学习 30 年了,我仍在学习。当我弄明白的时候,我会告诉你的。我一直觉得自己很愚蠢。难道我是唯一一个这样觉得的人吗?并不是!一直都是!我有时会从办公室里走出来,想'什么?人们真的会买我的书吗?人们真的愿意支付费用来参加我的课程,而我连这么一个愚蠢的东西都搞不定!'我妻子就会说'快回去把它弄好!'她是如此的慈爱和善良。

[Continues with discussion about why programming is hard]
编程很难是因为…

"Learning to program - it's hard. Why? Well, programming feels different than other skills, doesn't it? Especially to a beginner. 'Yeah, I'm good at cars, but I don't know this stuff.' Languages are scary, right? They see 'code' - that sounds like it's a mystery you're not supposed to know how it works. So the language is scary, there's codes The environments are scary. We have these IDEs, and you know, I look at modern development and they tell you 25 different steps you have to do before you start opening your first program. That's insane! That is absolutely insane!"
学习编程 - 这很难。为什么?嗯,编程确实与其他技能有所不同,不是吗?特别是对于一个初学者而言。'是的,我擅长汽车,但我不了解这些东西。'语言令人生畏,对吗?他们看到'代码' - 这听起来像是一种你不应该知道如何运作的神秘事物。所以语言令人生畏,有各种代码……环境也令人生畏。我们有这些 IDE,你知道,我看看现代开发,他们告诉你在开始打开第一个程序之前必须做 25 个不同的步骤。这是疯狂的!这绝对是疯狂的!

[Discusses various pieces of bad advice commonly given to beginners]
对新手常见的一些不当建议进行讨论

"The best way to start is to pick a problem you want to solve - I like this one, I like this advice, except it's terrible! Because, see, you know, I'd like to solve world peace - is that the first problem I should try? You know, having goals is good, but if the goals lead to inevitable failure and defeat, maybe we should pick a subset of saving the world first."
从一个您想要解决的问题开始是最好的方式 - 我喜欢这个建议,除了它太糟糕了!因为,你看,我想解决世界和平 - 这是我应该首先尝试解决的问题吗?你知道,设定目标是好的,但如果目标注定要失败和失败,也许我们应该先从拯救世界的子集开始。

"You'll stay motivated if you work on a real-world problem - until you feel like an idiot and leave! Because here's the problem with real world: the real world is messy, isn't it? And so I'm not so sure that we always want to be focusing on real-world problems to start."
如果你专注于解决一个真实世界的问题,你会保持动力 - 直到你感到自己像个白痴而放弃!因为真实世界有一个问题:现实世界很混乱,不是吗?所以我不太确定我们是否总是想专注于解决现实世界的问题来开始。

"Here's things I wish I'd been taught when I was a beginner, and I've only learned this after, boy, 20-30 years of teaching this, and I'm still learning it: Programming is not about languages. This is the question I hate the most on these forums, right? Reddit 'learn programming' - I'm there every day. 'What language should I start with?' And I have to stop because if I had quadruple size caps lock, I would use it - WRONG QUESTION! That's a stupid question, and here's the great thing: you're going to get reams of advice about it, all of it stupid!"
这些是我作为初学者时希望被教授的内容,这些都是在 20-30 年的教学经验后才学会的:编程不仅仅是关于语言。这是我最讨厌在这些论坛上看到的问题,对吧?Reddit 的'学习编程'版块,我每天都在那里。'我应该从哪种语言开始学习?'我不得不停下来,因为如果我有四倍大的大写锁定,我也会用它-这是错误的问题!这是一个愚蠢的问题,而且你会得到大量愚蠢的建议。

"Programming isn't about languages. Sure, you're going to pick one - I like Python - but the language ultimately doesn't matter that much. Some will make you feel better earlier, some will make you feel stupider earlier ('public static void main string args'). But the language doesn't really matter. Programming was never about languages."
编程并不关乎语言。当然,你需要选择一种语言——我喜欢 Python,但是语言最终并不重要。有些语言会让你更快上手,有些会让你更快感到无能为力("public static void main string args")。但是语言并不重要。编程从来不是关乎语言的。

"Here's my guys in the back right - in the first year of our program, I teach four programming languages, and you know the funny thing? That part's not the hard part. That's what they tell me - am I lying now?"
这里是我在后面右边的人-在我们项目的第一年,我教授四种编程语言,你知道有趣的是?那部分不是难点。他们告诉我的-我现在在说谎吗?

"No?" 没有?
"Okay, good. Okay good, I'll still pay you! Yeah, they think that's the hard part. No, the hard part is we keep changing paradigms. The hard part is, as soon as we know one language, I start talking about something deeper that we can learn with another one. Python's not a good language to teach direct memory management in, for example, because - thank you - it does it for us. But if you're a computer scientist, you better know what direct memory management is. That's when we're going to work in C and C++, make sense? Yeah, malloc and free You guys don't know that, you're Python people? Okay, good!"
好的,好的。好的,好的,我仍然会支付你!是的,他们认为这是最困难的部分。不,最困难的部分是我们不断改变范式。最困难的部分是,一旦我们掌握了一种语言,我就开始谈论我们可以用另一种语言学习的更深层次的东西。例如,Python 不是教授直接内存管理的好语言,因为它为我们做了这个。但是,如果你是计算机科学家,你最好知道什么是直接内存管理。那就是我们要在 C 和 C++中工作的时候,明白吗?是的,malloc 和 free...你们不知道吗,你们是 Python 人吗?好的,好的!

"Most people think that programming is about memorizing. 'I'll never learn all those codes!' And I'm like, 'Yeah, neither will I!' I don't know what you're talking about. I don't memorize syntax. I couldn't, because I use too many languages. You know, in a typical day I'm helping debug code in six, seven languages - there's no way I could memorize that!"
大多数人认为编程是关于记忆的。"我永远也学不会那些代码!"我就会说"是啊,我也不会!"我不知道你在说什么。我不记忆语法。我也做不到,因为我使用了太多语言。你知道,在一个典型的工作日里,我要帮助调试六七种语言的代码 - 我完全记不住那些。

"Okay, this is a good one: 'Most programming isn't about math.' You know - 'I'll never be a good programmer, I always hated math.' First of all, you hated math class; I'm not sure you've met math. Secondly, until you get into data science, gaming, and a few other specific areas, you could do fine in programming without using a lot of calculus. Right? Who used calculus today?"
好的,这是一个很好的例子:"大多数编程都与数学无关。"你知道的,"我永远也不会成为一个好的程序员,我总是讨厌数学。"首先,你讨厌数学课;我不确定你是否真的了解数学。其次,除非你进入数据科学、游戏等特定领域,否则你可以在编程中不用大量使用微积分就能做得很好。对吗?今天谁用过微积分?

That's what I'm saying. Okay, you did - you're very smart. And there are places we need it, and certainly, you know, I use algebra several times today because I taught a game programming class. But if I wasn't doing that, I might not need it every day. You can get started without math, and here's the fun thing: when you start programming, you're going to realize the kind of thinking you're doing is the kind of thinking that math was trying to teach you in the first place.
那就是我要说的。好的,你做到了 - 你非常聪明。确实有我们需要它的地方,我今天使用代数几次,因为我教授了一个游戏编程课。但如果我没有做那件事,我可能每天都不需要它。你可以不需要数学知识就开始编程,这里有一个有趣的事情:当你开始编程时,你会意识到你正在做的思维方式就是数学试图教会你的思维方式。

So there you go - programming languages! I love this one: programming languages are simpler than human languages. I know this because 30 years ago, I tried to learn Japanese and I completely failed. Until very recently, when I tried to learn Spanish, and now all the Japanese is coming out. "B Tomi son" - I'm the only person in the world who's fluent in span-human languages!
编程语言!我非常喜欢这个:编程语言比人类语言更简单。这是因为 30 年前,我试图学习日语,但完全失败了。直到最近,我试着学习西班牙语,现在所有的日语都回来了。"B Tomi son" - 我是世界上唯一一个精通西班牙语和人类语言的人!

How much vocabulary do they have? Lots! How many words? Like 100,000 thousands. Okay, how about the syntax rules? How complicated are they? Depends on the language. Oh dear lord! You know, my family's all learning Spanish because my daughter's going to school in Nicaragua, and you know, there's tenses I've never even heard of. You know, past future wonderful undescribed predatory tense - I don't know what it is, but I don't even understand it.
他们有多少词汇量?很多!有多少个单词?大约 10 万。好的,那语法规则呢?有多复杂?这取决于语言。噢,天哪!你知道,我家人都在学习西班牙语,因为我女儿要去尼加拉瓜上学,你知道,有一些我从未听过的时态。你知道,过去未来美妙未描述掠食动词时态 - 我不知道那是什么,但我完全不明白。

How about computer languages? How many words do they typically have in the vocabulary? Less than 100 - about 100. How consistent is the syntax? Painfully! Programming languages are actually designed to be much more sensible. They're not as flexible - poetry and programming languages not quite as successful, except Perl, of course. It has "bless," "kill," and "die" - those are functions in Perl.
计算机语言怎么样?它们的词汇量通常有多少个单词?少于 100 个-大约 100 个。它们的语法有多一致?令人痛苦!编程语言实际上是被设计得更加合理。它们没有那么灵活-诗歌和编程语言并不十分成功,除了 Perl 之外。它有"bless"、"kill"和"die"这些函数。

I can tell you my Perl joke: A thousand monkeys on typewriters - eventually, one of them would type Shakespeare, the others would all write Perl code! There's not many places you can use Perl jokes, that's what I'm saying.
我可以告诉你我的 Perl 笑话:一千只猴子打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打打,最终其中一只会打出莎士比亚的作品,其他的都会写出 Perl 代码!我要说的就是,能用 Perl 笑话的地方并不多。

Programming really isn't about the things most people think it is. Here's another one: "I can't type fast enough to be a programmer" - I've heard that one. Actually, probably you should be typing slower. How much of programming is typing? Close to none of it. Close to none! Is really that the issue? Again, it's about explaining things to the idiot computer - that's what programming is. And when we think about it that way, it's actually not quite so frightening.
编程并不是大多数人所认为的那些东西。再来一个:「我打字速度不够快,不适合做程序员」 - 我听过这句话。实际上,你可能应该打字更慢一些。编程中有多少是打字呢?几乎没有。这到底是不是问题所在?归根结底,编程就是与愚笨的计算机解释事物 - 这就是编程的本质。从这个角度来看,编程其实并不那么可怕。

Code isn't about language. Here's what I'm beginning to learn after teaching this for many, many years. Because I've taught beginning programming - pick a language: Perl (yes, I taught beginning programming in Perl), and Basic, and Pascal, and Logo (remember Logo? No, some of you don't), and Scratch. Give me a language - C, C++, Java - I've taught them all as beginning languages, and they started to run together.
代码不是关于语言。经过多年的教学,我正在学习这一点。因为我教授了初级编程 - 选择一种语言:Perl(是的,我教授了 Perl 初级编程),以及 Basic、Pascal 和 Logo(你还记得 Logo 吗?不,你们有些人可能不记得),还有 Scratch。给我一种语言 - C、C++、Java - 我都教授过作为初级语言,它们开始混在一起了。

I realize there are some common themes. It turns out when I'm teaching a beginner how to go from not a programmer to a programmer, there's really about seven or eight concepts, depending on how you look at them. You get those and you're done, and those concepts are universal across languages. That's pretty beautiful, isn't it?
我意识到这里存在一些共同主题。事实证明,当我在教初学者从非程序员转变为程序员时,根据你的观点,有大约七八个概念。你掌握了这些概念,就大功告成了,这些概念在各种语言中都是通用的。这真是太美妙了,不是吗?

If you know multiple languages, you know this to be true, right? Your first language is hard, your second language is harder, isn't it? Because you thought you knew the truth. Your third language, it's like "Dude, I'm seeing similarities here." By four or five, you know what you're doing. You're doing a - oh yeah, you were saying they asked me to do a project in Python, I said "Give me a weekend." Yeah, it gets to that point, doesn't it? Because we see these consistencies.
如果您会多种语言,您就知道这是真的,对吗?您的母语很难,您的第二语言更难,不是吗?因为您以为您知道真相。您的第三语言,就像"哥们,我在这里看到了相似之处。"到了第四或第五种语言,您就知道自己在做什么了。您在做一个 - 哦,是啊,他们让我用 Python 做一个项目,我说"给我一个周末。"是的,确实会到达那个地步,不是吗?因为我们看到了这些一致性。

Coding is only about eight main concepts. I'll show you my favorite few - how's that? They work in the same way in every language. When we're trying to teach people how to code, don't teach them code - teach them English, or teach them in English. The secret isn't code; the secret is algorithms and data. That's really what we're here to teach.
编码只涉及八个主要概念。我会给你展示我最喜欢的几个概念 - 怎么样?它们在每种语言中的工作方式都是一样的。当我们试图教人如何编码时,不要教他们代码 - 而要教他们英语,或者用英语教他们。秘密不在于代码;秘密在于算法和数据。这才是我们教学的真正目的。

Of course, let's pick a language that makes that easy - I nominate Python. If it chooses to run, it's going to win. We write out the concepts first, and then we convert to code later. This is so key - when my students come into me and they're like "I'm so messed up," the first thing they do is sit down, they open up their computer, and what do I do? I shut it on their fingers. Why? If you're lost in coding, it's probably because you shouldn't be coding yet. It's almost always the case.
当然,让我们选择一种简单的语言 - 我提名 Python。如果它选择运行,它就会赢。我们先写出概念,然后再转换为代码。这是关键所在 - 当我的学生来找我,说"我乱成一团了",他们首先做的就是坐下来,打开电脑,那我怎么做?我把它合上放在他们的手指上。为什么?如果你在编码中迷失了,很可能是因为你还不应该编码。这几乎总是如此。

You write out the concepts first and convert to code. In fact, I will grade your paper if you write a beautiful algorithm and not a line of code - you'll still probably pass. Doesn't happen often because if they write the algorithm well, the code comes. If you turn in beautiful code that runs great without any comments in it, I give it back. That's how important this is after midterm.
你先写出概念,然后转换为代码。事实上,如果你写了一个漂亮的算法而没有写任何代码,我也会给你打高分。这种情况并不常见,因为如果他们能很好地编写算法,代码也会跟上。如果你提交了一些运行良好但没有任何注释的漂亮代码,我会退回给你。这在期中考试后是很重要的。

Most beginners - this is so amazing - when you, if you are a beginner (and I still am), you get to this point where you think you don't understand how to write the code. I can't tell you how many times people say "I know what I'm doing, I just don't know which code to write." No! Almost every time somebody says "I just don't know how to write it" - no, that's not the problem. The real problem is they don't understand the problem they're trying to solve. They're jumping straight to coding without understanding algorithms.
对大多数初学者来说,这真是太神奇了。如果你是个初学者(我自己也还是),你会到这个地步,觉得自己不懂如何编写代码。我无法告诉你有多少人说"我知道自己在做什么,我只是不知道该写哪段代码。"错!几乎每次有人说"我不知道如何编写它"时,问题并不在此。真正的问题是他们不理解他们正试图解决的问题。他们直接跳到编码上,而没有理解算法。

I get that because coding's cool, right? You look like a hacker. I showed my son hackertyper.com - you know that site? Oh, you need this! Hackertyper.com - all you have to do is bang on the keyboard furiously and it looks like you're writing C code, and if you hit the right control sequence, it says like you're in or whatever. Yeah, it's awesome 'cause that's what all of the students think they're going to learn how to do anyway.
因为编码很酷,对吧?你看起来像是一个黑客。我向我的儿子展示了 hackertyper.com -你知道那个网站吗?噢,你需要这个!Hackertyper.com - 你所要做的就是狂按键盘,就能看起来像在写 C 代码,如果你按下正确的控制序列,它就会显示你已经进入之类的。是的,这太棒了,因为这就是所有学生认为他们会学会如何做的。

The real problem is that beginners don't always understand the problem they're trying to solve. They try to figure out how to do it before they try to figure out what to do. And really, experienced people like us - we do that too, don't we? Every day. Every day!
问题的真正根源在于初学者并不总是理解自己正在尝试解决的问题。他们试图弄清楚如何去做,而不是先弄清楚做什么。我们这些有经验的人也同样如此,难道不是吗?每天都是如此!

Here's one of my favorite ideas, and then we'll actually dig in and do some - sound good? Comments are code! All right, so we all know what comments are for - comments are there to explain code to other programmers, you agree? Sure, sure, which explains why we never write them, doesn't it? Because if the comments are there, first of all, it's their own dang fault if they can't understand my code. Secondly, I don't want to explain what it does until I'm sure I know, and that may never happen.
这里是我最喜欢的想法之一,然后我们实际上要深入研究并做一些 - 听起来不错?注释就是代码!好吧,所以我们都知道注释的作用 - 注释是为了向其他程序员解释代码,你同意吗?当然,当然,这就解释了为什么我们从不写注释,不是吗?因为如果注释在那里,首先要怪咎自己读不懂我的代码。其次,我不想解释它是做什么的,直到我确定自己知道,而这可能永远不会发生。

Little painful, painful little giggles there, yeah, 'cause this is true, right? We're all here. And you know, I got to get this thing delivered, man. It's deadline - I'll do my best to get the comments in at the last step, but I got to get it working before I can worry about that. Yeah, so comments are there to explain the code to other programmers, or better yet, yourself, because a week later you're like, "Crud, what did this do?"
这很痛苦,那里有令人痛苦的小嘻嘻声,是的,因为这是真的,对吗?我们都在这里。而且你知道,我必须把这件事交出去,兄弟。这是最后期限 - 我会尽最大努力在最后一步添加注释,但在担心那个之前,我必须先让它工作。是的,所以注释是为了向其他程序员解释代码,或者更好的是为了解释给自己,因为一周后你会像,"老天,这是什么?"

No, no, no! I finally learned the truth: comments are not there to explain the code to programmers. Code is there to explain the comments to the computer! That's profound. That is - that's all I got, good night, I'll see you!
不,不,不!我终于学到了真理:注释不是用来向程序员解释代码的。代码是用来向计算机解释注释的!这太深刻了。这就是我要说的,晚安,再见!

Code is there to explain comments to the computer - at least for beginners. But again, I still consider myself a beginner. You write your algorithm first, you got that algorithm first working, it's beautiful, and then how do you know it's done? It's like a turkey, right? The little thing pops out? No. How do you know that an algorithm is done? You look at every line, and at this point, maybe you've even decided what language you're going to use, and you say "I can do that, I can do that, I can do that - oh, better look that one up, break it up into smaller things. I can do it, I could do it, I could do it." At that point, now we can start thinking about code.
代码用于向计算机解释注释 - 至少对于初学者如此。但是,我仍然认为自己是一个初学者。你先写你的算法,让算法先工作,它很漂亮,然后你怎么知道它完成了?就像火鸡一样,对吧?小东西蹦出来了?不是。你怎么知道算法完成了?你查看每一行,此时也许你已经决定了要使用什么语言,你说"我可以做到,我可以做到,我可以做到 - 哦,最好再查一下,把它分解成更小的部分。我可以做到,我可以做到,我可以做到。"到了这个阶段,我们现在可以开始考虑编写代码了。

That sounds really mean, doesn't it? My students think so too until they do well, and they all earn more than me, so now they don't think it's so bad. So this is important idea. All right, so let's go into - I said there were only seven or eight main concepts. Let's do our favorite first four, how's that? No? Okay, it's been nice seeing you!
这听起来真的很刻薄,不是吗?我的学生也这么认为,直到他们表现出色,并且他们都赚的比我多,所以现在他们觉得这没那么糟糕了。这是个很重要的想法。好的,那么让我们来探讨 - 我说过只有七八个主要概念。让我们先从我们最喜欢的前四个开始,怎么样?不喜欢?好的,很高兴见到你!

Here's the way I like to think about it, because really, algorithms - you can say that and people are like "Eh, I don't know, I don't know," but let me show you exactly how we like to think about these. I actually have one chart that I'll make, and it was uglier than the slideshow so, you know, if you want it, I'll give it to you. But I have one chart and I say, "You understand this - it's an HTML table, it's that ugly - you understand this, you've got programming!" Oh, you want to do it in Java? One second, change it all. Okay great, I changed one column. So I just rebuild that table for every language we teach in.
这是我喜欢思考这个问题的方式,因为算法这个词 - 你可以说出来,但人们就会说"哦,我不知道,我不知道",但让我告诉你我们是如何思考这个问题的。我有一个图表,它比幻灯片更难看,如果你想要的话,我可以给你。但我有一个图表,我说"你懂这个 - 这是一个 HTML 表格,看起来很难看 - 但你懂,你有编程基础!"哦,你想用 Java 来做?好的,我改一下。好了,我已经为我们教的每种语言重建了那个表格。

But here's the ideas now - the first idea is about variables, right? Variables, about data. So those of you who are really beginners, today's our moment. If you're not a beginner, you're like "I know this," right? But someday you're going to teach it to someone. And the real issue isn't just a variable - okay, it's a place in memory to hold data, great, we know that. But here's the interesting thing about this approach to learning: I say first thing you need to know is there is such a concept as "make a new variable," and when I'm running an algorithm, this is one of the things I can pick. What am I going to do? I'm going to make a variable. So that's on your drop-down list of things you can do. Make sense? There's only about eight or nine of these, really.
但是这里有一些想法 - 第一个想法是关于变量,对吗?变量,关于数据。所以对于那些真正的初学者来说,今天就是我们的时刻。如果你不是初学者,你就会说"我知道这个"。但是总有一天你会把它教给别人。真正的问题不仅仅是一个变量 - 好的,它是一个内存中用来保存数据的位置,我们知道这一点。但是这种学习方法有一个有趣的地方:我说你需要知道的第一件事是存在"创建新变量"这样一个概念,当我运行一个算法时,这是我可以选择的事情之一。我要做什么?我要创建一个变量。所以这就在你可以做的事情的下拉列表上。明白吗?实际上只有大约八九个这样的概念。

But when you say that, as soon as you say "I'm going to make a new variable," some questions should pop in your mind. Some questions should pop in your mind, right? Doesn't matter what language you're in - no, same questions. Anytime we make a variable, I guarantee you're going to need to know: What's its name? What's its type? What sort of data does it hold?
但是当你说到这里时,一旦你说"我要创建一个新变量",就应该在你的脑海中弹出一些问题。你的脑海中应该弹出一些问题,对吗?不管你使用什么语言,都是一样的问题。每次我们创建变量,我可以保证你都需要知道:它的名称是什么?它的类型是什么?它包含什么样的数据?

Those of us who've been programming for a while know that computers are getting a little fussy about that. You know, we have integers that don't have decimal point stuff, and we have floating point numbers that have that, and then we have strings (which is the much cooler way to say text), and then we got other stuff too. And it depends on which language how fussy you are about that sort of thing, right? If this was a Java group, they'd be like "Yeah, strict data types, baby!" We're Python - we're like "Meh, it's all the same, we'll decide later." But does it still matter what type something is, even if maybe our language isn't too fussy about it? We shall see.
那些一直在编程的人都知道,计算机在这方面变得有些挑剔了。我们有不带小数点的整数,有带小数点的浮点数,还有文本类型(这是一种更酷的说法),还有其他类型。这取决于使用的编程语言,对数据类型的严格程度也不尽相同。如果这是一个 Java 群组,他们可能会说:"对,严格的数据类型,宝贝!"而我们 Python,则会说:"啊,都一样,我们稍后再决定。"但即使语言对数据类型不太严格,它是否仍然重要?让我们看看吧。

Initial value - what's its starting value? So would you agree whenever you make a variable in any language, you think of these things? There might be some others like scope, but I'm going to save that for functions. Scope doesn't mean much if you don't have functions yet.
初始值 - 它的起始值是多少? 所以你是否同意,无论在任何语言中,当你创建一个变量时,你都会考虑这些事情?可能还有一些其他的,比如作用域,但我会把那个留给函数。如果你还没有函数,作用域就没有太大意义。

So whenever I make a variable, that's what I think. Do you agree? Here's where you say yes no yes please go home? Okay, good, thank you! So how do you write an algorithm? This is the part I'm proud of! When it works, it's the part. See the scrolls?
只要我创建一个变量,那就是我的想法。你同意吗?这就是你说"是"..."不"..."是的请"..."回家"的地方。好的,谢谢!那么,如何编写算法呢?这就是我引以为豪的部分!当它工作时,就是那一部分。看到滚动条了吗?

How do you write an algorithm? Here's the beautiful thing: you must write in English! No coding allowed! Unless, of course, English isn't your favorite language - then Swahili, whatever, cool, awesome. Create whatever it is, I don't care, but your sentence has to answer those questions. It has to answer the question: What's its name? What's its starting value? And what's its type? That's your algorithm. Does that make sense?
如何编写算法?这里有一件美好的事情:您必须用英语写!不允许编码!当然,如果英语不是您最喜欢的语言,那么可以使用斯瓦希里语,无论如何,很酷,很好。创建任何东西,我不在乎,但您的句子必须回答这些问题。它必须回答这个问题:它的名称是什么?它的起始值是什么?它的类型是什么?这就是您的算法。这说得通吗?

So when we're teaching a beginner to make a variable, the first thing they need to know is "I need to make a variable," and then the second thing they need to know is "What questions should I always answer when I make a variable?" Does that make sense? And then when we do that - honestly, that's all they need. But see, if I could get away with it, I wouldn't even teach a language yet, but they don't believe it's real coding unless they're typing somewhere, so fine, we'll do it!
所以当我们教一个初学者如何创建变量时,他们需要知道的第一件事是"我需要创建一个变量",第二件事是"在创建变量时,我应该总是回答哪些问题?"这样说得通吗?然后当我们这样做时,老实说,这就是他们所需要知道的全部。但是看,如果我能逃脱的话,我甚至不会教他们一种语言,但是他们不相信除非他们在某个地方输入,否则就不是真正的编码,所以好吧,我们就这么做!

That's how we write this in Python: "name gets an initial value" - type? Huh, you're on your own! But that's how we do it in Python. So I can live with that. Can you live with that? Yeah, sure, 'cause we're Python programmers, so that's good.
这就是我们在 Python 中编写的方式:"name 获得初始值" - 类型?好吧,这由你自己来决定!但这就是我们在 Python 中的做法。所以我可以接受这样做。你能接受吗?是的,当然,因为我们是 Python 程序员,所以这很好。

So that's one of our concepts. Here's another concept - I mean, it seems trivial, doesn't it? But it isn't, it isn't - output! Right? What's another thing I can do? Well, I can tell the user stuff. I'm going to start here with the command line console because life is easier there, isn't it? We're in charge! I mean, in the GUI, the user's in charge, and who put them in charge? Not me!
这就是我们的一个概念。这里是另一个概念 - 我的意思是,它似乎很琐碎,不是吗?但它并不是,它并不是 - 输出!对吧?我还能做什么?好吧,我可以告诉用户一些东西。我将从命令行控制台开始,因为那里的生活更容易,不是吗?我们掌握主控权!我的意思是,在 GUI 中,用户掌握主控权,而把主控权交给他们的人是谁?不是我!

But output is pretty easy - there's only one thing to worry about: what message do I want to send the user? And of course, output's usually text, isn't it? Yes, it's text. So that's pretty easy, and we could write an algorithm for an output line too, couldn't we? Don't worry, there's a quiz coming! "Output the text message" - okay, that's really easy. Yeah, you code - yay for Python 3! Not "System.out.println," no not "Console.WriteLine" it's as easy as "print" - except I always yeah, "cout." Thank you! "Printer?" What's a "prin"? I don't know!
但输出很容易 - 只有一件事需要担心:我想向用户发送什么信息?当然,输出通常是文本,不是吗?是的,它是文本。所以这很容易,我们也可以为输出行编写一个算法,不是吗?别担心,还有一个问题即将到来!"输出文字消息" - 好的,这真的很容易。是的,你编码 - 耶,Python 3!不是"System.out.println",不是..."Console.WriteLine"...它就像"print"一样简单 - 除了我总是...是的,"cout"。谢谢!"打印机?"什么是"prin"?我不知道!

You know, I still mess up the parentheses sometimes because I did Python 2.7 for a long time, wrote a whole book in 2. So the parentheses sometimes throw me, but I can do this now. How much are we worried about the Python syntax? Have you seen how much we've stressed about that? Well, why not? Because you all know it, but why? Because that's the part we can look up! How do I do it in this language? That part Google will help us with, won't it? If you try to Google "how what problem am I trying to solve," you're going to get some very scary results. But if you know what you're trying to do - you know, "I'm trying to output text" - you can say "How do I output text in Python 3?" and the chances are you'll get something pretty close to this. Yes, so the coding part is the easy part - the algorithm part is the hard part!
你知道,有时候我仍然弄不清楚括号的使用,因为我以前一直在使用 Python 2.7,还写过一本用 2 写的整本书。所以括号有时会让我困惑,但我现在已经掌握了。我们有多担心 Python 语法呢?你有没有注意到我们对此非常着紧?为什么呢?因为你们都知道它,但原因是什么?因为这部分我们可以查阅!我如何在这种语言中实现它?谷歌会帮助我们解决这个问题,不是吗?如果你试图搜索"我要解决什么问题",你会得到一些非常吓人的结果。但如果你知道自己要做什么-比如"我想输出文本"-你就可以搜索"如何在 Python 3 中输出文本?"你很可能会得到非常接近的答案。是的,编码部分是容易的-算法部分才是难点!

Right, so we're getting to the point where we have enough of these tools we can start to put together a real program. There's, you know, input—now input I like talking about because this is the first one that really starts to talk about the real complexity of coding, isn't it? Because see, all of the other things were atomic; they could kind of stand on their own, but input is really—I mean, input has like dependencies, doesn't it?
好的,我们已经有足够的工具可以开始组装一个真正的程序了。有,你知道,输入—现在谈论输入是因为这是真正开始讨论编码复杂性的第一个环节,不是吗?因为其他的东西都是原子性的,可以独立存在,但输入确实有依赖性,对不对?

I mean, think about it: when I input something here, um, "Tell me the answer." Tell me the answer! Come on, 42! 42—that's a good one, I like that. Um, yeah, I'm coveting that t-shirt.
我的意思是,想一想:当我在这里输入某些东西时,嗯,"告诉我答案。"告诉我答案!来吧,42!42–这个很好,我喜欢。嗯,是的,我垂涎这件 T 恤。

It's not fair for me to ask you the answer if I didn't ask a question, is it? It's never stopped me as a teacher. But if I am asking for an answer, I should really give you a question. So an input implies that there was some question asked of the user—it may be in that statement as it is in Python, it may be another line, it doesn't matter much. But somehow, we're going to ask the user a question.
对不起,这对我来说并不公平,如果我没有问任何问题就要求你给我答案,对吗?作为老师,我从来没有被这种情况阻止过。但是,如果我要求你给出答案,我应该真正地给你一个问题。所以一个输入意味着已经向用户提出了某个问题——它可能就在那个语句中,就像在 Python 中一样,也可能在另一行,这并不重要。但不管怎样,我们都要问用户一个问题。

Well, okay, now um, "Throw me the ball!" Throw me the ball! Come on, you guys can help—throw me the ball, please! What ball? Yeah, you have a ball—throw it! You know what I should have done? I should have put up my mitt. I shouldn't ask for somebody to throw something if I'm not ready to catch it.
好吧,现在呃,"把球扔给我!"把球扔给我!拜托,你们能帮忙——把球扔给我,拜托!什么球?是的,你们有一个球——扔过来吧!我本应该做些什么?我本应该举起手套。我不应该要求有人扔东西给我,如果我还没准备好接住它的话。

Input—you have to have a variable to answer to, to hold the answer. You have to have a question that you ask them. So the crazy thing about input is it should never be the first line of your algorithm. You see what I'm saying? It doesn't make sense because there's like prerequisites. So you need to either in the input statement itself or in another statement, you need to ask a question and you already need to have a variable in place that can catch the answer.
您必须有一个变量来回答,来保存答案。您必须有一个问题来问他们。所以关于输入的疯狂之处在于,它不应该是您算法的第一行。您明白我的意思吗?这是没有意义的,因为有前提条件。所以您需要在输入语句本身或者在另一个语句中,提出一个问题,而您已经需要有一个变量可以捕获答案。

Well, that makes a lot of sense, doesn't it? And what does that have to do with Python syntax? Nothing—that's a different problem and an easier one, isn't it? That's an easier problem.
好的,这很有道理,不是吗?这和 Python 语法有什么关系呢?没有任何关系,这是另一个问题,而且更容易解决,不是吗?这是一个更容易解决的问题。

Okay, so how would we do an algorithm? Anyone—you want any line of algorithm as long as it answers those questions, makes me happy: ask the user a message and store the answer in variable. Beautiful! We good with that? You want to see code? You've seen the code, but it's easy—variable gets input, message.
好的,我们应该如何编写算法呢?无论是什么样的算法代码,只要能回答这些问题并让我高兴就行:要求用户输入一条消息并将其存储在变量中。很好!我们都同意这个吗?你想看代码吗?你已经看过了,但是很简单——变量获取输入,消息。

Yeah, but you see the point I'm trying to make: when we understand the concepts, the code itself becomes actually at some point—and this is why we don't always write comments, right? At some point, this is more clear than that, but not for a beginner—not for a beginner.
是的,但你看到我正试图表达的观点:当我们理解概念时,代码本身在某一点上实际上变得更加清晰 - 这就是为什么我们不总是编写注释的原因,对吗?在某些时候,这比那个更清楚,但对于初学者来说并非如此 - 对于初学者来说并非如此。

When teaching beginners, it’s important to remember they need to take their time with the process before jumping straight to the code. We sometimes forget that. To beginners, our approach can look like arrogance, but it’s really just forgetfulness.
当教授初学者时,重要的是要记住他们需要在跳到代码之前花时间进行这个过程。我们有时会忘记这一点。对于初学者来说,我们的方法可能看起来像是傲慢,但实际上只是遗忘了这一点。

Now, let’s see if we can write a program. We could with just a basic plan. But in real life, I would stop right here. No more code yet. At this stage, we’ve learned plenty. You can’t make me teach another line of code. What I’d do instead is grab paper and pencil and start writing algorithms.
现在,让我们看看我们是否可以编写一个程序。我们可以只有一个基本计划。但在现实生活中,我会在这里停下来。还没有更多的代码。在这个阶段,我们已经学到了很多。你不能强迫我教另一行代码。我要做的是拿起纸笔开始编写算法。

I’d prefer doing this in groups, not alone. If someone’s confused, they can find someone feeling confident and make them uncomfortable. That’s how learning works. But if anyone turns on a computer too early, I’ll slap it shut. I don’t want computers right now—I want brains. Those are better computers anyway, right?
我更喜欢以小组方式进行,而不是单独进行。如果有人感到困惑,他们可以寻找自信的人并让他们感到不舒服。这就是学习的方式。但是如果有人过早打开电脑,我会把它关掉。我现在不想要电脑,我想要大脑。那些才是更好的电脑,对吗?

This is the hard part for those of us who think in code. Sometimes, I even dream in code—it’s terrifying. Especially when my dreams involve memory leaks. That’s a bad place to be. But for now, let’s stay away from computers. Let’s write the algorithm.
这对于我们这些习惯用代码思考的人来说确实是一个难点。有时候,我甚至会在梦中编写代码 —— 那真是太可怕了。尤其是当我在梦中遇到内存泄漏时。那是一个非常糟糕的处境。不过现在,让我们远离电脑吧。让我们来写个算法吧。

Here’s an example of what that might look like:
这是一个示例,看起来可能是这样的:

  1. Create an integer variable for x.
    创建一个整数变量 x
  2. Create an integer variable for y.
    创建一个整数变量 y
  3. Create an integer variable for sum.
    创建一个整数变量 sum
  4. Ask the user for x and store the answer in x.
    要求用户输入 x 并将答案存储在 x 中。
  5. Ask the user for y and store the answer in y.
    要求用户输入 y 并将答案存储在 y 中。
  6. Add x and y and store the result in sum.
    添加 xy 并将结果存储在 sum 中。
  7. Print, “The answer is sum.”
    打印, "答案是 sum 。"

It’s simple and clean. Some might say, "Why not just write the code?" But beginners need to start this way. Writing out the logic first, before diving into syntax or tools, helps build the foundation.
它简单而清洁。有些人可能会说,"为什么不直接编写代码?"但初学者需要从这种方式开始。首先编写逻辑,然后再深入研究语法或工具,有助于建立基础。

Python makes this process even easier. We’re half a step away from Python code because Python is beautiful—well, except for some quirks like if __name__ == "__main__". That’s a bit clunky. And don’t even get me started on self. Beginners struggle with those things, and for good reason.
这个过程使用 Python 变得更加简单。我们离 Python 代码只有一步之遥,因为 Python 很漂亮——除了一些怪癖,如 if __name__ == "__main__" 。那有点笨拙。而且别让我开始谈论 self 。初学者很难理解这些东西,这是有充分理由的。

At this stage, we take the written plan and convert it into comments. Once that’s done, we can start writing the actual code, one line at a time. Beginners can use Google to figure out syntax, but the logic is already there. That’s the critical part. The actual programming language doesn’t even matter until now.
在此阶段,我们将书面计划转换为注释。完成后,我们可以开始一行一行地编写实际代码。初学者可以使用 Google 来了解语法,但逻辑已经存在。这是关键部分。实际编程语言直到现在才不重要。

The choice of editor? It doesn’t matter either. Beginners sometimes stress over finding the “perfect” editor, but it’s not about that. Personally, I’m a Vim guy. I love it. But I wouldn’t impose that on someone just starting out. The editor should stay out of the way. In fact, I’m not even a big fan of syntax highlighting or code completion. Those tools solve surface-level problems but don’t address the deeper issues—thinking clearly and solving problems well.
编辑器的选择并不重要。初学者有时会对找到"完美"的编辑器感到压力,但这并不关键。我个人是一名 Vim 用户,我非常喜欢它。但我不会强迫一个刚刚起步的人使用它。编辑器应该不引人注意。事实上,我甚至不太喜欢语法高亮或代码补全这样的工具。这些工具只解决表面问题,并没有解决更深层的问题,如清晰地思考和恰当地解决问题。

When teaching programming, the goal isn’t just to write code that works. It’s about writing algorithms that make sense and thinking through problems logically. That’s where the real learning happens.
在教授编程时,目标不仅仅是编写可以运行的代码。它关乎编写有意义的算法,并通过逻辑思考来解决问题。这就是真正的学习发生所在。

Don’t start with a solution—unless you’re using Git. Then it’s okay. Make it a new branch and go ahead.
不要从一个解决方案开始 - 除非你在使用 Git。那样就可以了。新建一个分支并继续。

But don’t start with a solution because you’re going to mess yourself up, aren’t you? People come to me all the time swearing that Python is broken because it’s not working, and it should.
但是不要从解决方案开始,因为你会把自己搞糊涂,不是吗?人们一直来找我,发誓 Python 坏了,因为它不工作,但它应该工作。

Alright, there’s something you’re not understanding—and that’s fine—but there’s something you’re not understanding. And often, your assumptions are the reason. You’re assuming things that aren’t true.
好了,你没有理解某些事情,这是可以接受的,但是你没有理解某些事情。而且通常,你的假设就是原因所在。你假设了一些不是真的事情。

Do some detective work, Sherlock. Let’s figure out what’s going on. Let’s get in there and find out what’s happening. There are lots of tools for that, but you have to start by understanding the problem.
做些侦探工作,夏洛克。让我们弄清楚发生了什么。让我们进去看看到底发生了什么。对此有很多工具,但你必须先了解问题所在。

A lot of times, I’ll just say, “Turn off the computer.” Here’s a whiteboard marker.
很多次,我会说"关闭电脑"。这里有一支白板笔。

When they moved my office, they were going to take away my whiteboard and my bookshelves. I told them, “You can take my computer.” True story. And they thought I was nuts. They said, “Alright, you can keep the whiteboard—you scare us a little.”
当他们搬迁我的办公室时,他们打算拿走我的白板和书架。我告诉他们,"你可以拿走我的电脑。"这是真实的故事。他们认为我疯了。他们说,"好吧,你可以保留白板—你让我们有点害怕。"

So, what happened here? It’s easy to assume the plus sign is broken. “Dang it, this thing doesn’t even know how to add!” That’s a normal assumption, isn’t it?
那里发生了什么?很容易假设加号坏了。"该死,这个东西连加法都不会!"这是一个正常的假设,不是吗?

But that’s not really the problem. Those of us who are experienced might feel superior because we already know the answer. But why? Because we’ve already felt like idiots in the past when we made the same mistake.
但这并不是真正的问题。那些有经验的人可能会感到优越,因为我们已经知道答案了。但为什么?因为我们过去曾经犯过同样的错误,感到像白痴一样。

We’ve all been there. We’ve all had that moment where we thought, “The plus sign must be broken.” But that’s not the problem. So, what’s really the problem?
我们都经历过那样的时刻。我们都曾经想过"加号一定坏了"。但这并不是问题所在。那么,问题究竟在哪里?

Try this. Python has an interactive mode—I love that. If I type something like Python + Meetup, what’s it going to say?
尝试这个。Python 有一个交互模式-我很喜欢这个。如果我输入类似 Python + Meetup 的东西,它会说什么?

Let’s see. “Python Meetup.” Wait a minute! You can’t add “Python” and “Meetup,” can you?
让我们看看。"Python 见面会。"等一下!你能把"Python"和"见面会"加在一起吗?

Here’s where you have to be careful. Someone might want to jump in and say, “Well, operator overloading is a form of polymorphism, and it’s actually concatenating rather than adding because it’s automatically detecting that these are strings and not integers.”
这里您需要当心。有人可能会想插话说:"好吧,运算符重载是多态性的一种形式,实际上是连接而不是相加,因为它会自动检测这些是字符串而不是整数。"

Yeah, no. Slap you with a wet fish for saying that around beginners.
是的,不。为在初学者面前说那句话,用湿鱼掴你一下。

When you’re working with beginners, that’s the worst thing you can do. They already feel confused. Now, they feel worse because it sounds like you just switched to speaking another language.
当您与初学者合作时,这是您可能做出的最糟糕的事情。他们已经感到困惑。现在,他们感觉更糟糕,因为听起来就像您刚刚切换到另一种语言。

Yes, all that technical explanation is true. And yes, it’s wonderful to understand eventually. But do you have to understand that on the first day? Absolutely not.
是的,所有这些技术解释都是正确的。是的,最终能理解这一切确实很棒。但你必须在第一天就全部理解吗?绝对不需要。

It’s enough to say: “The plus sign is so smart that it does different things depending on what it sees. If it sees numbers, it adds. If it sees text, it joins them together.”
足够说:"加号如此聪明,它根据所见做不同的事情。如果它看到数字,就会相加。如果它看到文本,就会将它们连在一起。"

And then you might say, “Hmm, it seems like Python thinks 5 and 3 are text. I wonder if that’s the problem. Can I test that?”
然后你可能会说,"嗯,似乎 Python 认为 5 和 3 是文本。我想知道这是否是问题。我可以测试一下吗?"

Now, let’s Google. Is there a way to find out what type of data something is? Yes! Is it type or typeof? I always mix up JavaScript and Python here. I usually guess wrong the first time, but it’s type in Python.
现在,让我们去 Google 一下。是否有办法找出某些数据的类型?是的!是 type 还是 typeof ?我总是把 JavaScript 和 Python 混淆。我通常第一次猜错,但是在 Python 中是 type

Alright, so we know that text can be joined (concatenated). Let’s see if 2 and 3 are actually being treated as text. The type function will tell us what we want to know.
好的,所以我们知道文本可以连接(连接)。让我们看看 2 和 3 是否实际上被视为文本。 type 函数将告诉我们我们想要知道的。

Okay, now we add a new tool to our toolbox. You see what I’m saying? Now we add a new tool, and we say, “Alright, cool. I need a new algorithm piece: convert to integer.” Go look it up, figure out what you have to do.
好了,我们在工具箱里添加了一个新工具。你明白我的意思吗?现在我们添加了一个新工具,我们说:"好的,很酷。我需要一个新的算法部件:转换为整数。"去查一查,看看你需要做什么。

Looks like we have an old variable, an INT variable, and we need to convert the old variable to an integer and store it in the INT variable. Oh look, there’s code for it! That’s all fun, isn’t it?
看起来我们有一个旧变量,一个 INT 变量,我们需要将旧变量转换为整数并将其存储在 INT 变量中。哦,看,这里有相关的代码!这很有趣,不是吗?

Now we have a new tool. And that’s how we continue growing: as we encounter a problem, we develop a new algorithmic tool to solve it. Does that make sense?
现在我们有了一个新工具。而这就是我们继续成长的方式:当我们遇到问题时,我们就开发新的算法工具来解决它。这说得通吗?

This is pretty fun, isn’t it? It is—really—in a geeky way.
这真有趣,是吗?这确实是一种极客方式。

Now we can try again with a new tool. Notice what I did: I killed my code. And yeah, maybe it took me hours to write that code. But let’s be honest—it didn’t take hours to write it. It took hours to understand it. And I understood it wrong.
现在我们可以尝试使用一个新的工具。注意我的行为:我终止了我的代码。是的,可能花了我好几个小时来编写那段代码。但说真的,编写它并没有花很长时间。花了好几个小时才弄明白它。而且我理解错了。

It’s really hard to get people to throw away code, isn’t it? But sometimes you have to. Fine—put it in a subdirectory if it makes you feel better. But start fresh. Use Git. I love Git.
实在很难让人放弃代码,是不是?但有时候必须这样做。没关系,如果这样让你感觉更好,可以把它放在一个子目录里。但从头开始。使用 Git。我喜欢 Git。

But start fresh because if the code was worth keeping, it would have worked. And you’re not losing the thought process—you’re just clearing up the mess. Sometimes, you just got yourself into a bad place.
但是从头开始,因为如果代码值得保留,它就应该能够工作。你并没有丢失思维过程,只是清理了一团乱麻。有时候,你只是陷入了一个糟糕的境地。

So now, I’m going to rewrite my algorithm. And I’ll be honest—I wrote this wrong the first time. I put it in the wrong order. But before I wrote any code, I thought about it and realized, “That’s in the wrong order. That’s not going to work.”
所以现在,我要重写我的算法。 我很诚实 - 我第一次写错了。 我把它放在了错误的顺序中。 但在我写任何代码之前,我想了想,意识到"这是顺序错误的。 这是无法工作的。"

You see, I’m thinking about programming before I write code. It’s often easier to see the order of things that way. I converted too early the first time. But now, looking at it, I can see what makes sense.
你看,在我写代码之前,我在思考编程。这样做通常更容易看清事物的顺序。第一次我转换得太早了。但是现在,看着它,我能明白什么是有意义的。

I could work this out on a whiteboard. I could be the computer. And now, I can put the code in. Will this work? Yeah, we can prove it. I can run it. And yeah, it works.
我可以在白板上解决这个问题。我可以成为计算机。现在,我可以输入代码了。这会成功吗?对,我们可以证明它。我可以运行它。对,它可以运作。

Alright, we’ve got branching and for-loops. But I want to talk a little about while-loops before we wrap up.
好的,我们已经学习了分支和 for 循环。但在结束之前,我想谈谈 while 循环。

For-loops are interesting. Sometimes, Python people get mad at me when they see the way I teach for-loops. I say that a for-loop has lots of parts: a sentry, a start, a finish, and a change.
对于循环很有趣。有时,当他们看到我教授对于循环的方式时,Python 开发者会对我感到生气。我说对于循环有很多部分:哨兵、起点、终点和变化。

And they’ll say, “That is such a C++ for-loop! What’s the matter with you?” And yeah—it is. But sometimes I want to teach Python, and sometimes I want to teach programming.
他们会说,"这是如此一个 C++的 for 循环!你怎么了?"是的,它确实如此。但有时我想教 Python,有时我想教编程。

When I’m teaching beginners, I’ll do it this way. If Python is their third language, we’ll use iterators. But if they’re new, this traditional structure lines up better with other languages.
当我在教初学者时,我会这样做。如果 Python 是他们的第三种语言,我们将使用迭代器。但是如果他们是新手,这种传统结构与其他语言更加一致。

More importantly, it’s better for learning how to debug properly. When you have a loop, what are the three things you always think about? Well, four things, really.
更重要的是,它更有利于学习如何正确调试。当你有一个循环时,你总是会考虑三件事吗?其实是四件事。

First, there’s the sentry. What is the variable that controls the whole thing? And then, there are three things about the sentry you need to know:
第一,有瞭望哨。什么变量控制着整个事情?然后,还有三件关于瞭望哨你需要知道的事情:

  • How does it start? 它是如何开始的?
  • How does it finish? 它完成了吗?
  • How does it change? 它是如何变化的?

It seems so simple, right? But how many loops have gone terribly wrong because one of those wasn’t handled correctly?
这似乎很简单,对吗?但是,由于其中一些没有正确处理,导致出现了多少次严重的错误循环呢?

What’s the most likely basic code structure to go wrong? A loop. Especially if you see a Boolean operator in there. Death to Boolean operators!
最有可能出错的基本代码结构是循环。特别是如果你在里面看到布尔运算符。布尔运算符必须死!

So yeah, Boolean operators—truth or false—you get the idea. But we’ll come back to that thought.
是的,布尔运算符——真或假——你明白了。但我们会回到这个想法。

Now, let’s talk about while-loops. What are the four things you need to know about a while-loop? What’s the sentry? How does it start? How does it end? How does it change?
现在,让我们来谈谈 while 循环。你需要知道一个 while 循环的四个事项是什么?检查条件是什么?它是如何开始的?它是如何结束的?它是如何改变的?

Oh wait—that’s not true. The while-loop has only one parameter. That’s the problem with while-loops. The while-loop implies a lot that it doesn’t require, and that’s why while-loops go wrong so often.
哦,等等 - 那不是真的。while 循环只有一个参数。这就是 while 循环的问题所在。while 循环隐含了很多它并不需要的东西,这就是 while 循环经常出错的原因。

If you’re going to make a while-loop, you have a holy obligation to think about what the sentry is—even though the while-loop doesn’t require it. You have to initialize the sentry before the loop, which means you have to plan ahead.
如果你打算使用 while 循环,你有责任考虑哨兵的性质,即使 while 循环本身并不需要它。在循环开始前,你必须先初始化哨兵,这意味着你需要提前规划。

Why are you writing code? You should be designing algorithms first. And somewhere inside the loop—who knows where—you have to change the sentry.
为什么你在写代码?你应该先设计算法。在循环中的某个地方 - 谁知道在哪里 - 你必须改变哨兵。

You have to change it in a way that guarantees the condition will be triggered at some point. Oh yeah, the condition! You never forget that one. But sometimes, you’ll write a condition that’s impossible to satisfy—like a marriage seminar or something.
你必须以某种方式改变它,以确保在某个时候会触发该条件。哦,是的,那个条件!你永远不会忘记那个。但有时,你会写一个不可能满足的条件,就像婚姻研讨会之类的。

So yeah, those are the same things you need to think about in a while-loop. That’s why I teach them first in the context of for-loops.
所以是的,这些都是在 while 循环中需要考虑的事项。这就是为什么我会先在 for 循环的背景下教授它们。

Speaker: 扬声器

Because how easy is it to mess that up? Oh, you don't? All right, here we go.
因为那么容易搞砸吗?噢,你不知道?好吧,我们开始。

Here's an example: the basic password loop. We've all done this one, right? It exits with a positive result if the user chooses the right password. But if they get it wrong it launches missiles.
这里是个例子:基本密码循环。我们都做过这个,对吗?如果用户选择正确密码,它会以正面结果退出。但如果他们输错了...它会发射导弹。

So, if you get it wrong three times—sorry about your luck—sending the missiles. Right? We've all done this. How are you going to code it?
所以,如果你错误三次 - 对不起,你的运气 - 发射导弹。对吧?我们都这样做过。你打算如何编码它?

Really, how are you going to code it? All right, we'll use a compound condition, right? With a Boolean.
真的,你打算如何编码它?好吧,我们将使用复合条件,对吗?使用布尔值。

Now, I love Boolean variables—don't get me wrong. It's Boolean operators that bug me. Here's why.
现在,我喜欢布尔变量——别误会我的意思。是布尔运算符让我烦恼。原因如下。

What condition do we need on this thing? Let's see:
我们需要对这个东西做什么条件?让我们看看:

  • tries >= 3
  • guess != correct

Yeah, that's it. Or is it? Because now guess is a negative, and Morgan's Law—it's a Boolean variable.
是的,就是这样。还是不是?因为现在 guess 是一个负数,而摩根定律——它是一个布尔变量。

Okay, take a picture because it's going away.
好的,拍一张照片,因为它就要消失了。

So, correct is initialized. tries = 0. keep_going = True.
所以, correct 已初始化。 tries = 0keep_going = True

Now, what I love about Boolean variables is that there’s not a lot that can go wrong. It’s about the cleanest variable type you’ve got. I love Boolean variables. I don’t love Boolean operators as much—unless I’m just working on Boolean variables with them.
现在,我最喜欢布尔变量的地方在于,不会出现太多的问题。这是最干净的变量类型了。我很喜欢布尔变量。我不像对布尔运算符那么喜欢——除非我只是在处理布尔变量。

But while keep_going, if this thing is True—and it better be—we’ll keep going. And through that, I can do whatever code I want.
但是,如果这个事情是 True ——而且最好如此——我们将继续前进。通过这种方式,我可以做任何我想做的代码。

Yes, I deliberately did not do the formatting thing because I don’t want to freak out beginners. It’s really cool, but not today.
是的,我故意没有做格式处理,因为我不想吓到初学者。这真的很酷,但不是今天。

Now, take a look: 现在,请看:

  • If guess == correct, then we’ll say, “That’s great! Here’s the treasure.”
    如果 guess == correct ,那我们就说:"太棒了!这就是宝藏。"
  • And then, look at this beautiful thing—that’s where the break statement goes, doesn’t it?
    然后,看看这个美丽的东西——那里就是 break 语句的地方,不是吗?

Now, we should never write break, should we? I know. Switch statements—thank you, Guido, for not including those.
现在,我们永远不应该写 break 吗?我知道。switch 语句--谢谢你,Guido,没有包括那些。

Yeah, so keep_going = False. That means the next time I evaluate this loop, we’re out. How clean is that? And what do I really mean by this line? I don’t want to keep going.
是的,所以 keep_going = False 。这意味着下次评估这个循环时,我们就完成了。这有多清晰?我到底想说什么呢?我不想继续了。

I like that. Do you like that? It’s much easier to follow.
我喜欢那个。你喜欢那个吗?那要容易得多了。

Else, if tries >= 3:
否则,如果 tries >= 3 :

  • Then we’re going to print: “Hey, too many wrong tries. Launching the missiles.”
    那么我们将打印:"嘿,尝试错误次数太多了。导弹发射。"

Once again, we’re not directly exiting the loop, but we’re telling it: the next time you evaluate, I don’t want to keep going anymore.
我们再次不是直接退出循环,而是在告诉它:下一次你评估时,我不想继续下去了。

You know what’s funny? I don’t know the last time I wrote a while loop that didn’t just say while keep_going. Because once you get used to this… man, it’s beautiful.
你知道什么是有趣的吗?我不记得上次写一个 while 循环时没有使用 while keep_going 。因为一旦你习惯了这种方式,那真是太棒了。

It is just beautiful. And I write a lot of games. You know, game code gets messy, doesn’t it? Let me tell you—no code gets messier than game code.
这真是美丽动人。我写了很多游戏。你知道,游戏代码很容易变得混乱,对吗?让我告诉你,没有任何代码会比游戏代码更乱糟糟的。

Partially because we don’t design for maintenance in gaming. You know it’s going to be out of date in a year. So, in gaming, you don’t design it to be maintained—you design it to be fast. And so, you write some junk.
部分原因是因为我们在游戏中没有设计维护。你知道它一年后就会过时。所以,在游戏中,你不设计它来维护 - 你设计它要快。于是,你写了一些垃圾。

Eventually, we’ll teach all these things in their time, but not today. You good with that?
总有一天,我们会在适当的时候教授这些东西,但不是今天。你同意这样吗?


Why Python? 为什么是 Python?

I mean, I’ve taken a lot of time to tell you tonight that the language doesn’t matter.
我的意思是,我花了很多时间告诉你,语言并不重要。

Yet it’s a Python group, and I do love Python.
尽管如此,这是一个 Python 群组,而且我确实喜欢 Python。

So, if the language doesn’t matter, why did we choose Python? Well, I’ll show you.
所以,如果语言无关紧要,为什么我们选择了 Python?好吧,我来告诉你。

You recognize this, right? What language are we in? Old-school C, man. This is the way God intended. Pointers everywhere. No strings—strings are for wusses.
您认识这个吗?我们在使用什么语言?老派的 C 语言,伙计。这就是上帝本来的意图。到处都是指针。没有字符串——字符串是给软蛋用的。

All right, here’s some C. And you know, “Hello, World” is too simple to really get the feel of a language, isn’t it?
好的,这里有一些 C。你知道,"Hello, World"太简单了,很难真正感受到一种语言的味道,不是吗?

So, I say we really need to do “Hello, User.” That is, it asks the user’s name, and then it does something with it. That’s the smallest program I think we can use to really get the sense of the flavor of a language. Would you agree?
你好,用户。

Would it be possible for me to take that little chart we just did and show you how to do all those things in C? Absolutely.
可以。


Moving On to Other Languages
继续学习其他语言

There’s C++, right? At this level, C++ looks like a dream, doesn’t it? No more printf. C++ must be easy—if you’ve done some.
有 C++,对吧?在这个层面上,C++看起来像一个梦想,不是吗?不再有 printf 。如果你已经做过一些,C++一定很容易。

Yeah. If… and… define… anyone? Yep.
是的。如果...和...定义...任何人?是的。

C++ is pretty nice at this level, but it gets hard fast.
C++很不错,但会变得很难。

Here’s my favorite: public static void main(String[] args).
这里是我最喜欢的: public static void main(String[] args) .

Have you ever tried to teach Java to a beginner? Have you ever been to a beginner Java class?
你有没有尝试过教 Java 给初学者? 你有没有参加过初学者 Java 课程?

Every Java teacher in the world who has to teach beginners—and this was me—they wanted me to teach this in Nicaragua. “Please teach this in Java.”
世界上每个不得不教授初学者的 Java 老师,而这个就是我,他们希望我在尼加拉瓜教授这门课程。"请用 Java 教授这个。"

I’m like, “Oh, okay, great. Please wave a dead chicken over your shoulder, turn around three times—it’s a ritual—throw salt, and type this line.”
我像是,"哦,好的,太棒了。请在你的肩膀上挥舞一只死鸡,转身三次——这是一种仪式——撒盐,然后输入这行文字。"

And they’re like, “We do not have a chicken.”
他们说,"我们没有鸡。"

Never mind, I don’t really mean that. It’s just a ritual.
别在意,我并不是真心的。这只是一种仪式而已。

Because I don’t want to teach you what a static method is yet—that doesn’t make sense if we haven’t done objects. And we shouldn’t be doing objects yet. You’re just trying to make a variable!
因为我还不想教你什么是静态方法——如果我们还没有接触对象,这是没有意义的。我们现在也不应该接触对象。你只是想创建一个变量!

So, this makes me crazy. Now, I love Java. I do.
所以,这让我疯狂。现在,我喜欢 Java。我确实如此。

But I love Java for more advanced programmers because it doesn’t let you do some stupid things we like to do anyway.
但我更喜欢 Java,因为它不允许我们做一些愚蠢的事情。


Back to Python 回到 Python

So, why Python? 所以,为什么选择 Python?

That’s why. 就是这样。

If you want to teach a beginner to program, which of these languages is easiest to translate from the algorithm to code that actually works? That’s what I love about Python.
如果你想教一个初学者编程,这些语言中哪个最容易从算法转换成实际可用的代码?这就是我喜欢 Python 的原因。

Since I don’t care about the language, how about we pick one that gets out of the way and gives them success?
既然我不关心语言,那不如我们选择一种可以让他们获得成功的语言吧?

I want them to succeed. I want them to feel proud. I want them to fail—because that’s going to happen—but I want them to overcome that failure.
我希望他们成功。我希望他们感到自豪。我希望他们失败——因为这将会发生——但我希望他们克服这种失败。

And so, a language that helps us do that? That makes me happy.
那么,一种帮助我们做到那一点的语言?这让我高兴。

You hear what I’m saying? That makes me happy.
你听到我在说什么了吗?这让我感到高兴。

And I like successful students.
我喜欢成功的学生。


They’re going to want to make games. Fine. We can do that.
他们将想要制作游戏。好的。我们可以做到这一点。

Somebody’s going to want to write a database? SQLite’s built-in. Good enough.
有人会想要写一个数据库吗?SQLite 内置的。足够好了。

They all want to do GUIs? Okay, fine. TK. Yeah, TK, but hey—it’s built in.
他们都想做图形用户界面?好吧,没问题。TK。是的,TK,但是嘿,它是内置的。

What do you want to do? Sure, we can do it. Get it out of your system.
你想做什么?好的,我们可以做。把它从你的系统中排除吧。

You want to do web apps? I taught that tonight. I showed them. This is their first Python class. I showed them Bottle because there’s no installation.
你要做 Web 应用程序吗?我今晚教授了那个。我向他们展示了。这是他们的第一堂 Python 课。我向他们介绍了 Bottle,因为它不需要安装。

See? I don’t want to deal with installing Flask on their computers.
看看?我不想处理在他们电脑上安装 Flask。


How cool is this? Isn’t this fun?
这真棒吗?这不是很有趣吗?

So, that’s really where I am.
所以,那就是我的现状。

I love to teach beginners because I love the process of learning. And I always learn far more than them.
我热爱教授初学者,因为我喜欢学习的过程。而且我总是比他们学到更多。

Thank you for your time. I’ll be around to answer any questions. You guys have been awesome.
感谢您的时间。我会在这里回答任何问题。你们真是太棒了。

Applause 掌声

Select a repo