我是靠谱客的博主 长情茉莉,最近开发中收集的这篇文章主要介绍Lecture 11: Debugging - After the System is Deployed,觉得挺不错的,现在分享给大家,希望可以做个参考。
概述
1 Reproduce the Bug
- Start by finding a small, repeatable test case that produces the failure.
- Once you’ve found a small test case, find and fix the bug using that smaller test case, and then go back to the original buggy input and confirm that you fixed the same bug.
2 Understand the Location and Cause of the Bug
Step1: Study the Data
- test input that causes the bug
- the incorrect results
- failed assertions
- stack trace from an exception.
Step2: Hypothesize
- Propose a hypothesis, consistent with all the data, about where the bug might be, or where it cannot be.
- It helps to think about your program as modules, or steps in an algorithm, and try to rule out whole sections of the program at once.
Step3: Experiment - Devise an experiment that tests your hypothesis
- Run a different test case
- Insert a print statement or assertion in the running program, to check something about its internal state.
- Set a breakpoint using a debugger, then single-step through the code and look at variable and object values.
2.1 Other Tips for the Location of the Bug
- Bug localization by binary search
- Prioritize your hypotheses
- Different parts of the system have different likelihoods of failure.
- Old, well-tested code is probably more trustworthy than recently-added code.
- Java library code is probably more trustworthy than yours.
- Swap components.
- If you suspect the Java runtime, run with a different version of Java.
- If you suspect the operating system, run your program on a different OS.
- If you suspect the hardware, run on a different machine.
- If you suspect your binarySearch() implementation, then substitute a simpler linearSearch() instead.
- Make sure your source code and object code are up to date.
- Get help.
- Sleep on it, If you’re too tired, you won’t be an effective debugger. Trade latency for efficiency. :)
3 Fix the Bug
- Ask yourself whether the bug was a coding error, like a misspelled variable or interchanged method parameters, or a design error, like an underspecified or insufficient interface.
- Think also whether the bug has any relatives.
Reference
[1] 6.005 — Software Construction on MIT OpenCourseWare | OCW 6.005 Homepage at https://ocw.mit.edu/ans7870/6/6.005/s16/
最后
以上就是长情茉莉为你收集整理的Lecture 11: Debugging - After the System is Deployed的全部内容,希望文章能够帮你解决Lecture 11: Debugging - After the System is Deployed所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复