Live data from Hacker News

Printf debugging is ok

polymonster.co.uk

91–100 of 152 posts

Re: Printf debugging is ok

#91
I joined a research project a while back that was mostly about squeezing performance out of something and testing various configurations. The previous researcher had set up a fancy metric collector that was cumbersome, besides also affecting the performance a little. I replaced it with printf + a Python script that parses logs.

That said, I was pleasantly surprised I was able to attach a debugger to that system. Some bugs really needed it.

Re: Printf debugging is ok

#92

Earlier quoted context omitted.

> The crashes/bugs I deal with are rarely straight down failures, they are often the 1 out of 100 runs kind, so printf debugging is the only way to go really. Another thing I’ve found helpful, is to write out a “system state dump” (say in JSON) to a file whenever certain errors happen. Like we had a production system that was randomly hanging and running out of DB connections. So now whenever the DB connection pool i…

Why not just dump a core, rather than going to all that effort?

Because it is a lot easier to analyse a few megabytes of JSON than a heap dump which is gigabytes in size.

Not my original idea, I got it from some Oracle products which have a similar feature (most notably Oracle Database)

Re: Printf debugging is ok

#93
post #27

Of course it's okay, and at the same time no one will use it as soon as something else is more convenient & effective. Been waiting for "something else" ~30 years & counting.

Merging PREEMPT_RT (real-time) into the Linux kernel only occurred in Sept, 2024, after 20 years of work, in part due to a fundamental conflict with printk(), the traditional "printf" of Linux, widely used for kernel debugging. Linus is unwilling to forego printf debugging in the kernel, and has blocked significant evolutions of Linux on its behalf.

That counts for a lot to me. Anti-printf people have to go a long way to convince me that it's somehow not ok. I use debuggers every day. I use some form of printf debugging every day. I use whatever affordance I can get my hands on, and I ignore the peanut gallery.

Re: Printf debugging is ok

#94

Earlier quoted context omitted.

To be frank, I actually find debugger to rarely be useful. When it is useful, it is super useful - but those occasions aren't that numerous, so I can totally believe that many people may get away without learning how to use it. It feels like 90% of my time in gdb is reading backtraces after segfaults, which I wouldn't really consider to be a use of a debugger. I'm still glad I can use it for the other 10%, but it's j…

GDB is a dog shit trash debugger. I keep forgetting that Linux and Mac have shit tools. I suppose if the only debugger available to me were GDB I would also prefer printf debugging! The typical modern dev loves to shit on Windows. But Visual Studio (the adult version, not VSCode) is still a best-in-class debugger. Xcode is bloated as hell but did help me last week. Linux has… poor bastards.

I've spent plenty of time with various debuggers for various platforms and languages, both graphical and CLI-based, and it really doesn't matter to what I said. A debugger may be someone's preferred tool anyway, sure, but the cases where it's actually non-trivially improving workflow are relatively rare. Most of the time it just makes you a bit faster, if at all.

Re: Printf debugging is ok

#95
post #89
post #87

Earlier quoted context omitted.

Things like variable watchpoints mean that debuggers are still the better option.

You can add the condition to the print statement and grep for it if it gets too verbose.

Watchpoints can tell you which function is causing the variable to change, making printf's conditional cannot.

Re: Printf debugging is ok

#97
If it's a one-off situation, as opposed to something that should be part of your long-term test cases? Then yes, using print-statements is fine. Everyone does it, this isn't (or shouldn't be) controversial.

Sometimes a series of print-statements are better for helping you understand exactly when and how a bug occurs. This is particularly true in situations where the debugger is difficult or impossible to use (e.g., multi-threading). Of course, in that situation, logging may be better, but that's just glorified printf.

Re: Printf debugging is ok

#98

If it's a one-off situation, as opposed to something that should be part of your long-term test cases? Then yes, using print-statements is fine. Everyone does it, this isn't (or shouldn't be) controversial. Sometimes a series of print-statements are better for helping you understand exactly when and how a bug occurs. This is particularly true in situations where the debugger is difficult or impossible to use (e.g., m…

the glorified printf :) I prefer over non glorified, as it goes to log for future reference etc, imho it has advantages over regular printf.

Re: Printf debugging is ok

#99

If it's a one-off situation, as opposed to something that should be part of your long-term test cases? Then yes, using print-statements is fine. Everyone does it, this isn't (or shouldn't be) controversial. Sometimes a series of print-statements are better for helping you understand exactly when and how a bug occurs. This is particularly true in situations where the debugger is difficult or impossible to use (e.g., m…

the glorified printf :) I prefer over non glorified, as it goes to log for future reference etc, imho it has advantages over regular printf.

Most of the time these days I'm starting to just want compile-in profiling or something. At some point I'm just logging every line of code executed + locals, and I wish that was easier to just ask for.
Post reply on HN