5 ms·
> You can pry my debug prints from my cold, dead hands. I clicked on this about to type exactly that phrase. Here's why: the CORE PROBLEM of debugging has not
by ajross 6y ago
> You can pry my debug prints from my cold, dead hands.
I clicked on this about to type exactly that phrase.
Here's why: the CORE PROBLEM of debugging has nothing to do with process, it's the need for the human developer to understand the operation of machine code when faced with a specific set of runtime conditions.
You can't debug by just reading code, because the bug only shows up at runtime. Most people agree with this.
Likewise, you can't debug just by WATCHING a program, for the same reason. You need to be reasoning about the operation of the abstracted code at the same time. And almost always you need to be inspecting and reasoning about the internal states driving the behavior.
Debugging tools, as nice as they might be, can only do the "watching" part. They are a fine way to do it, but you still need to be making the decision, based on careful analysis of the code, on which elements to watch.
So... given that you're staring at code in your editor and thinking about how to extract the needed internal state to validate your predictions... why not just print it?
That is: print/console debugging isn't a hard task you "have to do" in the absence of a fancy debugger, it's exactly the task that you must do if you're going to solve the problem. The fancy debugger, at best, is only saving your the time taken to TYPE the printf() expression. And in practice even that tends to parallelize with the analysis in my experience, as you realize things while typing out their expression.
- db48x 6y agoPernosco lets you record your program once, then query the resulting database over and over. This is like adding printfs to the program after it has run, any time you have a new idea for what it should have printed out. Here’s a demo: https://pernos.co/about/expressions/ https://pernos.co/about/expressions/ Notice in this demo how he clicked on a line number, and got back a list of all the times in the program where that line was executed. Not just a single breakpoint with the option to continue, but all of them. Then he queries for the value of a variable at all of those points, and gets all the values printed out simultaneously, as if there had been a printf at that line. Then he filters the list to show only calls made on a specific object, as if the printf had an if statement around it. All without needing to rerun the program, or even be on the same computer as where the recording was captured. This is what the author means when he says that all debugging tools can be _better_ than printf debugging, if only we put some more time into improving our tools.
- ajross 6y agoAgain: that simply saves me the time it takes to add logging to trace the value of that variable. It fails to account for the much larger amount of time needed to understand which variable to trace. By all means, use fancy tools like replay debuggers (of which Pernosco is only one example) if they make you happy. I'm just saying that (1) there is a hard cap on the value that tooling can provide, because the real limitation is between our ears. And so (2) I'm going to spend the limited learning bandwidth between my ears on things like genuine new technology and not better tools that might provide a mildly incremental improvement to tasks I do already.
- db48x 6y agoHmm. I see what you’re saying, but I’m not sure that there is a hard cap. Pernosco has allowed me to solve harder problems than I would be able to solve without it. Or perhaps there is a hard cap, but that cap is much higher than you would think. High–quality tools might get you closer to that cap than simpler tools would. For example, I participated in a project recently to extend Flex so that it could generate both Rust and Go code, in addition to C. Pernosco was an invaluable aid here. I was able to get Flex to generate a C program and also a Rust program, then compare the execution of those two programs. I recorded them both, and opened them each in their own window. Keeping them side–by–side, I could probe the innards of both programs simultaneously. Since both programs were supposed to implement the same state machine (and thus recognize the same list of tokens), it was easy to find places where the Rust version went off the rails. I was able to do in hours what would have taken days with any other method, if I had succeeded at all. The behavior of that state machine is not at all obvious, and I might never have unraveled it without Pernosco.
- ajross 6y ago> I was able to do in hours what would have taken days with any other method See... I think that's just wrong. Here's how I'd do that (knowing nothing about flex but having written similar state machine generators for non-lexing problems): + augment the generated code to dump the sequence of state transitions and tokens to stderr or whatever + run it in both environments + diff the output + Go back and add some metadata like __FILE__/__LINE__ or whatever as needed to find the bad data or state + Repeat as needed Now, is that as button-pushing-trivial as using a replay debugger? No, probably not. But it's not "days" of work either, it's like an hour to get a rig like that put together.
- klyrs 6y ago> You can't debug by just reading code, because the bug only shows up at runtime. Most people agree with this. Bullshit. I regularly find bugs in code review, just by reading code. I think this is true of most experienced programmers.
- eindiran 6y agoI don't think this is what OP was talking about: if your mental model of what the code is going to do is correct, then sure, you can just read the code and find bugs. AFAICT, OP is talking about debugging as updating your incorrect mental model of what the code is doing. If your mental model of the code does not result in the same output as the code itself, it is extremely helpful to dig into the behavior of the program rather than just reading the code again. For which inputs does my mental model of the code break? At what point in the code do things start to diverge from my mental model? Etc.
- ajross 6y agoExactly. It's mostly a semantics thing. Finding errors statically via code review and analysis (there are fancy tools to assist this process too!) is important, but it's not sufficient as we all know too well. Sometimes you just need to puzzle things out with runtime state. So yeah, in the text above I'd view "code review" and "static analysis" as distinct tasks from "debugging". And I'm only talking about the latter.