And will make mistakes. And therefore, you write your programs so that catastrophes don't occur when those mistakes are made.
就是人是很愚蠢的,会犯错误的,因此,你要这样设计你的程序,以达到当犯错误时避免大事故的目的。
>> They only use that when the program that you're running-- the program that you're referring to is going to your computer?
>它只有在你运行程序的时候才用到-,那你刚刚提到的程序,会到你的电脑上运行吗?
As every time we introduce a new programming concept, we'll relate it back, as we have been doing consistently, to defensive programming.
我们每次介绍一个,新的编程概念的时候,就会和以前讲的联系起来,就和我们介绍防卫性程序设计一样。
If you want to control a program file, open, copy, paste not get me ready for my trip to Stanford.
如果想要掌控一项程序文件,打开,复制粘贴,并不会铺平通向斯坦福的路。
Others said a lottery would make a difference, a fair procedure, Matt said, and some people were swayed by that.
其他人说,抽签会有所不同,马特所说的,公平的程序,的确有人为之动摇。
Because the program is constantly revising its strategies, in light of what's worked and what hasn't worked in the past.
因为程序会不断依据过去,有效无效经验修改其策略
We're going to be very, very good about releasing strong and clear APIs on how to build things.
我们会变得非常善于,发行关于怎样开发东西的有力的,清晰的应用程序接口。
So, that's a little bit about the chemistry that we're going to cover in this class, and now I'm going to talk a little bit about some of the policies and procedures.
以上是我们这个课程会讲到的一些内容,然后我要讲一些,关于这个课程的政策和程序,但首先让我介绍和我一起授这门课的同事。
One of the advantages of this is, that I don't have to worry about explicitly updating my variable. That happens for me automatically.
这样继续下去,这样做的一个优点是,我不用为更新变量来发愁了,程序会自动的为我进行这个操作,这一点很好。
You should acquire overtime this instinctive aversion to just code or programs that just look ugly because things that look ugly generally are not easy to maintain.
对于代码和程序你会有一种本能的讨厌,这是因为这些代码和程序看起来很丑陋,并且不容易维护。
So today is about writing some programs and empowering you to write your own starting this coming week when Pset One goes out via the website tonight by 7:00 p.m.
今天我们将要写一些程序,并且让你们,在接下来的一周写你们自己的程序,今天晚上七点,习题集1会发布在网站上。
We'll talk more about this later, but it often happens that when you change your program to solve one problem you break it, and things that used to work don't work.
我们以后会更多的去讨论者一点,但是经常发生的情况是当你因为,一个问题修改你的程序的时候,你修改了程序,但原来没问题的模块。
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 if the test is true, it will change the value of this program counter to point to some other place in the memory, some other point in that sequence of instructions, and you'll keep processing.
如果测试结果为真,它会改变程序计数器的结果去,指向记忆存储器里的其他地方,指令序列里的其他地方,然后你会继续这个过程。
I know you're bugged by my bad humor, but too bad. Maybe you're bugged by this, saying wait a minute, how does this thing stop? This is the kind of definition that your high school geometry teacher would have rapped your knuckles over.
我也知道你可能觉得我的冷笑话很烦,但是很不幸,可能你会觉得这个很烦,你会想等等,这个程序怎么停下来呢?,这就是你们高中几何。
All right so it has to live in RAM as opposed to the hard drive because otherwise things would be terribly slow as you know so it's much better if your programs live while they're running in RAM and they end up in what's called the tech segment.
好的,它存在内存中,而不是硬盘中,因为,否则程序会非常的缓慢,程序在内存中运行会好得多,它们在技术段,的地方结束。
You can kind of see where the syntax is going, looks like a loop, but you can kind of put blocks inside of you, and the little arrow suggests that once you get to the bottom just like our socks example, you're gonna do the following again.
从某种程度上你可以看到它的语法构成,像个循环,你也可以把,一些程序块放到循环中,如同短袜的例子,这个小箭头暗示你一旦到达底部,你将会重复接下来的事情。
On the other hand, as I said, never trust a programmer to do the right thing so we're going to check it.
另外,如我之前提到的,别相信程序员会一直保持正确,所以我们才要。
So let's look at a little example, and this is going to, excuse me, both allow us introduce the syntax as well as what we want to have as the flow of control inside of here.
让我们看个小例子,这个程序会,对不对,请允许我,一边顺着控制流进行,一边讲解语法。
Now in fairness, that particular problem kind of happened because so many companies ended up running so much code for many more years than the programmers actually thought they would be running it, but the idea is still the same.
公平起见,那个问题有时会发生,因为实际上,很多企业在这么多年里运行了,比程序员多得多的代码,虽然他们将运行它,但那个构想还是一样的。
So now, if I click the green flag, the program seems broken or--I don't know.
因此,如果你现在点击蓝色符号,程序可能会中断。
We would hire one other programmer to work on the client's site and build a hardware out, I would build the server software and then answer that question.
我们计划雇佣另一个程序设计师来做,客户网站,再准备好硬件,我还会编出一个服务器软件,一个月后,我们就会回答那个问题。
Right, so an exception then has this format that I can control as a programmer.
好的,所以一个异常会有这样的格式,我能把他当做一个程序员来控制。
It's a bad habit to get into, because when you come back to it, it may haunt you later on down the road. So really get into that notion of trying to be defensive as you program.
来运行程序的时候,错误就会出现缠住你了,因此现在我们真的要培养,在程序中有防卫性设计的概念。
Yeah, when the power goes out, or- so let me not answer it quite so facetiously.
有没有某一点程序会退出呢?,对,停电的时候。
We'd expect you to write now or perhaps ever since this program was written as part of an obfuscated C contest.
我希望你们现在就开始写程序,否则你们将会在C语言比赛中,写得非常糟糕。
I get a key error. Because, remember, these things are not ordered.
程序会返回一个键错误,因此,记住字典里的元素是无序的。
STUDENT: Yeah. It'll go forever. Absolutely, right?
学生:不可闻的声音:,程序会一直运行下去,绝对是?
And it probably, I think we can deduce, returns the right answer here.
然后程序也可能,我认为我们可以推断,程序会返回正确的答案。
The chess-playing computer programs think of moves, think of strategies no one's thought of before.
国际象棋程序会思考如何下子,会想出没有人曾想到的策略
应用推荐