Summary: Debugging Interlude—Avoiding/Finding Mistakes

This lesson summarizes the ideas discussed in this chapter.

As much as possible, use these techniques to help you to avoid making mistakes in your code:

  • Each method should have a clear and focused purpose
  • When a method has complex logic, divide the logic into portions performed by private methods that your public method can call
  • Clearly document each method’s purpose and preconditions
  • Ensure that any method another method calls is error-free by testing it separately in its own program
  • Use stubs for methods that you still need to implement
  • When debugging a method, trace its logic by writing temporary statements that either display the values of key variables or simply report the current stage of execution
  • Simplify the requirements or feature set of a complex program for your initial solution
  • Test your program extensively using reasonable data
  • Test data should include values within, outside of, and at the endpoints of each range of legal input
  • For programs that use real-time data, initial testing should use simulated but realistic data

Get hands-on with 1400+ tech skills courses.