Live data from Hacker News

Don’t look down on print debugging

blog.startifact.com

101–110 of 164 posts

Re: Don’t look down on print debugging

#101
post #59

While print-type debugging has a place, the reason there are a lot of articles dissuading the practice is the observed reality that people who lean on print debugging often have incomplete knowledge of the immense power of modern debugging tools. This isn't just an assumption I'm making: years of being in developer leadership roles, and then watching a couple of my own sons learning the practice, has shown me in hund…

Speaking from my own experience I'm not so sure that printf debuggers just have "incomplete knowledge [...] of modern debugging tools". I use printf (or the file-based equivalent, log files) quite a lot, but nobody can accuse me of not knowing good debugging environments. Also, what's "modern" about "Walk the call stack! See the parameters and values, add watches, set conditional breakpoints"? Those are all things we…

I said such users often have incomplete knowledge. Are there exceptions? Sure. Of course there are.

"Those are all things we had many decades ago"

I didn't claim this is some new invention, though. Though as someone who has been a heavy user of debuggers for DECADES, debuggers have dramatically improved in usability and scenarios where they are useful.

"So please refrain from calling people with different preferences uneducated."

But...I didn't. In fact I specifically noted that graduates of excellent CS programs often haven't experienced how great the debuggers in the platforms they target are.

We all have incomplete knowledge about a lot of things.

Re: Don’t look down on print debugging

#102
In the nightmare kitchen sink of web transpilers and meta-framework, yes just print it is often way more efficient than trying to make a sense of these useless stack traces, or set a brittle debugger configuration in your IDE that sooner than later will invariably lake a map to know what code it should show.

Re: Don’t look down on print debugging

#104
If you're using print debugging in python try this instead:

> import IPython; IPython.embed()

That'll drop you into an interactive shell in whatever context you place the line (e.g. a nested loop inside a `with` inside a class inside a function etc).

You can print the value, change it, run whatever functions are visible there... And once you're done, the code will keep running with your changes (unless you `sys.exit()` manually)

Re: Don’t look down on print debugging

#105
>Print debugging is awesome and you should feel no shame in using it!

print Debugging is my main goto. Plus I have no shame :)

I have this in buffer 'd' on vim and Emacs ready for use:

fprintf(stderr, "DEBUG %s %d -- \n", __FILE__, __LINE__); fflush(stderr);

Re: Don’t look down on print debugging

#106
post #95

While print-type debugging has a place, the reason there are a lot of articles dissuading the practice is the observed reality that people who lean on print debugging often have incomplete knowledge of the immense power of modern debugging tools. This isn't just an assumption I'm making: years of being in developer leadership roles, and then watching a couple of my own sons learning the practice, has shown me in hund…

The thing is, in interpreted languages land print debugging has a power no debugger gives you: live debugging on your production instance. Something is broken in prod, you cannot reproduce it in your test environment because you think it may be due to a config (some signing keys maybe) you can't check. And it looks like someone forgot to put logs around whatever is the problem. You can either: spend multiple hours tr…

With modern js stacks being somewhat compiled anyway, and the backend often being C# or Java I don't think that case is very applicable. Not to mention developers logging on production servers and making whatever changes they want being a huge red flag.

Re: Don’t look down on print debugging

#107
There are good arguments for both sides, and there is no contradiction. Why shouldn't they both be good tools, depending on the specific case?

I do print debugging most of the times, together with reasoning and some understanding what the code does (!), and I'm usually successful and quick enough with it.

The point here is: today's Internet, with all the social media stuff, is an attention economy. And also some software developers try to get their piece of the cake with extreme statements. They then exaggerate and maximally praise or demonize something because it generates better numbers on Twitter. It'd as simple as that. You shouldn't take everything too seriously. It's people crying for more attention.

Re: Don’t look down on print debugging

#108
post #41

My only complaint about print debugging is the sheer volume of commented out console.log statements I see across code bases. Or worse, not commented out and happily logging away on prod. Seriously, leave your console open as you browse around — you’ll be astounded by the amount of debug output just rolling along on production. Delete your debug cruft!

I have a perfect solution for this, that works for me at least. Adding a `..` to the end of a variable triggers a macro that changes `val` into something like `print("val:", val) // FIXME: REMOVE`. Then a pre-commit hook makes sure I am unable to commit lines matching this pattern.

[deleted]

Re: Don’t look down on print debugging

#109

While print-type debugging has a place, the reason there are a lot of articles dissuading the practice is the observed reality that people who lean on print debugging often have incomplete knowledge of the immense power of modern debugging tools. This isn't just an assumption I'm making: years of being in developer leadership roles, and then watching a couple of my own sons learning the practice, has shown me in hund…

You’re absolutely right - but it’s worth mentioning that print debugging is the only sanity-preserving way to debug distributed systems (spans are basically super fancy prints) or systems which need to run at full speed (optimized builds) to reproduce bugs… sometimes the easy way is the only way.

Re: Don’t look down on print debugging

#110

Earlier quoted context omitted.

I kinda want to push back against the blanket statement that there are articles pushing back on print debugging. That implies there’s well known mind share thinking about it? Is it real mind share? Is it bullshit? Print debugging is the literal pocket knife of debugging.

There are loads of articles discouraging print debugging, and it's a very real thing that people fight against (and for). Print style debugging is the first thing most programmers learn, and for some it absolutely becomes a bad habit. And to be clear, print debugging and pervasive, configurable logging are very different things and the latter is hugely encouraged (even with logging levels), while the former is almost…

Print'here' is very useful. I get a log of how many times that funcion is called. If I log some data I log how that data changes over time. Those are powerful tools.
Post reply on HN