43

There are many ways of doing debugging, using a debugger is one, but the simple one for the humble, lazy, programmer is to just add a bunch of print statements to your code.

i.e.

 def foo(x):
     print 'Hey wow, we got to foo!', x

     ...

     print 'foo is returning:', bar
     return bar

Is there a proper name for this style of debugging?

4
  • 14
    I find it strange how many people call this outdated when tracing is the only useful thing to evaluate how an invalid state was reached in the wild. Jul 18, 2010 at 0:18
  • 2
    This is an ancient technique, far pre-dating most of the languages mentioned below or their parochial names for it. IIRC, it was originally called "Tracing" or "Trace Debugging", at least in the late 60's and early 70's. Feb 21, 2012 at 15:08
  • 12
    I think that it is strange that people look down on this technique while it's about the only valid solution for debugging concurrent programs with real-time constraints, like UI interactions, for example.
    – madewulf
    Aug 26, 2012 at 23:11
  • "instrumentation by logging"
    – dchneric
    Apr 21, 2021 at 17:16

19 Answers 19

74

Yes - it's known as printf() debugging, named after the ubiquitous C function:

Used to describe debugging work done by inserting commands that output more or less carefully chosen status information at key points in the program flow, observing that information and deducing what's wrong based on that information.

-- printf() debugging@everything2

Native users of other languages no doubt refer to it by the default print / log / or trace command available for their coding platform of choice, but i've heard the "printf()" name used to refere to this technique in many languages other than C. Perhaps this is due to its history: while BASIC and FORTRAN had basic but serviceable PRINT commands, C generally required a bit more work to format various data types: printf() was (and often still is) by far the most convenient means to this end, providing many built-in formatting options. Its cousin, fprintf(), takes another parameter, the stream to write to: this allowed a careful "debugger" to direct diagnostic information to stderr (possibly itself redirected to a log file) while leaving the output of the program uncorrupted.

Although often looked down on by users of modern debugging software, printf() debugging continues to prove itself indispensable: the wildly popular FireBug tool for the Firefox web browser (and similar tools now available for other browsers) is built around a console window into which web page scripts can log errors or diagnostic messages containing formatted data.

3
  • I remember doing this with C sockets. Oh the pain. Especially when the writes to stdout started being delayed and required me to manually call fsync before things could start to make sense.
    – badp
    Jun 17, 2011 at 20:40
  • 4
    I found printf debugging especially useful when debugging a problem that occur in the middle of a loop. It's quite faster to skim through a log than watching what's going on the watch window.
    – Calmarius
    Nov 29, 2013 at 13:15
  • @Calmarius: Totally agree. Printf debugging is often the best way to debug software that runs in a loop -- which is basically all non-trivial software :). Oct 20, 2015 at 22:35
46

I thought the following quote would be apropos:

"The most effective debugging tool is still careful thought, coupled with judiciously placed print statements."

— Brian Kernighan, "Unix for Beginners" (1979)

0
45

I've heard it called Caveman Debugging

1
  • 1
    I came across this term in an Objective-C book and it seems to be something the author made up, but it is at least a prolific enough book to spread somewhat to Objective-C users in general and to a lesser extend users of other languages. However, it's an awesome term and nothing is keeping us from just calling it this wherever...
    – Jasper
    Mar 24, 2011 at 2:06
23

I call it Tracing.

2
  • I remember when I did Flash ActionScript programming, the trace() function was used for this. Oct 10, 2008 at 0:05
  • 1
    AFAIK, this (or possibly "Trace Debugging") is the original and correct term for it. This term for it dates back to at least the mid-60's (way before ActionScript). Feb 21, 2012 at 15:10
8

me and my team mates calling it "Oldschool Debuging".

7

Seat of your pants debugging :)

When you're on an embedded system, when you're at the bleeding edge and the language you're coding in doesn't have a debugger yet, when your debugger is behaving strangely and you want to restore some sanity, and you want to understand how re-entrancy is working in multi-threaded code,....

6

I call this "Hi, Mom" programming.

5

I have also heard the term "MessageBox debugging" from the VB crowd to refer to this 'style' of 'debugging'.

5

In the same sense as exploratory programming, I like calling it exploratory debugging. This follows when the debugger is not powerful enough to examine complex types in the program, or invoke helper functions separately, or you just don't know enough about a bug to use said features directly.

4

I embedded systems its often the only method to instrument the code. Unfortunately printing takes time and effects the real-time flow of the system. So we also instrument via "tracing" where information about the state of the system (function entry exit etc) is written to a internal buffer to be dumped and parsed later. Real embedded programmers can debug by blinking an LED ;)

1
  • 1
    Yep, blinking morse code so you can get more information than you can with a "Captain Pike's Chair" light. Done that. Dec 2, 2010 at 15:51
4

I've heard "Gutenberg debugging" being used, in the honor of the guy who invented the printing press.

4

I would call it simply "logging".

2

I usually refer to it as tracing.

Note that in Visual Studio you can set breakpoints which just add tracing. Right click on a breakpoint, select "when hit..." and check the "Print a message" option.

2

Also, in .Net you can add debugging statements (I think it actually is Debug.WriteLine) to output to the console. These statments are only included in debug builds - the compiler will automatically leave them out when you do a release build.

2

Classic Debugging

2

verbose debugging !

2

(Good logging is incredibly valuable for debugging problems in running production systems. Lots of useless verbose print statements aren't, but logging something interesting when something important or unexpected occurred is incredibly important. If the only way you know how to debug problems is with a debugger, you're going to find yourself in quite the tight spot when the service you've built is broken for some of your users but you can't reproduce the problem locally.)

1

Manual Assertions? Debugger Phobia?

1
  • 5
    I love how 'Debuggerphobia' rolls off the tongue. +1
    – Jerub
    Oct 10, 2008 at 6:03
1

I have always known it by the term 'quick-and-dirty debugging', or just 'dirty debugging' in short.

Not the answer you're looking for? Browse other questions tagged or ask your own question.