rules for tracking down the cause of a problem

From: Progmatic shelf-practical programming an introduction to computer sicence in python,  12.4 Debugging


Here are some rules for tracking down the cause of a problem:

 

1. Make sure you knowwhat the program is supposed to do.Sometimes

this means doing the calculation by hand to see what the

correct answer is. Other times, it means reading thedocumentation

(or the assignment) carefully or writing a test.

 

2. Repeat the failure. You can debugthings only when they go wrong,

so find a test case that makes the program fail reliably.Once

you have one, try to find a simpler one; doing this oftenprovides

enough clues to allow you to fix the underlying problem.

 

3. Divide and conquer. Once you havea test that makes the program

fail, try to find the first moment where something goeswrong.

Examine the inputs to the function or block of code where the

problem first becomes visible. If they are wrong, look at howthey

were created, and so on.

 

4. Change one thingat a time, for a reason. Replacing random bits of

code on the off-chance they might be responsible for yourproblem

is unlikely to do much good. (After all, you got it wrong the

first time....) Each time you make a change, rerun your testcases

immediately.

 

5. Keep records. After workingon a problem for an hour, you won’t

be able to remember the results of the tests you’ve run. Likeany

other scientist, you should keep records. Some programmersuse a

lab notebook; others keep a file open in an editor. Whateverworks

for you, make sure that when the time comes to seek help, you

can tell your colleagues exactly whatyou’ve learned.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值