Ď╗ăđÍ╗╩ă┐¬╩╝
未识别博客 · 2004-06-23(近似)
The 11 Truths of Debugging
╩▒╝ń: 04/06/07
Í«ă░┐┤┴╦úČÍđ╬─┴╦Ď╗ÁŃÎóŻÔúČŻß╣ű╦└╗˙Ďď╬¬Â¬┴╦úČŻ˝╠ýËÍ┤˛┐¬ word żË╚╗╗╣ď┌ í¬í¬ Şđđ╗╬ó╚ÝúČŞđđ╗Á┴░Š~
The 11 Truths of Debugging
1. Intuition and hunches are greatí¬you just have to test them out. When a hunch
and a fact collide, the fact wins. That's life in the city.
Í▒ż§║═索đ║▄ÍěϬ
ĘC
Í╗đŔ░Đ╦ű├ă▓Ô╩ď│÷└┤íú
2. Doní»t look for complex explanations. Even the simplest omission or typo can
lead to very weird behavior. Everyone is capable producing extremely simple
and obvious errors from time to time. Look at code criticallyí¬doní»t just sweep
your eye over that series of simple statements assuming that they are too simple
to be wrong.
▓╗ϬĐ░ŇĎŞ┤ďËÁ─ŻÔ╩═íúÎţ╝˛ÁąÁ─╩Ŕ║÷╗˛Ň▀└Óđ═ż═╗ßÁ╝Í┬╣ÍĎýđđ╬¬íú
3. The clue to what is wrong in your code is in the values of your variables and the
flow of control. Try to see what the facts are pointing to. The computer is not
trying to mislead you. Work from the facts.
ŇĎ│÷┤˙┬Ű┤Ý╬ˇÁ─¤▀╦¸úČż═ď┌─ŃÁ─▒ń┴┐ÍÁ║═┐ěÍĂ┴¸│╠Íđíú
4. Be systematic and persistent. Doní»t panic. The bug is not moving around in
your code, trying to trick or evade you. It is just sitting in one place, doing the
wrong thing in the same way every time.
▒ú│Í╠§└ÝúČ╝ß│Í▓╗đŞúČ▓╗Ϭż¬╗┼íú
5. If you code was working a minute ago, but now it doesní»tí¬what was the last
thing you changed? This incredibly reliable rule of thumb is the reason your
section leader told you to test your code as you go rather than all at once.
╚š╣ű─ŃÁ─┤˙┬ŰĎ╗ĚÍÍËă░╗╣║├║├Á─úȤÍď┌╚┤▓╗╣ĄÎ¸┴╦íú
-
─ŃÎţ║ˇÎ÷┴╦╩▓├┤Ş─»ú┐
6. Do not change your code haphazardly trying to track down a bug. This is sort
of like a scientist who changes more than one variable in an experiment at a
time. It makes the observed behavior much more difficult to interpret, and you
tend to introduce new bugs.
▓╗Ϭ╚╬ĎÔŞ─▒ń┤˙┬Ű└┤ÎĚÎ┘
bug
íú╗ߪŘ─ĐŻÔ╩═╣█▓ýÁŻÁ─¤Í¤ˇúČ▓óăĎ┐╔─▄Ďř╚Űđ┬Á─
bug
7. If you find some wrong code that does not seem to be related to the bug you
were tracking, fix the wrong code anyway. Many times the wrong code was
related to or obscured the bug in a way you had not imagined.
╚š╣űŇĎÁŻđę║═─ŃÎĚÎ┘Á─
bug
╬Ů╣ěÁ─┤Ý╬ˇ┤˙┬ŰúČŞ─ŇřÁ˘íú
8. You should be able to explain in Sherlock Holmes style the series of facts, tests,
and deductions that led you to find a bug. Alternately, if you have a bug but
caní»t pinpoint it, then you should be able to give an argument to a critical third
party detailing why each one of your functions cannot contain the bug. One of
these arguments will contain a flaw since one of your functions does in fact
contain a bug. Trying to construct the arguments may help you to see the flaw.
9. Be critical of your beliefs about your code. Ití»s almost impossible to see a bug
in a function when your instinct is that the function is innocent. Only when the
facts have proven without question that the function is not the source of the
problem should you assume it to be correct.
─Ń▓╗┐╔─▄ď┌Îď╚¤╬¬├╗┤ÝÁ─┤˙┬Ű└´├ŠŇĎ│÷
bug.
10. Although you need to be systematic, there is still an enormous amount of room
for beliefs, hunches, guesses, etc. Use your intuition about where the bug
probably is to direct the order that you check things in your systematic search.
Check the functions you suspect the most first. Good instincts will come with
experience.
─ŃđŔϬËđ╠§└ÝúČÁź═Č╩▒┴˘¤┬ÎŃ╣╗Á─┐Ň╝ń└┤索đúČ▓┬¤Űíú
11. Debugging depends on an objective and reasoned approach. It depends on
overall perspective and understanding of the workings of your code. Debugging
code is more mentally demanding than writing code. The longer you try to
track down a bug without success, the less perspective you tend to have.
Realize when you have lost the perspective on your code to debug. Take a
break. Get some sleep. You cannot debug when you are not seeing things
clearly. Many times a programmer can spend hours late at night hunting for a
bug only to finally give up at 4:00A.M. The next day, they find the bug in 10
minutes. What allowed them to find the bug the next day so quickly? Maybe
they just needed some sleep and time for perspective. Or maybe their
subconscious figured it out while they were asleep. In any case, the í░go do
something else for a while, come back, and find the bug immediatelyí▒ scenario
happens too often to be an accident.
í¬ Nick Parlante, Stanford University
Îţ║ˇĎ╗╠§úČ▓╗╩ă║▄«íúíúíú
carol
Ěó▒ÝË┌
04/06/07 21:00
ĎřË├(Trackback0)
Ă└┬█
Ěó▒ÝĂ└┬█
Ë├╗ž├ű:
Email:
͸Ď│:
Îţ║ˇŞŘđ┬
[ά╠¨]ŇŠÁ─┴╦ŻÔtelnet┬ú┐
[═╝]Introduction to Bluetooth
Record - June 15th~
[WIN CE] ďÂ│╠┐ěÍĂúČ╩┬░Ű╣Ž▒Â
┤Ë┐¬ĚóŻăÂ╚┐┤ smartphone
palm ╔¤╬ňĚN▓╗═ČÁ─ reset [ά]
ĚĘË´
The 11 Truths of Debugging
[ά╠¨]╬ó╚ÝSmartphoneËŽË├│╠đ˛╔Ŕ╝Ă╚Ű├┼
smartphone Ď╗└└
原始快照:web.archive.org