Debugging methods
Why programmers reach for printf more frequently than debuggers
Published: Sunday, Apr 11, 2021 Last modified: Tuesday, Nov 26, 2024
What's your theory for why programmers reach for printf-debugging more frequently than other modes (like step-debugging)?
— Amjad Masad (@amasad) April 9, 2021
printf
- easier to show your changes
- can allow you to look back in time
- fast and reliable
- available everywhere
- printfs don’t disappear like breakpoints
- proactive
- smallest complexity cost
- (structured) logging mindset can help with understanding - e.g. messages with some story telling, gives better context
- made it here! - “hello world” sanity testing
debugger
- reverse debugging is rare
- examine program execution without making changes to the code
- tracepoints are quicker and easier than adding printfs, when they work
- can be a security nightmare in production
- requires setup
- shows more state than your printfs might have missed
- lots of rsi inducing button pushing
- can be non-trivial to attach a debugger
- better when you are unfamiliar with the code since multiple stack levels are shown
- some debuggers allow you to edit code whilst running which can help improve iteration speed
- some debuggers are fragile, breakpoints missed etc
- debuggers changes timing behaviour, so you may never hit a timing bug
- debuggers are like magic and you don’t know why it worked
- debuggers can be difficult in asynchronous environments