Let's take a quick glimpse of what it's like to write a real program albeit a very trivial one.
下面是一个真正的程序,尽管它很简单。
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.
我举这个程序是有目的的,因为我希望你们这续期能学到,如何去查找你不知道的东西并,且弄懂它,们是干什么的,是什么意思。
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.
顺便作为参考,为了避免我们可能忘记一些代码的意思,我通常会用一两个简单的句子,在上面作出注释,那样会提醒我们这个程序是干嘛的。
The first step in the process is when I was Deputy WHCF, that I put on the wall a big white board calendar.
程序的第一步是,当我还是办公室副主任,我在墙上安了个,白色的日历板。
So how do chess-playing programs, and particularly the best chess-playing programs, how do they work? Well, they play chess the same way you do.
那么,下棋程序,特别是最好的下棋程序,是如何工作的呢,它们的下棋方式同你们如出一辙
A second broad area is applications.
第二个大的领域是应用程序。
But that's a procedural question.
这是程序上的问题。
All right, this is actually a very old piece of imperative knowledge for computing square roots, it's attributed to Heron of Alexandria, although I believe that the Babylonians are suspected of knowing it beforehand.
好,这是一个很古老的,关于计算平方根的程序性知识,是亚历山大的海伦提出的,不过我怀疑在那之前,巴比伦人就已经猜想过了。
For instance in the past, we had that silly little program for computing the average of some quizzes and it was actually a pretty bad implementation because I had essentially hard coded in the number of quizzes.
比如在以前,我们做了一个,计算平均数的程序,这是一个相当挫的实现,因为我硬编码了测试的数字。
RAM You probably know your computer has something called RAM which is where documents and programs live just temporarily while you're running them 'cause RAM tends to be pretty fast and whereas your hard disk is where programs and files live permanently.
也许你知道电脑有一个,正在使用的程序和文件都暂时存放在那里,而且会加快电脑速度,而硬盘是程序和文件,永久存储的地方。
And what I want to be talking about is modules of one sort, and of course that's because what we're interested in is modularity.
我想要说的是一种类型的模块,当然这是因为我们关注的是程序的可组合性,我们如何处理复杂程序呢?
The chess-playing program makes moves these guys haven't thought of.
象棋程序的走法,是这些程序员也未曾想到过的
So all of these programs or commands that we've been using thus far for the piece set in class, take what we call command line arguments, they are the zero or more words that follow the program's name.
所有我们一直在课堂上使用的,这些程序或者命令,携带着命令行参数,它们是跟在,程序名的后面的一个或多个单词。
Now just to get used to the conventions, 0 because this is the program you'll use not for problems at 0 but for 1 to start writing programs, notice at the top in this window just reminds you what you're working on.
我们要入乡随俗,习惯这样的界面,因为这是你们将要用到的程序,不是为习题集0,而是0,而是为习题集1开始写程序的,注意窗口顶部,这是用来提醒你,你工作在何种环境。
But it turns out that on Macs and if you have the right software on PCs, you can kind of get a teaser of what this environment tends to look like and be forewarned, what you're about to see is intentionally very underwhelming.
事实上,它是运行在苹果机上的,如果你在电脑上有正确的软件,可以去看看这个环境大致是怎么样的,提前说下,这个程序不会让你印象深刻,我是故意这样做的。
So what we would see, I'm going to completely fake this, is a program that operates like that.
所以我们会看到,我要完全掩盖这一点,就好像程序真的是那样执行的。
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?
因此基础的思想是对的,但是程序没能满足,正确答案在给定的区间内这个条件,对不对?
It's not nearly as graphical but at least we're not hardcoding programs that are otherwise uninteresting.
这可不是绘画,我们至少不是在硬编码程序,那是没有趣味的。
Essentially, this command make is just another program that uses GCC to compile my program for me but make is configurable.
从本质上来看,make命令就是一个,调用GCC来编译我们程序的程序,只不过make是可以配置的。
The point I'm trying to make is, fixed-program computers is where we started, but it doesn't really get us to where we'd like to be.
我要指出的一点是,我们从固定程序计算机开始说起,但它并不能让我们到达我们想去的地方。
And now let's take a look at what this program actually does.
让我们看看到底这个程序是做什么的。
What is it about the thought that the computer is just following a program?
电脑仅仅只是在执行程序,这个观点到底是什么样的
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.
对不对?进行终结测试然后递增,实际上我要,因为某些你们,马上要明白的原因我把这里注释了,但是我通常会一直这么做,这样能让我看到每一步都做了什么,如果我运行这个程序,它会在每一步都,进行显示,这能帮助我让我确信程序是,在以正确的方式递增。
So we can watch this run here.
我们来看看程序是怎么运行的。
It just really wasn't designed very well.
是那个程序或软件没有设计好。
So let's try running Silly.
这个程序是用来测试一个数组是不是回文的。
Everything seems to work.
程序貌似是起作用的。
Real simple programs.
真的是很简单的程序。
Even if we could build a program, even if we had built programs that can be creative, that can do things that nobody's thought of before, all the program is doing is following its program, right?
即使我们能编写一个程序,即使我们已经编写出具有创造力的程序,它们可以做一些从来没有人想到过的事情,程序所做的只不过是执行程序,对吗
But literally all I can do at this stage is write what we would call a straight-line program, that is, a program in which we execute in which we execute the sequence of instructions one by one.
但是字面上来说,我们现在学到的,都是所谓的直线程序,也就是,一个接一个的执行,一系列的,指令的程序。
应用推荐