Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft materials for debugging workshop #75

Merged
merged 29 commits into from
Sep 20, 2024

Conversation

robmoss
Copy link
Owner

@robmoss robmoss commented Aug 22, 2024

These materials are being prepared for an "Introduction to Debugging" workshop at the Spectrum Annual Meeting 2024 (23-25 September), as proposed in our August 2024 meeting.

See the discussion in our August 2024 meeting for further background.

These materials are being prepared for an "Introduction to Debugging"
workshop at the Spectrum Annual Meeting 2024 (23-25 September), as
proposed in our August 2024 meeting.
Copy link

github-actions bot commented Aug 22, 2024

PR Preview Action v1.4.8
Preview removed because the pull request was closed.
2024-09-20 01:12 UTC

@robmoss
Copy link
Owner Author

robmoss commented Aug 22, 2024

@EamonConway @jomonman537 please see the online previous.

@robmoss
Copy link
Owner Author

robmoss commented Aug 22, 2024

In particular, I hope the debugger demo achieves a good balance between simplicity and showing what a debugger can do.

This is followed by two examples for participants to try themselves:

  • The first one is similar in complexity to the demo, but has one small error for participants to find;
  • The second one is more complex, but reveals an important difference between Python and R.

The Techniques and tools page is currently incomplete, and may or may not belong in the workshop itself. It's intended as an opportunity to step back and look at the bigger picture of writing code that's easier to debug, learning debugging skills, etc — many of which are summarised in the manifesto poster at the start of the materials.

I'll share this draft with the participants at our August meeting for feedback, and see if anyone has code examples they can contribute for others to explore and debug.

@robmoss
Copy link
Owner Author

robmoss commented Aug 22, 2024

@EamonConway I'm particularly pleased with the debugger session recording at the bottom of this page — I've written a tool for scripting these terminal sessions, which can also add chapter markers and comments.

This page now begins with a short list of key concepts for using a
debugger, and has a short introduction paragraph before the debugger
session recordings (where we direct participants to use editors that
support running a debugger from within the editor itself).
I wrote this tool to generate the scripted debugger session recordings.
@EamonConway EamonConway self-requested a review August 27, 2024 23:24
@EamonConway EamonConway self-assigned this Aug 27, 2024
> You can run function 1 tests and get good answers, and then run function 2 test and get good answers, but this is because they are not sharing the state of the mutable variable.
> Sounds like a great inclusion as a mini chapter.

These are great ideas! The one drawback of the mutable data example is that it won't work in R, because it's copy-on-write. But that's no big deal. In fact, now that I think about, this difference us surely worth highlighting! People who are familiar with only one of these two languages need to be aware of this important difference if they begin using the other language.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great. I think it will shock some people to realise that their two favourite languages have drastic different behaviour.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! I'm not sure how much (if any) of the "Commentary" box I should leave in the published materials ... perhaps I should collect explanations for the two exercises in a separate page at the end?


## Searching for the root cause

Print statements, debuggers, REPLs, last good version, recent changes, assert statements, comment out code ...
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do we think of highlighting the "debuggers" in bold capitals to drive home that this is what you should use (the others are okay and help, but im straight to debuggers)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This page was a brain dump, and definitely needs to be edited/revised. Yes, I want to drive home the point that debuggers are the most direct means for observing what the code is actually doing, as opposed to what you think it's doing


## After it's fixed

Test cases, defensive programming, shorten the feedback loop, what coding practices might make such a mistake easier to find next time (e.g., small functions, frequent commits).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree about test cases for after its fixed, but should we also suggest test cases for when its found?
I personally think of tests that make sure the bug is reproduced before fixing code, then when I have fixed it, I have a suite of tests that should pass by ensuring the bad state is not hit. That way if it sneaks back in (which it has in the past) I catch it.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree in principle, my only reservation is whether this would require a reasonably detailed treatment of writing (and running) test cases, and whether that's feasible to cover within the same workshop. But hey, maybe an example of test cases for the Python vs R example would be good, in that they'd be more than a toy example?


Is the error reproducible, or does it come and go?

Write a failing test?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh we suggest the failing test here! I think adding it again at the point of my previous comment is also good.

Copy link
Collaborator

@EamonConway EamonConway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi,
I've left some comments for this, it is looking great.
One thing I noticed about this is that we are using the command line (which i do), but it might cause confusion for some.
Should we have an example using say Rstudio?
This will not be general, but might highlight that there are programs that make it easier for those that arent sitting around with terminal open every day.

@robmoss
Copy link
Owner Author

robmoss commented Aug 28, 2024

Hi, I've left some comments for this, it is looking great. One thing I noticed about this is that we are using the command line (which i do), but it might cause confusion for some. Should we have an example using say Rstudio? This will not be general, but might highlight that there are programs that make it easier for those that arent sitting around with terminal open every day.

I'm using terminal examples because they're simple to script and record, and people can copy the text at any point. I don't want to record videos for graphical editors (RStudio, PyCharm, Spyder, VS Code, etc) but I do want to show live demos using one or more of those editors in the workshop.

I haven't indicated this in the materials yet, except for a tip ("Interactive debugging sessions") in the Stepping through code section.

We now present the example (square numbers) on the next page, followed
by the two example exercises. Solutions to these exercises have been
added at the end of the workshop.
@robmoss
Copy link
Owner Author

robmoss commented Aug 28, 2024

I've separated the explanation of what a debugger does (Using a debugger) from the first example (Square numbers), and added solutions to the subsequent exercises at the end of the content.

I still need to flesh out and revise Techniques and tools. I'm tempted to rename this to something else, to indicate that this is about stepping back, taking stock of what we've covered, and thinking about what else you should consider when approaching debugging in your own projects.

But what should we call it? Some of the titles I've considered (none of which I'm thrilled with) include "Where to from here?", "Learning by doing", "Building your skills", and "The bigger picture". Maybe you have better suggestions?

@robmoss
Copy link
Owner Author

robmoss commented Aug 28, 2024

For now I've called it Building your skills and made some revisions, still needs a little more work.

The reader must now expand each solution to see the details.
This includes examples of reading strack traces produced by example
Python and R scripts.
@robmoss
Copy link
Owner Author

robmoss commented Aug 30, 2024

I've added a page about Understanding error messages where we can explain how to read stack traces, using simple Python and R scripts as examples. I think it's ready to share with our CoP, what do you think @EamonConway @jomonman537 ?

These cannot be accessed without UNSW credentials.
Also add support for light and dark terminal themes, and use the
Tomorrow Day and Tomorrow Night colour palettes, respectively.
@EamonConway
Copy link
Collaborator

I've added a page about Understanding error messages where we can explain how to read stack traces, using simple Python and R scripts as examples. I think it's ready to share with our CoP, what do you think @EamonConway @jomonman537 ?

From the meeting we had yesterday: It would be good to elaborate ever so slightly on the stack trace. We do not want to explain what the stack is, but it would be good to know that it is just popping information about the error off a queue. That way, when you are erroring within a library function (where you may not know whats happening) you can realise that you just keep going back up the stack trace until you see a function you recognise and call your self. This indicates where the error should be.

@@ -0,0 +1,12 @@
# Debugging manifesto

<figure markdown="span">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could consider listing a few errors that we have found ourselves around here?
Something that springs to mind is an "error" someone came to me with in a library, but in reality they didnt read the documentation and they thought an error code of 1 was good.

@robmoss
Copy link
Owner Author

robmoss commented Sep 17, 2024

I've added a page about Understanding error messages where we can explain how to read stack traces, using simple Python and R scripts as examples. I think it's ready to share with our CoP, what do you think @EamonConway @jomonman537 ?

From the meeting we had yesterday: It would be good to elaborate ever so slightly on the stack trace. We do not want to explain what the stack is, but it would be good to know that it is just popping information about the error off a queue. That way, when you are erroring within a library function (where you may not know whats happening) you can realise that you just keep going back up the stack trace until you see a function you recognise and call your self. This indicates where the error should be.

@EamonConway I've added an example of a long stack trace, what do you think?

@robmoss
Copy link
Owner Author

robmoss commented Sep 17, 2024

For the workshop next week, I'm tempted to leave the square numbers exercise as something that participants can choose to do, but not go through it myself. Instead, I've added a pause in the previous page for participants to try setting breakpoints and stepping through code with an even simpler example.

@robmoss
Copy link
Owner Author

robmoss commented Sep 17, 2024

Nobody has submitted a more detailed code example for us to work through, and I'm having difficulty coming up with a good example off the top of my head — the best I can think of is a reasonably simple SIR-type model with a typo that, e.g., negates one of the rates.

@robmoss
Copy link
Owner Author

robmoss commented Sep 17, 2024

Also noting that we need to merge this PR by the end of the week, so that the materials are available to participants — I will have very limited capacity (if any) to work on this next week, since we'll all be at the meeting.

@robmoss
Copy link
Owner Author

robmoss commented Sep 19, 2024

I've added two real-world stories of using debuggers to find and fix problems quickly: the first is an example of my own work from two days ago (Python), the other is a recent example from Michael Lydeamore (R). Check them out!

@EamonConway
Copy link
Collaborator

I've added a page about Understanding error messages where we can explain how to read stack traces, using simple Python and R scripts as examples. I think it's ready to share with our CoP, what do you think @EamonConway @jomonman537 ?

From the meeting we had yesterday: It would be good to elaborate ever so slightly on the stack trace. We do not want to explain what the stack is, but it would be good to know that it is just popping information about the error off a queue. That way, when you are erroring within a library function (where you may not know whats happening) you can realise that you just keep going back up the stack trace until you see a function you recognise and call your self. This indicates where the error should be.

@EamonConway I've added an example of a long stack trace, what do you think?

I think this demonstrates the point. I think if we go too far on making the stack trace long it might be too impossible to decode.

@robmoss
Copy link
Owner Author

robmoss commented Sep 19, 2024

FYI, I'm planning to merge this by 12pm tomorrow (Friday), so please let me know if you have any final comments or feedback!

@EamonConway
Copy link
Collaborator

This is looking really good. Ive just read through it all and it will make a great workshop

@robmoss
Copy link
Owner Author

robmoss commented Sep 20, 2024

I've added a final page to thank everyone who contributed to these materials, participated in the practice run, and/or provided feedback.

@robmoss robmoss merged commit d3efcbd into master Sep 20, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants