Back-2-Basics: Code Contracts

13
Please Set Phones To Vibrate [email protected] David McCarter BACK-2-BASICS: CODE CONTRACTS

description

Overview on how to use .NET Code Contracts for a better why to do parameter/ value checking.

Transcript of Back-2-Basics: Code Contracts

Page 1: Back-2-Basics: Code Contracts

Please SetPhones ToVibrate

[email protected]

David McCarter

BACK-2-BASICS: CODE CONTRACTS

Page 2: Back-2-Basics: Code Contracts

[email protected]

About David McCarter

$12

Specia

l

•Microsoft MVP•David McCarter’s .NET Coding Standards• dotnetcodingstandards.notlong.co

m•dotNetTips.com• 700+ Tips, Tricks, Articles, Links!

•Open Source Projects:• http://codeplex.com/dotNetTips

•San Diego .NET Developers Group• www.sddotnetdg.org

•UCSD Classes• http://

dotnetdaveclasses.notlong.com

Page 3: Back-2-Basics: Code Contracts

dotNetDave Conference DVD! Packed full of:

Videos of all sessions from 2010 & 2011(1)!

Slide decks from 2011 & 2010!

Demo projects from 2011 & 2010!

David McCarter’s .NET interview Questions!

Extras Conference Photos

from 2010! Surprise videos!

Only

$15!

Book + DVD $25!

Page 4: Back-2-Basics: Code Contracts

Agenda

Overview Demo’s!

Summary

5

Page 5: Back-2-Basics: Code Contracts

Overview

Page 6: Back-2-Basics: Code Contracts

Introduction to Code Contracts New API + tools from Microsoft System.Diagnostics.Contracts MSIL rewriting Inspired by Spec# Included in .NET 4.0 but…

Download available now for .NET 3.5 and VS2008

http://research.microsoft.com/en-us/projects/contracts/

Page 7: Back-2-Basics: Code Contracts

Design by Contract

A discipline of analysis, design, implementation, management

Applications throughout the software lifecycle: Getting the software right: analysis, design ,

implementation Debugging & testing Automatic documentation Getting inheritance right Getting exception handling right Maintenance Management

Page 8: Back-2-Basics: Code Contracts

Design by Contract

Every software element is intended to satisfy a certain goal, or contract For the benefit of other software

elements (and ultimately of human users)

The contract of any software element should be Explicit Part of the software element itself

Page 9: Back-2-Basics: Code Contracts

The three questions

What does it expect?

What does it promise?

What does it maintain?

Precondition

Postcondition

Classinvariant

Page 10: Back-2-Basics: Code Contracts

Real World Contracts!

Demo’s

Page 11: Back-2-Basics: Code Contracts

Summary

Page 12: Back-2-Basics: Code Contracts

Resources

Microsoft Research http://research.microsoft.com/en-us/

projects/contracts/ Channel 9

http://channel9.msdn.com/Search/?Term=code%20contracts

Page 13: Back-2-Basics: Code Contracts

[email protected]

Questions?•Presentation Downloads• slideshare.com/dotnetdave

•Please Rate My Session:• speakerrate.com/

dotnetdave•David McCarter’s .NET Coding Standards• dotnetcodingstandards.notlong.co

m•Geek Swag• geekstuff.notlong.com