Original article:
Http://coolshell.cn /? P = 1719
(
Cool Shell
)
Next, let me introduce you to a program debugging method-the "Rubber Duck program debugging method". This method is outstanding in the debugging field and is very convenient and simple to implement, you can experiment almost anytime, anywhere without the support of any software or hardware. You can even print out your program and debug it on paper.
So why is this method called Rubber Duck? Because the Rubber Duck is a small toy that Westerners like best when taking a bath, it should be essential for every household. Because this method was invented by Westerners, it was named "Rubber Duck.
Well, let's not talk much about it. The following is the entire debugging method process.
- Find a rubber duck. You can borrow, steal, Rob, buy, and make your own ...... You need to get a rubber duck.
- Put the Rubber Duck in front of you. The standard practice is to put it on your desk, computer display side, or keyboard side, it's your front and face you.
- Then open your source code. Whether it's in a computer or printed.
- To the Rubber Duck, explain all the code you wrote in a row and line carefully to the Rubber Duck. Remember, this is an explanation. You need to explain your thoughts, ideas, and opinions. Otherwise, it can only be an expression, not an explanation.
- When you explain your thoughts, opinions, or ideas to the Rubber Duck that keeps silence, you will find that your thoughts, opinions, or ideas are deviated from the actual code, so you find the bug in the code.
- If you find the bug, remember to thank the Rubber Duck.
What? Do you think this method is too "stupid" or "mentally retarded? Yes, it seems that the brain of the person who will do this seems to be a bit faulty. However, what I want to tell you is that this method is indeed valid.This is the prototype of "code review ".
! Let me explain it to you.
Once a problem is described in sufficient detail, its solution is obvious.
The above sentence means
Once a problem is fully described, the solution is obvious.
I believe that everyone here has had this experience. When you cannot find the cause of the problem in your life and death, when you seek help from others, when you explain your thoughts, intentions, or background to others, you have not explained the cause of the problem. I believe you will have such an experience. This is the meaning of this method.
Therefore, the "Rubber Duck" is just a form. Its main purpose is to "self-check" the code you write, that is, to explain it to yourself. Of course, to prevent you from being a "splitting" programmer,
It is necessary to introduce the "Rubber Duck" (although it is still a bit mental, it is better than splitting the mind ). Therefore, the essence is code.
Review. For code review, let's take a look at several tips in my article "code review ".
, You will understand more of them.
Finally, I 'd like to share with you the prop "Rubber Duck ". Yes, you may not be able to find the "Rubber Duck" by our side, but you can find your colleagues and friends to make this "Rubber Duck ",
Of course, they do not necessarily have a "Rubber Duck", because your colleagues or friends will give their opinions and opinions freely when you explain them, which is quite annoying. Several prompts in code review
And the advantages and disadvantages of Pair Programming
I also talked about it for your reference.
(Full text)