C ++中的合同设计? [英] Design by Contract in C++?

查看:155
本文介绍了C ++中的合同设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是任何有助于在c ++应用程序中通过契约原则实现设计的库。
编辑:

Is that any library that aids in implementing design by contract principle in c++ application.


寻找比ASSERT
更好的东西,比如


推荐答案

p>我遵循以下文章的教导:

I followed the teachings of the following articles:


  • (Miro
    Samek,C / C ++ Users Journal,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?.

这篇关于C ++中的合同设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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