4

Can someone explain the concepts that Spec# might be moving into C# 4.0, regarding Code Contracts?

  • What are code contracts (Looks to be a compile time checking pattern)
  • should I be excited about this?
  • Am I correct in assuming that we move what would be runtime checks to compile time?

Thanks!

George Stocker
  • 57,289
  • 29
  • 176
  • 237
FlySwat
  • 172,459
  • 74
  • 246
  • 311
  • .NET Rocks had a decent podcast on spec#. Its a year ago since I listened to it, but im pretty sure they talk about your first and last bullet point. Its worth checking out for a fast overview of spec#. Link: http://www.dotnetrocks.com/default.aspx?showNum=237 – Tom Jelen Dec 24 '08 at 00:15

2 Answers2

3

I personally am a big fan of a guy called Bertrand Meyer who wrote this book called Object Oriented Software Contruction and created a language called Eiffel which endoreses Design By Contract or Contract based programming.

  1. Code Contract is a kind of agreement between 2 software entities that may or may not interact. More or less like interfaces but more precise.
  2. I am not sure if everyone should or would be excited about this.
  3. Your assumption is somewhat correct.

You might want to see this series of videos link

Perpetualcoder
  • 13,501
  • 9
  • 64
  • 99
2

Here's a good description of code contracts straight from Microsoft Research. It sounds like the main benefits are:

  • Improved testability
  • Static verification
  • API documentation (in code)
Marc Novakowski
  • 44,628
  • 11
  • 58
  • 63