One of the advantages of this is, that I don't have to worry about explicitly updating my variable. That happens for me automatically.
这样继续下去,这样做的一个优点是,我不用为更新变量来发愁了,程序会自动的为我进行这个操作,这一点很好。
In fact, as a little helper, notice what it's sort of automatically including for me: What's this thing here?
事实上,作为一个帮助程序,请注意,它为我自动分类:这个是什么东西?
bug It's not true now. If there is a bug in the program it's there for only one reason.
如果程序中有一个,那一定是有原因的,是你通过例如犯了。
We had a very efficient process that was run by a scheduler.
我们有个很高效的程序,那是有一个日程员负责的。
And it's hard to imagine a simpler program than this. So we very quickly realize that exhaustive testing is just never feasible for an interesting program.
更简单的程序了,因此我们很快的意识到,对一个程序来说详尽的,测试是永远不可行的。
And in fact, one of the lessons you may already be realizing with P sets is that things seem to take twice, three times, four times longer than you actually might think.
从习题集中你可能已经得出的一个教训就是,程序所花的实际时间往往是你开始以为的两倍,三倍,四倍甚至更长。
I want the function, which is a little tool, a line of code I can include in my own programs and generally those tools live in sections two or three of the manual.
我想要一个函数,那是一个小工具,在我程序中可以包含的一行代码,通常这些工具在手册的第二节,或第三节。
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.
比如在以前,我们做了一个,计算平均数的程序,这是一个相当挫的实现,因为我硬编码了测试的数字。
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.
所有我们一直在课堂上使用的,这些程序或者命令,携带着命令行参数,它们是跟在,程序名的后面的一个或多个单词。
I'm then printing bracket one, bracket two, bracket three, bracket dot, dot, dot up until the total number of arguments, 1 whatever that may be, and it's going to be at least one because the program always has a name.
然后我打印,括号等等等,知道打印完所有的参数,不管那个最大值可能是什么,它将至少为,因为程序总是有一个名字。
Essentially, this command make is just another program that uses GCC to compile my program for me but make is configurable.
从本质上来看,make命令就是一个,调用GCC来编译我们程序的程序,只不过make是可以配置的。
Now as an aside, I'll admit this is a completely useless program, much like the first couple of ones we did because why would you write a program just to solve this?
说点题外话,我承认这是一个完全无用的程序,跟我们之前写的两个程序一样,我们为什么需要写个程序来解决这个数学运算呢?
Now, mind you, it was 20 years ago that this program was operational, 20 years.
现在,提醒你们,这是20年前,运行的一个程序,20年了。
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 check the answers, and say yeah that's what we expected. But it also involves reasoning. About why that's an appropriate set of inputs to test it on it.
然后说对,这就是我想要的结果,但是它跟推理也有关系,表现在关于为什么这是一个,测试我们程序的适合的输入集。
And that's basically the process of ascertaining why the program is not working.
这其实是一个查明为什么程序,不运行或者不按期待中运行的过程。
It's a valuable tool that you want to have as a programmer.
对于作为一名程序员的你来讲,这是很有价值的一个工具。
And it's called Silly because it's really a rather ugly program. It's certainly not the right way to write a program to do this.
它之所以被称为Silly因为,它实在是一个相当丑的程序,当然以这种方式去写一个程序是不对的。
It's basically an example of a fixed-program computer.
它基本上是固定程序计算机的一个范例。
So let's try running Silly.
这个程序是用来测试一个数组是不是回文的。
And so very often I would find myself with gigabytes worth of data, at night I needed to analyze this data and look for this patterns and frankly the reality was sometimes I could spend 10-15 minutes whipping up a little script, a little program that unfortunately would take eight hours or more to run.
我经常会发现十亿字节的数据,晚上我就需要分析这些数据并,找出模型,坦白说,有时,我会花10-15分钟来编写一个小脚本,一个小程序,但不幸的是,运行它可能需要8个小时或更多时间。
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.
但是字面上来说,我们现在学到的,都是所谓的直线程序,也就是,一个接一个的执行,一系列的,指令的程序。
And this is useful because if you're actually writing a program that's interactive or that you want to change overtime much like you would a game, hopefully, the game is not going to have the bad guys, for instance, always standing in the same place or the rocks or whatever it is falling from the sky in the same place 'cause it would very quickly become a very tedious game.
这是很有用的,因为如果,写一个交互的程序或者,希望每次游戏都不一样,我们希望,游戏中的坏人物,别老是站在同一个地方或者同一块石头上,或者从天空中同样的位置落下,因为这立刻会使游戏变得乏味。
So I start this program by declaring as I did before a global variable X. It is global simply because it is not inside any of my functions.
在程序的开始,我声明,一个全局变量X,它是一个全局的,因为它不在任何一个函数里面。
It's just hard to keep track of them at first but they all generally mean the same thing, provide additional input to this program called GCC by just specifying it on the command line.
刚开始是很难理解这些词的,但其实都是一个意思,所以,只要在命令行上为这个程序,再添加一个名曰GCC的输入就OK啦。
So the hint is that this is our first program that's not been called buggy something. All right.
提示是这是我们的第一个程序,那不是一个,有bug的东西,好的。
- The fact that I've called it X, is really just a programming -- it's a feature of the programming language that I, the human, can now refer to it.
事实是我叫它为X,它实际上只是一个程序-,它是程序的一个特写,我们可以参考使用它。
It's a little more readable because I'm using a Boolean value that tells me, the programmer, this is true or this is false.
它更具有可读性一点,因为我使用了一个bool值,它告诉我或程序员,这是正确的或这是错误的。
It's being handed a picture that looks like this, and inside each baz of these squares is a word foo and bar and baz as well as the program's name.
它传递一个像这样的图画,在每个,长方形中是一个单词foo和bar和,还有程序的名字。
应用推荐