C coding debugging tip #2: comment out all suspicious code


A student sought help from me for his programming project as he did not manage to debug the program.  One reason is: he could not identify the error among many lines of code.
Watch the video above which show the debugging process and techniques.  Hope it helps to improve your debugging techniques in programming.

What have you learnt in the above video, in terms of debugging technique?

Summary:

  • Mistake #1: Type too many commands at one go before "Compile & Run".
  • Debugging Tip #1:  comment out all the suspicious statements (code) using //

Explanation:

Mistake #1: Type too many commands at one go before "Compile & Run"

  • He typed in many commands (statements) at one goThen, he compiled and run the program.  When he saw the error message, it is very difficult for him to identify which code gave the error. Is it line 23 or ??

Debugging Tip #1:  comment out all the suspicious statements (code) using //

When this happens, one possible debugging technique is to comment out (//) all the suspicious statements (code) using //.  See screenshot below.
Debugging techniques. Comment out all the suspicious statements (codes)

After that, add back the suspicious statement (code) one at a timeRemember to compile & run for each & every statement (code) added.  Make sure it does NOT give you error before you proceed to add in another statement (code).

To be continued



Post a Comment

0 Comments