Earlier quoted context omitted.
You said "click", I need to leave my keyboard. Generally when I am coding I auto-run the tests on save. This means that to printf-debug I just add a message or two (and if I am coding I might already have a couple of useful ones lying around) and save. Then in less than a second I have a trace trough my program in the terminal. If I want to inspect a different variable I just add another print and run again. With a d…
So basically tracepoints, without touching the program code.
Icecream: Never use print() to debug again in Python
211–220 of 271 posts
Re: Icecream: Never use print() to debug again in Python
#212Earlier quoted context omitted.
You can also use the breakpoint() introduced in py3.7 via PEP533 https://www.python.org/dev/peps/pep-0553/
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
#213I am always going to use print to debug in every programming language I can until the day I die.
Agreed, it's the simplest way to test and validate specific assumptions. Debuggers are useful tools, but it takes you just as long but usually longer to get to the same answer: is what I think is happening here actually happening here?
Re: Icecream: Never use print() to debug again in Python
#214I see print debugging and breakpoint debugging as two different tools, both very useful. Print statements are useful when you don’t know where to put a breakpoint, of course, but also when it’s important to see the real-time execution along with the debug logs. Breakpoints are of course insanely helpful when you know where to put them, but also can be peppered about suspect areas and used with steps to cover wider ra…
Re: Icecream: Never use print() to debug again in Python
#215For 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.
I was wondering whether someone would notice that it's a clone of q! Thanks! :) q has the additional feature that you can decorate any function or method with `@q`, which causes invocations to be logged with arguments, return values, and exceptions. Really handy for tracing what's happening in your program.
Re: Icecream: Never use print() to debug again in Python
#216Earlier quoted context omitted.
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
Why would the amount of characters possibly matter?
Seriously though... when I'm in debugging mode, speed and efficiency in completing the task is paramount. So, every character I save typing, the better!
Re: Icecream: Never use print() to debug again in Python
#217Earlier quoted context omitted.
Sometimes sticking the debugger into the wheel makes stuff come flying over the handle bars in spectacular ways that have nothing to do with what you wish to observe. You might not even know which wheel to jam the debugger stick into, if the behaviour is complex. In these cases prints work well as a less intrusive way to get a rough idea of what is going on.
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?
Re: Icecream: Never use print() to debug again in Python
#218Earlier quoted context omitted.
What I imagine Macha is arguing for is that the cost of using print is extremely small, smaller at least than breakpoints. No one is saying breakpoints are useless, sometimes printing is 'cheaper' in time and effort in order to locate the region code of code in which using breakpoints is cheaper.
Yes, print() and breakpoints are different tools with different uses and there's cases where one is superior to the other. This is why some tools now offer logpoints, which are basically print() inserted via a breakpoint UI rather than in your code where you can forget to remove them
Re: Icecream: Never use print() to debug again in Python
#219Earlier quoted context omitted.
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
Why would the amount of characters possibly matter?
Re: Icecream: Never use print() to debug again in Python
#220Earlier quoted context omitted.
Yes, print() and breakpoints are different tools with different uses and there's cases where one is superior to the other. This is why some tools now offer logpoints, which are basically print() inserted via a breakpoint UI rather than in your code where you can forget to remove them
Oh please tell me about those tools.