News for hackers. Stuff that matters.
Re:Icecream: Never use print() to debug again in Python by est on Tuesday March 30, 2021 @04:47AM (#26632389)
You can also use the breakpoint() introduced in py3.7 via PEP533

https://www.python.org/dev/peps/pep-0553/

Re:Icecream: Never use print() to debug again in Python by EamonnMR on Tuesday March 30, 2021 @09:08AM (#26634125)
Pre 'breakpoint()' you could always use import pdb; pdb.set_trace()

That said, sometimes you don't want to interrupt execution and see your results in real time.

Re:Icecream: Never use print() to debug again in Python by beaugunderson on Tuesday March 30, 2021 @10:14PM (#26642810)
I like `from IPython import embed; embed()` because you get an entire ipython instance with access to all local variables :)
Re:Icecream: Never use print() to debug again in Python by animal_spirits on Tuesday March 30, 2021 @09:10AM (#26634150)
I like to use PDB++ which is a drop in replacement for PDB

https://github.com/pdbpp/pdbpp

Re:Icecream: Never use print() to debug again in Python by vonwoodson on Tuesday March 30, 2021 @07:19AM (#26633268)
Bump. This is the most correct way to debug python programs VS using print statement.
Re:Icecream: Never use print() to debug again in Python by taneq on Tuesday March 30, 2021 @07:56AM (#26633549)
Debugging virtually anything real-time that interacts with other systems will require some kind of logging (of which printf() is the trivial case). Step-through debugging is great but far from universally applicable.
Re:Icecream: Never use print() to debug again in Python by vlovich123 on Tuesday March 30, 2021 @08:20AM (#26633737)
Setting a breakpoint that prints and continues is appropriate if performance doesn’t matter. It gets trickier if it does. In those cases RR seems like the best idea rather than prints. At least that’s the theory.

In my experience the conditions on the ground are different though. Tooling availability is inconsistent, which is why such approaches don’t always work. Reverse debugging isn’t available on all platforms/languages. Debuggers (or at least the C/C++ ones) are slow in how they inject instrumentation code to evaluate - rather than compiling expressions into native codes to conditionally trap, they seem to trap unconditionally and evaluate the conditional using their introspection language (there are valid reasons why it’s done this way but it has serious performance impacts). In compiled languages, the evaluation of the expression can be difficult/impossible to write because of this (not enough type information available, validation is late binding meaning mistakes are extra expensive, etc.

At the end of the day, when your tools fail you, print debugging is easier to use to accomplish the task rather. Getting tooling to work effectively is more time consuming and frequently not possible.

Re:Icecream: Never use print() to debug again in Python by stjohnswarts on Tuesday March 30, 2021 @11:31AM (#26635776)
It's a way, it's hardly "the most correct way". Jeesh sometimes hackernews people. There are all kinds of ways to debug, and sometimes code has to run in different version of python. I find logging with various levels of "debug info" is best for me, but I hardly think that is "the most correct way"
Re:Icecream: Never use print() to debug again in Python by gnulinux on Tuesday March 30, 2021 @09:57AM (#26634651)
Correct in what way? I can think of many real time systems that cannot be debugged with a pdb breakpoint.
Re:Icecream: Never use print() to debug again in Python by hyperbovine on Tuesday March 30, 2021 @12:17PM (#26636511)
Most correct you say? Based on what? Mind you we're talking about code that will never even ship in the vast majority of cases. Ergo, do whatever works best for you.