Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 292
Jerub Avatar asked Oct 09 '08 23:10

Jerub


People also ask

What is called for print debugging?

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.

What are debugging statements?

The debugger statement invokes any available debugging functionality, such as setting a breakpoint. If no debugging functionality is available, this statement has no effect.

What are the debugging techniques?

There are two types of debugging techniques: reactive debugging and preemptive debugging. Most debugging is reactive — a defect is reported in the application or an error occurs, and the developer tries to find the root cause of the error to fix it.


2 Answers

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.

like image 78
Shog9 Avatar answered Sep 18 '22 14:09

Shog9


I've heard it called Caveman Debugging

like image 34
paxos1977 Avatar answered Sep 19 '22 14:09

paxos1977