3 ms·
Debuggers are a great learning tool, but I’ve found they’re useless when diagnosing production issues. At best, you’re using C/C++ and after the crash, you get
by hedora 5y ago
Debuggers are a great learning tool, but I’ve found they’re useless when diagnosing production issues. At best, you’re using C/C++ and after the crash, you get a minidump from a customer/server.
Eventually, I learned to write code that was so obviously correct and had such good error messages that I haven’t needed to use a debugger in a long time.
In fact, I don’t even know how to invoke a debugger for most languages I know.
Edit: The other good trick is to write your code so that it keeps enough state on the heap to extract useful information from core dumps. For instance, you can keep global references to lists of state that helps track issues down, and make sure they work as expected in -O3 builds. I have definitely played that game in the past.
- pjmlp 5y agoThey are only useless when the production is built with stacks that don't support stuff like Application Insights, ETW or JFR/JMX.
- labawi 5y agoReminds me of the time needed to write an application that would be particularly hard to test (was critical, handled distributed state). Managed to write it so obviously correct, that I couldn't think of anything to test before releasing the clustered version. I only ever managed to find 2 bugs, both of which were silly and unimportant. During development, I did use REPL to run/evaluate most of the functions, on 1-2 inputs, and found a couple of silly, immediately evident bugs. Development took a couple of days, testing was about as mentioned and I really didn't want to debug. These days, I'm amazed how people can stand to write anything at all complicated in haphazard ways, but then get to spend similar or greater time playing whack-a-mole with bugs to maybe get most of the important bugs. Yes, good tooling can make debuggers usable. OTOH, if you need debuggers, I would consider it a shortcoming of the programming methods/structures/styles and usually even entire stacks, where debugging is practically necessary.
- thu2111 5y agoDebuggers aren't quite as useful with C++ indeed. But that's a good reason to use C++ less. I diagnose issues drastically faster with a debugger all the time. Often I'll write a unit test that reveals a bug, but just looking at the code doesn't quite reveal where the bug is. But sticking a few breakpoints in the right places and examining the data structures directly makes it really obvious. Eventually, I learned to write code that was so obviously correct and had such good error messages that I haven’t needed to use a debugger in a long time. Nobody needs to use a debugger, just like nobody needs to use most tools. They're just very helpful when they work correctly and are used correctly.
- galangalalgol 5y agoI've spent much of my career debugging C++ in rather large code bases, after inserting said bugs myself usually. If you have a set if inputs that make the problem reproducible, a debugger usually makes finding the error trivial. The only times it has taken a while is when someone (not me in this case) has done something horrible with unsafe casts, ignoring data hiding to violate a class invariant, or memcpy, or... So basically old style C. Building for release with debug info helps. Debugging with a debug build is easier sometimes, but sometimes it masks or in rare cases, creates bugs.