通过添加“打印”语句进行调试的正确名称是什么? [英] What is the proper name for doing debugging by adding 'print' statements
问题描述
有很多方法进行调试,使用调试器是一个,但简单的一个谦逊,懒惰的程序员只是在你的代码中添加一堆打印语句。
ie
def foo(x):
/ pre>
print'嘿哇,我们到了foo !',x
...
打印'foo正在返回:',bar
返回条
这种调试风格有正确的名称吗?
解决方案是 - 它被称为
printf()
调试,以无处不在的C函数命名:
使用
来描述由
完成的调试工作,输入更多的
或
的精确选择状态
信息在关键点
程序流程,观察
信息,并根据该信息推导出错误
。
- printf()debugging @ everything2
其他语言的本机用户无疑是通过默认的打印/日志/跟踪命令来指定它们的编码平台,但是我已经听说过许多这种技术的printf()名称也许这是由于它的历史:BASIC和FORTRAN具有基本但可维护的
fprintf()
,需要另一个参数,要写入的流:这允许仔细的调试器将诊断信息指向stderr
(可能本身重定向到日志文件),同时使程序的输出未被破坏。尽管经常看不到现代调试软件的用户,printf()调试继续证明自己是不可或缺的:Firefox Web浏览器中非常受欢迎的FireBug工具(和类似的功能)现在可用于其他浏览器的工具)围绕一个控制台窗口构建,网页脚本可以记录包含格式化数据的错误或诊断消息。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?
解决方案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
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 tostderr
(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.
这篇关于通过添加“打印”语句进行调试的正确名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!