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

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

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

JoshDevHub
Copy link
Contributor

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

  • I have thoroughly read and understand The Odin Project Contributing Guide
  • 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
  • The Because section summarizes the reason for this PR
  • The This PR section has a bullet point list describing the changes in this PR
  • If this PR addresses an open issue, it is linked in the Issue section
  • If any lesson files are included in this PR, they have been previewed with the Markdown preview tool to ensure it is formatted correctly
  • If any lesson files are included in this PR, they follow the Layout Style Guide

@ChargrilledChook
Copy link
Member

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

@JoshDevHub
Copy link
Contributor Author

@ChargrilledChook You're slacking! 🐔

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.

Copy link
Member

@ChargrilledChook ChargrilledChook left a comment

Choose a reason for hiding this comment

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

Good stuff @JoshDevHub, I think this is most of the way there, I only have one typo nit.

Some things that I think we could (optionally) improve but are not required:

  • It would be good to subtly introduce the concept of a breakpoint by showing an example of using binding.irb twice, and exiting to proceed to the next binding. Maybe even showing putting binding.irb inside a loop. We wouldn't even have to necessarily use the word "breakpoing"
  • It could be good to update the puts / p section slightly and put a bit more emphasis on using p for debugging. Maybe even something like an info box with a mini cheatsheet. Could even introduce pp too, potentially.

Outside of those minor details and ideas, my only concern is course structure. I think it might be worthwhile putting a bit of a gap inbetween this lesson and the rdbg lesson, otherwise we're introducing two tools without any real opportunity to show how rdbg builds on and improves irb.

But then where would it go? Unless it goes somewhere in the middle of the basic Ruby projects, it would get introduced in a spot just after it would have been really useful. Maybe directly after those projects is fine, but the current structure is a bit of an issue for things like this (ie big info dump with the basics section then 4 projects chained together).

An alternative would be to move this lesson earlier in the basic Ruby section.

In any case I'm probably rambling at this point, let me know your thoughts. I've made some decent progress on the rdbg basics lesson so if you have any capacity to work on this and get it ready for a release, that would be great ❤️ if not all good, but let me know

Thus, adding a `binding.pry` line in our code is similar to creating a breakpoint in JavaScript.

To see this point in action, try running the following:
You can add `binding.IRB` at multiple points in the execution of your program. To see this in action, try running the following:
Copy link
Member

Choose a reason for hiding this comment

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

Accidental capitalisation here

@ChargrilledChook
Copy link
Member

Closes #25914

@ChargrilledChook ChargrilledChook linked an issue Jul 22, 2023 that may be closed by this pull request
@JoshDevHub
Copy link
Contributor Author

@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 💪

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?


Using the same example above, you can use one of pry-byebug's commands to figure out what `name = name.upcase` will return. You won't need to quit the session or add another `binding.pry` beneath it. Enter `next` to step over to the next line.
To proceed with the program, you can run the `exit` command, which will end the first IRB session and continue execution of the code. Because there's a 2nd `binding.irb`, it stops again. You can now see how `name` has changed and what `greeting` has been defined as.
Copy link
Contributor Author

@JoshDevHub JoshDevHub Jul 23, 2023

Choose a reason for hiding this comment

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

Regarding your 1st point about showing multiple binding.irb, I already have this type of thing happening here, yeah? I definitely could change this example (or add a new one) that uses it inside of a loop.

Copy link
Member

Choose a reason for hiding this comment

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

Yep this is a great addition, I was thinking more a simple code example to illustrate. Not required, but I think a nice addition.

Hopefully people don't get stuck before reading on to the part on how to exit 😅

Copy link
Contributor

Choose a reason for hiding this comment

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

I'll say as a newby it took me a minute to figure out the exit command :). Perhaps in future updates, we can add something like "if you get stuck, sometimes it helps to read a bit past where you are! TOP builds on content, so you might have a question that we're just about to answer"

@JoshDevHub
Copy link
Contributor Author

JoshDevHub commented Aug 12, 2023

@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.

Copy link
Contributor

@kamranzafar4343 kamranzafar4343 left a comment

Choose a reason for hiding this comment

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

Just reviewing it, Thank you all for your contribution! I appreciate the effort you've put into this commit. The code looks clean and well-organized. Keep up the good work!

@SumonGFC
Copy link
Contributor

SumonGFC commented Oct 9, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content: Ruby Involves the Ruby course
Projects
No open projects
Status: 👀 In progress / review
Development

Successfully merging this pull request may close these issues.

Ruby: Rework existing debugging lesson to use binding.irb
5 participants