It gives you a lot of expressive convenience, you can write the programs much more cleanly, but most importantly, it's fast.
你可以把一些程序写的更清楚,最重要的是,它的效率非常高。
I made a ton of random things when I was at Harvard and most of them no one ever saw.
我在哈佛写了许多程序,很多都没人见过。
If we're going to write programs, we need at least two things: we need some representation for fundamental data.
如果我们要去写程序,我们需要至少两件事情:,我们需要一些能代表基础数据的东西。
It's because the programmer or programmers that wrote that software might have been pretty specific but not specific enough.
这是因为程序员写的软件,可能已经相当具体,但还是不够具体。
So let me just to try something a little more interesting, and then we'll get to writing some simple programs.
让我们来试试更加有趣的,一些事情吧,然后,我们再去写一些简单的小程序。
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开始写程序的,注意窗口顶部,这是用来提醒你,你工作在何种环境。
And so now we're going to try and see if we can write a simulation that will give us some insight as to which of these might be better or worse.
现在我们回来看看我们能否,写一个程序来看看,哪一种选择会更好。
Because the first time I wrote the program, I didn't have anything like that here and a stock could go to and then recover.
因为我第一次写这个程序的时候,我什么也没有,一只股票可以等于0然后再恢复。
OK, here we go, here we go, you see, I'm doing it down here, I can't see it, does that-- ah, I hear his sighs of relief, OK, good. There we go. Better. All right.
好,我们开始,大家可以看到,我在这里写这个程序,我看不见,这是不是-啊,我听到大家放松的叹气了,好,让我们开始吧,好多了,好。
So really, once we start writing more interesting programs, you would have to type out long annoying commands like that to just compile more sophisticated programs.
实际上,一旦我们开始写一些更复杂的程序时,你们可能要键入那样一些长的,讨厌的命令,来编译跟高级的程序。
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会发布在网站上。
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.
让我们继续来介绍其他几个功能,以便我们最终能开始写程序,那样可以打印图表或与用户交互,打游戏之类的。
Take your time. So, let's actually now take a 2-minute break, we're gonna change tapes and we'll come back and we'll actually write programs with a real computer and some real animated characters.
不急,现在休息2分钟,我们要换个录像带,一会再上课,等会开始写程序,构建一些动画人物。
Now we're gonna hand you some framework, that code that we wrote with some blanks to get you accustomed to the idea of one, writing larger programs than time might allow if you were doing it on your own.
现在就提供给你们一些框架,在代码中有些空白,是为了让你们了解其中的思想,如果是你自己,若时间允许,那就尽量写大的程序。
I could have just done this, and the only reason I didn't here is just because now I look - at this, and now it's just getting confusing for me -- even for someone who's been programming for a while.
我本可以这样做,我之所以没有这样做是因为,现在我看着这个,它是我有点迷惑了-,甚至是对于某些已经写了一段时间程序的人来说。
Well, thus far, I haven't written any programs that themselves take any such arguments, and yet it turns out I can do exactly that.
到现在为止,我还没有写任何的,它们自己携带参数的程序,但是,我完全可以这样做。
So I am going to on the fly write a very simple little main program that just illustrates some of the syntax that we can then visualize more interesting.
我很快的写了一个很简单地小程序,来说明一些语法,我们使它变得更有趣些。
So I wrote a little program called "chart" that, based on some data I happened to hardcode into the program, shows us their numbers for the past several years.
我写了一个叫做“图表“的小程序,基于我在程序中硬编码的一些数据,向我们显示在过去几年中我们课程的人数。
Right, so the things we want you to take away from this are, get into the habit of using pseudo code when you sit down to start a problem, write out what are the steps.
好,这儿我想大家明白的就是,养成解决问题时先写伪代码的好习惯,把步骤都写出来,我想要告诉你们的是一个好的程序员。
Deep equality, we get to define, that's what I did by writing same point.
我们需要自己定义,也就是我写比较是不是,同一个点的那个程序。
So now after all these stupid setup, we can finally dive in to the actual program.
把这些规定的东西写好后,我们才能写真正的程序。
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?
说点题外话,我承认这是一个完全无用的程序,跟我们之前写的两个程序一样,我们为什么需要写个程序来解决这个数学运算呢?
We'd expect you to write now or perhaps ever since this program was written as part of an obfuscated C contest.
我希望你们现在就开始写程序,否则你们将会在C语言比赛中,写得非常糟糕。
And when we do a simulation, we're pulling the samples from some distribution.
当我们写一个仿真程序的时候,我们就是从一些分布中进行了采样。
All you have to include in your own programs is the so-called header file.
你们自己写的程序只需要包括,头文件就可以了。
So, an alternative to that that is incredibly common in just the programming world and in industry is to actually not write programs on your own personal computer but to actually write and run them on a server, someplace where the software is all standardized.
那么,在编程界和工业界普遍,使用的一个解决方案是,不在你自己的电脑上写程序,而是在服务器上编程运行,服务器上的软件都是标准化的。
So let's go ahead and write a slightly more interesting program.
好,我们继续,写一个颇为有趣的,程序。
You'll see this was written by a former student of ours.
你将会看到我以前一个学生写的程序。
I stress it in particular because I know you're all going to get into this stage; you've got a problem set due in a couple of hours, you're still writing the code, you don't want to waste time, and I'm going to use quotes on "waste time", doing those extra things to do the defensive programming, you just want to get the darn thing done.
我特别强调了这一点,因为我知道你们都会慢慢成为程序员;,你在写代码过程中造成了一系列的错误,你还在写代码,你不想浪费时间,我想把“浪费时间“用引号圈起来,浪费时间来做因为防卫性程序设计,而带来的这些额外的事情,你只想赶紧把程序写完,这不是一个好习惯,因为当你做完回头。
应用推荐