是否应该保留调试代码? [英] Should debugging code be left in place?

查看:41
本文介绍了是否应该保留调试代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不建议将调试代码保留在适当的位置吗?

Is leaving debugging code in place a discouraged practice?

例如,我当前正在使用的程序(用Java编写)可以发送电子邮件.有多种发送失败的电子邮件的方法.因此,在 Email 类的 send 方法中,我传递了一个布尔参数 boolean fail ,如果为true,则会导致该方法失败.这可以让我测试发送失败的电子邮件是否得到正确处理.

For example, a program (written in Java) I'm currently working on can send emails. There are various ways emails that failed to send are handled. So in the method send in the Email class, I pass a boolean argument boolean fail which, if true, causes the method to fail. This allows me to test whether the emails that failed to send are correctly handled.

在整个程序中,我还有其他实例.显然,最终生产代码中的任何地方都不会告诉程序失败.但是,如果需要更改它们的相应功能,将这些调试工具保留在原处会不会有任何危害?

I have other instances of this throughout the program as well. Obviously, nowhere in the final production code will the program be told to fail. But is there any harm in leaving these debugging tools in place in case their corresponding features ever need to be changed?

推荐答案

除了可以注释或取消注释调试逻辑之外,如果可以将调试设置为基于环境变量运行,那么将其保留在原处通常是一种好习惯.它将为您(或其他人)在旅途中派上用场.将来,您只需将DEBUGGING设置为TRUE即可查看调试逻辑,显然在生产中,您可以将其设置为FALSE.

Rather than commenting or uncommenting debugging logic, if you can set up your debugging to run based on an environment variable, leaving it in place is generally good practice. It will come in handy for you (or someone else) down the road. In the future you'd simple set DEBUGGING to TRUE to see your debugging logic, and obviously in production, you'd set it to FALSE.

这篇关于是否应该保留调试代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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