Browse by Tags

Code Contracts…are cool again!
Wed, Apr 22 2009 21:49
Why, you ask? Simply because now they’re usable from within any version of Visual Studio (though you’ll only have static checking if you’re using VSTS). I’m not sure on how I missed that announcement (ok, I missed it because I got really “depressed” after the initial requisites for using it and never looked back!), but now I’m really excited and will start migrating... Read More...
by luisabreu | with no comments
Filed under:
Code contract is out
Wed, Feb 25 2009 18:29
Check the announcement here and the site is here . Read More...
by luisabreu | with no comments
Filed under: ,
Contract reference assemblies
Wed, Nov 19 2008 22:29
If you look closely at your bin folder, you’ll see that besides getting your project’s assembly, you’ll also have another assembly with the your_Assembly_name.Contracts.dll name. This assembly is known as the contract reference assembly and it only has the public “interface” of the types defined on your assembly and their respective contracts. Why do we need... Read More...
by luisabreu | with no comments
Filed under: ,
Code contracts: the missing methods
Tue, Nov 18 2008 20:58
In the last posts, I’ve been talking extensively about Code Contracts . If you’re a reader of this blog, you know that I’m hooked on it. I’ve just been reviewing the previous posts and I’ve noticed that I didn’t mention the Assert and Assume methods. Both are used for testing state and  assumptions on a specific point of the program. As you might expect... Read More...
by luisabreu | with no comments
Filed under: ,
Code Contracts and runtime rewriting
Wed, Nov 12 2008 22:43
Today we’re going to keep looking at Code Contracts . Until now, I’ve been concentrating essentially in presenting its use and mentioning how great it is to have static analysis (ie, have something that goes through your code at compile time and detects several places which might breaking existing contracts). Today it’s time to take a look at the advantages associated... Read More...
by luisabreu | with no comments
Filed under: ,
Using quantifiers on Code Contracts
Sun, Nov 9 2008 14:25
Code Contracts also supports are quantifiers (with several limitations, as we’ll see). This means that you can check a predicate against elements in a collection or interval. You can use the ForAll method for running a predicate over several elements maintained on an collection or interval. The Exists method will let you apply a predicate and see if there is... Read More...
Code Contracts and compatibility with existing code
Sat, Nov 8 2008 12:09
Before using Code Contracts , you’ll probably already written several lines of validation code for testing requirements on your methods. I’ll keep using the Person class to illustrate some code that you might have before using the Code Contracts library . So, in the past, you might have something like this: public class Person {        ... Read More...
by luisabreu | with no comments
Filed under: ,
Adding Code Contracts to your interfaces
Fri, Nov 7 2008 20:52
[Update: I’ve changed the code so that the contract class implements the interface explicitly. This is required for getting static analysis. One more thing: the first release of the project has a bug and  even if you implement the interface explicitly, you won’t get static analysis.] One of the interest things Code Contracts lets you do is define additional... Read More...
by luisabreu | with no comments
Filed under: ,
More on Code Contracts: out parameters and field access on preconditions
Thu, Nov 6 2008 21:57
In this post we’ll keep looking at how Code Contracts can really help you improve your code. Today, we’ll see how one can use fields and out parameters in contracts. Lets start with fields. Ok, the title is a little misleading…you can use fields in your contract. But what happens when you need to define a contract on an private field from a public method? Well... Read More...
by luisabreu | with no comments
Filed under: ,
Code Contracts: don’t use the overloads that receive a string
Thu, Nov 6 2008 21:18
In my first post about Code Contracts I’ve mentioned that in my machine static analysis wasn’t picking up those evident scenarios where the code was breaking the predefined contracts. Today I’ve got the confirmation on the PEX forum (which, btw, is the place where you should post your questions regarding this framework while we don’t have a discussion place for... Read More...
by luisabreu | with no comments
Filed under: ,
More on code contracts: checking return values and old values
Thu, Nov 6 2008 21:01
Today I’ll keep writing about the new Code Contracts framework and we’ll see how we can use the write contracts that validate method return values and “old” values. Lets start with method return values… As you might expect, you’re able to refer to return values on your postconditions. To show you the kind of thing you’ll be writing, we will start by changing... Read More...
by luisabreu | with no comments
Filed under: ,
More on Code Contracts
Wed, Nov 5 2008 21:51
Yesterday I was really excited after finding out that we’ll finally have a library for performing Design By Contract verifications on our code. Ok, the runtime validations could already be simulated by writing some code (I’ve already written several helpers classes in my current applications), but the truth is that the Code Contracts library adds static verification... Read More...
Code contracts are here!
Tue, Nov 4 2008 23:25
Ok, I know I’ve asked for design by contract on C# and that didn’t made it into C# 4.0. However, I’ve just discovered something even better (especially if you’re a VB programmer): we’re getting support for it on the form of a library and some msbuild tasks that are able to perform static and runtime analyses. There’s an installation package that should work on... Read More...