I've decided that I need to be able, in my program, to swap the value of two variables. All right.
我觉定在我的程序中,我可以,交换两个变量值,好的。
By putting it in a function bug if I find a bug and I change my program I can just run the function again.
把我输入的值放到一个函数里,如果以后我在程序中发现了一个,并对程序进行更改的话,我可以直接。
You double click an icon, the program gets loaded into memory, well, conceptually where does your program end up?
双击一个图标,程序就被加载到内存中,那么,程序在哪里结束?
And indeed, when they program these things, the programmers will feed in game after game after game of the great chess games in history.
的确,当人们编写游戏程序时,会在这些程序中,一局接一局地,输入历史上那些最伟大的棋局
The strategy then often is to figure out how, what sort of program can solve these problems and then we go on to ask, "How could this program be instantiated in the physical brain?"
心理学家们通常要先弄清,什么样的程序可以解决这些问题,然后我们会接着问到,"这个程序在我们的生理大脑中,是如何进行编译的"
Certain double stranded RNA sequences will cause in the cell a process of degradation of very specific RNA sequence.
一些双链RNA序列能够在细胞中开启,特定RNA序列的降解程序
And in the process of tidying it up and making it prettier, I'll often by accident find the bug.
让我的程序更漂亮些,在这个清理美化代码的过程中,我常常无意中发现我的错误。
And then I say, oh you know I've used lists all over this program. I'll bet this isn't the only place where I've made this mistake.
变化引起的边缘效应,然后我的意思是,你知道的我在这个程序中一直都在用数组,我敢打赌我犯了这种错不止一次。
But let's suppose that I realize that I'm doing a lot of addition in my programs, and I actually want to factor out what seems to becoming a lot of copy, paste.
但是假如我在程序中做了很多加法,我实际上想要提出那些,复制粘贴的东西。
Well as we'll see later in the term, we're going to use a lot of randomness in a lot of our programs. Where we essentially do the equivalent of flipping coins or rolling dice.
我们会在晚些时候学到,我们会在很多程序中,用到一系列的随机检验,这跟掷骰子或者扔硬币差不多。
But it's a valuable thing. It says, in each case, I return some useful value from this procedure.
但是这就是变量,是在每个例子中,我从这个程序中返回了一些有用的值。
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.
好的,它存在内存中,而不是硬盘中,因为,否则程序会非常的缓慢,程序在内存中运行会好得多,它们在技术段,的地方结束。
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.
我写了一个叫做“图表“的小程序,基于我在程序中硬编码的一些数据,向我们显示在过去几年中我们课程的人数。
And henceforth I'm gonna start calling these tools, these monickers that I can use as building blocks in my own program, it's gonna be called a function as we'll see.
从此以后,我将在我的程序里把这些工具,称为我们可以用来写代码的组件,在我自己的程序中,我们将了解到它被叫做为一个函数。
With simple branching, how long is it going to take to run a piece of code?
但是在简单分支程序中,执行一个程序,要多长时间呢?
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.
来运行程序的时候,错误就会出现缠住你了,因此现在我们真的要培养,在程序中有防卫性设计的概念。
We'd expect you to write now or perhaps ever since this program was written as part of an obfuscated C contest.
我希望你们现在就开始写程序,否则你们将会在C语言比赛中,写得非常糟糕。
Right. We're not going to have 140,000 variables in my program.
对的,在我的程序中没有140,000个变量。
So, in this program when we call this version of swap 1 and 2 do not end up here, right?
所以,在这个程序中,当我们调用这个swap版本1,和版本2,不是在这里结束,对不?
So you say well, rather than rushing off and fixing this one bug, let me pull back and ask, bug is this a systematic mistake that I've made throughout the program?
因此我们应该回头想想,这是不是我在整个程序中都,在犯的一个系统性错误,而不是匆匆忙忙的去修复这一个,如果确实是系统性错误的话?
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.
我想要一个函数,那是一个小工具,在我程序中可以包含的一行代码,通常这些工具在手册的第二节,或第三节。
OK. Having done this now, I can simply go ahead and run this, and in fact if I go up here to run, you'll see I've got both an option to check the module, though in this case I'm just going to run it.
好,讲完了这些,我可以去执行程序了,实际上如果我在这里运行,你们会看到我同样得到了,一个可以同时检查模块的选项,虽然在这个例子中我就是直接去运行程序了。
> That lets the compiler know that you want to use some actual compiled code from that library.
>,那是告诉编译器我们想要在程序库中,使用一些当前的编译后的代码。
So thankfully, you can do multiple things at once in a program because of what we'll call threads.
因此,谢天谢地,我们在一个程序中可以,同时做几件事情,而每件事情被称为一个线程。
Why? Because typically, you're doing that to use it somewhere else in the program.
为什么要这么做呢?因为你经常会在程序中,用到这一点。
It gives us the power to have complete dynamism in our program.
它在我们的程序中,起着动态,分配的功能。
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.
我特别强调了这一点,因为我知道你们都会慢慢成为程序员;,你在写代码过程中造成了一系列的错误,你还在写代码,你不想浪费时间,我想把“浪费时间“用引号圈起来,浪费时间来做因为防卫性程序设计,而带来的这些额外的事情,你只想赶紧把程序写完,这不是一个好习惯,因为当你做完回头。
Because we obviously can't, in any course, or even any set of courses, tell you everything you'll ever want to know in life we've seeded some things in this program that will be unfamiliar, so during the time you're studying the program, get online, look it up, figure out what they do.
因为在任何一门课上或者几门课上,我们都不可能告诉你,所有你想知道的事情,我们在这个程序中,加上了一些你们不熟悉的东西,所以在你们研究这个程序的时候,你们可以上网找资料,弄懂它是干什么的。
A huge one is, are you actually running the code you're looking at in your editor.
一个很大的错误就是你运行的程序,是否是你在编辑器中看到的程序。
应用推荐