The magical "Little Yellow Duck Debugging Method"

Hello everyone, welcome to Crossin's programming classroom!

There is a mysterious debugging method circulating in the programmer world, called " Little Yellow Duck Debugging Method" (Rubber Duck Debugging).

c2d98dfe0292da111263ae36f5a4c650.jpeg

That's right, it's the little yellow duck.

What's the meaning? That is to say, when you are overwhelmed by a piece of code, and you can’t see where the problem is no matter how you look at it. You can explain your code line by line to a little yellow duck. Not only explain the function of the code, you'd better tell the duck what you want to achieve, what method you plan to achieve, why you want to achieve it, and so on. When you are talking and talking, hey, suddenly you understand where the problem is. It's just so magical.

This is not my nonsense, this method has been verified by a large number of programmers.

Why is there such a magical effect?

In principle, this is probably because: when we are stuck by a bug in the program, if we continue to follow the original train of thought to find the answer, it is easy to fall into the misunderstanding of our own thinking and not be aware of it. But when you have to explain your code to another person or object, you have to rearrange your thinking, change your perspective, and look at the code more comprehensively to see some different details.

And this trick is not only useful for programming, but also for other problems. Have you ever had such an experience, someone came to you to ask a question, and then he started to talk about his question, and suddenly said in the middle of the speech: "Oh, I understand!" and then left you with a confused face in place. At this time, in fact, you have already been a little yellow duck without knowing it.

So, next time you encounter a bug when writing code, you can also try this little yellow duck debugging method.

Guess you like

Origin blog.csdn.net/qq_40523737/article/details/131467560