Ask HN: Why are we not using debuggers more?
13 points| pentab | 3 years ago
Are you also avoiding debuggers? If so, why? What makes debugging so tedious?
13 points| pentab | 3 years ago
Are you also avoiding debuggers? If so, why? What makes debugging so tedious?
PaulHoule|3 years ago
I use Jetbrains tools and have an easy time debugging in Java, Python and Javascript. In Java I'd say that you can use unit tests to interactively experiment the same way people do with the CLI in Python with the difference that you get unit tests out of the deal as opposed to having lines scroll away in the console.
I use WebStorm to debug Javascript programs that run in npm but if it is running in the browser I just use the "developer tools" from Firefox, Chrome, Edge or Safari. I think there is some way to attach WebStorm to a running web browser but I've never figured it completely out.
I think the Unix culture is allergic to debugging. It's not that hard to use gdb from the command line and in fact you can do some pretty awesome things with it such as embedded system debugging or debugging the C++ and Java sides of an application at the same time, but for a long time I kept trying graphical front ends for gdb such as ddd that "just don't work".
vr46|3 years ago
It’s not just Unix culture that’s allergic to debugging, it’s every chancer and charlatan the world over.
alfonmga|3 years ago
Back in the days when I didn't use one, it was a miserable developer experience. Thanks to Go and his great decision of having unit testing built into their standard now writing tests and debugging them is a joy.
Far are the days of not using a debugger because the programing language of choice didn't treat debuggers/unit testing as a first-class citizen. I could say that now I sleep a lot better thanks to coding my backends on Go and having the confidence that I can go as much depth as I want to fix any bug.
Debugging for me is an automatic action like drinking water when you're thirsty; two clicks (set breakpoint and click the debug button) and I'm back into the debugger, again.
[0]: https://github.com/go-delve/delve
sdevonoes|3 years ago
You put a "print" statement dumping whatever data structure you want, you run the program again, and voila you got something. Now, the "where to put the print" is an art on itself of course. If you don't know where to put it, then either you start writing multiple "print"s here and there (following an approach similar to binary search) or you use a debugger and go step by step until you find right place to inspect.
The problem with debuggers is that they do not work out of the box. If you use the terminal, then you have use an external program and read its manual to understand how to debug, how to put breaks. Depending on the platform you are using, you may require even an executable to run the debugger on. Sometimes you don't have an executable. Sometimes you don't know where the "entry" point of your program is, but you know where the bug relies. Some debuggers require you to point the debugger to the entry point.
If you use an IDE like Jetbrains', then for debugging you need as well to do some (minimal) setup as well (the last week I had to debug a Node.js program: it was simple, but it didn't work out of the box. Also, when I open my IDE on a different Node.js repository, my debugging setup was gone).
themodelplumber|3 years ago
First, if you can fix most issues with a glance or a brief stare, using a debugger never really feels necessary. It may also feel less like using your own brain and solving a puzzle, and puzzle-solving is a huge part of human psychology (see post title).
Also, the story of the last N years has been the text editor, not the IDE. The IDE and its world is really where the integrated debugging story is a big deal.
But if you are using a text editor--or text editors--integrating debugging is less of a thing. Your time may be better spent with various productivity-focused changes for ergonomics, like studying or changing keyboard shortcuts, installing or writing plugins, setting up your own scaffolding using system tools integration, and so on.
Plus once you know the various shortcuts, it's maybe more fun to use them and zip around adding prints than it is to debug. You also gain practice this way, after all.
But if you moved from text editors to IDEs, IMO you probably brought that same set of practices along.
Anyway, good q, I've thought about this recently as well.
AH4oFVbPT4f8|3 years ago
mdcds|3 years ago
Sometimes you don't know what you don't know.
But yeah, these days I rely on the debugger heavily. Even for Python :)
suprjami|3 years ago
Right now I'm writing some stuff which takes over the terminal and works in recursive loops (ncurses roguelike map generator) so print debugging is a hassle. It's actually quicker to use a debugger.
I find that attaching gdb and running "bt" and "info locals" or inspecting variables with "p" is much cleaner than printing, and helps me visualise what the code is doing much better.
This use of a debugger for "little things" is immensely helpful for when I need to use a debugger at work to solve "big things", which are usually remotely and after-the-fact with a core file, so printing isn't even an option there.
bobajeff|3 years ago
As to why they are a last resort. For me it was just having to learn the debugger and also setting up the debugging environment. For every binary needs to be built with debugging symbols and any libraries you're wanting to step through you have to find the symbols for those too.
Also I think it depends on how low level the language and what kind of program it is.
Some languages/environment don't have debuggers or they aren't very good. I wouldn't say most debuggers that are mature are super great to use either.
pentab|3 years ago
Could you give some examples or languages/environments with "bad" debuggers?
bluefirebrand|3 years ago
The code I write is also a lot more asynchronous nowadays, and debuggers are fairly worthless for async code imo. Pausing on a breakpoint conceals issues with asynchronous timing that good logging will show immediately.
I still believe debuggers should be a part of every developers toolkit, but like anything else, pick the tool for the job and sometimes print statements are just the easiest and fastest. Actually in a lot of cases.
Delk|3 years ago
I often find it a lot faster to set up breakpoints and fire up the debugger than to write debug statements. At least in some IDEs, breakpoints are a single click each, and if you have to restart the application/module/whatever anyway, doing that in a debugger instead of a non-debug run is also just a click. I can then inspect any variable values at the breakpoint instead of having to explicitly include all potentially interesting ones in the debug output.
When I'm trying to figure out a problem in code I'm writing rather than one in production, the debugger is often my first resort.
I'm mostly writing plain old backend code without asynchronicity, though.
Debug output (at a reasonable level) is still useful even outside of asynchronous program flow, of course, because it might give immediate clues for problems encountered in testing or production. If you don't have a good idea of where to look, debug output from several places might also be nicer than having the program stop at lots of breakpoints that turn out to not be useful.
mindcrime|3 years ago
DecoPerson|3 years ago
If you force yourself to use the debugger more, you will in the process both familiarise yourself with it and iron out any configuration kinks. Learn those keyboard shortcuts, figure out how to make it autoconnect and break on exceptions, find out how to evaluate expressions on the fly, …
You + That tool = maybe goodness. Maybe not.
m4xm4n|3 years ago
I also do a lot of web stuff, and if you're running some server process and you're not running the server process through a debugger directly, then you need to find and attach to the server PID, etc., then maybe deal with threads, and it's just a lot of upfront effort when I could just find the issue by throwing a puts/print somewhere or writing a test.
I'm not anti-debugger, I'm just busy and it's easier to put something in my code (which is how I frequently jump into debuggers too, e.g. binding.irb, binding.pry, debugger, byebug, etc.)
the CLI debuggers (gdb, lldb, etc.) are great when I really need them, but they're a pain in the ass to setup with things that are not C or C++, editor integrations sometimes need setup, and using them without setting breakpoints visually is tedious.
brailsafe|3 years ago
eurasiantiger|3 years ago
jamisonbryant|3 years ago
I'll give it another crack because I have just started a new job (new machine, new PHP, new everything) but I have my doubts it will work this time, either.
Setting up debugging for PHP has got to get a whole lot easier and user-friendly, IMO.
porcoda|3 years ago
bjourne|3 years ago
I do use a lot of analysis tools like Valgrind which imho are way more useful than debuggers. Linters and static analysis tools can also be really useful for early bug detection.
ok_dad|3 years ago
Other than that, debuggers are very superior to print statements and such. You can’t pause a print statement and inspect the objects you didn’t print!
pentab|3 years ago
Would you be willing to use one of those?
rgavuliak|3 years ago
Taikonerd|3 years ago
I know that "remote debugging" is a thing, but I would need to talk with our network guys about firewall exceptions to allow me to connect to the Kubernetes pod over port XYZ. That sounds like a hassle, and I'm not sure they'd allow it.
pentab|3 years ago
I would guess that it also supports debugging.
Matthias247|3 years ago
jollyllama|3 years ago
Ancalagon|3 years ago
altruios|3 years ago
Gibbon1|3 years ago
anamax|3 years ago
One nice property of asserts is that they keep working even when your attention is elsewhere.
roflyear|3 years ago
salawat|3 years ago
t. Grumpy maintainer
pentab|3 years ago
vlod|3 years ago
TLDR: He doesn't understand why a lot of SV big-tech companies are hostile to debuggers.
[0] https://youtu.be/I845O57ZSy4?t=3410
engineerDave|3 years ago
blacksqr|3 years ago
Learning and effectively using a debugger can require as much cognitive load as programming itself.
Given that, using a debugger takes you out of your programming mindset and into debugger mindset. Using prints, asserts, etc. keeps you in programming mindset, so you can find and fix the problem and get back to coding without the need for cognitive gearshifting.
pentab|3 years ago
Personally, I think "too much" is when you get a large table of all variables and their values; it is quite hard to locate the one you care about...