将代码合约部署到生产环境中是不是不好?
我引用这个答案(强调我的):
查看 ContractClass 和 ContractClassFor 属性。这允许您在单独的程序集中编写带有代码协定的类。这使您可以将合约用于开发工作,不会使您的代码混乱,并且也意味着您不必使用实时代码部署合约
为什么您不希望合同已部署?
从最佳实践的角度来看,合同是否严格用于开发和质量控制?
I am referencing this answer (emphasis mine):
Have a look at the ContractClass and ContractClassFor attributes. This allows you to write classes with the code contracts in separate assemblies. This allows you to have the contracts available for dev work, doesn't clutter your code and also means you don't have to deploy the contracts with the live code
Why would you not want the contracts deployed?
Are contracts, from a best-practices point-of-view, strictly for development and quality control?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您通常不想在发布版本上部署后置条件合约。这是为了确保您不会让使用您的程序集的人遇到由您负责的错误。我确信还有其他原因,但这是我想到的第一个原因。
目前,据我所知,关于代码契约还没有单一的最佳实践观点。使用代码契约有不同的方法(在代码契约用户手册中进行了描述),并且每种方法都有其自己的特定准则。
正如我在评论中所述,您引用的答案也不完全正确。
You generally don't want to deploy postcondition contracts on release builds. This is to make sure that you don't confront people using your assemblies with errors that are your responsibility. I'm sure there are other reasons, but this is the first one that pops to my mind.
Currently, there is no single best-practices point-of-view that I know of regarding Code Contracts. There are different ways to use Code Contracts ( which are described in the Code Contracts User Manual ), and each one has it's own specific guidelines.
The answer you're referencing is also not completely correct, as I've stated in the comments.