In my mind printf is like an automated debugger. With a debugger I need to kill my auto-run command, run the program, set breakpoints, type to see what variables I want to inspect, maybe switch stack frames, maybe step through a bit. If I want to inspect a different variable I just add another print and run again. Then in less than a second I have a trace trough my program in the terminal. This means that to printf-debug I just add a message or two (and if I am coding I might already have a couple of useful ones lying around) and save. Generally when I am coding I auto-run the tests on save. You said "click", I need to leave my keyboard. Getting tooling to work effectively is more time consuming and frequently not possible. In compiled languages, the evaluation of the expression can be difficult/impossible to write because of this (not enough type information available, validation is late binding meaning mistakes are extra expensive, etc.Īt the end of the day, when your tools fail you, print debugging is easier to use to accomplish the task rather. Debuggers (or at least the C/C++ ones) are slow in how they inject instrumentation code to evaluate - rather than compiling expressions into native codes to conditionally trap, they seem to trap unconditionally and evaluate the conditional using their introspection language (there are valid reasons why it’s done this way but it has serious performance impacts). Reverse debugging isn’t available on all platforms/languages. Tooling availability is inconsistent, which is why such approaches don’t always work. In my experience the conditions on the ground are different though. In those cases RR seems like the best idea rather than prints. Setting a breakpoint that prints and continues is appropriate if performance doesn’t matter.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |