使用生产不赞成对的if..else断言()..块? [英] Is using assert() for production not favored over if..else.. blocks?

查看:127
本文介绍了使用生产不赞成对的if..else断言()..块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,使用断言(...)让我的code更短,更易于阅读,而不是冗长的如果..else .. 块。然而,是否有良好的技术的理由不使用断言(...)航运code,当它一回事同时使用更少的code测试收益价值?

I am finding that using assert(...) makes my code shorter and easier to read, as opposed to lengthy if..else.. blocks. However, are there good technical reasons not to use assert(...) in shipping code, when it does the same thing as testing a return value while using less code?

推荐答案

看了这篇文章 - HTTP ://www.advogato.org/article/949.html 我将分享约断言我的信仰

Having read this article - http://www.advogato.org/article/949.html I will share my beliefs about assert.

1。)是的,它的优良使用断言当事情绝对应符合您所声称的条件。

1.) Yes it's fine to use assert when something absolutely should meet the condition you are asserting.

2)许多语言让你提出主张时,C没有例外可能会产生更难一点诊断不直接看问题的源代码错误,自定义错误。

2.) Many languages allow you to raise custom errors when asserting, C not having "Exceptions" may produce errors that are a little harder to diagnose without directly looking at the source in question.

这篇关于使用生产不赞成对的if..else断言()..块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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