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?
这种调试方式是否有正确的名称?
50
Yes - it's known as printf()
debugging, named after the ubiquitous C function:
是的 - 它被称为printf()调试,以无处不在的C函数命名:
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
- 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.
其他语言的原生用户毫无疑问通过可用于其编码平台的默认print / log /或trace命令来引用它,但我听说过“printf()”名称用于以其他语言引用此技术可能这是由于它的历史:虽然BASIC和FORTRAN具有基本但可维护的PRINT命令,但C通常需要更多的工作来格式化各种数据类型:printf()是(并且通常仍然是)最方便的意味着为此,提供了许多内置的格式化选项。它的堂兄fprintf()接受另一个参数,即要写入的流:这允许小心的“调试器”将诊断信息定向到stderr(可能自身重定向到日志文件),同时保持程序输出不被破坏。
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.
虽然现代调试软件的用户经常看不起,但printf()调试仍然证明自己是不可或缺的:用于Firefox网络浏览器的流行的FireBug工具(以及现在可用于其他浏览器的类似工具)是围绕控制台窗口构建的。网页脚本可以记录包含格式化数据的错误或诊断消息。
29
I've heard it called Caveman Debugging
我听说它叫做Caveman Debugging
24
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初学者”(1979)
17
I call it Tracing.
我称之为追踪。
6
me and my team mates calling it "Oldschool Debuging".
我和我的队友称之为“Oldschool Debuging”。
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.
与探索性编程一样,我喜欢称之为探索式调试。当调试器的功能不足以检查程序中的复杂类型,或单独调用辅助函数,或者您只是不了解直接使用所述功能的错误时,就会出现这种情况。
5
I call this "Hi, Mom" programming.
我称之为“嗨,妈妈”编程。
5
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,....
当你在嵌入式系统上时,当你处于最前沿时,你编写的语言还没有调试器,当你的调试器表现得很奇怪并且你想要恢复一些理智,你想要要理解多线程代码中的重入是如何工作的,....
4
I have also heard the term "MessageBox debugging" from the VB crowd to refer to this 'style' of 'debugging'.
我也听过VB人群中的“MessageBox调试”这个术语,指的是'调试'的'风格'。
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 ;)
我嵌入式系统通常是检测代码的唯一方法。不幸的是,打印需要时间并影响系统的实时流程。因此,我们还通过“跟踪”进行检测,其中有关系统状态(函数入口退出等)的信息被写入内部缓冲区以便稍后转储和解析。真正的嵌入式程序员可以通过闪烁LED进行调试;)
3
I've heard "Gutenberg debugging" being used, in the honor of the guy who invented the printing press.
为了纪念发明印刷机的人,我听说“Gutenberg调试”正在使用中。
3
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.
请注意,在Visual Studio中,您可以设置仅添加跟踪的断点。右键单击断点,选择“点击时...”并选中“打印消息”选项。
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.
此外,在.Net中,您可以添加调试语句(我认为它实际上是Debug.WriteLine)以输出到控制台。这些语句仅包含在调试版本中 - 编译器会在您执行发布版本时自动将它们排除在外。
2
Classic Debugging
1
Manual Assertions? Debugger Phobia?
手动断言?调试器恐惧症?
1
verbose debugging !
详细调试!
1
(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
I have always known it by the term 'quick-and-dirty debugging', or just 'dirty debugging' in short.
我总是用“快速和脏调试”这个词来形容它,或者简称为“脏调试”。