And the only thing that's differing is the name of the type and the name of the variable I'm using.
其中唯一的区别是数据类型的名字,和我使用的变量名字。
But I'm just not the type of person to pay for a brand name, like a huge brand name.
但我不是那种为了大品牌花大价钱的人。
Partly to show you that it's kind of weird, but also to tell you that one of the things you want to do is exercise what I'm going to call some type discipline.
一定程度上来说这有点儿怪,但是还是想要告诉你们的是,你们需要做一些,我称之为类型规范的练习。
There's a whole bunch of blocks that we'll look at in more fun detail on Friday but I'm going to pick the easiest one here and I'm going to type Hello CS50 in this string, "Hello CS50", zooming in say how nice the puzzle pieces are nicely interlocked?
今天我们看到的各种图块,到下周五我会仔细讲解其中的精妙之处,但今天我只想举一个最简单的例子,我要在这儿键入字符串,放大窗口,然后看看这漂亮的图形和文字,是如何美妙地连结在一起的?
I'm sort of love this movie, I'm start expecting certain type of character sort of boring character.
但我还是有些喜欢这部电影,至少开始喜欢个别角色,尽管他看起来可能有些没劲。
So that way you can have an idea if, oh, I do really understand this but I'm a little bit slow, maybe I need to practice this one type of problem a little bit longer so I can get up to speed so I'm going to be able to get through all this in terms of the exam time.
这样你就可以知道,假设,噢,我真的懂这个,但是我的速度有点慢,或许我需要在练习这个类型的题目上,多花一点时间,这样我就可以提高自己的速度,可以全部做完,在考试规定的时间内。
OK, now, if I actually do this, and I'm going to show you the example, I just, what did I type over there, I got p was a c point.
传入了其他的参数,好,现在,如果我,实际上要做这个的话,我要给大家看个例子。
So when I type, I'm sorry, I shouldn't say type, c point although I would have typed it, p dot x, here's what basically happens.
处于特定点的实例的这个概念,我知道它来自于这个类,这个类,when,I,write,因此当我输入,抱歉,我不该说输入的,当我写,虽然我需要输入它,p,x的时候。
Here I'm declaring another data type altogether.
这里我声明另一个数据类型。
Now what I'm going to try and do is read in a set of values, but I'm going to give a type of value as well as the messages.
现在我要做的是输入一些值,并关注异常,我会输入消息以及一种其他的值。
I am going to run a program called Nano nano hello c and type nano hello.c and I'm gonna type the following very quickly without much explanation because we'll dive into this more next week.
我要运行一个Nano程序,键入,我快速写下下面的内容,不打算做过多的解释,因为下周我们会深入了解这些。
So, I'm going to type foo enter, foo enter and I type different things. All right.
我输入foo,回车,foo,回车,我输入不同的东西,好的。
The format is the same. I'm going to ask for some input, and then I am going to use that procedure to check, is this the right type of value. And I'm trying to use that to do the coercion if you like. Same thing if it works, I'm going to skip that, if it not, it's going to throw the exception.
格式是一样的,我需要一些输入,然后我要用一个过程来检查,是否是正确的值,然后你就可以做强制转换了,如果能运行,那是一样的,我打算跳过这段,如果不正确,那就会抛出一个异常。
So, summarizing better, assert is something you put in to say to the user, make sure you're giving me input of this type, but I'm going to guarantee you the rest of the code works correctly. Exceptions and exception handlers are saying, here are the odd cases that I might see and here's what I'd like to do in those cases in order to try and be able to deal with them.
所以更好的总结下,断言就是你放在那里告诉用户,保证你输入的是这种类型的,但我能保证剩下的代码运行正确,异常和异常处理做的事,这里有些我能预期的异常情况,并且这里有些情况,我能尝试处理。
So I'm going to go over here, and I'm going to type test search-- I can type and if you look at your handout, it's just a sequence of tests that I'm going to do OK. So initially, I'm going to set up the list to be the first million integers.
大家可以看看你们的课堂材料,那儿有一些我要做的实验,好,一开始我先去建立个,含有一百万个integer的数组,对,这有点儿简单,但是这给我提供了这样一个有序的数组。
And I'm storing the answer in a variable called "answer" that's of type float.
我把这个答案存储在一个float类型的,叫做“answer“的变量中。
And then I run a loop in which I read something in, I check to see if it's the right type, if it is, I change that variable to say it's now the correct type, which means the next time through the loop, I'm going to say I'm all set and I'm going to bounce out.
因为我还没输入,然后我运行一个循环,循环内部我输入一些东西,然后看看是不是正确的类型,如果是的话我改变input,Ok为真,来证明输入数是正确的类型,这就意味着下一次运行这个循环的时候,就可以跳出循环继续执行了。
Then I'm declaring a variable called n, it's of type int.
然后我声明了一个变量n,它是int型的。
So with the fact that I'm now just back at my prompt is a good thing so now GCC hello c if I type this command GCC hello.c, this is gonna run this program that Apple wrote in this case GCC or someone else wrote called GCC.
也就是说我们现在安全返回,说明一切正常,现在我输入这条命令:,这代表运行hello,c这个程序,是由“Apple“或其他人编写的,名为。
应用推荐