curriculum icon indicating copy to clipboard operation
curriculum copied to clipboard

Ruby: Debugging Lesson: replace `pry` with `binding.irb` in ruby debugging lesson

Open JoshDevHub opened this issue 2 years ago • 7 comments

Because

This PR is partially addressing #24994

The eventual goal is to have two lessons here. One that introduces more basic debugging concepts (reading stack trace and errors, print statement debugging, etc.) and another lesson that sets learners up with the more interactive debugging tools. This lesson is being converted to one that just reveals some of the more basic concepts, meaning that references to pry have been removed. In its place, I've included information about binding.irb, which I think is a good primer for interactive debugging while holding off a bit on the complexities of stepping through code.

This PR

  • Removes references to pry.
  • Adds a section for using binding.irb

Issue

Related to #24994

Additional Information

I've made this a draft PR because I expect to iterate on this some. There are a couple of things that I think are worth discussing:

  1. Should the debugging exercise assignment still be placed here? Or should it perhaps be moved to the lesson that will follow this one? This might also be an opportunity to rethink the debugging exercises (see the Issue for some thoughts on this).
  2. I didn't touch any p/puts stuff, but I feel like some of it could be improved. It currently only mentions nil as a potential problem for using puts over p, but there are a couple of other pretty significant distinctions to be made I think:
    • p returns its arguments, whereas puts returns nil. This makes p nice for reducing any thought or regard for how what you're adding to the code is affecting the way it functions.
    • p reveals a more "code"-like representation of objects. This is of course the reason behind the nil thing, but I'd say the impacts of this go beyond just nil.
  3. The section for "How to Start Debugging" feels pretty slight. I think it could be a good idea to add more. It might also be a good idea to move it to the next lesson when all of the tools will have been introduced.
  4. I had to scrub most of the readings in the Assignment section because they were pry focused. I'd definitely be interested in finding other outside resources that focus on the tools in this updated lesson. Unfortunately, I wasn't able to find any good articles on binding.irb. I definitely welcome any additional resources people know of or can find that cover p debugging or binding.irb.

Pull Request Requirements

  • [x] I have thoroughly read and understand The Odin Project Contributing Guide
  • [x] The title of this PR follows the location of change: brief description of change format, e.g. Intro to HTML and CSS lesson: Fix link text
  • [x] The Because section summarizes the reason for this PR
  • [x] The This PR section has a bullet point list describing the changes in this PR
  • [x] If this PR addresses an open issue, it is linked in the Issue section
  • [x] If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • [x] If any lesson files are included in this PR, they follow the Layout Style Guide

JoshDevHub avatar Mar 25 '23 17:03 JoshDevHub

Thanks @JoshDevHub , will aim to review in the next 48 hours - feel free to ping me if I slack :chicken:

ChargrilledChook avatar Mar 26 '23 06:03 ChargrilledChook

@ChargrilledChook You're slacking! :chicken:

I don't actually mind, but I figured with it being the weekend, you may have some time to give it a look. So I thought I'd shoot you a reminder.

JoshDevHub avatar Mar 31 '23 15:03 JoshDevHub

Closes #25914

ChargrilledChook avatar Jul 22 '23 06:07 ChargrilledChook

@ChargrilledChook I can absolutely still work on this. I'll fix the capitalization and look into those other ideas. Glad to see this all coming along :muscle:

Regarding the positioning in the course, I think this specific lesson could jump earlier in the basics. Maybe directly after 'Loops' could be a good candidate?

JoshDevHub avatar Jul 22 '23 15:07 JoshDevHub

@ChargrilledChook Apologies for taking a while on this. I did want to add more for puts/p. I've sat down a couple of times to write some content, but it always felt messy and inelegant. Then I remembered your "mini-cheatsheet" idea, which honestly sounds like an excellent way to quickly communicate the difference.

Do you have any ideas about how to approach that kind of thing though? Tables didn't feel quite right to me from experimenting in the Lesson Preview tool (small example here). Was wondering if you had an idea in mind for it.

JoshDevHub avatar Aug 12 '23 05:08 JoshDevHub

I have nothing to do with this PR, but I just wanted to add some notes here:

  • since binding.irb opens an IRB session, it is possible to mutate state (and execute any arbitrary code) in the local context. I don't think was talked about in the changes made in this draft, but I think it should (as both a warning and a feature)
  • Might be worth mentioning another way to use irb to probe/debug: Start an irb session in project directory, then require_relative the project_file.rb so that the irb session has access to all of the code in project_file.rb (also works with internal binding.irbs ) -- useful for testing out an interface without having to modify a driver script below the class definition
  • Learners will likely already be familiar with break-points and step into/out of/over from the Foundations course. It might be worth it to mention that this will be (is supposed to be) covered in a later lesson
  • corresponding mentions of pry in the exercises repo: lines 46 to 49 in the exercise file and line 41 in the spec

SumonGFC avatar Oct 09 '24 18:10 SumonGFC

Love to see this additional section being added. Slightly related. Here's an additional resource that helped me immensely in understanding how binding.pry works. https://github.com/radanskoric/ruby_debug_tutorial

I think knowing about both and understanding how they are different will help students when to use what. Any way we can combine the two?

roasted-oolong avatar Jan 29 '25 21:01 roasted-oolong