Ask HN: How to Teach Debugging?
9 comments
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.
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.
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.
You're right to emphasize the looping it takes to solve bugs. Many students are not prepared for this.
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...
- https://blog.isquaredsoftware.com/2023/06/presentations-debu...
Very interesting, thanks!
Using outlines/flowchards & data science class assignment, can setup automated tests[0][1] of common issues in order to provide more detailed feedback than python.
[0] : Automated testing with python using pytest, tox, and github actions : https://www.youtube.com/watch?v=DhUpxWjOhME
[1] : Short overview of python debugging tools/techniques : https://www.linkedin.com/advice/3/what-most-effective-ways-d...
https://medium.com/@yellalena/a-guide-to-debugging-python-co...
Why logging/debugging : https://www.youtube.com/watch?v=w9JfBb0M5LU
python ide's : https://www.datacamp.com/tutorial/data-science-python-ide
https://towardsdatascience.com/practical-debugging-for-data-...
https://khuyentran1401.github.io/Efficient_Python_tricks_and...
https://towardsdatascience.com/practical-debugging-for-data-...
https://github.com/PacktPublishing/Debugging-Machine-Learnin...
https://github.com/topics/debugging?l=python
[0] : Automated testing with python using pytest, tox, and github actions : https://www.youtube.com/watch?v=DhUpxWjOhME
[1] : Short overview of python debugging tools/techniques : https://www.linkedin.com/advice/3/what-most-effective-ways-d...
https://medium.com/@yellalena/a-guide-to-debugging-python-co...
Why logging/debugging : https://www.youtube.com/watch?v=w9JfBb0M5LU
python ide's : https://www.datacamp.com/tutorial/data-science-python-ide
https://towardsdatascience.com/practical-debugging-for-data-...
https://khuyentran1401.github.io/Efficient_Python_tricks_and...
https://towardsdatascience.com/practical-debugging-for-data-...
https://github.com/PacktPublishing/Debugging-Machine-Learnin...
https://github.com/topics/debugging?l=python
Liken it to working on a crossword puzzle
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