被断言邪? [英] Is assert evil?

查看:114
本文介绍了被断言邪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开始语言的创造者

Go不提供断言。他们是不可否认的方便,但我们的经验是,程序员使用它们作为拐杖,以避免考虑适当的错误处理和报告。正确的错误处理意味着服务器后继续非致命错误,而不是崩溃操作。正确的错误报告意味着错误直接了点,从节省跨preting大碰撞痕迹的程序员。 precise错误是特别重要的当程序员看到的错误是不熟悉code。

Go doesn't provide assertions. They are undeniably convenient, but our experience has been that programmers use them as a crutch to avoid thinking about proper error handling and reporting. Proper error handling means that servers continue operation after non-fatal errors instead of crashing. Proper error reporting means that errors are direct and to the point, saving the programmer from interpreting a large crash trace. Precise errors are particularly important when the programmer seeing the errors is not familiar with the code.

你怎么看待这种观点?

推荐答案

没有,没有什么错断言只要你使用它意。

No, there's nothing wrong with assert as long as you use it as intended.

也就是说,它应该是追赶案件不可能发生,在调试过程中,相对于正常的错误处理。

That is, it's supposed to be for catching cases that "can't happen", during debugging, as opposed to normal error handling.


  • 断言:在程序的逻辑本身的故障

  • 错误处理:一个错误的输入或系统状态不是由于程序中的错误

这篇关于被断言邪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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