What is the proper name for doing debugging by adding 'print' statements [closed]
Asked Answered
I

19

45

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?

Involucrum answered 9/10, 2008 at 23:19 Comment(4)
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.Henleyonthames
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.Becalm
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.Sik
"instrumentation by logging"Bunns
M
77

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.

Merrillmerrily answered 9/10, 2008 at 23:21 Comment(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.Ratable
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.Hymeneal
@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 :).Accessory
G
47

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)

Greenburg answered 26/10, 2008 at 21:47 Comment(0)
R
45

I've heard it called Caveman Debugging

Rumor answered 9/10, 2008 at 23:58 Comment(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...Seda
P
23

I call it Tracing.

Prolific answered 9/10, 2008 at 23:31 Comment(2)
I remember when I did Flash ActionScript programming, the trace() function was used for this.Renatarenate
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).Becalm
F
8

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

Felicio answered 9/10, 2008 at 23:25 Comment(0)
B
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,....

Ballottement answered 10/10, 2008 at 5:7 Comment(0)
M
6

I call this "Hi, Mom" programming.

Mcnutt answered 10/10, 2008 at 4:35 Comment(0)
B
5

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

Bergh answered 9/10, 2008 at 23:42 Comment(0)
G
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.

Gravettian answered 9/10, 2008 at 23:46 Comment(0)
F
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 ;)

Frasco answered 10/10, 2008 at 0:7 Comment(1)
Yep, blinking morse code so you can get more information than you can with a "Captain Pike's Chair" light. Done that.Garrygarson
H
4

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

Housebreaking answered 20/8, 2012 at 9:47 Comment(0)
H
4

I would call it simply "logging".

Hymeneal answered 29/11, 2013 at 13:29 Comment(0)
C
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.

Carlita answered 9/10, 2008 at 23:51 Comment(0)
F
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.

Fulgurite answered 10/10, 2008 at 0:4 Comment(0)
M
2

Classic Debugging

Manakin answered 10/10, 2008 at 0:31 Comment(0)
F
2

verbose debugging !

Farmstead answered 10/10, 2008 at 4:42 Comment(0)
M
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.)

Meissner answered 10/10, 2008 at 5:9 Comment(0)
A
1

Manual Assertions? Debugger Phobia?

Alage answered 9/10, 2008 at 23:34 Comment(1)
I love how 'Debuggerphobia' rolls off the tongue. +1Involucrum
C
1

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

Cawthon answered 10/10, 2008 at 5:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.