PROFESSOR: I want to take a few minutes at the start of today's lecture to wrap up a few more things about debugging.
教授:我想在今天讲座的开头,再花几分钟讲完调试的剩余内容,然后我们再讲主要内容。
You find some way of systematically going through the list. Yet, I often see people, when they're debugging, proceeding at what, to me, looks almost like a random fashion of looking for the bug.
是不是目标元素,我们有一种系统化的,遍历数组的方法,然后我经常看到,有些人调试的时候。
I emphasize this because it often leads to a different debugging strategy.
因为这会导致不同的调试策略,所以我要强调这一点。
So one of the things I want you to notice here is that testing and debugging are not the same thing. When we test, we compare an input output pair to a specification.
这里我想大家注意的一件事,就是测试和调试是不同的两件事情,我们测试的时候,我们把输入输出,跟程序的规格说明书对比下。
Patience is an important part of the debugging process. I have not rushed.
耐心是调试过程中的一个重要部分,我没有着急,我冷静的慢慢的。
OK. All right, let me show you one other tool that I want to use. Which is, I've written that piece of code, I ought to check it. Well, I could just run it, but another useful thing to do is, I'm, especially as I want to debug these things, is to simulate that code.
好,那么,让我给大家讲下,我想用的另外一个工具吧,也就是,我已经写好了这一块代码,我应该去检查检查,那么我可以去运行它,但是特别是当我想要调试代码的时候。
Since I'm not sure I won't need to go back to it.
我注释掉了之前的调试语句。
There's a lecture I've given several times at hospitals, to doctors, on doing diagnosis of complex multi illnesses. And I go through it and almost the same kind of stuff I'm going to talk to you about, about debugging.
一个实验室内的实验,为什么实验不对呢?,我也在医院给医生关于,诊断复杂的多种疾病做过很多讲座,我想了想,那和我给你们讲的,关于调试其实都是一回事。
In line with what I said about debugging.
这和我在讲调试的时候是一致的。
Alright, that's the end of my, maybe sermon is the right word on debugging. Polemic, I don't know. I hope it will be helpful. And I hope you'll remember some of these things as you try and get your programs to work.
这就是我有关调试好习惯的一些废话,也许你们会有争议,我希望这些对你们会有帮助,而且我希望你在调试的时候,会想起我今天讲的这些话。
I guess it's not macho enough, John, to just, you know, you know, go off and do things by hand, you ought to just run them, but it's a valuable tool to get into, so let me do that here.
我认为这不太男人了,John,你知道的,他们仅仅是认为比起用手做来,更应该直接去运行程序,但是这确实是调试代码的非常有价值的工具,让我在这里给大家演示下吧。
So I'm going to have an assignment of y, I'm going to have an assignment of iters left, I've got a comment that I had borrowed in order to do some debugging, and then what do I want it to do?
因此我需要对y进行赋值,需要对iters,left进行赋值,还有一个我用的别人的,用来调试的一些注释,那么接下来我希望程序怎么运行呢?
How to fix it. When I think about debugging, I think about it in terms of what you learned in high school as the scientific method.
怎么来修复bug,当我谈论到调试的时候,我认为你们应该依照在高中,在科学方法学中学过的。
应用推荐