• I will be posting code that you can play with, and I suggest you go through exactly this kind of exercise.

    我给你一些你的上的代码,我建议你们,多进行一些这种实验。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Having now used this pseudo code to line things up, I can start putting some additional structure on this.

    代码把这些事情串起来后,我可以开始进行,一些结构方面的优化了。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • In fact, this example would compile because you can use curly braces in this way to encapsulate lines of code, but realize for now, that, not good.

    实际上,这个例子可以编译,因为你可以这种方式来压缩代码行,但是请认识到,那个,不太好。

    哈佛公开课 - 计算机科学课程节选

  • And for reference, incidentally, in case you ever forget what the point of some exercise was, I'll almost always comment the code up top with a quick sentence or two that reminds you what this program does.

    顺便作为参考,为了避免我们可能忘记一些代码的意思,我通常会一两个简单的句子,在上面作出注释,那样会提醒我们这个程序是干嘛的。

    哈佛公开课 - 计算机科学课程节选

  • And to see that I've written another version of this, which I'm going to use here, where I'm going to give it a little indentation.

    我已经写另一个版本的代码,我将把它在这儿,我会在这儿加一点儿缩进。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And get into the habit of using it to help you define what is the flow of control.

    然后是养成代码,来帮助你定义控制流的习惯。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • If I decide there's a better way to get input, and there is, then I can make it to change what I don't have to change the code that uses the input.

    如果我觉得有更好的获取输入的方法,我可以直接改去这种方式,而不更改使了,输入处的代码

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • It's inside the memory of the machine, which means we have access to it, we can change it, we can use it to build new pieces of code, as well as we can interpret it.

    它在机器的存储器里面,就是说我们可以进入它,改变它,可以它来编写新代码,当然也可以翻译它。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Well, the first line of code, I'll fix the purple next time around so it's more legible.

    第一行代码,我紫色标记,这样增加了可读性。

    哈佛公开课 - 计算机科学课程节选

  • Give you some examples. What have we talked about? We've talked about things like using comments to highlight what you're doing in the code, to make it easier to debug.

    给大家举些例子,我们一直在强调什么来着?,我们讲过要注释来说明,你在代码中进行的操作,以便于调试。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And so what I was hinting at earlier when you put semicolons in the wrong place, and then proceed to have curly braces around arbitrary lines of code, you're creating an even more local scope there, which is generally not the right intended behavior.

    在之前我暗示了,当你把一个分号放在错误的地方时,然后开始花括号,括上任意行的代码,你在那里创建了一个局部范围,那个不是故意的行为。

    哈佛公开课 - 计算机科学课程节选

  • I'm going to use my own special program that will color code things for me in class, but the idea is the same; it's a text editor.

    我将我自己专门的程序,那个会分类为我标出代码的颜色,但是那个思想是一样的,这是一个文本编辑器。

    哈佛公开课 - 计算机科学课程节选

  • hey'd rather single step it through using Idol or something, than just read it and try and figure things out. The most important thing to remember when you're doing all of this is to be systematic.

    比起阅读代码发现错误来他们,宁愿内置的操作层,或者其他工具一步完成,你要记住的最重要的事情,就是要系统化的去做调试。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • So let's actually see how we solve this with this function with actual code.

    然我们看看怎样,这个函数和代码解决这个问题。

    哈佛公开课 - 计算机科学课程节选

  • First one, when I write a piece of code, especially code that has branches in it, when I design test cases for that piece of code, I should try and have a specific test case for each possible path through the code.

    第一点,当我们写代码的时候,尤其是一些含有分支语句的代码的时候,当我为这些代码,设计测试例的时候,我应该为每一个可能的程序路径,都设计一个特别的例。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • But now, there is an opportunity for us to implement this in code.

    不过现在,我们有机会,用代码实现它。

    哈佛公开课 - 计算机科学课程节选

  • I can, oh, these have got some remnants which we really don't need.

    我可以,哦,这里有些我们不上的代码

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Now, how can I use code that someone else wrote?

    那么,我们怎样才能别人写的代码呢?

    哈佛公开课 - 计算机科学课程节选

  • Ten lines of code. Twenty lines of code.

    10来行代码,20来行代码就可以。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Computing square root. I'm going to capture it in a piece of code, I'm going to be able to refer to it by a name, and I'm going to suppress the details, meaning inside of that computation, you don't need to know what it does. You just need to know, if I give it the right kind of input, it'll give me back an input that satisfies the contract that I set up.

    比如计算平方根,我会一段代码来说明,我将给它命名,并且忽略细节,意思就是在这一段计算过程中,你不知道它做了什么,你只需知道,如果我进行了正确的输入,它将会给我符合条件的输出。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I think the easiest way to look at what this does, is let's take a really simple example- I want to make sure I put the right things out- I've got a simple little list of values there.

    到底做了什么,就是让它跑一个简单的例子,我想要确信我找到了正确的元素-,这里我一个简单的小的列表-,如果我去代码里面看。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • And what it's saying semantically is, using that variable as my placeholder, have it walk through this collection, starting at the first thing, execute that code, then the next thing, execute that code, and so on.

    它的语义意思就是,把这个变量应为我的占位符,它来遍历这个集合,从第一个元素开始,执行代码,然后下一个元素,再执行代码

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • Because as you'll soon find, when you're writing programs 0 that aren't just four lines long but are 40 or 400 which very quickly becomes easy, you'll find that even you the next morning have no idea what this code does for whatever reason, and just having some English comments is a huge boon to comprehension for yourself and others.

    你们自己写程序时就会发现,40行甚至400行代码来代替繁杂拥挤的4行代码0,将会让事情简化许多,你会发现,即使由于某些原因,你不知道如何写代码,先写些注释,于人于己,都是好事,易于理解嘛。

    哈佛公开课 - 计算机科学课程节选

  • I've certainly written code that has this problem, I've tried to use my own code that has this problem, and good to us, right, good hygiene, I'm going to use that word again here, of getting into the habit of writing defensive code up front, it's part of that collection of things that you ought to do is a great thing to do.

    我举手了吧?,我当然写过犯这种错误的程序了,我也尝试过应含有这种错误的代码,不错,好的卫生,我还是要这个词,对我们有帮助,养成写防卫性,代码的好习惯,是你应该做的,一系列事情之一,也是我们日后要做的主要的事情。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • In Scratch you may have realized that, "I could implement my program this way with these puzzle pieces, but it kind of feels -- like I could use these puzzle pieces instead" -- that's absolutely the case in programming.

    在Scratch中你可能已经意识到,“我可以这一段代码来,执行我的程序,不过这有点感觉到,我可以这些代码段来代替“,那绝对是编程中的一个情况。

    哈佛公开课 - 计算机科学课程节选

  • to do sqrt, or square root-- no, I'm going to square root use sqrt, that's the name I'm using here-- square root a hundred different places in some piece of code. Without function, I'd have to copy that piece of code everywhere.

    让我做一下准备,想象一下我要调sqrt或者-,不,我会调sqrt函数,这是我在这里的名字,我得把这段代码到处复制。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • I spotted an error here, I could have spotted it by running it on different test sets, and using prints things, another way of doing it, but this idea of at least simulating it on simple examples lets you check a couple of important questions.

    操作么?我在这里发现了一个错误,我也可以通过运行不同的测试集,或者运print声明来发现这个错误,但是至少应该简单的例子来手工模拟下,代码的思想可以让你,对一些很重要的问题进行检验。

    麻省理工公开课 - 计算机科学及编程导论课程节选

  • With C you can just line everything up on the left here because it's just text.

    C语言,你只要把代码排在这里的左边,因为只是文本。

    哈佛公开课 - 计算机科学课程节选

  • When you're all out of specific cases and you want to handle everything else, you literally say "default:" And here I could end the program with break, but it's kind of unnecessary because once I'm at the bottom of the curly braces, that's it.

    当它不在你列出的所有情况中,为了处理其他的情况,你可以“default:“,这里我可以break来终止这段代码,但是它是有点,不必要的,因为我已经在这个花括号的,底部了,就这样了。

    哈佛公开课 - 计算机科学课程节选

  • So conceptually the key difference here, besides the syntax looking slightly different, it just means that if you want a chunk of code to execute no matter what initially, ; you can use the do while loop; if you want to check a condition first, you can use the while loop.

    所以概念上,则关键的区别是,除了语法看起来有点不同,它的意思是如果你想要一段代码,最初无论如何都要执行,你就可以do,while循环;,如果你想要先检查条件,你可以while循环。

    哈佛公开课 - 计算机科学课程节选

$firstVoiceSent
- 来自原声例句
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定
小调查
请问您想要如何调整此模块?

感谢您的反馈,我们会尽快进行适当修改!
进来说说原因吧 确定