Earlier quoted context omitted.
Which debugger would you recommend?
For Python: ipdb. In your code, you can just drop in "import ipdb; ipdb.set_trace()" and the execution will stop there with an interactive prompt. Alternatively start the script through (i)pdb and set breakpoints. You can also use plain pdb ("import pdb; pdb.set_trace()"), which has the advantage that it comes with the Python stdlib, but the interactive prompt is less fancy (no history, no autocompletion, etc).
Icecream: Never use print() to debug again in Python
241–250 of 271 posts
Re: Icecream: Never use print() to debug again in Python
#242I am always going to use print to debug in every programming language I can until the day I die.
Absolutely, I don't understand why using print() or its equivalent in other languages is looked down upon. It's quick way to narrow down the "area of search" before bringing in the big guns.
Re: Icecream: Never use print() to debug again in Python
#243Re: Icecream: Never use print() to debug again in Python
#244I use PySnooper[1] when code behavior deviates inscrutably from my mental model. Like Icecream, PySnooper exhorts, "Never use print for debugging again." A simple example: import pysnooper @pysnooper.snoop() def add_up(numbers): total = 0 for number in numbers: total += number return total add_up([123, 456]) When run, PySnooper prints the activity of the decorated function or method: $ python example.py Source path:.…
There's also https://github.com/alexmojaki/snoop For comparison: 19:32:30.66 >>> Call to add_up in File "/home/joel/example.py", line 5 19:32:30.66 ...... numbers = [123, 456] 19:32:30.66 ...... len(numbers) = 2 19:32:30.66 5 | def add_up(numbers): 19:32:30.66 6 | total = 0 19:32:30.66 7 | for number in numbers: 19:32:30.66 .......... number = 123 19:32:30.66 8 | total += number 19:32:30.66 .............. total = 123…
Re: Icecream: Never use print() to debug again in Python
#245Earlier quoted context omitted.
I don't understand your wheel analogy, sorry. > You might not even know which wheel to jam the debugger stick into, if the behaviour is complex. If you don't know where to put a breakpoint, how do you know where to put a print statement?
Imagine putting breakpoints in multiple tight loops in the stage of narrowing the search space. Imagine how many times you need to click next. A conditional breakpoint will only help if you know the condition you're looking for, but there's stage before that of "Well, what looks strange during execution". Also for multithreaded code, stopping one thread dead for long enough for a human to investigate it can inadverte…
Re: Icecream: Never use print() to debug again in Python
#246Earlier quoted context omitted.
How is changing code simpler than literally clicking on the line number to set a breakpoint?
When I use a debugger I often feel like I'm looking through a soda straw. I can only see the state at that one instance in time. Just because I know the line of code where the exception occurred, doesn't tell me which data caused it, and breaking on exceptions is often too late. Instead I'm stuck hitting continue over and over until I finally see something out of place, realize I went to far and have to start over ag…
Re: Icecream: Never use print() to debug again in Python
#247Earlier quoted context omitted.
How is changing code simpler than literally clicking on the line number to set a breakpoint?
When I use a debugger I often feel like I'm looking through a soda straw. I can only see the state at that one instance in time. Just because I know the line of code where the exception occurred, doesn't tell me which data caused it, and breaking on exceptions is often too late. Instead I'm stuck hitting continue over and over until I finally see something out of place, realize I went to far and have to start over ag…
We agree with your critique of traditional debuggers and Pernosco tackles that "temporal visibility" problem head on.
Re: Icecream: Never use print() to debug again in Python
#248For an even easier-to-remember alternative, there’s q: https://github.com/zestyping/q All you need is `import q`. q works like a function (q(x)), like a variable (q|x and q/x, so you get different operator precedences) and like a decorator (@q), so it can be used in practically any circumstance for a quick debug print. Plus, the name sounds like you’re interrogating something.
This is actually really cool. I was going to say that so many people miss the point of print debugging and as a consequence forget to shorten the import line as much as possible. from icecream import ic;ic() is 28 characters import q;q() is 12 characters print() is 7 characters
from icecream import install
install()
in main, and from then on icecream counts as a built-in, so you can just say ic(). Four characters.Re: Icecream: Never use print() to debug again in Python
#249Earlier quoted context omitted.
Why would the amount of characters possibly matter?
I find it important because it lowers the barrier of entry to print debugging. I have found myself using less prints in Java than in Python both because of static typing and having to write the full `System.out.println`. This is also important to me because I am very cautious of not doing a file-level import (I don't want to commit a file with the dependency). The fewer characters it takes, the easier it is for me to…
Re: Icecream: Never use print() to debug again in Python
#250Earlier quoted context omitted.
In this case, it would seem it took a little reinvention in order to let the wheel's discovery be known.
Not used it, but ic seems to be compatible back to python 2.7 so not really comparable. I can't use the builtin thing in my python code because the host software for my plugins is running python 3.6 embedded and only recently upgraded from 3.3 in the latest release so if I want to maintain backwards compatibility I can never use the new python builtin. I expect lots of other people are in the same position.