HACKER Q&A
📣 fdeage

How to Teach Debugging?


I am teaching a data science class to people with little to no programming experience. The course uses Python and various ML libraries, and Docker.

I find very difficult to provide the students with a general method of debugging. I find Feynman's method ("think hard and solve it") discouraging.

Anything more step-by-step?

EDIT: typo


  👤 MatthiasPortzel Accepted Answer ✓
0. Define the intended behavior and the current behavior.

1. Come up with a hypothesis for why they don’t match

2. If you’re unable to come up with a hypothesis (“I’m sure it should work”), then that means you’re assuming something that isn’t true. Identify one of your assumptions and take it as your hypothesis.

3. Gather data until you’ve either proved or disproved your hypothesis. This can be done by designing an experiment, inspecting variable values using print statements, reading documentation, or etc.

4. With this new information, circle back to the problem. Either attempt a fix, or generate a new hypothesis and start at 1.

Students, and programmers of all skill levels, get stuck at every step. Some other tips:

* Ask for help only with the step that you’re stuck on. You can ask for help creating a hypothesis, but don’t ask for help gathering data at the same time. This keeps questions focused.

* Be mentally prepared to run through this loop many many times until the problem is fixed.


👤 acemarke
Yeah, I did a talk on "Debugging JavaScript" that really is mostly language-agnostic and focuses on the core scientific method approach:

- https://blog.isquaredsoftware.com/2023/06/presentations-debu...




👤 dhunter_mn
Liken it to working on a crossword puzzle