by kissgyorgy · 5y ago · 0 comments
>>> print(f"{d['key'][1]=}")
d['key'][1]='one'f-strings's `=` is awesome. I'm overjoyed it was added to Python. I use it all the time.
That said, IceCream does bring more to the table, like:
- Stynax highlighting.
- Pretty prints data structures.
- Returns its value for nesting.
- Integrates with logging via `ic.configureOutput()`.
etcI hope that helps!
One question: in most cases, I get an output like `ic| tmp.py:9 in nonesuch() at 03:23:52.479` What is the "at 03:23:52.479", and how do I turn it off? Looks like it's some sort of timer function, but I don't see it in the readme. Python3.7 on Linux.
That said, sometimes you don't want to interrupt execution and see your results in real time.
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.
>>> print(f"{d['key'][1] = }")
d['key'][1] = 'one'
It works with any expression you like, not just variables: >>> print(f'{np.sin(np.pi/4.) = }')
np.sin(np.pi/4.) = 0.7071067811865475 julia> x = 4711
4711
julia> @show x
x = 4711
4711It's convenient, don't get me wrong, but it's not exactly groundsbreaking. Unlike breakpoint[1].
[0] https://doc.rust-lang.org/std/macro.dbg.html
[1] https://docs.python.org/3/library/functions.html#breakpoint it's not groundsbreaking on its own but the ability to very easily hook into it and replace the breakpoint hook by an arbitrary callable? Super useful.
icecream, the subject of this post, returns its parameter unmodified without multiple evaluations.
The fine article
> icecream, the subject of this post, returns its parameter unmodified without multiple evaluations.
That would be my point, yes.
python3 myscript.py --enableFstringDebugging=true
So that I could get rid of lots of conditional statements, e.g.: if debug:
print (f"some useful debugging info")