图书馆以促进“合同设计"的使用.原则 [英] Library to facilitate the use of the "design by contract" principle

查看:77
本文介绍了图书馆以促进“合同设计"的使用.原则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何库可帮助在C ++应用程序中实现按合同设计原则?

Is there any library that aids in implementing the design by contract principle in a C++ application?

尤其是,我正在寻找一个适合使用该原理的库,例如

In particular, I'm looking for a library that facilities the usage of the principle, something like this.

推荐答案

我遵循了以下文章的教导:

I followed the teachings of the following articles:

  • 是异常还是错误? (米罗 Samek,《 C/C ++用户杂志》,2003年)
  • 按合同提供简单设计支持 C ++语言(Pedro Guerreiro,TOOLS,2001年)
  • An exception or a bug? (Miro Samek, C/C++ Users Journal, 2003)
  • Simple Support for Design by Contract in C++ (Pedro Guerreiro, TOOLS, 2001)

我最终应用的几乎是Samek的方法.仅创建用于REQUIRE,ENSURE,CHECK和INVARIANT的宏(基于现有的assert宏)非常有用.当然,它不如本地语言支持那么好,但是无论如何,它可以使您从该技术中获得大部分实用价值.

What I ultimately applied was pretty much Samek's approach. Just creating macros for REQUIRE, ENSURE, CHECK and INVARIANT (based on the existing assert macro) was very useful. Of course it's not as good as native language support but anyway, it allows you to get most of the practical value from the technique.

对于库,我认为使用一个库不值得,因为断言机制的一个重要价值是它的简单性.

As for libraries, I don't think that it pays to use one, because one important value of the assertion mechanism is its simplicity.

有关调试代码和生产代码之间的区别,请参见>何时应将断言保留在生产代码?.

For the difference between debug and production code, see When should assertions stay in production code?.

这篇关于图书馆以促进“合同设计"的使用.原则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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