This is the place where people typically slip up in debugging. They don't think in advance what they expect the result to be.
实验就推翻了你的假设了,人们在做调试的时候往往忽略了这一点,他们做实验之前并没有想想。
PROFESSOR: I want to take a few minutes at the start of today's lecture to wrap up a few more things about debugging.
教授:我想在今天讲座的开头,再花几分钟讲完调试的剩余内容,然后我们再讲主要内容。
But just so you've been teased with them, "-ggdb" is a flag that's going to enable what are going to be called "debugging symbols."
但是你们刚才被他们忽悠了,“-ggdb“是用来使能“调试标志“功能,的一个标记“
Debugging is a different process.
调试就是另外一个过程了。
The two best debugging tools are the same now that they have almost always been.
最好的两个调试工具一直,以来基本没怎么变过。
See if we can find it here. And notice, by the way, that I commented out the previous debugging line, rather than got rid of it.
我们再去从它们的中间开始尝试,看看我们能不能发现问题源,顺便说一下,请注意。
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.
这里我想大家注意的一件事,就是测试和调试是不同的两件事情,我们测试的时候,我们把输入输出,跟程序的规格说明书对比下。
Does it give you the answer that you expected it to give? Often, in practical problems, you'll spend just as much time doing performance debugging. Why is it slow?
它返回了期待中的结果了么?通常,在实际的问题中你会花,同样多的时间在性能调试上,它为什么运行这么慢?
And I've put it in my debugging code.
调试的代码中去,然后运行看看结果。
Patience is an important part of the debugging process. I have not rushed.
耐心是调试过程中的一个重要部分,我没有着急,我冷静的慢慢的。
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.
一个实验室内的实验,为什么实验不对呢?,我也在医院给医生关于,诊断复杂的多种疾病做过很多讲座,我想了想,那和我给你们讲的,关于调试其实都是一回事。
So a word about debugging.
关于调试我们来说几句。
They didn't apparently call it debugging.
在编号70的传送带那。
That gets us to debugging.
这就需要我们去调试了。
Typically, even though they don't breed, there are many bugs. And keep in mind that the bug goal of debugging is not to eliminate one bug.
这是件好事,其实即使bugs不会繁殖,也会有很多,并且请记住调试的目的,并不是去消除一个。
So printf itself is primitive but useful debugging tool.
printf“本身在早期就是有用的调试工具。
it's not as good as helping debug, sorry, that's the wrong way of saying it's not as good at catching some things before you run them, it is easier at some times in debugging as you go along on the fly.
它在帮助我们调试方面可能不是太优秀,对不起,这么说有点不正确,它在运行前捕捉错误,可能不是那么优秀,可能边运行边调试,会更容易一些。
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.
是不是目标元素,我们有一种系统化的,遍历数组的方法,然后我经常看到,有些人调试的时候。
Getting good at this is probably the single most important skill for debugging.
熟悉这一点对调试来说,可能是最重要的技能了。
Algorithms for searching. Debugging is simply a search process.
调试简单点来说,就是一个搜索的过程。
That, by the way, is also a good debugging tool.
顺便说一下,这是一种很好的调试方法。
Alright. Now debugging is a learned skill.
好,发展到现在调试是一门。
In line with what I said about debugging.
这和我在讲调试的时候是一致的。
And at considerable length 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.
这就是我有关调试好习惯的一些废话,也许你们会有争议,我希望这些对你们会有帮助,而且我希望你在调试的时候,会想起我今天讲的这些话。
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,当我谈论到调试的时候,我认为你们应该依照在高中,在科学方法学中学过的。
应用推荐