Print debugging is not that different from setting logging level to DEBUG and those logging calls should already be there in code and give meaningful insight so I don't get printing being often ridiculed. For over ten years of commercial work I used a debugger only a couple of times and in most cases it was against someone else's code, usually when things were completely broken and I needed to get backtraces from mul…
You’ve only used a debugger a couple of times in 10 years? Yikes.
The unreasonable effectiveness of print debugging
341–350 of 366 posts
Re: The unreasonable effectiveness of print debugging
#342Whenever this comes up, I think of this quote from The Practice of Programming by Brian W. Kernighan and Rob Pike [0]: > As personal choice, we tend not to use debuggers beyond getting a stack trace or the value of a variable or two. One reason is that it is easy to get lost in details of complicated data structures and control flow; we find stepping through a program less productive than thinking harder and adding o…
There's a part of me that wants to say that that opinion has to be taken with a grain of salt and a lump of paying attention to who is offering it. Circa 1999, one would assume that Brian Kernighan and Rob Pike are largely drawing experience from working with C, which is a relatively verbose language. Single stepping through C code in a debugger is indeed a laborious process. If you read accounts from Smalltalk devel…
Re: The unreasonable effectiveness of print debugging
#343Earlier quoted context omitted.
Let us not forget the war to end all wars: Tabs vs spaces
Tabs are the clear winner here, since they unambiguously denote which level of indent is in use, take only one character (octet) per indent level, and can be visually adjusted on any moderately advanced editing program to an end users taste WITHOUT modifying the source code. This __wouldn't matter__ if we all just used TABS for indent level and if spaces were ignored for that: I also prefer tabs to show in a GUI code…
Multi people teams (or just one person editing on different platforms depending on need) using different editors and with different preferences would like to have a word with you here.
Re: The unreasonable effectiveness of print debugging
#344I've never understood print debugging, at least in a web dev/nodejs context. I don't begrudge people having their own approach to things, but almost universally when I see people use print debugging they seem to take quite a bit longer than just break pointing at the problem area. If your code is in an unexpected state, it's much easier to hit a breakpoint, examine local values, and then backstep through the call sta…
Could it be... because they don't know where the problem area is yet? Which is what the original article and most comments in favor of print debugging say.
Re: The unreasonable effectiveness of print debugging
#345In my experience, people who downplay debuggers don’t have the option to use effective debuggers. Debugging C++ and especially C# in Visual Studio is wonderful. Debugging Java in Eclipse can be great. Meanwhile GDB and most other language debuggers are painful and every IDE integration I’ve seen of them has been horribly unreliable. I’ve heard there’s a culture in parts of Google where kids go through uni using GDB b…
... and it's still a royal pain to get your program to display stuff on some text console when you want those printfs.
Also, you have to use Windows. I'd rather avoid that if i can.
Re: The unreasonable effectiveness of print debugging
#346Earlier quoted context omitted.
Breaking is just the default behavior when a breakpoint is hit, you can generally attach whatever behavior / conditions you want using the debugger's scripting language.
Reading through the majority of this comment section, I get the impression that those who like print statements find value because they aren’t proficient with modern debuggers, rather than they find print statement valuable even though they’re proficient with debuggers.
Re: The unreasonable effectiveness of print debugging
#347Earlier quoted context omitted.
Also, in almost all languages debuggers are an afterthought. Take e.g. the situation with Golang, Haskell or Python. Either there is no useful debugger or there is one, but it came late and still cannot debug everything the language does.
Not sure what situation you are talking about. Debugging Python is as easy as right-clicking a file in Pycharm and pressing debug. Why care if it was an afterthought when it for the past decade has worked perfectly.
Also, pycharm isn't really what I would call a proper debugger yet, attaching remote running processes for example just doesn't work reliably yet and is very new anyways. Debugging embedded targets just doesn't work. Multithreading is iffy (but that's unfortunately normal in Python).
Re: The unreasonable effectiveness of print debugging
#348Earlier quoted context omitted.
In a world with perfect optimizing compilers that never introduce bugs, we should never "need" print debugging. But that's not where I live, so I'll keep using print debugging. On the other hand... adding print statements can also invalidate certain optimizations (an excellent source of heisenbugs), so I'll never stop using debuggers either
Print debugging is essential in distributed systems. Sitting in the debugger waiting for human input often leads to timeouts and not covering the case you want. Of course, sometimes adding the prints, or even just collecting values to be printed later also changes execution flow, but like do the best you can.
Setting up remote debugging I’ll agree is more difficult than a local application, but each remote machine can automatically run startup commands and not require user input; commands can be run at particular places too (to print output etc) with conditional trace points, all while not impacting the code itself.
Main point is that folks don’t spend enough time learning the debugger, as print statements are easier. But using the debugger is a better practice in my opinion in the case where print statements are added just for a quick test, then removed.
Re: The unreasonable effectiveness of print debugging
#349Earlier quoted context omitted.
I tried using it but got stuck on having to learn Lisp to understand my config file.
I'm not sure what's difficult about (map! :n "ff" #'save-buffer) ; Save (map! :n "fq" #'kill-current-buffer) ; Quit a buffer or (defun my/org-buffer-check () "Check that we are in org-directory, and the buffer name is in that directory" (and (string= org-directory default-directory) (seq-contains (directory-files org-directory nil) (buffer-name) 'string=))) the latter being easily represented as: function my/org-buff…
Re: The unreasonable effectiveness of print debugging
#350Earlier quoted context omitted.
I think this is the standard algorithm and it's absolutely terrible. People poke at things, which ends up giving a linear search across a possibly huge system. Even if the "guess" is intelligent, it's not like you can trust it. If you actually fully understood the system, you would know what's wrong and you wouldn't be debugging. Do a bisect instead. The complexity is O(log n). It's probably slower than if you guess…
Your algorithm is for creating programs or adding new features. Not reslly for debugging already broken stuff. I would agree that hoing from less to more complexity is a great heuristic for making those guesses on what to check.