Icecream: Never use print() to debug again in Python
91–100 of 271 posts
Re: Icecream: Never use print() to debug again in Python
#92 print(f"{d['key'][1]=}")
d['key'][1]='one'
My immediate reaction was: How can I make this `form` easier to type. And that's what `Iceacream` does. Reviewed their code and realized they work with AST and inspection.I recently started to learn (Common )Lisp. I realize how easy it would be to write a macro in Lisp that would implement the functionality of `Iceacream`, in a few lines of code.
Re: Icecream: Never use print() to debug again in Python
#93Re: Icecream: Never use print() to debug again in Python
#94Instead of introducing a new library, why not just instruct your editor to do the heavy lifting for you? For instance, I've written a small Emacs function that asks for the argument to print in the Minibuffer and then inserts it once quoted, once unquoted. It's quite nice to have such a function for any programming language you use and bind it to the same keyboard short-cut.
For one, people not using emacs, or whatever editor it would be, can use it.
Re: Icecream: Never use print() to debug again in Python
#95I 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
#96Instead of introducing a new library, why not just instruct your editor to do the heavy lifting for you? For instance, I've written a small Emacs function that asks for the argument to print in the Minibuffer and then inserts it once quoted, once unquoted. It's quite nice to have such a function for any programming language you use and bind it to the same keyboard short-cut.
For one, people not using emacs, or whatever editor it would be, can use it.
Re: Icecream: Never use print() to debug again in Python
#97I 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.
printf("%d", my_long_var);
Might seem correct and work correctly on one platform, but fail on another. scanf() is arguably even worse since it can cause memory corruption.These days compilers have diagnostics to catch those errors, but if you rely on those you can't use dynamic format strings, which means you're effectively using a subset of C with a stronger type checker than C. That's a pretty good state but it's definitely not "old style printf()"; old style printf() was insecure.
And don't get me started on the convoluted macro invocations necessary to correctly convert int32_t, int64_t, size_t and ptrdiff_t. And that's with the newest standard: IIRC there was no standard way to print long long in C, at the time when C++ already supported it.