Skip to content

Latest commit

 

History

History
170 lines (99 loc) · 5.26 KB

strategies.md

File metadata and controls

170 lines (99 loc) · 5.26 KB

Debugging Strategies and Tools

Sciware Session #4

https://github.com/flatironinstitute/learn-sciware-dev

Flatiron Reveal js theme

Available for everyone to use!

Instructions here:
https://sciware.flatironinstitute.org/Theme_Demo/

Thanks Liz Lovero!

Next Time

  • Sept 26 or Oct 3
  • Thurs, 3-5 pm
  • Advanced Testing or HPC Cluster Intro
  • Location TBD

Let's discuss on #sciware Slack channel

Goals for Today

Foster an environment which encourages participation across experience levels, coding language fluency, technology choices, and scientific disciplines.

  • Avoid discussions between a few people on a narrow topic
  • Provide time for people who haven't spoken to speak/ask questions
  • Work together to make discussions accessible to novices

Schedule

About 15 mins each

  • Overview of Debugging Strategies - Kelle Cruz, CCA
  • System Tools - Dylan Simon, SCC
  • Pycharm Debugging Tools - Tibi Tesileanu, CCB
  • Emacs and gdb (C++) - Nick Carriero, SCC
  • gdb web frontend (C++) - Nils Wentzell, CCQ
  • C++/LLVM Sanitiziers - Olivier Parcollet, CCQ

Debugging Strategies

by Glenford J. Myers, Corey Sandler, Tom Badgett

Chapter 8 Debugging

Debugging Can Be Unpleasant

  • Bugs represent mistakes and an ego hit
  • Debugging is mentally taxing and tiring
  • Debugging can take you down rabbit holes
  • You probably weren't taught helpful strategies to help

Error-Locating Principles

THINK.

Without looking at the code.

  • Review in your mind how the program is designed and how it should be performing
  • Concentrate on the process for correct performance, and then imagine ways in which the code may be incorrectly designed

Sleep on It

  • The human subconscious is a potent problem solver.
  • If error is not located in approximately 30 mins, set it aside and do something else
  • If solution arises while sleeping, capture it with a recording before going back to sleep

Describe Problem to Someone Else

  • Talking to someone else may lead to the solution without any verbal assistance from the listener.

Use Debugging Tools Cautiously

  • Debugging tools need to be used in conjunction with problem solving strategies

Experimentation is a Last Resort

  • A haphazard approach is inefficient and could result in compounding the problem by introducing new errors

Error Repairing Techniques

Errors Tend to Cluster

  • When repairing an error, examine its immediate vicinity for anything else which looks suspicious.

Fix the Error, Not the Symptom

  • Be careful to find all instances of an error, not just the one causing the failing right now

Bug Fixes Are Often Wrong

  • Corrections are more error prone than original code and should be tested more rigorously
  • Regression testing is important to help catch new errors potentially introduced by bug fixes

([xkcd #1739](https://xkcd.com/1739/))

Debugging Methods

  • Use induction or deduction to form hypotheses
  • Eliminate and/or refine possible hypotheses
  • Prove the hypothesis
  • Fix the error
  • Run regression tests

Debugging by Testing

Two types of test cases:

  • for testing: to expose previously undetected error
    Can cover many conditions with a small number of test cases
  • for debugging: to provide information useful in locating suspected error
    cover only a single condition in each test

As you track down bugs, write more tests!

Learn from Mistakes

  • When and where was the error made?
  • Who made the error?
  • What was done incorrectly?
  • How could the error have been prevented?
  • Why wasn't it detected earlier?
  • How could it have been detected earlier?