Monday, November 21, 2022

Carefully examine the data at a routine's entry and exit points

When debugging a routine, we can resolve many problems by first examining its entry point or pre-conditions, which include its program state and input parameters, and then its exit point or post-conditions, which include its program state and return values.  Problems at the entry point indicate that the code leading to the routine is faulty, while problems at the exit point indicate that the routine is faulty.  If there are no problems at entry and exit, then the fault lies not in the routine.  

To debug a sequence of routines, it helps to create log messages for indicating the entries into and exits from the routines and the data at these points.  This is more communicative than the use of breakpoints, although breakpoints are usually easier to use.  It is important to verify and not assume.  


Reference:

Diomidis Spinellis, "Effective Debugging: 66 Specific Ways to Debug Software and Systems"

No comments:

Post a Comment

Mirdin Coding Tips

Tradeoffs for Pre and Post Conditions for Code Blocks A weaker precondition or less preconditions for a code block will be more general and ...