3 ms·
Print based debugging and infrequent developers
- drewcoo 4y agoI think tha what matters isn't actually how you can debug on your machine. What matters is how you can diagnose and fix a production problem. Without a debugger. Without SSH, ideally. Only with whatever monitoring or logging or other signaling you've set up. And similarly, probably mattering more, how can someone else diagnose in production that way? If you debug on your dev box using the same signals you'd have in production, you'll end up in that sweet spot when the pager goes off.
- toast0 4y agoI can understand why it's desirable to avoid access to production, but having access to production with the right tools available (debugger, tcpdump, etc), can drastically shorten the cycle between problem discovery and fixes. Yeah, you can do it with both hands tied behind your back, but are you getting enough value out of it?
- hyperman1 4y agoAs the saying goes, you can spare yourself 10 minutes of thinking with a few hours of debugging. A debugger works if you're in unknown territory, e.g. an inherited code base or some third party library. You have only a vague idea what the code does, you don't know if the original author was good or bad, you can't modify the code... Also good if you have some platform corruption going on, like a C pointer gone wild and overwriting unrelated data, hardware that's not completely functioning as it should, some virus scanner or security contraption injecting its own crap in your code for your supposed good... Using a debugger on your own code generally means you did not think things trough. Adding assertions will help you trap the trouble closer to its point of origin. Print debugging is good for dumping inputs and outputs, and maybe complex intermediate state. As you have a full programming language available, you can add a few if statements to only dump state if it is relevant to your problem. The nice thing is, assertions and print debugging nicely evolve to production: The first can be enabled with a feature toggle, the second nicely evolves to logging. This means your prod executable is not only good at doing its job, it's also good at helping you troubleshoot on a bad day. Use the dev bugs to train yourself and your program to troubleshoot the prod bugs.
- musicale 4y agoLogging is a pretty useful technique, and not just for debugging. Auditing/state validation is also useful.
- invalidname 4y agoLogging isn't print debugging... Logging is long term and you would log significant things. Print debugging is stuff you need to remove before commit. Stuff that tracepoints/logpoints can probably handle better for most developers.
- invalidname 4y agoThe post tries to take a Luddite approach of avoiding a debugger and chuck it up to experience. I used print debugging in platforms where debuggers suck (mobile, embedded). I also understand other developers of kernels, language runtime, etc. that take that approach. In the cases I used that it was due to lack of options. Tracepoints are almost always superior to print debugging: * You can't forget them in the code before commit * You can chain them with breakpoints and each other * You can use conditional tracepoints * You don't need to recompile/restart Logging is great but it's not print debugging... It's a long term strategy and is committed to version control. * Y