this post was submitted on 30 Sep 2023
381 points (89.9% liked)

Programmer Humor

32077 readers
790 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 11 months ago (3 children)

Coming off as a noob here, but how do you actually utilize the debugger.

Mostly working on python stuff in VS Code, sometimes I just run the code and look at the error. Sometimes I try the debug and run option but it acts the same as just running the code; there's some stuff like variables window but I don't know how to utilize the information to debug.

[–] [email protected] 10 points 11 months ago (1 children)

Debuggers allow you to step through code and inspect the program state at any moment during execution. You can even sometimes run commands inline to see how stuff reacts.

This means you can usually just hover a variable or something in your IDE while execution is paused and see its current value without having to restart execution every time you want to print something different.

[–] [email protected] 3 points 11 months ago* (last edited 11 months ago)

You can even sometimes run commands inline to see how stuff reacts.

It's honestly not a bad way to write some of the more complex lines of code too. In python/vscode(ium), you can set a breakpoint where you're writing your code and then write the next line in the watches section. That way you can essentially see a live version of the result you're getting. I especially like this for stuff like list comprehension, or indexing logic where you might normally expect a possible off by one or key error.

[–] [email protected] 5 points 11 months ago

I don't know how to use vscode. In general in Python you can do breakpoint() and your code will pause there and become interactive. If you're running in docker you'll want to attach to the container. When it hits the breakpoint you basically drop into a normal python repl with extra features.

https://docs.python.org/3/library/pdb.html

This is really, really, good for debugging and developing. You can interactively examine stuff and try stuff right there. You don't have to rerun the whole thing to be like "ok what's the second item in the list? Is this syntax right to sort it?" or whatever you're trying to do

I use pdb++ for syntax highlighting and some other qol features, too.

[–] [email protected] 2 points 11 months ago

Coming off as a noob here, but how do you actually utilize the debugger.

Ostensibly I debug Python in VSCode by installing the correct plugins and adding appropriate run configs to the debugger launch configuration.

But honestly I debug most of it with import pdb; pdb.set_trace()...