If we're going to write programs, we need at least two things: we need some representation for fundamental data.
如果我们要去写程序,我们需要至少两件事情:,我们需要一些能代表基础数据的东西。
Divide and conquer to make our programs modular so we can write them a little piece at a time and understand them a little piece at a time.
我们把程序分解为模块逐个击破,以便我们能一次写一小段,一次理解一点儿,现在我觉得。
Not just in sort of mathematical things like chess or math, there are, as you know, programs that can write music.
不止是下棋或数学这类跟数理有关的事,你知道,有些程序甚至能创作音乐
So let's go ahead and introduce a couple other capabilities so that we can finally start writing programs that maybe print out charts or interact with the user, play games, or the like.
让我们继续来介绍其他几个功能,以便我们最终能开始写程序,那样可以打印图表或与用户交互,打游戏之类的。
It's also nice, by the way, that there are these electronic programs that immediately figure out the nutrient breakdown of what you're eating.
顺便说一句,好在现在很多的电脑程序,能快速分析出你所吃食物的营养成分
And a large part of being a good programmer, or learning to be a good programmer, is learning how to debug. And it's one of these things where it's harder.
没人能凭本能做好它,如果你相当一名优秀的程序员,或者想通过学习成为一名优秀的程序员,很重要的一部分就是学习怎么去调试。
This is on purpose, because one of the things I hope you have learned to do this semester, is look up things you don't know, and figure out what they do. What they mean.
我举这个程序是有目的的,因为我希望你们这续期能学到,如何去查找你不知道的东西并,且弄懂它,们是干什么的,是什么意思。
It turns out there's a new function strlen S-T-R-L-E-N that you probably have not used yet called strlen, S-T-R-L-E-N, programmers early on and still like to be succinct but communicates sufficiently what they mean.
结果这里有个新的函数,你可能没有使用过,叫做,早期的和现在的程序员喜欢简洁地,但是能充分的传达他们的意思。
And then we try and get our simulation to match the past, and hope that that will help it predict the future.
尝试让仿真程序能和这一部分实际数据相符,并且希望它能够帮我们对未来进行预测。
Still all the computer can do, all the robot can do is automatically, necessarily, mechanically follow the program.
即便如此,电脑所能做的,机器人所能做的,只是自动地必然地机械地执行程序
But I would choose to sit down for these particular projects right around midnight so that when I woke up my program was giving me the results I wanted.
我可能会,为了这些特殊的项目一直等到半夜,这样我醒来时,程序就能给我想要的结果。
We want you to have a sense of why some programs complete almost before you're done typing it.
一些程序你输入进去它,就能给出结果而另外一些,却要整夜整夜的跑。
You can play not against yourself; you can program the computer to play against yourself-- you can program the computer to play against you.
你不仅能和自己对打;,也可以设定电脑程序和自己对打-,你自己玩,-你也可以设计电脑程序让你和电脑玩。
Right, so an exception then has this format that I can control as a programmer.
好的,所以一个异常会有这样的格式,我能把他当做一个程序员来控制。
Where we put our whole program together, and we say does the whole thing work?
也就是把我们的整个程序组合起来,然后看看它们在一起能不能正常运行?
OK, you say, come on, I've seen these all the time. Every time I type something into my program, it does one of these things, right?
好了,或者你要说,我总是能看见这些,每一次我在程序里输入一些内容的时候?
So first of all, I've got to be careful about the end test. But the second thing is, OK, if it stops whenever this is less than two, am I convinced that this will always halt?
小心最后一次比较,其次,如果少于两个元素程序停止了,我们能确信这总是应该终止的么?,答案是肯定的,因为我在做什么?
The natural inclination here is to say, "These computer programs, these robots are feeling emotion."
这边人们可以自然而然地说,这些计算机程序,这些机器人能感受情感
And one of the ways you can make a program crash, intentionally or not, is to essentially use up too much memory or call too many functions and what happens is, bam, one hits the other and bad things happen.
其中一个方式能使你的程序崩溃掉,有意或无意的,它本质上使用了太多的内存,或者调用了太多的函数,所发生的,崩掉,一个冲突了另一个,然后发生了坏事情。
Same way that I have multiplication or division as a primitive, functions are going to give me, or somebody else who wrote them for me as part of a library, a new primitive that I'm going to be able to use.
我在用乘法或者除法当做原语,这些函数,或者别人写程序库中的函数,将会给我返回一个,我能使用的新原语。
What that means, in a stored-program computer, is that I can provide to the computer a sequence of instructions describing the process I want it to execute.
它的意思就是说,我可以给一个存储程序计算机,提供一系列,描述我希望,能执行的过程的指令。
Well, other than prejudice, what would stop us from saying the program was being creative?
那么,除了偏见,还有什么能阻止我们说程序具有创造力呢
Now, efficiency is obviously an important consideration when you're designing code, although I have to admit, at least for me, I usually want to at least start initially with code that works, and then worry about how I might go back and come up with more efficient implementation.
现在,当你设计程序的时候效率,是不得不考虑的问题,虽然我必须承认,至少对我来说,我是先担心程序能不能运行,再去把它的效率优化的,我喜欢可靠点的东西。
And those are two things that you'd like to do with every looping construct you write: you'd like to be able to assure yourself that they will always terminate, and then the second thing you'd like to do, is to assure yourself that it does give you back a reasonable answer.
就是现在我有了能去检查程序,是不是做了正确的操作的能力:,这就是你们在写每个循环程序的时候,都要注意的两个事情:,第一件事情是要确保程序可以终结,第二件你要做的事情,就是要确保程序返回了正确的答案。
In an era of computers with quite sophisticated computer programs, it seems, at the very least, natural to talk about beliefs, desires, and reasoning and strategizing.
在一个有着能搭载极端复杂程序的电脑的时代,最起码,谈论信仰,欲望,论证,谋划,是很自然的事
No traces of desires and memories and intentions and beliefs to eventually be recovered if only we have the right surgery,or procedure,or psychotherapy, or what have you.It's gone.
没有一丝的欲望,记忆,意愿和信念能被追回,无论什么样的手术,程序或者精神疗法,都无可挽回。
If you can figure out why fails on three letters instead of 12, you'll be more than half way to solving the problem.
如果你能明白为什么程序,在输入三个字母的单词的时候没法运行,你就已经解决了问题的一半了。
So the basic idea was fine, but I failed to satisfy the initial condition that the answer had to be between the lower bound and the upper bound. Right?
因此基础的思想是对的,但是程序没能满足,正确答案在给定的区间内这个条件,对不对?
The last point I want to make to you is, you've started writing programs that you would think of as being inherently iterative.
能反映递归特性的程序,我最后一点想说的是,你已经开始编写你认为。
We're checking the end test and incrementing, actually I was going to, I commented that out for a reason you'll see in a second, but I, normally I would keep this on, which would let me, at each step, see what it's doing. If I ran this, it would print out each step. Which is helping me make sure that it's incrementing the right way.
对不对?进行终结测试然后递增,实际上我要,因为某些你们,马上要明白的原因我把这里注释了,但是我通常会一直这么做,这样能让我看到每一步都做了什么,如果我运行这个程序,它会在每一步都,进行显示,这能帮助我让我确信程序是,在以正确的方式递增。
应用推荐