Posted By: Peli de Halleux | Apr 23rd @ 11:59 AM | 33,290 Views | 9 Comments
Manuel Fähndrich and Peli de Halleux sit down for a quick coding session that shows how to use Code Contracts and Pex together. Code Contracts can be used to specify what your code should do, they get turned into runtime checks which Pex can analyse and try to find counter-examples for. This was a fun session with Manuel and really shows the synergy of the two tools/approaches.

Both tools can be downloaded from Devlabs or our academic project pages.

The Research in Software Engineering team (RiSE) coordinates Microsoft's research in Software Engineering in Redmond, USA.

Rating:
3
0
vesuvius
vesuvius
Das Glasperlenspiel
I'm having problems downloading this (in that I cannot at the moment).

 Anyone else have any joy?
aL_
aL_
Rx ftw

thats really cool Smiley
ive been using pex for a while and its really quite amazing how complex tests it can create  Smiley

vesuvius
vesuvius
Das Glasperlenspiel
No, the problem is fixed now.

Thank you.
exoteric
exoteric
I : Next<I>
It's quite nice to see this for .Net, especially with the smart code injection.

The embedded contract language is not as clean as in Eiffel, obviously
     put (x: ELEMENT; key: STRING) is
                     -- Insert x so that it will be retrievable through key.
             require
                     count <= capacity
                     not key.empty
             do
                     ... Some insertion algorithm ...
             ensure
                     has (x)
                     item (key) = x
                     count = old count + 1
             end
Also.  I don't quite agree that ensurances should come first (contrary to Eiffel), but granted, using the embedded technique where ther contracts are blended in with the rest of the code, it may be a better technique for readability. Maybe.
It's also striking how much use of contracts can be devoted to the type constraint for reference types that nullness not be part of the domain. How nice it would be with a simple language extension, even if only interpreted as a contract
     add (Point! x)
It's again the annoying wrong-default situation; as with of nullness over non-nullness there's also the variance over invariance (well, im/mutability if you will).
That Code contracts actually implements the old- and result-semantics is very nice. 
Can we now expect .Net to be littered with Code Contracts all over for increased code correctness?
(oops, there goes the beautiful formatting heh)
MaF
MaF
Sure, language syntax would be nice, but that's the language designers job. We've been there (Spec#), done that. We can only influence main stream languages so much. What we are doing now is providing mechanisms and tools without being language designers. Languages can then opt-in and provide whatever syntax they want.

The advantage to the programmer of course is that in the meantime, until language designers make up their mind, they can already work with this technology.
Does it work with the code contracts feature in .net 4.0?
Charles
Charles
Welcome Change

It makes sense, in the context of .NET, that this tooling is designed to be language independent (just like .NET...). Why should every managed language have to provide the same internal semantics and language-appropriate syntax when a single shared library and IDE toolset gives all CLS compliant languages the same functionality for free? I think you guys are doing the right thing here.

Keep on pushing the envelope (independent of language design).
C

Microsoft Communities