Tech News
← Back to articles

Things you can do with a debugger but not with print debugging

read original related products more articles

Things you can do with a debugger but not with print debugging

People do or do not use debuggers for a variety of reasons. For one thing, they are hard to setup in many codebases. Second, you can’t use them when your application is running on remote environments (such as kuberenetes). So, anecdotally, I have seen way more people using Print/ log.Debug compared to a debugger.

Which is a shame, because while debug logging is convenient at times, debuggers can do some things which you can’t easily simulate via debug logging.

Debuggers let you See all the way up the call stack

In most debuggers you can see all the callers and inspect the state there. So if you don’t know how we got to some stage, you can select the parent frame in the debugger menu and check the variables, or evaluate an expression there.

Debuggers can evaluate expressions dynamically

Most debuggers for high-level languages let you evaluate expressions involving function calls and even modify the state of the running program.

This doubles as an REPL with access to all your program state.

Debuggers can catch exceptions at the source

All debuggers have exception breakpoints which stop at the point where exception is thrown. This is super handy to inspect the exact state and figure out why exception happened. In almost all debuggers, you can also limit this functionality to uncaught exceptions only.

... continue reading