通过添加“打印”语句进行调试的正确名称是什么? [英] What is the proper name for doing debugging by adding 'print' statements

查看:152
本文介绍了通过添加“打印”语句进行调试的正确名称是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有很多方法进行调试,使用调试器是一个,但简单的一个谦逊,懒惰的程序员只是在你的代码中添加一堆打印语句。



ie

  def foo(x):
print'嘿哇,我们到了foo !',x

...

打印'foo正在返回:',bar
返回条
/ pre>

这种调试风格有正确的名称吗?

解决方案

是 - 它被称为 printf()调试,以无处不在的C函数命名:


使用
来描述由
完成的调试工作,输入更多的

的精确选择状态
信息在关键点
程序流程,观察
信息,并根据该信息推导出错误


- printf()debugging @ everything2



其他语言的本机用户无疑是通过默认的打印/日志/跟踪命令来指定它们的编码平台,但是我已经听说过许多这种技术的printf()名称也许这是由于它的历史:BASIC和FORTRAN具有基本但可维护的 PRINT 命令,C通常需要更多的工作来格式化各种数据类型: printf()迄今为止(通常仍然是)最方便的手段是提供许多内置的格式化选项。它的表弟 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 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.

这篇关于通过添加“打印”语句进行调试的正确名称是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆