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?

Andrew Grimm
  • 78,473
  • 57
  • 200
  • 338
Jerub
  • 41,746
  • 15
  • 73
  • 90
  • 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. – Georg Fritzsche Jul 18 '10 at 00: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. – RBarryYoung Feb 21 '12 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 '12 at 23:11
  • "instrumentation by logging" – dchneric Apr 21 '21 at 17:16

19 Answers19

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.

Shog9
  • 156,901
  • 35
  • 231
  • 235
  • 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 '11 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 '13 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 :). – Brent Bradburn Oct 20 '15 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)

Bill Karwin
  • 538,548
  • 86
  • 673
  • 828
45

I've heard it called Caveman Debugging

oz10
  • 153,307
  • 27
  • 93
  • 128
  • 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 '11 at 02:06
23

I call it Tracing.

David Segonds
  • 83,345
  • 10
  • 45
  • 66
  • I remember when I did Flash ActionScript programming, the trace() function was used for this. – Dean Rather Oct 10 '08 at 00: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). – RBarryYoung Feb 21 '12 at 15:10
8

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

nickf
  • 537,072
  • 198
  • 649
  • 721
RWendi
  • 1,446
  • 5
  • 20
  • 38
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,....

NeilDurant
  • 2,082
  • 2
  • 14
  • 14
6

I call this "Hi, Mom" programming.

An̲̳̳drew
  • 13,375
  • 13
  • 47
  • 46
5

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

Sergio Acosta
  • 11,418
  • 12
  • 62
  • 91
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.

Don Wakefield
  • 8,693
  • 3
  • 36
  • 54
4

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

styts
  • 1,003
  • 1
  • 8
  • 19
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 ;)

humble_guru
  • 526
  • 1
  • 3
  • 3
  • 1
    Yep, blinking morse code so you can get more information than you can with a "Captain Pike's Chair" light. Done that. – Wayne Conrad Dec 02 '10 at 15:51
4

I would call it simply "logging".

Calmarius
  • 18,570
  • 18
  • 110
  • 157
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.

Wedge
  • 19,513
  • 7
  • 48
  • 71
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.

Dr8k
  • 1,088
  • 5
  • 11
2

Classic Debugging

2

verbose debugging !

Nrj
  • 6,723
  • 7
  • 46
  • 58
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.)

Jonathan
  • 2,132
  • 1
  • 11
  • 8
1

Manual Assertions? Debugger Phobia?

JamesSugrue
  • 14,891
  • 10
  • 61
  • 93
1

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

ayaz
  • 10,406
  • 6
  • 33
  • 48