Well, you wake up in the morning and it is raining and being the conscientious and reliable young people that I know you to be, you probably forget to do it.
嗯,你早上醒来,并且在下雨,作为一个认真的,可信赖的年轻人,我知道你会这样做,你可能忘记了做。
that you know it's not going to happen or you know it's not useful to do.
你知道这事没发生的可能,或者这么做并不会起到什么作用。
You'd pull out your pencil and paper, you can do it as a matrix inversion if you know how to do that, or you can just simply do substitution of one equation into another to solve it.
你知道你在小学的时候是怎么做的对吧?,你拿出你的笔和纸,如果你会的话,你可以解一个方程组,或者你可以单纯地。
Well, I suppose one possible response would be, "You know, you couldn't really do that.
我想可能会有人回应说,你知道,你其实并不能真的那样做
We don't know the time and we don't know how high it's rising so you can ask, "How am I supposed to deal with this problem?"
我们既不知道时间,又不知道最高点的高度,那你就会问了,这道题该怎么做呢
If you know it' s going to work, it's not an experiment.
如果在做实验时,你已经知道这个成分会起作用,那这就不是一个真正意义上的实验了。
So what the guy would do is he would say okay you've got--if it was local money if it was from this town if it was New Haven money there were New Haven banks the guy would immediately know what it's worth.
所以,那个人将会做的是说,好的,你的钱-如果它是当地货币,如果来自这个城镇,如果是纽黑文的纸币,当时有纽黑文银行,那么这个人将立刻知道它值多少钱。
And you want to know what they would do if they were in your shoes.
你想知道如果他们站在你的角度考虑他们会怎么做。
because you don't know what they'll do with the money.
因为你不知道他们会拿钱来做什么。
That goes back to that idea of sort of discipline coding. It's easy to have assumptions about what you think are going to come into the program when you writ it. If you really know what they are use them as search, but if you think there's going to be some flexibility, you want to prevent the user getting trapped in a bad spot, and exceptions as a consequence are a good thing to use.
这又回到了规范编码的想法上来了,在你写代码的时候考虑,什么会进入你的代码的思考是简单的,如果你真的知道,他们是用他们来做搜索的,而你希望有一定的灵活性,你想要阻止用户,陷入一个艰难的境地,那么异常是非常实用的。
Suppose that there were some sort of genetic marker and, although we didn't have a tattoo that you would just have to look at, -- but you could have genetic counseling-- have your DNA examined and you could tell, if you had the DNA testing, how much time you had left.
假设有某种基因标记,虽然我们没有,让你不得不去看的在身上的标记了,但你可能会去做基因咨询-,检查你的DNA,如果你做了DNA化验的话,你就能知道自己还剩多少时间。
Computing square root. I'm going to capture it in a piece of code, I'm going to be able to refer to it by a name, and I'm going to suppress the details, meaning inside of that computation, you don't need to know what it does. You just need to know, if I give it the right kind of input, it'll give me back an input that satisfies the contract that I set up.
比如计算平方根,我会用一段代码来说明,我将给它命名,并且忽略细节,意思就是在这一段计算过程中,你不用知道它做了什么,你只需知道,如果我进行了正确的输入,它将会给我符合条件的输出。
But notice what this does. The first thing it does is, it says, let's check and make sure x is greater than or equal to 0. If it isn't, notice what's going to happen. None of that block is going to get executed, and it's going to come down here and print out a useful piece of information, which says, hey, you gave me a negative number. I don't know how to do this.
做的是和以前一样的事情,但是注释它做了什么,第一件做的事情就是,程序说,要去检查并且确信x是大于等于0的,如果不是的话,请注意会发生什么,下面的代码都不会被执行,程序会到这里来然后显示一些有用的信息,信息会说,嘿,你给了我一个负数,我不知道该怎么弄这个了。
应用推荐