News for hackers. Stuff that matters.

Ask HN: 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 Feynmann's method ("think hard and solve it") discouraging.

Anything more step-by-step?

( 7 comments | 3 points | on HN )
Re:Ask HN: How to Teach Debugging? by MatthiasPortzel on Monday March 11, 2024 @12:22PM (#39670116)
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.

Re:Ask HN: How to Teach Debugging? by fdeage on Monday March 11, 2024 @01:35PM (#39671091)
Thanks! It's like an extended Feynman. It also reminds me of this: https://jvns.ca/blog/2022/12/08/a-debugging-manifesto

You're right to emphasize the looping it takes to solve bugs. Many students are not prepared for this.

Re:Ask HN: How to Teach Debugging? by acemarke on Monday March 11, 2024 @11:52AM (#39669704)
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...

Re:Ask HN: How to Teach Debugging? by fdeage on Monday March 11, 2024 @12:33PM (#39670287)
Very interesting, thanks!
Re:Ask HN: How to Teach Debugging? by dhunter_mn on Monday March 11, 2024 @12:05PM (#39669872)
Liken it to working on a crossword puzzle
Re:Ask HN: How to Teach Debugging? by sn9 on Monday March 11, 2024 @04:29PM (#39672906)
Re:Ask HN: How to Teach Debugging? by sargstuff on Thursday March 14, 2024 @07:41AM (#39702598)