Live data from Hacker News

Icecream: Never use print() to debug again in Python

github.com

51–60 of 271 posts

Re: Icecream: Never use print() to debug again in Python

#51

Why don't people just use a debugger? It boggles my mind that people live with print style debugging. Depending on the project, it can be such a timer waster and just plainly worse in all aspects. Especially in Pycharm for me, it is incredibly easy. Even when running over ssh in remote computers I can use my debugger.

There is a place for both. Sometimes I really do want to see a sequence of events, or it may not be possible to run a debugger.

I work on an automated voice agent for restaurant drive-throughs, specifically the code that connects the voice agent to the existing point of sale system. When something goes wrong in a store, having a log of the API interactions between the voice agent and the POS is essential for troubleshooting.

Recently I updated the logging with a code generator option. I can place an order by voice on my local test setup, and it writes out a Python script that replays the same API calls, ready to run in a standalone API tester. This is super handy for testing.

But none of this is a substitute for a good debugger. For me it is a powerful thing to be able to stop the code at a breakpoint and see the actual values of all the variables at that point in time.

And it's not just for debugging. I jumped into this project after it had already been developed for a couple of years, and needless to say there is a lot that I did not understand about the code.

Of course I can read the code and use Ctrl+Click in PyCharm to see the definition of a function. But to really understand it, there is nothing like setting a breakpoint and looking at live data.

Re: Icecream: Never use print() to debug again in Python

#52

Why don't people just use a debugger? It boggles my mind that people live with print style debugging. Depending on the project, it can be such a timer waster and just plainly worse in all aspects. Especially in Pycharm for me, it is incredibly easy. Even when running over ssh in remote computers I can use my debugger.

> Why don't people just use a debugger? I only speak for myself, but I find that time spent inside a debugger is "lost", and bound to be re-spent again and again if you ever find new problems with the same code. I pretty much prefer to add assertions, logging and comments to my program, that will stay there and make further re-reads easier and more useful. As a matter of principle, I never use a debugger (except for…

Asserts are great, but when they fail, you still need to figure out why it happened. Nice environments allow you to debug the state at the point of assertion, python certainly doesn't make that convenient.

Re: Icecream: Never use print() to debug again in Python

#53
post #32

Why don't people just use a debugger? It boggles my mind that people live with print style debugging. Depending on the project, it can be such a timer waster and just plainly worse in all aspects. Especially in Pycharm for me, it is incredibly easy. Even when running over ssh in remote computers I can use my debugger.

It's strange, when developing C# and the like I'd go crazy without a debugger... and yet, in Python I've hardly ever used one. That might be because it's hard to develop C# without already being in an environment that puts an emphasis on easy debugging (Visual Studio), whereas I'm developing Python in whatever text editor I happen to be using at the moment and never really bothered to try out anything other than the…

For me the debugger really shines when I need to trace the behavior of some library. It’s worth the effort to instrument the codebase I’m working on with good logging, but doing that to every library I call would be insane.

Re: Icecream: Never use print() to debug again in Python

#56

Why don't people just use a debugger? It boggles my mind that people live with print style debugging. Depending on the project, it can be such a timer waster and just plainly worse in all aspects. Especially in Pycharm for me, it is incredibly easy. Even when running over ssh in remote computers I can use my debugger.

For what, exactly? Just saying "I can use my debugger" doesn't really help.

Debuggers give you a lot of information at a particular point (stack frame) in execution time, whereby print-ing can give you a filtered view of what happen(ed) during a full run.

When I can mark breakpoints and store the stack at that time (for each pass through that bp) in a inspectable gui tree (a list for linear execution path, a tree for threads etc) then I won't need print statements any more.

Re: Icecream: Never use print() to debug again in Python

#60

I 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.
Post reply on HN