Ah, debug!

xiaoxiao2021-03-06  14

I saw a lot of Jon Bentley's "Programming Pearls", and especially in practice for debugging, I want to share it with everyone.

text:

debugging

Every programmer knows that debugging is a difficult thing. But skilled commissioning can make this project simple. Some programmers have been upset to describe them for a few hours, and the executive personnel have asked a few questions. After a few minutes, the programmer looked at the code at the eyes. Professional debugers will never forget,

Regardless of the fact that the system behavior looks mysterious, there must be some logical explanation. There is a distant history in the York City Research Center of IBM. A programmer recently installed a new workstation. Everything is normal when he sits down, but when he stands up, he can't log in to the system. The behavior has 100% repetitive: When sitting down, you can log in to stand up and never log in.

Most of us are just on the back of the chair, and they can't understand such a situation. How do you know that the poor guy is standing? But the excellent tutor knows that there must be a big article. The easiest to suspect is the electrical theory. Is the wire under the carpet loose? Is there a static problem? But no family is an electrical problem. A colleague of a machine is finally asking for a question: How is the programmer standing and sitting when you log in? Try again and then try again.

The problem is on the keyboard: two keycaps are loose. When the programmer sat down because he was touched, so did not pay attention to this problem; but when he stood up, he was in and tap the keyboard. He has to make mistakes. I learned this, the professional commissioner took the truce, tightened the two swaying keycaps, and everything was normal.

A banking system in Chicago has been working hard for a few months, but it can't be thought about it, the first time the international data stopped working. The programmer took a few days to chase the code, but they could not find any commands that stop the program. When this problem is more careful, they find that when they enter some data with Ecuador, the program will stop. More careful detection shows that the program explains it as a request to stop running the program when the user is typed in the capital name (Quito, "

Bob Martin once saw a system "Work Once TWICE". The system is correct when the transaction is processed, and then a small error occurs without exception in subsequent transactions. After the system restarts, it is normal when processing the first transaction, but all subsequent transactions have failed. When Martin is called "Work Once TWICE", the developers immediately knew that the program was loaded, and the program was loaded correctly, but the first transaction was not reset correctly.

No matter what circumstances, the appropriate question will lead the league programmer to quickly find the annoying bug :: "Do you have different things when you stand and sit? I can see your login every time. Way? "" Accurately, what did you entered before exiting the program? "" How many times? "How many times?"

Rick Lemons said that in debugging or his best class is to watch magic performance. The magician played 6 people who could not be able to discover, and Lemons found himself also tend to believe them. Then he reminded himself

What is unliked by people is absolutely impossible, he also carefully observes every trick to unlock it obvious contradiction. He first started from the basic principles of his familiarity - physical law - starting from that. This attitude makes Lemons one of the best debugers I have ever seen.

转载请注明原文地址:https://www.9cbs.com/read-67594.html

New Post(0)