将语言合同添加到语言中 [英] Add Code Contracts to Languages

查看:107
本文介绍了将语言合同添加到语言中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得代码cotracts是切片面包以来最好的东西。但是,如果代码合同是C#或VB标准语言功能的一部分,并且自动编译
作为C#/ VB编译器的一部分(而不是秒),我相信代码合同的性能会大大提高。编译)。 CC可以是方法签名的一部分,如下所示。 C#/ VB语言团队还可以在语言中添加一些关键字以支持代码合同。

I think code cotracts is the best thing since sliced bread. However I believe the performance of code contracts would be greatly improved if code contracts were a part of the C# or VB standard language features and automatically compiled as part of the C#/VB compiler (instead of a second compile). CC could be part of the method signiture as shown below. The C# / VB language teams could also add a few keywords to the languages to support code contracts.

以下示例显示了我将来想要的一个示例(关键字:需要,确保,结果)

The following example shows an example of what I would like in the future (keywords: requires, ensures, result)


public int DoSomething(string s) [requires s != null, ensures result >= 0]
{
   return s.Length;
}

推荐答案

我们与语言团队进行过多次讨论。他们一直非常支持,但(可以理解)希望看到人们在承诺提供语法和编译器支持之前从使用合同中获得实际好处。所以现在
我们将继续使用基于库的方法。但随着越来越多的人分享你的热情,它将更有可能被采纳!
We have had many discussions with the language teams. They have been extremely supportive, but would (understandably) like to see people getting actual benefit from using contracts before they commit to providing syntax and compiler support. So for now we are going to continue on with the library based approach. But as more people share your enthusiasm it will make it more likely to be adopted!


这篇关于将语言合同添加到语言中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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