When there are some thing wrong in code, I should do what?
I should read code to find w开发者_开发技巧hat's wrong? Or debug, or output some key information.
When I read the code, I may miss the detail in code.
When I debug, I may don't know what the code is really is. When I output some information, I may be confused by some not really key things about the code's wrong.You do all of the above in some combination depending on exact symptoms. There's no "one size fits all" solution that you could apply without thought.
For example, if the problem can be easily reproduced - often you just attach a debugger and figure out "how you've got there" or just wait till the program crashes under debugger.
Based on your (correct) analysis, the answer is obvious: do all 3. Also, add in a step for unit testing :)
Firstly read the following book: Debugging by David J Agans - it should be required reading for all neophyte programmers.
精彩评论