And notice because I have just one line of code inside of each of these branches, what have I clearly omitted?
请注意因为我在每个分支中只有一行代码,显然地我省略了什么?
And in the process of tidying it up and making it prettier, I'll often by accident find the bug.
让我的程序更漂亮些,在这个清理美化代码的过程中,我常常无意中发现我的错误。
You will be able to infer from some of our code how in fact you can implement some more sophisticated programs.
你可以从一些代码中推断出,应该要怎样实现一些较复杂的程序。
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.
我想要一个函数,那是一个小工具,在我程序中可以包含的一行代码,通常这些工具在手册的第二节,或第三节。
Right, so here's a little piece of code that's going to print out the smallest value of three.
好,那么这一小段代码,就是会显示出,三个值中最小的来。
And then what I get to do inside the curly braces is literally line by line enumerate the cases that I want to apply to the following code.
然后我们在花括号中要做的是,逐行地列举接下来我想要,应用的代码。
s1 It's a little square, it's going to be called s1 and that's what exists as of line two of this program, GetSting but now I've called get string.
这是一个正方形,叫做1,这就是程序中第二行代码所表示的,现在我调用。
But thankfully now in 2010, we're at the point where there's a whole lot of free and open source software that you can integrate into your projects that other nice people have made available.
不过幸好在2010年,现在有很多可用的开源,代码软件,你可以将其融合,到你的工程中。
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.
现在就提供给你们一些框架,在代码中有些空白,是为了让你们了解其中的思想,如果是你自己,若时间允许,那就尽量写大的程序。
But I got a couple of other of these strange looking things in there with underbars to them.
我可以在这片代码中看到这些,然后我需要一些可以给我,返回这些信息的东西,但是这里还有一些看起来。
What does that say? It says if in the code up here I get an exception of that sort, I'm going to go to this place to handle it.
这意味着如果在代码中,我得到一个这样的异常,我能到这里来处理它。
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.
从此以后,我将在我的程序里把这些工具,称为我们可以用来写代码的组件,在我自己的程序中,我们将了解到它被叫做为一个函数。
Suppose I want to compute square roots a lot of places in a big chunk of code.
假设我想在一大段代码中,计算很多次平方根。
So if you're coming from prior background, your code might work a little differently on a different system if you don't use those flags.
如果你来自一个先前的背景,如果你们没有使用这个版本标志的话,在一个不同的系统中,你的代码可能运行地不太一样。
That means it was something I didn't understand. So I'm going to be cautious and systematic.
这就意味着代码中有一些,我没有理解的东西,因此我需要谨慎,并且系统化的去寻找这个错误。
You need to, if you want something to be printed out inside your code, you need to tell the machine to do that.
你需要,如果你想要,在代码中显示一些东西的话,你需要告诉机器这么做。
> That lets the compiler know that you want to use some actual compiled code from that library.
>,那是告诉编译器我们想要在程序库中,使用一些当前的编译后的代码。
The only thing that compiler needs to know is kind of what pattern to look for in the rest of your code.
编译器需要知道的唯一的东西是,用来在剩下的代码中寻找的函数形式。
We hand you a bunch of programming code that we wrote because this is very much the norm in the real world.
我们给你们一些我们自己写的代码,因为在现实世界中这都是非常正常的。
Now you have a set of parentheses as we'll see int i=0 in actual code and then I have int I equal 0.
你将会在实际的代码中看到一对圆括号,比如,我们让。
Because if I don't specify a name for this input, I have no way of actually referring to it in subsequent lines of code.
因为如果我不给这个输入定义一个名字,在随后的代码中,我就没有办法使用它。
Because there will not be time to look at that code for the first time during the quiz, and figure out what it's doing.
因为在考试中,是没有时间去第一次看代码,并弄懂它的意思的。
Give you some examples. What have we talked about? We've talked about things like using comments to highlight what you're doing in the code, to make it easier to debug.
给大家举些例子,我们一直在强调什么来着?,我们讲过要用注释来说明,你在代码中进行的操作,以便于调试。
I want to just use it, I shouldn't have to worry about what variables I use inside of it, I have shouldn't have to worry about where that is in the code, I should be able to just abstract it away. And that's what we want to add today, are those two things.
我只是想使用它,我不用考虑我在这段代码中,使用的是什么变量,我完全不用考虑代码的内容,只要抽象就好,我们今天想补充的内容就是这两点。
And when I do this test, what I want to do, is say I'm going to pick the middle spot, and depending on the test, if I know it's in the upper half, I'm going to set my start at the mid point and the end stays the same, if it's in the front half I'm going to keep the front the same and I'm going to change the endpoint.
如果我知道目标数可能,再比中值点大的区间里,我可能就会把开始点设为中值点,而尾点不变,如果在小的那个区间里,就保持开始点不变而把尾点设为中值点,你们可以看到这儿的代码,就是这么做的,对不对?它是怎么做的?
And now in a sentence, what does this one actually do?
现在在句子中可以看出,这行代码做了什么?
So there's a return branch on every possible path through the code. And that's valuable, it's something you want to think about as your right your own.
所以代码中每条可能的路径,都会有一个返回值分支,这是非常有价值的,当你自己写程序的时候也应该考虑这件事。
bugs That is a problem that may not terminate.
随机的在代码中去搜寻。
So let's look at the second example, all right, I keep doing that -- this piece of code from here to here gives me a way of now creating a hash table of size 256.
所以让我们来看一下第二个例子,好的,我继续做那件事,这段代码中从这里到这里,是创建一个大小为256的哈希表。
I should also warn you that this code includes some Python concepts, at least one, that you have not yet seen.
我得事先说明这个代码中,包括了一些你没见过的Python语言的概念,至少一个。
应用推荐