Live data from Hacker News

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

github.com

71–80 of 271 posts

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

#71
post #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.

It definitely has its place. The problem is mostly that you have to actually change your code to debug it, and then remember to change it back.

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

#72

I am always going to use print to debug in every programming language I can until the day I die.

Why not taking the (short) time to learn using a debugger? This is way more efficient way to work for complex situations.

After having developed in an environment where I couldn't use a debugger (kernel drivers) I actually think that debugging with prints is better than a debugger most of the time, as it forces you to think about the code and where the failure might be. Right now I only use a debugger when I'm in C++ and I want to get a stack trace for a segmentation fault. In almost all of the other cases I get a broad location with the logging statements (always there), think about what could be happening and then put some prints to test it. Even for memory corruptions I don't use debuggers now, the address sanitizers in clang plus valgrind do the job far better.

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

#73

I promise the 15 minutes it takes to learn to use the debugger will save years of your life

Not necessarily. I know very well how to use a debugger, but nowadays I just prefer to use prints: it forces to you actually think about what's happening instead of just looking at it. It's also more useful in situations where putting a debugger actually changes behavior (high performance systems, parallel programs).

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

#74

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.

print is built in and runs everywhere my code runs. It never breaks and i never have to remember to install it. I never have to configure it or update it.

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

#75

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.

Debuggers are great. But to unboggle your mind, here’s why I don’t use a Python debugger. I don’t write enough Python to justify the time to learn the debugger. I write just enough to help my staff/teammate fix their problem or debug some tool I’m using and move on. I’ve been doing this long enough to lose interest in digging deeply into each language. I learned gdb for C. After that I learned jdb and Eclipse for Jav…

I just use IntelliJ IDEs for all programming languages I write in and the debugger experience is the same everywhere.

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

#76
post #65

Earlier quoted context omitted.

Do you have any concrete usage examples of that? I’ve only used breakpoint() to stop execution while debugging.

In the docs you can look up breakpoint, it has a lot of features amongst other things you can register a custom handler. I use it in selenium tests so I can either debug on error or just print the error message and continue

Could you provide a concrete example? It's still unclear to me why one wants a custom breakpoint() handler.

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

#77

Earlier quoted context omitted.

I have debugger set in pycharm and use it all the time. I also use print all the time, often along with the debug tool. They are very complimentary and neither tool can do everything the other can.

TBF if you always run your programs in pycharm and use its debugger, you can trivially use non-suspending "evaluate and log" breakpoints instead of print.

But prints work equally well in any environment.

I can remove prints by just checking out the latest version of the file.

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

#78

I am always going to use print to debug in every programming language I can until the day I die.

Actually rust has the functionality of Icecream as a buildin command "dgb" and you quickly find yourself using it over print

And Julia with @show.

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

#79

I promise the 15 minutes it takes to learn to use the debugger will save years of your life

Not necessarily. I know very well how to use a debugger, but nowadays I just prefer to use prints: it forces to you actually think about what's happening instead of just looking at it. It's also more useful in situations where putting a debugger actually changes behavior (high performance systems, parallel programs).

Exactly. And prints are cross platform cross language etc.

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

#80

I am always going to use print to debug in every programming language I can until the day I die.

The old style printf from C is still the best formatting tool for output/debugging. The C++ style was just a distraction without introducing anything of real value. log4xyz has some nice features in terms of enabling/disabling at runtime, through a config, but ultimately, printf rules.
Post reply on HN